63 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 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<FormatInfo> GetFilteredFormatList(SortedBindingList<FormatInfo> RawList)
 | |
|         {
 | |
|             List<FormatInfo> result = new List<FormatInfo>();
 | |
| 
 | |
|             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
 | |
|                 // added check for a list count of zero.  Was getting null error from data gotten from customer
 | |
|                 if (fList == null || fList.Count == 0)
 | |
|                 {
 | |
|                     _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;
 | |
|         }
 | |
|     }
 | |
| }
 |