From 55a78eb84534a920ea6a7f06b224c6a94a1b1056 Mon Sep 17 00:00:00 2001 From: Chris Glavan Date: Tue, 3 Oct 2023 09:03:06 -0400 Subject: [PATCH] C2023-017: ~Moved original code for populating the filtered list to a separate static class named FormatUtility in Volian.Controls.Library ~Renamed method to GetFilteredFormatList ~Updated code to reference new static class and method ~Added logic to other applicable forms --- .../frmFolderProperties.cs | 5 +- .../frmProcedureProperties.cs | 48 +-------------- .../frmSectionProperties.cs | 2 +- .../frmVersionsProperties.cs | 2 +- .../Volian.Controls.Library/FormatUtility.cs | 61 +++++++++++++++++++ .../Volian.Controls.Library.csproj | 1 + 6 files changed, 68 insertions(+), 51 deletions(-) create mode 100644 PROMS/Volian.Controls.Library/FormatUtility.cs diff --git a/PROMS/VEPROMS User Interface/frmFolderProperties.cs b/PROMS/VEPROMS User Interface/frmFolderProperties.cs index 0f5729a7..7c55c5dc 100644 --- a/PROMS/VEPROMS User Interface/frmFolderProperties.cs +++ b/PROMS/VEPROMS User Interface/frmFolderProperties.cs @@ -13,6 +13,7 @@ using DevComponents.DotNetBar.Controls; using System.Drawing.Imaging; using VEPROMS.Properties; using DescriptiveEnum; +using Volian.Controls.Library; namespace VEPROMS { @@ -150,8 +151,8 @@ namespace VEPROMS ppCmbxFormat.DataSource = null; ppCmbxFormat.DisplayMember = "FullName"; ppCmbxFormat.ValueMember = "FullName"; - ppCmbxFormat.DataSource = FormatInfoList.SortedFormatInfoList; - if (_FolderConfig != null && _FolderConfig.MyFolder != null) _cmbxformatOriginal = _FolderConfig.MyFolder.FormatID; + ppCmbxFormat.DataSource = FormatUtility.GetFilteredFormatList(FormatInfoList.SortedFormatInfoList); + if (_FolderConfig != null && _FolderConfig.MyFolder != null) _cmbxformatOriginal = _FolderConfig.MyFolder.FormatID; if (_FolderConfig.FormatSelection != null) { ppCmbxFormat.SelectedValue = _FolderConfig.FormatSelection; diff --git a/PROMS/VEPROMS User Interface/frmProcedureProperties.cs b/PROMS/VEPROMS User Interface/frmProcedureProperties.cs index f373df6d..4f90856c 100644 --- a/PROMS/VEPROMS User Interface/frmProcedureProperties.cs +++ b/PROMS/VEPROMS User Interface/frmProcedureProperties.cs @@ -18,7 +18,6 @@ namespace VEPROMS { public partial class frmProcedureProperties : DevComponents.DotNetBar.Office2007Form { - private readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private bool _Initializing = false; private string _DefaultFormatName = null; //private string _DefaultPagination = null; @@ -189,7 +188,7 @@ namespace VEPROMS ppCmbxFormat.ValueMember = "FullName"; //C2023-017: Retrieves a filtered list of formats for the current plant - ppCmbxFormat.DataSource = PopulateFormatList(FormatInfoList.SortedFormatInfoList); + ppCmbxFormat.DataSource = FormatUtility.GetFilteredFormatList(FormatInfoList.SortedFormatInfoList); if (_ProcedureConfig.MyProcedure.MyProcedureInfo.ActiveFormat != null) _cmbxformatOriginal = _ProcedureConfig.MyProcedure.MyProcedureInfo.ActiveFormat.FormatID; if (_ProcedureConfig.FormatSelection != null) ppCmbxFormat.SelectedValue = _ProcedureConfig.FormatSelection; @@ -259,51 +258,6 @@ namespace VEPROMS } - //C2023-017: Remove any formats that are not applicable to the current plant - private IList PopulateFormatList(SortedBindingList RawList) - { - List result = new List(); - - try - { - //Get the top folder configuration XML of the PROMS treeview and load - //the Formats node to retrieve the available formats for this plant - FolderInfo fi = FolderInfo.GetTop(); - System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument(); - xDoc.LoadXml(fi.Config); - XmlNodeList fList = xDoc.GetElementsByTagName("Formats"); - - //We need to check to see if the current database has been updated with the necessary changes - //to the folder configuration value. If so then build the list of available to be returned - //to the calling code - if (fList == null) - { - _MyLog.InfoFormat("Filtered format list not available: Database update needed for config value of top folder record"); - return RawList; - } - else - { - //Create a string array that we can use to filter the raw list and add the format to the return value - string[] availableFormats = fList[0].Attributes["Active"].Value.Split(','); - foreach (FormatInfo item in RawList) - { - if (Array.IndexOf(availableFormats, item.ApplicablePlant.ToString()) > -1) - { - result.Add(item); - } - } - } - } - catch (Exception ex) - { - //On any exception simply return the original list that was passed in - _MyLog.ErrorFormat("Error loading filtered format list - PopulateFormatList(): {0}", ex.Message); - return RawList; - } - - return result; - } - #region General tab /// diff --git a/PROMS/VEPROMS User Interface/frmSectionProperties.cs b/PROMS/VEPROMS User Interface/frmSectionProperties.cs index c5027764..f3346895 100644 --- a/PROMS/VEPROMS User Interface/frmSectionProperties.cs +++ b/PROMS/VEPROMS User Interface/frmSectionProperties.cs @@ -364,7 +364,7 @@ namespace VEPROMS ppCmbxFormat.DataSource = null; ppCmbxFormat.DisplayMember = "FullName"; ppCmbxFormat.ValueMember = "FullName"; - ppCmbxFormat.DataSource = FormatInfoList.SortedFormatInfoList; + ppCmbxFormat.DataSource = FormatUtility.GetFilteredFormatList(FormatInfoList.SortedFormatInfoList); if (_SectionConfig.MySection.MySectionInfo.ActiveFormat != null) _cmbxformatOriginal = (int)_SectionConfig.MySection.MySectionInfo.ActiveFormat.FormatID; if (_SectionConfig.FormatSelection != null) ppCmbxFormat.SelectedValue = _SectionConfig.FormatSelection; diff --git a/PROMS/VEPROMS User Interface/frmVersionsProperties.cs b/PROMS/VEPROMS User Interface/frmVersionsProperties.cs index 196b5239..b3e88c6f 100644 --- a/PROMS/VEPROMS User Interface/frmVersionsProperties.cs +++ b/PROMS/VEPROMS User Interface/frmVersionsProperties.cs @@ -168,7 +168,7 @@ namespace VEPROMS ppCmbxFormat.DataSource = null; ppCmbxFormat.DisplayMember = "FullName"; ppCmbxFormat.ValueMember = "FullName"; - ppCmbxFormat.DataSource = FormatInfoList.SortedFormatInfoList; + ppCmbxFormat.DataSource = FormatUtility.GetFilteredFormatList(FormatInfoList.SortedFormatInfoList); _cmbxformatOriginal = _DocVersionConfig.MyDocVersion.FormatID; if (_DocVersionConfig.FormatSelection != null) diff --git a/PROMS/Volian.Controls.Library/FormatUtility.cs b/PROMS/Volian.Controls.Library/FormatUtility.cs new file mode 100644 index 00000000..d66e4a17 --- /dev/null +++ b/PROMS/Volian.Controls.Library/FormatUtility.cs @@ -0,0 +1,61 @@ +using Csla; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using VEPROMS.CSLA.Library; + +namespace Volian.Controls.Library +{ + public static class FormatUtility + { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + //C2023-017: Remove any formats that are not applicable to the current plant + public static IList GetFilteredFormatList(SortedBindingList RawList) + { + List result = new List(); + + try + { + //Get the top folder configuration XML of the PROMS treeview and load + //the Formats node to retrieve the available formats for this plant + FolderInfo fi = FolderInfo.GetTop(); + System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument(); + xDoc.LoadXml(fi.Config); + XmlNodeList fList = xDoc.GetElementsByTagName("Formats"); + + //We need to check to see if the current database has been updated with the necessary changes + //to the folder configuration value. If so then build the list of available to be returned + //to the calling code + if (fList == null) + { + _MyLog.InfoFormat("Filtered format list not available: Database update needed for config value of top folder record"); + return RawList; + } + else + { + //Create a string array that we can use to filter the raw list and add the format to the return value + string[] availableFormats = fList[0].Attributes["Active"].Value.Split(','); + foreach (FormatInfo item in RawList) + { + if (Array.IndexOf(availableFormats, item.ApplicablePlant.ToString()) > -1) + { + result.Add(item); + } + } + } + } + catch (Exception ex) + { + //On any exception simply return the original list that was passed in + _MyLog.ErrorFormat("Error loading filtered format list - PopulateFormatList(): {0}", ex.Message); + return RawList; + } + + return result; + } + } +} diff --git a/PROMS/Volian.Controls.Library/Volian.Controls.Library.csproj b/PROMS/Volian.Controls.Library/Volian.Controls.Library.csproj index 9226433f..9c76fbf7 100644 --- a/PROMS/Volian.Controls.Library/Volian.Controls.Library.csproj +++ b/PROMS/Volian.Controls.Library/Volian.Controls.Library.csproj @@ -240,6 +240,7 @@ FindReplace.cs + Form