예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (filePaths.Length > 0)
            {
                bStart.Enabled     = false;
                bChooseXML.Enabled = false;
                foreach (string file in filePaths)
                {
                    string[] fileTemp = file.Split('.');
                    if (fileTemp.Length > 1)
                    {
                        if (!fileTemp[fileTemp.Length - 1].ToLower().Equals("xml"))
                        {
                            MessageBox.Show("File selected is not a .XML");
                            System.Windows.Forms.Application.Exit(); return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("File selected is not a .XML");
                        System.Windows.Forms.Application.Exit(); return;
                    }
                    tbXML.Text = file;
                    CreateExcelFile c;
                    LoadXML         l;
                    LoadTemplate    t;


                    runParser = new Thread(delegate()
                    {
                        try
                        {
                            t = new LoadTemplate(this);
                            l = new LoadXML(this, t, tbXML.Text);
                            c = new CreateExcelFile(this, l, t);
                        }
                        finally
                        {
                            GC.Collect();
                            GC.WaitForPendingFinalizers();
                            string[] temp = file.Split('\\');
                            WriteToConsole("EBOM created using " + temp[temp.Length - 1]); Thread.Sleep(1500);
                            System.Windows.Forms.Application.Exit();
                        }
                    });
                    runParser.Name = "CreateEBOM";
                    runParser.Start();
                }
            }
            //createDataTable();
            //dataGrid.Dock = DockStyle.Top;
            //this.dataGrid.Paint += new PaintEventHandler(dataGrid_Paint);
            //this.dataGridView1.Scroll += new ScrollEventHandler(dataGridView1_Scroll);

            //this.dataGridView1.CellPainting +=

            //    new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);
        }
예제 #2
0
        private void bStart_Click(object sender, EventArgs e)
        {
            string[] fileTemp = tbXML.Text.Split('.');
            if (fileTemp.Length > 1)
            {
                if (!fileTemp[fileTemp.Length - 1].ToLower().Equals("xml"))
                {
                    MessageBox.Show("File selected is not a .XML");
                    System.Windows.Forms.Application.Exit(); return;
                }
            }
            else
            {
                MessageBox.Show("File selected is not a .XML");
                System.Windows.Forms.Application.Exit(); return;
            }



            bStart.Enabled     = false;
            bChooseXML.Enabled = false;

            CreateExcelFile c;
            LoadXML         l;
            LoadTemplate    t;


            runParser = new Thread(delegate()
            {
                try
                {
                    t = new LoadTemplate(this);
                    l = new LoadXML(this, t, tbXML.Text);
                    c = new CreateExcelFile(this, l, t);
                }
                finally
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    if (end)
                    {
                        System.Windows.Forms.Application.Exit();
                    }
                    Action myACtion = () =>
                    {
                        bStart.Enabled     = true;
                        bChooseXML.Enabled = true;
                    };
                    getpMainFrame(myACtion);
                }
            });
            runParser.Name = "CreateEBOM";
            runParser.Start();
        }
예제 #3
0
        public LoadXML(MainFrame m, LoadTemplate l, string XMLfile)
        {
            mainframe = m;
            xmlFile   = XMLfile;
            template  = l;
            if (mainframe.end)
            {
                return;
            }

            properties     = new List <string>();
            propertyValues = new List <string>();
            headers        = new List <string>();
            unsorted       = new List <List <string> >();
            sorted         = new List <List <LoadTemplate.myCell> >();
            openXML();
            getHeaderTitles();
            getPartInfo();
            sort();
        }
