CSLA - Extension

This commit is contained in:
2026-09-01 08:21:41 -04:00
parent dcd2fbc294
commit dab65dbfb6
30 changed files with 2703 additions and 5680 deletions
+91 -162
View File
@@ -13,10 +13,8 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.Xml;
using System.Drawing;
using System.ComponentModel;
using System.Collections.Generic;
using Volian.Base.Library;
@@ -33,17 +31,12 @@ namespace VEPROMS.CSLA.Library
get { return _AllFormats; }
set { _AllFormats = value; }
}
public CriteriaAllFormats(bool allFormats)
{
_AllFormats = allFormats;
}
}
public CriteriaAllFormats(bool allFormats) => _AllFormats = allFormats;
}
public partial class Format
{
public static Format GetJustFormat(int formatID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Format");
try
{
Format tmp = GetCachedByPrimaryKey(formatID);
@@ -67,14 +60,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteriaJustFormat
{
private int _FormatID;
public int FormatID
{ get { return _FormatID; } }
public PKCriteriaJustFormat(int formatID)
{
_FormatID = formatID;
}
}
private readonly int _FormatID;
public int FormatID => _FormatID;
public PKCriteriaJustFormat(int formatID) => _FormatID = formatID;
}
private void DataPortal_Fetch(PKCriteriaJustFormat criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch JustFormat", GetHashCode());
@@ -123,92 +112,66 @@ namespace VEPROMS.CSLA.Library
}
public class FormatEventArgs
{
private string _Status;
public string Status
{
get { return _Status; }
set { _Status = value; }
}
public FormatEventArgs(string status)
{
_Status = status;
}
}
public string Status { get; set; }
public FormatEventArgs(string status) => Status = status;
}
public delegate void FormatEvent(object sender,FormatEventArgs args);
public partial class Format:IFormatOrFormatInfo
{
#region PlantFormat
[NonSerialized]
private PlantFormat _PlantFormat;
public PlantFormat PlantFormat
{ get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this, Config)); } }
#endregion
public static event FormatEvent FormatLoaded;
private static void OnFormatLoaded(object sender, FormatEventArgs args)
{
if (FormatLoaded != null)
FormatLoaded(sender, args);
}
public IFormatOrFormatInfo MyIParent { get { return MyParent; } }
public override string ToString()
{
//return Name;
//return PlantFormat.FormatData.Name;
return FullName;
}
public string FullName
public PlantFormat PlantFormat => _PlantFormat ?? (_PlantFormat = new PlantFormat(this, Config));
#endregion
public static event FormatEvent FormatLoaded;
private static void OnFormatLoaded(object sender, FormatEventArgs args) => FormatLoaded?.Invoke(sender, args);
public IFormatOrFormatInfo MyIParent => MyParent;
public override string ToString() => FullName;
public string FullName
{
get
{
if (ParentID == 1) return Description + " (" + Name + ")";
if (Description.StartsWith("*")) return Description.Substring(1) + " (" + Name + ")";
if (ParentID == 1) return $"{Description} ({Name})";
if (Description.StartsWith("*")) return $"{Description.Substring(1)} ({Name})";
// C2019-029: if UCF, just use description & name, using parent is confusing
if (Config != null && Config != "") return Description + " (" + Name + ")";
return MyParent.Description + " - " + Description + " (" + Name + ")";
if (Config != null && Config != "") return $"{Description} ({Name})";
return $"{MyParent.Description} - {Description} ({Name})";
}
}
public static void UpdateFormats(string fmtPath, string genmacPath)
{
Format basefmt = null;
Format parent = null;
// Load base format.
basefmt = AddFormatToDB(null, "base", false, DateTime.Now, "Migration", fmtPath, genmacPath);
if (basefmt == null) return;
// Load base format.
Format basefmt = AddFormatToDB(null, "base", false, "Migration", fmtPath, genmacPath);
if (basefmt == null) return;
// now loop through all files... If there is an _ in the name, it's a subformat
// (for example, AEP_00.xml) skip it in main loop, it's handled for each format.
DirectoryInfo di = new DirectoryInfo(fmtPath); //(@"c:\development\fmtall");
FileInfo[] fis = di.GetFiles("*.xml");
OnFormatLoaded(null, new FormatEventArgs(fis.Length.ToString() + " Formats to Load"));
OnFormatLoaded(null, new FormatEventArgs($"{fis.Length} Formats to Load"));
foreach (FileInfo fi in fis)
{
//if (fi.Name.ToUpper() == "WCN2ALL.XML"|| fi.Name.ToUpper() == "OHLPALL.XML")
//{
bool issub = (fi.Name.IndexOf("_") > 0) ? true : false;
bool issub = (fi.Name.IndexOf("_") > 0);
if (!issub && fi.Name.ToLower() != "baseall.xml")
{
string fmtname = fi.Name.Substring(0, fi.Name.Length - 7);
// remove the all.xml part of the filename.
try
{
parent = AddFormatToDB(basefmt, fmtname, issub, DateTime.Now, "Migration", fmtPath, genmacPath);
if (parent != null)
Format parent = AddFormatToDB(basefmt, fmtname, issub, "Migration", fmtPath, genmacPath);
if (parent != null)
{
// now see if there are any subformats associated with this, if so
// add them here...
DirectoryInfo sdi = new DirectoryInfo(fmtPath); //("c:\\development\\fmtall");
FileInfo[] sfis = di.GetFiles(fmtname + "_*.xml");
FileInfo[] sfis = di.GetFiles($"{fmtname}_*.xml");
foreach (FileInfo sfi in sfis)
{
string nm = sfi.Name.Substring(0, sfi.Name.Length - 7);
OnFormatLoaded(null, new FormatEventArgs("Loading SubFormat " + sfi.Name));
//Console.WriteLine("Processing {0}", sfi.Name);
//frmMain.Status = string.Format("Processing Format {0}", sfi.Name);
OnFormatLoaded(null, new FormatEventArgs($"Loading SubFormat {sfi.Name}"));
try
{
AddFormatToDB(parent, nm, true, DateTime.Now, "Migration",fmtPath,genmacPath);
AddFormatToDB(parent, nm, true, "Migration",fmtPath,genmacPath);
}
catch (Exception ex)
{
@@ -242,7 +205,7 @@ namespace VEPROMS.CSLA.Library
string fmtname = Path.GetFileNameWithoutExtension(fi.Name);
try
{
AddEPFormatToDB(fmtname, DateTime.Now, VlnSettings.UserID, epPath);
AddEPFormatToDB(fmtname, VlnSettings.UserID, epPath);
}
catch (Exception ex)
{
@@ -283,16 +246,15 @@ namespace VEPROMS.CSLA.Library
_ = LookupFormats;
}
private static Format AddFormatToDB(Format parent, string format, bool issub, DateTime Dts, string Userid, string fmtPath, string genmacPath)
private static Format AddFormatToDB(Format parent, string format, bool issub, string Userid, string fmtPath, string genmacPath)
{
string fmtdata = null;
FileInfo fmtfi = null;
string genmacdata = null;
XmlDocument xd = null;
OnFormatLoaded(null, new FormatEventArgs("Loading Format "+format));
//string path = "c:\\development\\fmtall\\" + format + "all.xml";
string path = fmtPath + "\\" + format + "all.xml";
OnFormatLoaded(null, new FormatEventArgs($"Loading Format {format}"));
string path = $"{fmtPath}\\{format}all.xml";
if (File.Exists(path))
{
try
@@ -301,12 +263,11 @@ namespace VEPROMS.CSLA.Library
fmtfi = new FileInfo(path);
xd = new XmlDocument();
xd.Load(srf);
//xd.Load(path);
fmtdata = xd.OuterXml;
}
catch (Exception ex)
{
OnFormatLoaded(null, new FormatEventArgs("Error Loading Format " + format));
catch (Exception)
{
OnFormatLoaded(null, new FormatEventArgs($"Error Loading Format {format}"));
_MyLog.ErrorFormat("AddFormatToDB('{0}','{1}')", (parent == null)?"Base": parent.Name, path);
return null;
}
@@ -315,8 +276,7 @@ namespace VEPROMS.CSLA.Library
// Do we need genmac - only if non-subformat
if (!issub)
{
//path = "c:\\development\\genmacall\\" + format + ".svg";
path = genmacPath + "\\" + format + ".svg";
path = $"{genmacPath}\\{format}.svg";
if (File.Exists(path))
{
try
@@ -327,9 +287,8 @@ namespace VEPROMS.CSLA.Library
//xdg.Load(path);
genmacdata = xdg.OuterXml;
}
catch (Exception ex)
{
//frmMain.AddError(ex, "AddFormatToDB('{0}','{1}')", parent.Name, path);
catch (Exception)
{
_MyLog.ErrorFormat("AddFormatToDB('{0}','{1}')", parent.Name, path);
return null;
}
@@ -344,12 +303,11 @@ namespace VEPROMS.CSLA.Library
if (parent != null)
{
XmlNode nmnode = xd.SelectSingleNode("//FormatData");
if (nmnode is XmlElement)
{
XmlElement xm = (XmlElement)nmnode;
nmattr = xm.GetAttribute("Name");
}
}
if (nmnode is XmlElement xm)
{
nmattr = xm.GetAttribute("Name");
}
}
// use the format name if base or non sub. If it's a sub, remove the "_".
string fname = issub ? format.Replace("_", "") : format;
Format rec = null;
@@ -369,40 +327,39 @@ namespace VEPROMS.CSLA.Library
rec = rec.Save();
}
}
catch (Exception ex)
catch (Exception)
{
//frmMain.AddError(ex, "AddFormatToDB-make format('{0}','{1}')", parent.Name, path);
//Do Nothing --- if Debugging: frmMain.AddError(ex, "AddFormatToDB-make format('{0}','{1}')", parent.Name, path);
}
return rec;
}
//C2025-023 - Electronic Procedures - Modifications to PROMS
//Procedure to load the EP format fiels into the DB
private static void AddEPFormatToDB(string formatname, DateTime Dts, string Userid, string epPath)
private static void AddEPFormatToDB(string formatname, string Userid, string epPath)
{
string fmtdata = null;
FileInfo fmtfi = null;
XmlDocument xd = null;
OnFormatLoaded(null, new FormatEventArgs($"Loading Format {formatname}"));
OnFormatLoaded(null, new FormatEventArgs("Loading Format " + formatname));
string path = Path.Combine(epPath, formatname + ".xml");
string path = Path.Combine(epPath, $"{formatname}.xml");
if (File.Exists(path))
{
try
{
using (StreamReader srf = new StreamReader(path))
{
fmtfi = new FileInfo(path);
xd = new XmlDocument();
xd.XmlResolver = null;
xd.Load(srf);
FileInfo fmtfi = new FileInfo(path);
XmlDocument xd = new XmlDocument
{
XmlResolver = null
};
xd.Load(srf);
fmtdata = xd.OuterXml;
}
}
catch (Exception ex)
catch (Exception)
{
OnFormatLoaded(null, new FormatEventArgs("Error Loading Format " + formatname));
OnFormatLoaded(null, new FormatEventArgs($"Error Loading Format {formatname}"));
_MyLog.ErrorFormat($"AddEPFormatToDB('{path}')");
return;
}
@@ -414,7 +371,7 @@ namespace VEPROMS.CSLA.Library
{
EPFormatFile.UpdateEPFormat(formatname, fmtdata, Userid);
}
catch (Exception ex)
catch (Exception)
{
_MyLog.ErrorFormat($"AddFormatToDB-make format('{path}')");
}
@@ -441,13 +398,10 @@ public partial class FormatInfo : IFormatOrFormatInfo
[Serializable()]
private class FormatIDCriteria
{
private int _FormatID;
public int FormatID { get { return _FormatID; } }
public FormatIDCriteria(int formatID)
{
_FormatID = formatID;
}
}
private readonly int _FormatID;
public int FormatID => _FormatID;
public FormatIDCriteria(int formatID) => _FormatID = formatID;
}
private void DataPortal_Fetch(FormatIDCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfoList.DataPortal_Fetch", GetHashCode());
@@ -478,17 +432,10 @@ public partial class FormatInfo : IFormatOrFormatInfo
throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex);
}
}
//end transition report stuff
public virtual Format GetJustFormat()
{
return _Editable = Format.GetJustFormat(_FormatID);
}
public static bool HasLatestChanges()
{
if (!HasSeqTabFmtTabToken()) return false;
return true;
}
private static bool HasSeqTabFmtTabToken()
//end transition report stuff
public virtual Format GetJustFormat() => _Editable = Format.GetJustFormat(_FormatID);
public static bool HasLatestChanges() => HasSeqTabFmtTabToken();
private static bool HasSeqTabFmtTabToken()
{
using (FormatInfo fi = FormatInfo.Get("WCN2"))
{
@@ -517,17 +464,13 @@ public partial class FormatInfo : IFormatOrFormatInfo
return _PROMSBaseFormat;
}
}
public static void Reset()
{
_PROMSBaseFormat = null;
}
public static void Reset() => _PROMSBaseFormat = null;
public static FormatInfo Get(string name)
{
try
{
FormatInfo tmp = DataPortal.Fetch<FormatInfo>(new NameCriteria(name));
//AddToCache(tmp);
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up FormatInfo
@@ -563,14 +506,10 @@ public partial class FormatInfo : IFormatOrFormatInfo
}
protected class NameCriteria
{
private string _Name;
public string Name
{ get { return _Name; } }
public NameCriteria(string name)
{
_Name = name;
}
}
private readonly string _Name;
public string Name => _Name;
public NameCriteria(string name) => _Name = name;
}
private void DataPortal_Fetch(NameCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.DataPortal_Fetch", GetHashCode());
@@ -611,17 +550,11 @@ public partial class FormatInfo : IFormatOrFormatInfo
#region PlantFormat
[NonSerialized]
private PlantFormat _PlantFormat;
public PlantFormat PlantFormat
{ get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this, Config)); } }
#endregion
public IFormatOrFormatInfo MyIParent { get { return MyParent; } }
public override string ToString()
{
//return Name;
//return PlantFormat.FormatData.Name;
return FullName;
}
public string FullName
public PlantFormat PlantFormat => _PlantFormat ?? (_PlantFormat = new PlantFormat(this, Config));
#endregion
public IFormatOrFormatInfo MyIParent => MyParent;
public override string ToString() => FullName;
public string FullName
{
get
{
@@ -632,15 +565,9 @@ public partial class FormatInfo : IFormatOrFormatInfo
return MyParent.Description + " - " + Description + " (" + Name + ")";
}
}
public StepSectionLayoutData MyStepSectionLayoutData
{
get { return PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData; }
}
public StepSectionPrintData MyStepSectionPrintData
{
get { return PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData; }
}
}
public StepSectionLayoutData MyStepSectionLayoutData => PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData;
public StepSectionPrintData MyStepSectionPrintData => PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData;
}
public partial class FormatInfoList
{
/// <summary>
@@ -658,7 +585,8 @@ public partial class FormatInfo : IFormatOrFormatInfo
throw new DbCslaException("Error on FormatInfoList.GetAll", ex);
}
}
private void DataPortal_Fetch(CriteriaAllFormats myCrit)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private void DataPortal_Fetch(CriteriaAllFormats myCrit)
{
this.RaiseListChangedEvents = false;
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfoList.DataPortal_Fetch", GetHashCode());
@@ -716,7 +644,8 @@ public partial class FormatInfo : IFormatOrFormatInfo
protected class FormatInfoListUsedCriteria
{
}
private void DataPortal_Fetch(FormatInfoListUsedCriteria criteria)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private void DataPortal_Fetch(FormatInfoListUsedCriteria criteria)
{
try
{
@@ -749,13 +678,13 @@ public partial class FormatInfo : IFormatOrFormatInfo
}
public class FormatVersion
{
private string _Title;
public string Title { get { return _Title; } }
private int _FormatID;
public int FormatID { get { return _FormatID; } }
private int _VersionID;
public int VersionID { get { return _VersionID; } }
public FormatVersion(string title, int formatID, int versionID)
private readonly string _Title;
public string Title => _Title;
private readonly int _FormatID;
public int FormatID => _FormatID;
private readonly int _VersionID;
public int VersionID => _VersionID;
public FormatVersion(string title, int formatID, int versionID)
{
_Title = title;
_FormatID = formatID;