Exemplo n.º 1
0
        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.");
        }
Exemplo n.º 2
0
 public void start() // main order of the program.
 {
     runParser = new Thread(delegate()
     {
         try
         {
             try
             {
                 excelSection template  = new excelSection(); //initiating necessary objects
                 sort sort1             = new sort();
                 countParts countParts1 = new countParts();
                 excelFileHandler1      = new excelFileHandler(this);
                 excelFileHandler1.run(ref template, ref sort1, ref countParts1);                                                                                                                                   // read template excel file
                 xmlFileHandler xmlFileHandler1 = new xmlFileHandler(this, template, filename);                                                                                                                     // read source xml file
                 sort1.start(this, sort1, xmlFileHandler1.componentAttributes, template.Htext, template.HcolumnIndex, countParts1);                                                                                 // sort xml file info
                 EBOMexcelFile eBOMexcelFile1 = new EBOMexcelFile(excelFileHandler1, sort1.sorted, template, xmlFileHandler1.exportFileName, this, xmlFileHandler1.totalPartCount, xmlFileHandler1.titleBlockInfo); // create new EBOM from xml file using template file info
                 writeToConsole("Complete");
                 mainFrameScreen1.enableStartButton(true);
                 mainFrameScreen1.enableSourceButton(true);
             }
             catch (Exception e)
             {
                 MessageBox.Show(e.ToString());
             }
             finally
             {
                 try
                 {
                     Marshal.FinalReleaseComObject(excelFileHandler1.xlWorkSheet);
                     //template.xlWorkBook.Close(false, misValue, misValue);
                     excelFileHandler1.xlWorkBook.Close(SaveChanges: false);
                     //template.xlWorkBook.Close();
                     Marshal.FinalReleaseComObject(excelFileHandler1.xlWorkBook);
                     excelFileHandler1.xlWorkBooks.Close();
                     Marshal.FinalReleaseComObject(excelFileHandler1.xlWorkBooks);
                     excelFileHandler1.xlApp.Quit();
                     Marshal.FinalReleaseComObject(excelFileHandler1.xlApp); // excel objects don't releast comObjects to excel so you have to force it
                 }
                 catch {}
             }
         }
         finally
         {
             GC.Collect();
             GC.WaitForPendingFinalizers();
         }
     });
     runParser.Name = "CreateEBOM";
     runParser.Start();
 }
Exemplo n.º 3
0
        private bool getSort(sort sort1, List <string> unsortedRow, List <string> sortedRow)
        {
            for (int a = 0; a < sort1.type.Count; a++)
            {
                double result = 0;
                switch (sort1.type[a])
                {
                case "ascending":
                {
                    result = alphaNumericSort(unsortedRow[sort1.column[a]], sortedRow[sort1.column[a]]);
                    break;
                }

                case "descending":
                {
                    result = alphaNumericSort(unsortedRow[sort1.column[a]], sortedRow[sort1.column[a]]) * -1;
                    break;
                }

                case "setorder.beginning":
                {
                    result = setOrderBeginning(sort1.customSort[a], unsortedRow[sort1.column[a]], sortedRow[sort1.column[a]]);
                    break;
                }

                case "setorder.end":
                {
                    result = setOrderEnd(sort1.customSort[a], unsortedRow[sort1.column[a]], sortedRow[sort1.column[a]]);
                    break;
                }
                }

                if (result < 0) //unsorted row belongs before sorted row
                {
                    return(true);
                }
                else if (result == 0) //unsorted cell matched sorted cell - continue testing same row
                {
                    continue;
                }
                else if (result > 0) //unsorted row belongs after sorted row
                {
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        public void parseSort(Range cell, ref sort sort4)
        {
            string[] sortInfo = cell[1, 1].Text.Split(']')[1].Split('('); // possible cell content [Sort](1)P,C,CN,L,R(4)incrementing
            int      sortNum  = sortInfo.Length;

            for (int a = 1; a < sortNum; a++)
            {
                string[] tempDelimiter = sortInfo[a].Split(')')[1].Split(',');
                sort4.priority.Add(Convert.ToInt32(sortInfo[a].Split(')')[0]));
                sort4.column.Add(cell[1, 1].Column - 1);
                //if (tempDelimiter[0].Equals("ascending")) sort4.type.Add("ascending");
                //else if (tempDelimiter[0].Equals("descending")) sort4.type.Add("descending");
                //else if ()
                //else sort4.type.Add("Custom");
                sort4.type.Add(tempDelimiter[0]);
                sort4.customSort.Add(new List <string>());
                for (int b = 1; b < tempDelimiter.Length; b++)
                {
                    sort4.customSort[sort4.customSort.Count - 1].Add(tempDelimiter[b]); // should make above cell entry into { {1, *column* , *sortType* P,C,CN,L,R} , {4, *column*, incrementing} }
                }
            }
        }
Exemplo n.º 5
0
        public void parseCell(Range cell, int row, int column, ref int totalRows2, ref int totalColumns2, ref excelSection template3, ref sort sort3, ref countParts countParts2)
        {
            /////////////////////// find and parse tag //////////////////////////
            string tag = parseTag(cell[1, 1]);

            switch (tag)
            {
            case "TextHere":
            {
                populateTitleBlockCell(cell[1, 1], ref template3); cell[1, 1].Value = "";
                break;
            }

            case "HeaderHere":
            {
                populateHeaderList(cell[1, 1], ref template3); cell[1, 1].Value = "";
                break;
            }

            case "BodyHere":
            {
                populateBodySectionCell(cell[1, 1], ref template3);  cell[1, 1].Value = "";
                break;
            }

            case "Sort":
            {
                parseSort(cell[1, 1], ref sort3); cell[1, 1].Value = "";
                break;
            }

            case "Footer":
            {
                getFooterInfo(cell[1, 1], ref template3.footerColor, ref template3.footerList); cell[1, 1].Interior.Color = 16777215; cell[1, 1].Value = "";
                break;
            }

            case "Group":
            {
                getQuantityGrouping(column, ref countParts2.groupedColumns); cell[1, 1].Value = "";
                break;
            }

            case "Quantity":
            {
                getQuantityColumn(column, ref countParts2.quantityColumn); cell[1, 1].Value = "";
                break;
            }

            case "EndRow":
            {
                totalRows2 = row; cell[1, 1].Value = "";         // change loop iterator limit variable for rows if EndRow tag is found
                break;
            }

            case "EndColumn":
            {
                totalColumns2 = column; cell[1, 1] = "";         // change loop iterator limit variable for columns if EndColumn tag is found
                break;
            }
            }
        }
Exemplo n.º 6
0
        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.");
        }
Exemplo n.º 7
0
 public void run(ref excelSection template1, ref sort sort1, ref countParts countparts1)
 {
     openTemplateFile(ref xlApp, ref xlWorkBooks, ref xlWorkBook, ref xlWorkSheet);
     readTemplateFile(ref xlWorkSheet, totalRows, totalColumns, ref template1, ref sort1, ref countparts1, mainFrame1);
 }