private static void ShowProgress(SPECIFICATION pkgSpec, double percent) { //if ((percent % 1) == 0) { Console.Write("\r " + (Math.Floor(percent) + "% : " + pkgSpec.ServicePartNo + " ").PadRight(40)); } }
/// <summary> /// processSpec method: For each spec, try to process the spec via the ARINVT rules /// </summary> private static string processSpec(string SpecsFolder, SPECIFICATION pkgSpec, double percent, List <DETAILS> currentDetails, List <BOM> currentBOM, List <REMARKCODE> currentRemarkCode, REMARK rmk, string rawSpec) { //if (pkgSpec.isB969F()) { //Create CSV Directory.CreateDirectory(SpecsFolder); arinvtTable.process(SpecsFolder, pkgSpec, currentDetails, currentBOM, currentRemarkCode, rmk, rawSpec); } return(pkgSpec.ServicePartNo); }
/// <summary>ReadDownloadedSpecFile method does the following: /// <list type="bullet"> /// <item><description>Retrieve specs from the spec file (already downloaded)</description></item> /// <item><description>For each spec, try to process the spec via the ARINVT rules</description></item> /// <item><description>Insert parsed spec line into staging table using SQLLoader</description></item> /// <item><description>try insert staging (tempARINVT_for_GSPPS) values into ARINVT</description></item> /// </list> /// </summary> private static void ParseSpecFile(string GSPPSSourceFolder, string sourceFile, string SpecsFolder) { Console.WriteLine("\n Parsing... "); #region READ LINE BY LINE //* FileInfo fStream = new FileInfo(GSPPSSourceFolder + sourceFile); long fileLength = fStream.Length; string rawLine = String.Empty; string currentServicePartNumber = ""; string packedServicePart = ""; SPECIFICATION pkgSpec = null; List <DETAILS> currentDetails = new List <DETAILS>(); List <REMARKCODE> currentRemarkCode = new List <REMARKCODE>(); List <BOM> currentBOM = new List <BOM>(); REMARK rmk = null; string rawSpec = ""; int index = 0; //keep track of current spec //int lineCounter = 0; //keep track of current line in file int rawLineLength = 0; using (StreamReader sr = new StreamReader(GSPPSSourceFolder + sourceFile)) { while (sr.EndOfStream == false) { rawLine = sr.ReadLine(); rawLineLength += rawLine.Length; //calculate progress //keep track of current stream position double percent = Math.Round((rawLineLength) * 100f / fileLength, 2); #region DATA if (rawLine.StartsWith("HDR")) //HEADER: Reset the current Service Part Number { pkgSpec = null; rmk = null; currentDetails.Clear(); currentRemarkCode.Clear(); currentBOM.Clear(); currentServicePartNumber = ""; packedServicePart = ""; rawSpec = ""; } else if (rawLine.StartsWith("TRL")) //TRAILER: Reset the current Service Part Number { if (pkgSpec != null) { index = index + 1; processSpec(SpecsFolder, pkgSpec, percent, currentDetails, currentBOM, currentRemarkCode, rmk, rawSpec); arinvtTable.InsertIntoDataFile(true); ShowProgress(pkgSpec, percent); } pkgSpec = null; rmk = null; currentDetails.Clear(); currentRemarkCode.Clear(); currentBOM.Clear(); currentServicePartNumber = ""; packedServicePart = ""; rawSpec = ""; } else if (rawLine.StartsWith("DET1")) ///HEADER SPECIFICATION { if (pkgSpec != null) { index = index + 1; processSpec(SpecsFolder, pkgSpec, percent, currentDetails, currentBOM, currentRemarkCode, rmk, rawSpec); arinvtTable.InsertIntoDataFile(false); ShowProgress(pkgSpec, percent); } currentDetails.Clear(); currentRemarkCode.Clear(); currentBOM.Clear(); currentServicePartNumber = ""; packedServicePart = ""; rawSpec = ""; pkgSpec = new SPECIFICATION(rawLine); rawSpec += (rawLine + System.Environment.NewLine); currentServicePartNumber = pkgSpec.ServicePartNo; packedServicePart = pkgSpec.PackedServicePart; } else if (rawLine.StartsWith("DET2") && currentServicePartNumber != "") //DETAIL/LEVEL { DETAILS pkgLevel = new DETAILS(rawLine, currentServicePartNumber, pkgSpec); rawSpec += (rawLine + System.Environment.NewLine); currentDetails.Add(pkgLevel); } #endregion #region Others /* * else if (rawLine.StartsWith("DET3") && currentServicePartNumber != "") //REMARK CODE * { * REMARKCODE rmkCode = new REMARKCODE(rawLine, currentServicePartNumber); * rawSpec += (rawLine + System.Environment.NewLine); * currentRemarkCode.Add(rmkCode); * } * else if (rawLine.StartsWith("DET4") && currentServicePartNumber != "") //REMARK * { * rmk = new REMARK(rawLine, currentServicePartNumber); * rawSpec += (rawLine + System.Environment.NewLine); * * } * else if (rawLine.StartsWith("DET5") && currentServicePartNumber != "") //BOM * { * BOM bom = new BOM(rawLine, currentServicePartNumber); * rawSpec += (rawLine + System.Environment.NewLine); * * currentBOM.Add(bom); * } * //*/ #endregion } } //*/ #endregion //in case there are data items not inserted into the sql loader data file arinvtTable.InsertIntoDataFile(true); //SQLLoader.RunControlFile(arinvtTable); SQLLoader.RunControlFile(arinvtTable.GetControlFilePath(), arinvtTable.GetSqlLoaderTableName(), arinvtTable.TotalItems()); arinvtTable.StageIntoRealTable(); }