//main procedure of estimate data filling public void FillWith(Estimate es) { inputEstimate = es; MainDataFill(); MaterialStringsFill(); ResumesFill(); }
//main function - pull estimate data from Word file public Estimate Parsing(string filepath) { tableForParse.ConnectToDocment(filepath); Estimate es = new Estimate(filepath.Substring(filepath.LastIndexOf("\\") + 1)); tableForParse.ChooseTable(Convert.ToInt32(configDictionary[HEADERTABLENUMBER])); string estimateCode, estimateName; ParsingHeader(out estimateCode, out estimateName); es.Code = estimateCode; es.Name = estimateName; tableForParse.ChooseTable(Convert.ToInt32(configDictionary[TABLENUMBER])); double equip = 0, depot = 0, transport = 0; bool isResumeFind = false; foreach (Cell currentCell in tableForParse.SelectedTable.Cells) //check every cell in table and by regexp pattern try to find interesting element { if ((currentCell.ColumnIndex != Convert.ToInt32(stringShiftFirst)) && (currentCell.ColumnIndex != Convert.ToInt32(resumeShiftFirst)) && (currentCell.ColumnIndex != Convert.ToInt32(costShiftFirst))) continue; string currentCellText = RemoveUnvisibleCharacters(currentCell.Range.Text); if ((currentCell.ColumnIndex == Convert.ToInt32(stringShiftFirst)) && (Regex.IsMatch(currentCellText, configDictionary[ISNUMBERPATTERN])) && !(isResumeFind)) //like number of estimate string { Console.Write("Parse element #{0}...\t", currentCellText); EstimateString parsingEsS = ParsingString(currentCell); //then parse this and next cells and add result into Estimate if (parsingEsS != null) { es.Add(parsingEsS); Console.WriteLine("Parsing complete"); } else { Console.WriteLine("Parse ERROR!"); } //i += Convert.ToInt32(stringShiftLength); continue; } else if (Regex.IsMatch(currentCellText, configDictionary[ISRESUMEPATTERN])) //like total result string { Console.Write("Parse resume...\t"); EstimateString resumeString = ParsingResume(currentCell); //parse this too if (resumeString != null) { es.AddResumeString(resumeString); Console.WriteLine("Parsing complete"); } else { Console.WriteLine("Parse ERROR!"); } isResumeFind = true; //i += Convert.ToInt32(resumeShiftLength); continue; } //like the other strings, necessary to us else if ((isResumeFind) && (Regex.IsMatch(currentCellText, configDictionary[ISTOTALPATTERN]))) es.ResumeString.CurrentTotalCost = ParsingCost(currentCell); else if ((isResumeFind) && (Regex.IsMatch(currentCellText, configDictionary[ISOVERHEADSPATTERN]))) es.ResumeString.CurrentOverheads = ParsingCost(currentCell); else if ((isResumeFind) && (Regex.IsMatch(currentCellText, configDictionary[ISESTIMATEPROFITPATTERN]))) es.ResumeString.CurrentProfit = ParsingCost(currentCell); else if (Regex.IsMatch(currentCellText, configDictionary[ISEQUIPMENTPATTERN])) equip = ParsingCost(currentCell); else if (Regex.IsMatch(currentCellText, configDictionary[ISDEPOTPATTERN])) depot = ParsingCost(currentCell); else if (Regex.IsMatch(currentCellText, configDictionary[ISTRANSPORTPATTERN])) transport = ParsingCost(currentCell); } es.AddEquipment(equip, transport, depot); tableForParse.DisconnectFromDocument(); return es; }