public void start(mainFrame mainFrame1, sort sort1, List <List <string> > unsorted, List <string> headers, List <int> headerIndex, countParts countParts1) { sortTheSortList(); sorted = new List <List <string> >(); sorted.Add(unsorted[0]); bool insertHere = false; for (int a = 1; a < unsorted.Count; a++) { for (int b = 0; b < sorted.Count; b++) { insertHere = getSort(sort1, unsorted[a], sorted[b]); if (insertHere) { insertRow(unsorted[a], b, ref sorted); break; } //else sorted.Add(unsorted[a]); } if (!insertHere) { sorted.Add(unsorted[a]); } } mainFrame1.writeToConsole("finished sorting components."); countParts1.updateQuantity(countParts1.quantityColumn, countParts1.groupedColumns, headerIndex[0], ref sorted); mainFrame1.writeToConsole("finished updating quantities."); }
public xmlFileHandler(mainFrame mainFrame1, excelSection excelSection1, string filePath) { try { //instantiate all the necessary lists and objects for handling the XML componentAttributes = new List <List <string> >(); titleBlockInfo = new List <string>(); TBindex = new int[excelSection1.TBtext.Count]; Hindex = new int[excelSection1.Htext.Count]; xmlFileParser xmlFileParser1 = new xmlFileParser(); XmlDocument xmlRead = new XmlDocument(); openXML(xmlRead, filePath); // load the xml file into the xmlRead object XmlNodeList partAttributesNodeList = xmlRead.SelectNodes("GRID")[0].SelectNodes("COLUMNS")[0].SelectNodes("COLUMN"); XmlNodeList componentNodeList = xmlRead.SelectNodes("GRID")[0].SelectNodes("ROWS")[0].SelectNodes("ROW"); readHeaderAttributes(partAttributesNodeList, xmlFileParser1, excelSection1.TBtext, ref TBindex); readHeaderAttributes(partAttributesNodeList, xmlFileParser1, excelSection1.Htext, ref Hindex); readComponents(componentNodeList, xmlFileParser1, TBindex, Hindex, ref titleBlockInfo, ref componentAttributes, ref totalPartCount); setupExcel(filePath); mainFrame1.writeToConsole("Finished reading xml file."); } catch (Exception e) { MessageBox.Show(e.ToString()); throw e; } }
private void readTemplateFile(ref Worksheet xlWorkSheet1, int totalRows1, int totalColumns1, ref excelSection template2, ref sort sort2, ref countParts countParts2, mainFrame mainFrame2) { excelFileParser excelFileParser1 = new excelFileParser(); excelFileParser bodyRows = new excelFileParser(); for (int row = 1; row < totalRows1; row++) { if (mainFrame.end) { throw new Exception("User is closing the program"); } for (int column = 1; column < totalColumns1; column++) { excelFileParser1.parseCell(xlWorkSheet.Cells[row, column], row, column, ref totalRows1, ref totalColumns1, ref template2, ref sort2, ref countParts2); } mainFrame2.writeToConsole("Row " + row + " finished."); } mainFrame2.writeToConsole("Finished reading template file."); }
public EBOMexcelFile(excelFileHandler excelFileHandler2, List <List <string> > componentList, excelSection template, string fileName, mainFrame mainFrame1, int xmlPartCount, List <string> titleBlockInfo) { populateTitleBlock(excelFileHandler2.xlWorkSheet, titleBlockInfo, template.TBrowIndex, template.TBcolumnIndex); mainFrame1.writeToConsole("Finished writing title block."); populateHeaderRow(excelFileHandler2.xlWorkSheet, template.Htext, template.HrowIndex, template.HcolumnIndex); mainFrame1.writeToConsole("Finished writing header row."); int finalCount = populateBody(excelFileHandler2.xlWorkSheet, componentList, template, mainFrame1); mainFrame1.writeToConsole("Finished writing body."); mainFrame1.missingParts(compareComponentCounts(xmlPartCount, finalCount)); createFooter(excelFileHandler2.xlWorkSheet, componentList.Count + template.rowIndex[0][0], template.footerColor, template.footerList); mainFrame1.writeToConsole("Finished writing footer."); if (!saveExcelFile(excelFileHandler2.xlWorkSheet, fileName)) { excelFileHandler2.xlWorkBook.Close(SaveChanges: false); } mainFrame1.writeToConsole("Saved new EBOM file."); }
private int populateBody(Worksheet excel, List <List <string> > componentList, excelSection template1, mainFrame mainFrame2) { int numberOfTemplateRows = template1.backGroundColor.Count; int startRow = template1.rowIndex[0][0]; int row = 0; int finalCount = 0; int match = 0; for (int a = 0; a < componentList.Count; a++)// for each row { if (mainFrame.end) { throw new Exception("User is closing the program"); } row = a % template1.backGroundColor.Count; for (int b = 0; b < componentList[a].Count; b++) // for each column { writeData(excel.Cells[startRow + a, template1.columnIndex[row][b]], componentList[a][b]); // write cell text } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.backGroundColor[row][b] == template1.backGroundColor[row][c]) { match++; } else { break; } } if (template1.backGroundColor[row][b] == 16777215) { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Interior.Color = template1.backGroundColor[row][b]; } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.rightLineStyle[row][b] == template1.rightLineStyle[row][c]) { match++; } else { break; } } if (template1.rightLineStyle[row][b] == XlLineStyle.xlLineStyleNone) { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Borders.LineStyle = template1.rightLineStyle[row][b]; } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.rightWeight[row][b] == template1.rightWeight[row][c]) { match++; } else { break; } } if (template1.rightWeight[row][b] == XlBorderWeight.xlThin) { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Borders.Weight = template1.rightWeight[row][b]; } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.bottomLineStyle[row][b] == template1.bottomLineStyle[row][c]) { match++; } else { break; } } if (template1.bottomLineStyle[row][b] == XlLineStyle.xlLineStyleNone) { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Borders.LineStyle = template1.bottomLineStyle[row][b]; } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.bottomWeight[row][b] == template1.bottomWeight[row][c]) { match++; } else { break; } } if (template1.bottomWeight[row][b] == XlBorderWeight.xlThin) { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Borders.LineStyle = template1.bottomWeight[row][b]; } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.leftLineStyle[row][b] == template1.leftLineStyle[row][c]) { match++; } else { break; } } if (template1.leftLineStyle[row][b] == XlLineStyle.xlLineStyleNone) { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Borders.LineStyle = template1.leftLineStyle[row][b]; } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.leftWeight[row][b] == template1.leftWeight[row][c]) { match++; } else { break; } } if (template1.leftWeight[row][b] == XlBorderWeight.xlThin) { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Borders.LineStyle = template1.leftWeight[row][b]; } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.textFont[row][b] == template1.textFont[row][c]) { match++; } else { break; } } if (template1.textFont[row][b] == "Calibri") { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Text.Name = template1.textFont[row][b]; } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.textSize[row][b] == template1.textSize[row][c]) { match++; } else { break; } } if (template1.textSize[row][b] == 11) { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Text.Size = template1.textSize[row][b]; } for (int b = 0; b < componentList[a].Count; b += match + 1)// for each column { match = 0; for (int c = b + 1; c < componentList[a].Count; c++) // for each column of the same row after the 'b' column { if (template1.textColor[row][b] == template1.textColor[row][c]) { match++; } else { break; } } if (template1.textColor[row][b] == 0) { continue; // skip matching segment if already default setting. } Range range = getRange(excel, b, b + match, a + startRow, template1.columnIndex); // get like cells range.Text.Color = template1.textColor[row][b]; } mainFrame2.writeToConsole("Row " + a + " finished."); finalCount++; } return(finalCount); }