private void ProcessBomItems(int nFirstPartRow) { int row = nFirstPartRow; string strPN = null, strDesc = null, strFindNum = null, strQty = null, strRefDes = null; Regex reLevelOne = new Regex(@"\.\s1"); Regex rePart = new Regex(@"^Part\b"); while (row <= ValueArray.GetLength(0)) { if (reLevelOne.Match(ValueArray[row, (int)Column.Level].ToString()).Success&& rePart.Match(ValueArray[row, (int)Column.SubClass].ToString()).Success) { strPN = ValueArray[row, (int)Column.BeiNum].ToString().Trim(); strDesc = ValueArray[row, (int)Column.BeiDesc].ToString().Trim(); strFindNum = ValueArray[row, (int)Column.FindNum].ToString().Trim(); strQty = ValueArray[row, (int)Column.Quantity].ToString().Trim(); if (ValueArray[row, (int)Column.RefDes] == null || string.IsNullOrWhiteSpace(ValueArray[row, (int)Column.RefDes].ToString())) { strRefDes = "No Ref Des"; } else { strRefDes = ValueArray[row, (int)Column.RefDes].ToString().Trim(); } BomMap.Add(strFindNum, new List <string> { strPN, strDesc, strRefDes, strQty }); } ++row; } }
private void ClearData() { FileType = null; FileName = null; FullFilePath = null; AssemblyName = null; DateOfListing = null; AssyDescription = null; Rev = null; RouteList.Clear(); BomMap.Clear(); BomLines.Clear(); }
private void ClearData() { FileType = null; FileName = null; FullFilePath = null; if (ValueArray != null && ValueArray.Length > 0) { Array.Clear(ValueArray, 1, ValueArray.Length); } BomMap.Clear(); AssemblyName = null; DateOfListing = null; AssyDescription = null; Rev = null; }
private void ParseBaanBom() { //1/29/2019 - Casa 56 setup sheet shows ref des U163 with paste pn - real pn got skipped bcuz it was Manufactured instead of //purchased. Commenting out the line below and changing 'Purchased' to .* in the regex //Tested this fix with a setup sheet from every customer done in LN so far. Should be good to make permanent. //Regex reItemInfoRow= new Regex(@"1\s+\|\s*([0-9]{1,4})/\s+([0-9])\|(\S+)\s*\|(.*)\|Purchased\s+\|\s*([0-9]{1,4}).*\|.*\|.*\|.*\|.*\|.*\|.*\|\s*(\d+\.\d+)"); //Captures 1-FindNum, 2-Seq, 3-PN, 4-Operation, 5-BOMQty //Regex reItemInfoRow = new Regex(@"1\s+\|\s*([0-9]{1,4})/\s+([0-9])\|(\S+)\s*\|(.*)\|.*\|\s*([0-9]{1,4}).*\|.*\|.*\|.*\|.*\|.*\|.*\|\s*(\d+\.\d+)"); //Captures 1-FindNum, 2-Seq, 3-PN, 4-Operation, 5-BOMQty Regex reItemInfoRow = new Regex(@"1\s+\|\s*([0-9]{1,4})/\s+([0-9])\|(\S+.*)\|(.*)\|.*\|\s*([0-9]{1,4}).*\|.*\|.*\|.*\|.*\|.*\|.*\|\s*(\d+\.\d+)"); //Captures 1-FindNum, 2-Seq, 3-PN, 4-Operation, 5-BOMQty ///Line above is another fix for the reItemInfoRow regex. Part numbers are now coming with spaces in them, ///so, I guess we have part phrases now, not part numbers, unbelievable. ///anyway the regex now has to capture the part number field and then trim it in case of leading or trailing space between separators | ///See other line below, trimming strPN variable ///5/2/2019 /// Regex reDate = new Regex(@"Date\s+:\s(\d{2}-\d{2}-\d{2})"); Regex reRefDes = new Regex(@"^\s+\|\s(\w+)\s+\|\s+\|\s+\d{1,4}\.\d{4}\s+\|\r?$"); Regex reAssemblyName = new Regex(@"Manufactured Item\s+:\s+(\S+)"); Regex reRev = new Regex(@"Revision\s*:\s+(\S+)"); Regex reRouteList = new Regex(@"^\s+\|\s+(\d{1,4})/\s+\d\s+\|\s+([A-Z]?\d{1,4})\s+\|(.*)\|\d{2}-\d{2}-\d{2}\s+\|\s+\|\s+\w+\s+\|\s+\w*\s+\|\s+\d{1,3}\s+\|\s+\d+\.\d+\s+\|\s+\d+\.\d+\s*\|\s+\|\r?$"); Regex reDescription = new Regex(@"^Description\s+:\s+(.*)"); bool bDateFound = false; bool bAssemblyNameFound = false; bool bRevFound = false; bool bDescriptionFound = false; string strCurrentFnSeq = null; try { foreach (string line in BomLines) { if (bDateFound == false) { Match m = reDate.Match(line); if (m.Success) { DateOfListing = m.Groups[1].Value; bDateFound = true; continue; } } if (bAssemblyNameFound == false) { Match m = reAssemblyName.Match(line); if (m.Success) { AssemblyName = m.Groups[1].Value; bAssemblyNameFound = true; continue; } } if (bDescriptionFound == false) { Match m = reDescription.Match(line); if (m.Success) { AssyDescription = m.Groups[1].Value.TrimEnd(); bDescriptionFound = true; continue; } } if (bRevFound == false) { Match m = reRev.Match(line); if (m.Success) { Rev = m.Groups[1].Value; bRevFound = true; continue; } } Match match = reItemInfoRow.Match(line); if (match.Success) { string strFnSeq = match.Groups[1].Value + ":" + match.Groups[2].Value; //string strPN = match.Groups[3].Value; //testing capturing part number row with wildcard, no restriction between pipes, so need to trim //see next line string strPN = match.Groups[3].Value.Trim(); string strDesc = match.Groups[4].Value; string strOp = match.Groups[5].Value; string strBOMQty = match.Groups[6].Value.Trim(); strBOMQty = strBOMQty.Trim('0'); if (strBOMQty.EndsWith(".")) { strBOMQty = strBOMQty.Trim('.'); } if (strBOMQty.Equals("")) { strBOMQty = "0"; } if (BomMap.ContainsKey(strFnSeq)) { MessageBox.Show(string.Format("Duplicate Findnum/Sequence combination found!\nThis should not happen! Check BOM:\n" + "Key: = {0}, PN: = {4}\nExisting Values: {1}, {2}, {3}" + "\nNot adding new part to BOM", strFnSeq, BomMap[strFnSeq][0], BomMap[strFnSeq][1], BomMap[strFnSeq][2], strPN), "BOM Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { BomMap.Add(strFnSeq, new List <string> { strPN, strOp, strDesc.Trim(), "", strBOMQty }); if (!string.IsNullOrEmpty(strCurrentFnSeq) && BomMap[strCurrentFnSeq].Count > 2) { BomMap[strCurrentFnSeq][3] = BomMap[strCurrentFnSeq][3].TrimEnd(','); } strCurrentFnSeq = strFnSeq; } continue; } Match matchRds = reRefDes.Match(line); if (matchRds.Success) { BomMap[strCurrentFnSeq][3] += matchRds.Groups[1].Value + ","; continue; } Match matchRouteList = reRouteList.Match(line); if (matchRouteList.Success) { string strRouteStep = matchRouteList.Groups[1].Value + ":" + matchRouteList.Groups[2].Value + ":" + matchRouteList.Groups[3].Value.Trim(); RouteList.Add(strRouteStep); } } BomMap.ElementAt(BomMap.Count - 1).Value[3] = BomMap.ElementAt(BomMap.Count - 1).Value[3].TrimEnd(','); foreach (string key in BomMap.Keys) { if (BomMap[key][3].Equals("")) { BomMap[key][3] = "No Ref Des"; } } } catch (Exception e) { MessageBox.Show("Error parsing BAAN file.\nMake sure it's a valid BaaN BOM and try again.\nParseBaanBom()\n" + e.Message, strCurrentFnSeq, MessageBoxButton.OK, MessageBoxImage.Error); ClearData(); IsValid = false; throw; } }