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
@@ -18,7 +18,6 @@ using System.IO;
using System.Threading;
using System.Xml;
using System.Text.RegularExpressions;
//using VEPROMS.Properties;
namespace VEPROMS.CSLA.Library
{
@@ -26,8 +25,6 @@ namespace VEPROMS.CSLA.Library
{
public static DocVersion GetFromDB(int versionID) // get data from database (don't look in cache first)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a DocVersion");
try
{
DocVersion tmp = DataPortal.Fetch<DocVersion>(new PKCriteria(versionID));
@@ -146,18 +143,15 @@ namespace VEPROMS.CSLA.Library
return _DocVersionConfig;
}
}
private void _DocVersionConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Config = _DocVersionConfig.ToString();
}
#endregion
#region UserSettings
/// <summary>
/// These settings are set on the user interface side.
/// This is used to control whether the Name and/or Title is displayed
/// next to the tree nodes in the user interface
/// </summary>
private bool _DisplayTreeNodeNames = true;
private void _DocVersionConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) => Config = _DocVersionConfig.ToString();
#endregion
#region UserSettings
/// <summary>
/// These settings are set on the user interface side.
/// This is used to control whether the Name and/or Title is displayed
/// next to the tree nodes in the user interface
/// </summary>
private bool _DisplayTreeNodeNames = true;
public bool DisplayTreeNodeNames
{
get { return _DisplayTreeNodeNames; }
@@ -182,50 +176,12 @@ namespace VEPROMS.CSLA.Library
rtnstr += Title;
}
return rtnstr;
//return string.Format("{0} - {1}", Name, Title);
}
#region IVEDrillDown
//public System.Collections.IList GetChildren()
//{
// return null;
//}
//public bool HasChildren
//{
// get { return _ItemID > 0; }
//}
//public IVEDrillDown ActiveParent
//{
// get
// {
// return MyFolder;
// }
//}
//private Format _ActiveFormat = null;
//public Format ActiveFormat
//{
// get
// {
// if (_ActiveFormat == null)
// _ActiveFormat = LocalFormat != null ? LocalFormat : ActiveParent.ActiveFormat;
// return _ActiveFormat;
// }
// set
// {
// _ActiveFormat = null;
// }
//}
//public Format LocalFormat
//{
// get { return MyFormat; }
//}
public ConfigDynamicTypeDescriptor MyConfig
{
get { return DocVersionConfig; }
}
#endregion
public DocVersionInfo MyDocVersionInfo
{ get { return DocVersionInfo.Get(VersionID); } }
}
#region IVEDrillDown
public ConfigDynamicTypeDescriptor MyConfig => DocVersionConfig;
#endregion
public DocVersionInfo MyDocVersionInfo => DocVersionInfo.Get(VersionID);
}
public partial class DocVersionInfo : IVEDrillDownReadOnly
{
public TimeSpan tsTimeOut = TimeSpan.FromSeconds(6);
@@ -249,9 +205,10 @@ namespace VEPROMS.CSLA.Library
}
return exists;
}
// The following dictionary is used to store the state of the ro.fst check so that it is
// not made repeatedly in NewerRoFst. (B2017-050)
private static Dictionary<string, bool> NewerRoFstLookup = new Dictionary<string, bool>();
// The following dictionary is used to store the state of the ro.fst check so that it is
// not made repeatedly in NewerRoFst. (B2017-050)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, bool> NewerRoFstLookup = new Dictionary<string, bool>();
private static bool AddToRoFstLookup(string key, bool result)
{
if (!NewerRoFstLookup.ContainsKey(key)) NewerRoFstLookup.Add(key, result);
@@ -267,7 +224,6 @@ namespace VEPROMS.CSLA.Library
RODbInfo rdi = RODbInfo.GetJustRODB(roFstInfo.RODbID);
string rofstPath = rdi.FolderPath + @"\ro.fst";
//if (!File.Exists(rofstPath)) return false;
if (!pathExists(rofstPath))
{
_MyLog.WarnFormat("RO Path '{0}' could not be found", rofstPath);
@@ -369,10 +325,10 @@ namespace VEPROMS.CSLA.Library
return _SearchDVPath;
}
}
public string SearchPath { get { return ""; } }
public string SearchPath => "";
// B2021-076: Proms search results are not presented in order when printed to PDF
public string SearchDefaultSort { get { return string.Empty; } }
// B2021-076: Proms search results are not presented in order when printed to PDF
public string SearchDefaultSort => string.Empty;
#endregion
#region UnlinkEnhancedDocVersion
@@ -420,22 +376,15 @@ namespace VEPROMS.CSLA.Library
#region DocVersion Config
[NonSerialized]
private DocVersionConfig _DocVersionConfig;
public DocVersionConfig DocVersionConfig
{ get { return (_DocVersionConfig != null ? _DocVersionConfig : _DocVersionConfig = new DocVersionConfig(this)); } }
private void DocVersionConfigRefresh()
{
_DocVersionConfig = null;
}
#endregion
public DocVersionConfig DocVersionConfig => _DocVersionConfig ?? (_DocVersionConfig = new DocVersionConfig(this));
private void DocVersionConfigRefresh() => _DocVersionConfig = null;
#endregion
#region MOVE TO DOCVERSION CONFIG
#region MOVE TO DOCVERSION CONFIG
private string GetProfile(string grp, string nam)
{
return GetProfile(grp, nam, false);
}
private string GetProfile(string grp, string nam) => GetProfile(grp, nam, false);
private string GetProfile(string grp, string nam, bool flag)
private string GetProfile(string grp, string nam, bool flag)
{
DocVersionConfig dvcfg = DocVersionConfig;
string buff = null;
@@ -454,16 +403,14 @@ namespace VEPROMS.CSLA.Library
}
// B2021-066: Procedure PC/PC resolve procedure number with Unit Specific info
public string UnitSpecific(string str, int len, ItemInfo ii)
public string UnitSpecific(ItemInfo ii)
{
ProcedureInfo pi = ii as ProcedureInfo;
if (!(ii is ProcedureInfo pi)) // B2022-004: Don't crash if Proc PC/PC (ii is from a list, so wasn't an ItemInfo)
{
pi = ProcedureInfo.Get(ii.ItemID);
}
if (pi == null) // B2022-004: Don't crash if Proc PC/PC (ii is from a list, so wasn't an ItemInfo)
{
pi = ProcedureInfo.Get(ii.ItemID);
}
if (pi == null) return "";
if (pi == null) return "";
// B2023-035 for save the current select child (selectedSlave) and use the child number
// that was selected when printed. This is needed for when "Other" applicability
@@ -478,9 +425,8 @@ namespace VEPROMS.CSLA.Library
}
string unitdes = "ID";
string prefix = null;
string fromunitdes = null;
str = ItemInfo.ConvertToDisplayText(pi.MyContent.Number);
bool hastoken = false;
string str = ItemInfo.ConvertToDisplayText(pi.MyContent.Number);
bool hastoken = false;
// Determine if there is a token in the procedure number data, default is ID
if (str.ToUpper().Contains(@"<U"))
@@ -503,28 +449,29 @@ namespace VEPROMS.CSLA.Library
}
}
if (unitdes == "NUMBER")
fromunitdes = DocVersionConfig.Unit_Number;
else if (unitdes == "ID")
fromunitdes = DocVersionConfig.Unit_ID;
else if (unitdes == "NAME")
fromunitdes = DocVersionConfig.Unit_Name;
else if (unitdes == "TEXT")
fromunitdes = DocVersionConfig.Unit_Text;
// B2021-145: For applicability, the tree view & pdf file name are not getting resolved when using any of the OTHER tokens
// B2022-023 also check for other followed by a space
else if (unitdes == "OTHERTEXT" || unitdes == "OTHER TEXT")
fromunitdes = DocVersionConfig.Other_Unit_Text;
else if (unitdes == "OTHERNUMBER" || unitdes == "OTHER NUMBER")
fromunitdes = DocVersionConfig.Other_Unit_Number;
else if (unitdes == "OTHERNAME" || unitdes == "OTHER NAME")
fromunitdes = DocVersionConfig.Other_Unit_Name;
else if (unitdes == "OTHERID" || unitdes == "OTHER ID")
fromunitdes = DocVersionConfig.Other_Unit_ID;
else
fromunitdes = DocVersionConfig.Unit_ID;
string fromunitdes;
if (unitdes == "NUMBER")
fromunitdes = DocVersionConfig.Unit_Number;
else if (unitdes == "ID")
fromunitdes = DocVersionConfig.Unit_ID;
else if (unitdes == "NAME")
fromunitdes = DocVersionConfig.Unit_Name;
else if (unitdes == "TEXT")
fromunitdes = DocVersionConfig.Unit_Text;
// B2021-145: For applicability, the tree view & pdf file name are not getting resolved when using any of the OTHER tokens
// B2022-023 also check for other followed by a space
else if (unitdes == "OTHERTEXT" || unitdes == "OTHER TEXT")
fromunitdes = DocVersionConfig.Other_Unit_Text;
else if (unitdes == "OTHERNUMBER" || unitdes == "OTHER NUMBER")
fromunitdes = DocVersionConfig.Other_Unit_Number;
else if (unitdes == "OTHERNAME" || unitdes == "OTHER NAME")
fromunitdes = DocVersionConfig.Other_Unit_Name;
else if (unitdes == "OTHERID" || unitdes == "OTHER ID")
fromunitdes = DocVersionConfig.Other_Unit_ID;
else
fromunitdes = DocVersionConfig.Unit_ID;
DocVersionConfig.SelectedSlave = docVerSelectedSlave; //B2023-035 reset the selected Slave
DocVersionConfig.SelectedSlave = docVerSelectedSlave; //B2023-035 reset the selected Slave
// adjustments to the procedure number for applicability can be defined in 2 places:
// 1) mstr below: working draft properties/Applicability/Procedure number field for each unit can have text. The '#' in this
@@ -569,16 +516,16 @@ namespace VEPROMS.CSLA.Library
else
if (procAppl) prefs.Add(tokRepAndPrefix);
}
if (procAppl && tokRepAndPrefix != "") prefix = prefix + (prefix == null ? tokRepAndPrefix : (prefix != null && prefix.Length > 0 && prefix[prefix.Length - 1] != ',' ? "," : "") + tokRepAndPrefix);
if (procAppl && tokRepAndPrefix != "") prefix += (prefix == null ? tokRepAndPrefix : (prefix != null && prefix.Length > 0 && prefix[prefix.Length - 1] != ',' ? "," : "") + tokRepAndPrefix);
}
str = Regex.Replace(str, @"\<[uU]-[a-zA-Z]+\>", "");
str = Regex.Replace(str, @"\<[uU]\>", "");
return (!sometext) ? str: "[" + prefix + "]" + str;
return (!sometext) ? str: $"[{prefix}]{str}";
}
public string UnitSpecific(string str, int len)
public string UnitSpecific(string str)
{
// This routine retrieves the procedure number format from the
@@ -587,20 +534,8 @@ namespace VEPROMS.CSLA.Library
string retvalu = "";
string asis = "#";
if (str == null || str.Equals(string.Empty)) return retvalu; // return a null (empty) string
/*
* Bug fix: B2005-017 3/2/2005
* Need to use the largest procedure number length that's in the
* SET.DFF file. "LargestNumber" is the largest length after the
* procedure number is replaced via the SET.INI file "replace" list.
*
if(len==0)len=LargestNumber;
*/
// TODO: Do we need this line?-->>> if(len==0)len=LargestRawSetNumber;
//GetPrivateProfileString("unit", "procedure number", asis, mstr, MAXPATH, "proc.ini");
string pnum = asis;
//rhm/jcb stuff 20120511
//string mstr = GetProfile("Unit", "ProcedureNumber", true);
string mstr = DocVersionConfig.Unit_ProcedureNumber;
if (mstr != null && !mstr.Equals(string.Empty))
pnum = mstr;
@@ -684,11 +619,11 @@ namespace VEPROMS.CSLA.Library
case 'P':
//TODO: THIS IS A GLOBAL IN THE 16 BIT CODE!!!!
string procnumber = "";
pn = UnitSpecific(procnumber, 0);
pn = UnitSpecific(procnumber);
retval = GetProfile(pn, substr, true);
break;
}
if (retval == null) // .Equals(string.Empty))
if (retval == null)
swptr++;
}
str += sav;
@@ -752,13 +687,9 @@ namespace VEPROMS.CSLA.Library
#endregion
ItemInfoList _Procedures = null;
public ItemInfoList Procedures
{ get { return (_Procedures != null ? _Procedures : _Procedures = ItemInfoList.GetList(_ItemID, (int)E_FromType.Procedure)); } }
public void ResetProcedures()
{
_Procedures = null;
}
public static void ResetProcedures(int versionID)
public ItemInfoList Procedures => _Procedures ?? (_Procedures = ItemInfoList.GetList(_ItemID, (int)E_FromType.Procedure));
public void ResetProcedures() => _Procedures = null;
public static void ResetProcedures(int versionID)
{
string key = versionID.ToString();
if (_CacheByPrimaryKey.ContainsKey(key))
@@ -778,31 +709,12 @@ namespace VEPROMS.CSLA.Library
foreach (DocVersionInfo dvi in _CacheList)
dvi.ResetProcedures();
}
#region IVEReadOnlyItem
public System.Collections.IList GetChildren()
{
return Procedures;
}
//public bool ChildrenAreLoaded
//{
// get { return _iil == null; }
//}
public bool HasChildren
{
get { return _ItemID > 0; }
}
public IVEDrillDownReadOnly ActiveParent
{
get
{
return MyFolder;
}
}
public FormatInfo ActiveFormat
{
get { return LocalFormat != null ? LocalFormat : ActiveParent.ActiveFormat; }
}
public FormatInfo LocalFormat
#region IVEReadOnlyItem
public System.Collections.IList GetChildren() => Procedures;
public bool HasChildren => _ItemID > 0;
public IVEDrillDownReadOnly ActiveParent => MyFolder;
public FormatInfo ActiveFormat => LocalFormat ?? ActiveParent.ActiveFormat;
public FormatInfo LocalFormat
{
get
{
@@ -810,17 +722,14 @@ namespace VEPROMS.CSLA.Library
return MyFormat;
}
}
public ConfigDynamicTypeDescriptor MyConfig
public ConfigDynamicTypeDescriptor MyConfig => DocVersionConfig;
#region PasteChild
public ItemInfo PasteChild(int copyStartID) // pastes into an 'empty' docversion
{
get { return DocVersionConfig; }
}
//public bool HasStandardSteps()
//{ return false; }
#region PasteChild
public ItemInfo PasteChild(int copyStartID) // pastes into an 'empty' docversion
{
ItemInfo cpItem = ItemInfo.Get(copyStartID);
try
#pragma warning disable IDE0059 // Unnecessary assignment of a value - Kept for Side Effect and Debugging
ItemInfo cpItem = ItemInfo.Get(copyStartID);
#pragma warning restore IDE0059 // Unnecessary assignment of a value
try
{
DocVersionInfo dvi = DataPortal.Fetch<DocVersionInfo>(new VersionPastingPartCriteria(VersionID, copyStartID, DateTime.Now, Volian.Base.Library.VlnSettings.UserID));
ItemInfo tmp = dvi.Procedures[0] as ItemInfo;
@@ -831,8 +740,8 @@ namespace VEPROMS.CSLA.Library
}
return tmp;
}
catch (Exception ex)
{
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("Details were written to the Error Log.", "Paste Failed", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
return null;
}
@@ -869,23 +778,12 @@ namespace VEPROMS.CSLA.Library
rtnstr += Title;
}
return rtnstr;
//return string.Format("{0} - {1}", Name, Title);
}
//public string ToString(string str,System.IFormatProvider ifp)
//{
// return ToString();
//}
public ItemInfo LastChild()
{
return MyItem.LastSibling;
}
public ItemInfo FirstChild()
{
return MyItem;
}
#endregion
#region DataPortal
private void DataPortal_Fetch(VersionPastingPartCriteria criteria)
public ItemInfo LastChild() => MyItem.LastSibling;
public ItemInfo FirstChild() => MyItem;
#endregion
#region DataPortal
private void DataPortal_Fetch(VersionPastingPartCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.DataPortal_Fetch", GetHashCode());
try
@@ -899,10 +797,12 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@VersionID", criteria.VersionID);
cm.Parameters.AddWithValue("@StartItemID", criteria.StartItemID);
cm.Parameters.AddWithValue("@DTS", criteria.DTS); //ABC
cm.Parameters.AddWithValue("@UserID", criteria.UserID); //ABC
SqlParameter param_ContentID = new SqlParameter("@ThisVersionID", SqlDbType.Int);
param_ContentID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_ContentID);
cm.Parameters.AddWithValue("@UserID", criteria.UserID); //ABC
SqlParameter param_ContentID = new SqlParameter("@ThisVersionID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_ContentID);
cm.CommandText = "PasteDocVersionChild";
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
@@ -934,12 +834,9 @@ namespace VEPROMS.CSLA.Library
#region Extension
partial class DocVersionInfoExtension : extensionBase
{
public override void Refresh(DocVersionInfo tmp)
{
tmp.DocVersionConfigRefresh();
}
public override void Refresh(DocVersionInfo tmp) => tmp.DocVersionConfigRefresh();
}
}
#endregion
public ROFstInfo GetROFst(int rodbid)
{
@@ -967,7 +864,8 @@ namespace VEPROMS.CSLA.Library
rodbid, DocVersionAssociations.Count, VersionID, MyFolder.Name);
return null;
}
private static List<int> _HasBadRODBIDProblem = new List<int>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<int> _HasBadRODBIDProblem = new List<int>();
private bool FirstBadRODBIDProblemDetected
{
get
@@ -977,49 +875,13 @@ namespace VEPROMS.CSLA.Library
return true;
}
}
public bool IsFolder
{
get
{
return false;
}
}
public bool IsDocVersion
{
get
{
return true;
}
}
public bool IsProcedure
{
get
{
return false;
}
}
public bool IsSection
{
get
{
return false;
}
}
public bool IsStep
{
get
{
return false;
}
}
public int MultiUnitCount
{
get
{
return DocVersionConfig.Unit_Count;
}
}
private string[] _UnitNames;
public bool IsFolder => false;
public bool IsDocVersion => true;
public bool IsProcedure => false;
public bool IsSection => false;
public bool IsStep => false;
public int MultiUnitCount => DocVersionConfig.Unit_Count;
private string[] _UnitNames;
public string[] UnitNames
{
get
@@ -1138,7 +1000,8 @@ namespace VEPROMS.CSLA.Library
{
public DocVersionNonEnhancedListCriteria() { ;}
}
private void DataPortal_Fetch(DocVersionNonEnhancedListCriteria criteria)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping until replace CSLA")]
private void DataPortal_Fetch(DocVersionNonEnhancedListCriteria criteria)
{
this.RaiseListChangedEvents = false;
try