예제 #4
0
        public CreateExcelFile(MainFrame m, LoadXML x, LoadTemplate t)
        {
            mainframe = m;
            XML       = x;
            template  = t;
            if (mainframe.end)
            {
                return;
            }
            try
            {
                setupExcel();
                cleanUpTemplateArtifacts();
                writeTitleBlock();
                colorAllRows();
                writeBodyInfo();
                writeFooterInfo();
                saveExcelFile();
                ////Start the Microsoft Excel Application
                ////string excelTemplate = System.AppDomain.CurrentDomain.BaseDirectory + "template.xlsx";
                //ExportFileName = System.IO.Path.ChangeExtension(XML.xmlFile, null) + ".xlsx";


                //template.xlApp = template.template.xlAppOpen;
                //if (template.xlApp == null)
                //{
                //    MessageBox.Show("Excel is not properly installed!!");
                //    return;
                //}
                //template.template.xlWorkBooks = template.template.template.xlWorkBooks2;
                //try
                //{
                //    template.xlWorkBook = template.template.xlWorkBook2;
                //}
                //catch (Exception e) { return; }
                //template.xlWorkSheet = template.template.xlWorkSheet2;

                ////template.xlWorkSheet.Cells[1, template.columnEnd+1] = "";
                //template.xlWorkSheet.Cells[1, template.columnEnd] = "";
                //template.xlWorkSheet.Cells[template.rowEnd, 1] = "";
                //foreach (LoadTemplate.myCell cell in template.titleBlock) writeData(cell);
                //foreach (LoadTemplate.myCell cell in template.headerRow) writeData(cell);
                //for (int a = template.bodyRowStart; a < template.rowEnd; a++)
                //{
                //    for (int b = 1; b < template.columnEnd; b++)
                //    {
                //        template.xlWorkSheet.Cells[a, b] = ""; // clear all artifacts from body and footer section.
                //        template.xlWorkSheet.Cells[a, b].Interior.Color = 16777215;
                //    }
                //}
                //mainframe.WriteToConsole("Finished writing Title Block");

                //for (int a = 0; a < XML.sorted.Count; a++)
                //{
                //    Range range = template.xlWorkSheet.Range[template.xlWorkSheet.Cells[XML.sorted[a][0].rowIndex, XML.sorted[a][0].columnIndex], template.xlWorkSheet.Cells[XML.sorted[a][XML.sorted[a].Count - 1].rowIndex, XML.sorted[a][XML.sorted[a].Count-1].columnIndex]]; // get whole row
                //    range.Interior.Color = template.bodyColors[a % template.bodyColors.Count]; // change color of whole row
                //    if (XML.sorted[a][XML.sorted[a].Count - 1].rightLineStyle != XlLineStyle.xlLineStyleNone) // check if we need to set borders
                //    {
                //        for (int b = 0; b < template.bodyRows[a].Count; b++)//set borders
                //        {
                //            template.xlWorkSheet.Cells[XML.sorted[a][b].rowIndex, XML.sorted[a][b].columnIndex].Borders(XlBordersIndex.xlEdgeRight).LineStyle = XML.sorted[a][b].rightLineStyle;
                //            template.xlWorkSheet.Cells[XML.sorted[a][b].rowIndex, XML.sorted[a][b].columnIndex].Borders(XlBordersIndex.xlEdgeRight).Weight = XML.sorted[a][b].rightWeight;
                //            template.xlWorkSheet.Cells[XML.sorted[a][b].rowIndex, XML.sorted[a][b].columnIndex].Borders(XlBordersIndex.xlEdgeBottom).LineStyle = XML.sorted[a][b].bottomLineStyle;
                //            template.xlWorkSheet.Cells[XML.sorted[a][b].rowIndex, XML.sorted[a][b].columnIndex].Borders(XlBordersIndex.xlEdgeBottom).Weight = XML.sorted[a][b].bottomWeight;
                //            template.xlWorkSheet.Cells[XML.sorted[a][b].rowIndex, XML.sorted[a][b].columnIndex].Borders(XlBordersIndex.xlEdgeLeft).LineStyle = XML.sorted[a][b].leftLineStyle;
                //            template.xlWorkSheet.Cells[XML.sorted[a][b].rowIndex, XML.sorted[a][b].columnIndex].Borders(XlBordersIndex.xlEdgeLeft).Weight = XML.sorted[a][b].leftWeight;
                //        }
                //    }
                //}


                //int c = 0;
                //foreach (List<LoadTemplate.myCell> cellRows in XML.sorted)
                //{
                //    foreach(LoadTemplate.myCell cell in cellRows) writeData(cell);
                //    mainframe.WriteToConsole("Finished writing row: " + ++c);
                //}
                //mainframe.WriteToConsole("Total Part Count: " + XML.totalPartCount);
                //if (c != XML.totalPartCount) MessageBox.Show("WARNING!\nNot all parts exported to BOM from xml.");
                ////template.xlWorkBook.SaveAs(System.AppDomain.CurrentDomain.BaseDirectory + "New EBOM1 " + template.time + ".xlsx");
                //int footerOffset = 2;
                //float height = (float)template.xlWorkSheet.Range[template.xlWorkSheet.Cells[1, 1], template.xlWorkSheet.Cells[footerOffset + template.bodyRowStart + XML.sorted.Count, 1]].Height;
                //int textBoxWidthModifier = 512;
                //float textBoxHeightModifier = 48;

                //Microsoft.Office.Interop.Excel.Shape textBox = template.xlWorkSheet.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 30, height, 60, 30);
                //textBox.Fill.ForeColor.RGB = System.Drawing.Color.DodgerBlue.ToArgb();

                //string footerVal = "";
                //for (int i = 1; i <= template.footerList.Count; i++)
                //    footerVal += "Note " + i + '-' + template.footerList[i - 1] + '\n' + '\n';

                //textBox.TextFrame.Characters().Text = footerVal;
                //textBox.Height = template.footerList.Count * textBoxHeightModifier;
                //textBox.Width = textBoxWidthModifier;
                //bool excelFileIsOpen = false;
                //do
                //{
                //    try
                //    {
                //        template.xlWorkBook.SaveAs(ExportFileName);
                //    }
                //    catch (Exception e)
                //    {
                //        MessageBox.Show("Please close the Excel file with the same name as the .XML file that was chosen.");
                //        excelFileIsOpen = true;
                //        continue;
                //    }
                //    excelFileIsOpen = false;
                //}
                //while (excelFileIsOpen);
            }
            finally
            {
                //object misValue = System.Reflection.Missing.Value;
                mainframe.WriteToConsole("Finished Saving Excel File");
                Marshal.FinalReleaseComObject(template.xlWorkSheet);
                //template.xlWorkBook.Close(false, misValue, misValue);
                template.xlWorkBook.Close(SaveChanges: false);
                //template.xlWorkBook.Close();
                Marshal.FinalReleaseComObject(template.xlWorkBook);
                template.xlWorkBooks.Close();
                Marshal.FinalReleaseComObject(template.xlWorkBooks);
                template.xlApp.Quit();
                Marshal.FinalReleaseComObject(template.xlApp); // excel objects don't releast comObjects to excel so you have to force it
            }
        }