/// <summary> /// 装载XML文件:根据路径返回LIST集合 /// </summary> /// <param name="xmlpath"></param> /// <returns></returns> public static List <StoreArea> LoadStoreXML(string xmlpath) { StoreModbusList.Clear(); if (!File.Exists(xmlpath)) { MessageBox.Show("存储区的XML文件不存在!"); } else { XmlDocument xdoc = new XmlDocument(); xdoc.Load(xmlpath); foreach (XmlNode noodroot in xdoc.ChildNodes) { if (noodroot.Name == "Root") { foreach (XmlNode noodtool in noodroot.ChildNodes) { if (noodtool.Name == "StoreArea") { StoreArea objVar = new StoreArea(); objVar.StoreType = XMLAttributeGetValue(noodtool, "StoreType"); objVar.StartReg = int.Parse(XMLAttributeGetValue(noodtool, "StartReg")); objVar.Length = int.Parse(XMLAttributeGetValue(noodtool, "Length")); StoreModbusList.Add(objVar); } } } } } return(StoreModbusList); }
/// <summary> /// 获取所有的存储区域对象 /// </summary> /// <returns></returns> public static List <StoreArea> GetLIstStoreArea() { if (!File.Exists(pathStoreArea)) { return(null); } List <StoreArea> listStoreArea = new List <StoreArea>(); XmlDocument xdoc = new XmlDocument(); xdoc.Load(pathStoreArea); XmlNode noodroot = xdoc.SelectSingleNode("//Root"); foreach (XmlNode noodtool in noodroot.ChildNodes) { if (noodtool.Name == "StoreArea") { StoreArea objVar = new StoreArea(); objVar.StoreType = GetValueByAttribute(noodtool, "StoreType"); objVar.StartReg = int.Parse(GetValueByAttribute(noodtool, "StartReg")); objVar.Length = int.Parse(GetValueByAttribute(noodtool, "Length")); listStoreArea.Add(objVar); } } return(listStoreArea); }
private void InventoryNumberRangeSearchExecute() { StoreDataList.Clear(); IWorkbook workbook = null; //新建IWorkbook對象 string fileName = string.Concat(AppSettingConfig.FilePath(), "/", AppSettingConfig.StoreManageFileName()); FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); workbook = new XSSFWorkbook(fileStream); //xlsx數據讀入workbook Regex checkStoreAreaPattern = new Regex(string.Concat("(^", StoreArea.Replace(",", ")+|(^"), ")+")); Regex checkExceptAreaPattern = new Regex(string.Concat("(", ExceptArea.Replace(",", ")+|("), ")+")); Regex checkTextileNamePattern = new Regex(string.Concat("(", TextileName.Replace(",", ")+|("), ")+")); for (int sheetCount = 1; sheetCount < workbook.NumberOfSheets; sheetCount++) { ISheet sheet = workbook.GetSheetAt(sheetCount); //獲取第i個工作表 IRow row; // = sheet.GetRow(0); //新建當前工作表行數據 if (!checkTextileNamePattern.IsMatch(sheet.SheetName)) { continue; } var colorList = new List <StoreData>(); for (int rowNumber = 1; rowNumber <= sheet.LastRowNum; rowNumber++) //對工作表每一行 { if (rowNumber > 70) { break; } row = sheet.GetRow(rowNumber); //row讀入第i行數據 if (row != null) { if (row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ColorName) == null) { break; } ICell countInventory = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.CountInventory); if (countInventory == null || string.IsNullOrEmpty(countInventory.ToString()) || (countInventory.CellType == CellType.Formula && countInventory.CachedFormulaResultType == CellType.Error)) { continue; } double cellValue = countInventory.NumericCellValue; //獲取i行j列數據 string storeArea = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.StorageSpaces) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.StorageSpaces).ToString(); if (cellValue <= MaxNumber && cellValue >= MinNumber && checkStoreAreaPattern.IsMatch(storeArea) && !checkExceptAreaPattern.IsMatch(storeArea)) { colorList.Add(new StoreData { ColorName = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ColorName) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ColorName).ToString(), StoreArea = storeArea, FabricFactory = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.FabricFactory) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.FabricFactory).ToString(), ClearFactory = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ClearFactory) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ClearFactory).ToString(), CountInventory = cellValue.ToString(), CheckDate = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.CheckDate) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.CheckDate).ToString() }); } else { continue; } } else { break; } } DateTime result; var soretColorList = colorList.OrderBy(o => o.FabricFactory).ThenBy(o => o.ClearFactory).ThenBy(o => Convert.ToDouble(o.CountInventory)).ThenByDescending(O => DateTime.TryParse(O.CheckDate, out result) == true ? result : DateTime.Now.AddDays(-360)); if (soretColorList.Count() > 0) { StoreDataList.Add(new StoreData { TextileName = sheet.SheetName, ColorName = "", CountInventory = "" }); } foreach (var item in soretColorList) { StoreDataList.Add(item); } } fileStream.Close(); workbook.Close(); }