private void btn_Setting_Fill_SWCP_Click(object sender, EventArgs e) { //Test Codes /* Snapshot a = new Snapshot(); a.Load(this.tbx_Setting_Snapshot.Text); test = a.CompareData("ABS", "F190", "L2CVA2BG6FG000518"); */ //End of Test Codes tbx_SWCP_Result.Text = ""; try { tbc_Main.SelectTab(tbp_SWCPGen.Name); IVSStructure EBOM = new IVSStructure(tbx_Setting_EBOM.Text); Snapshot theSS = new Snapshot(); DirectoryInfo theVBFDir; DirectoryInfo ExportVBFDir; string[] VBFFileNameList = new string[1]; if (cbx_SWCP_ifCompare.Checked == true) { if (theSS.Load(this.tbx_Setting_Snapshot.Text)) { } else { throw new Exception("SnapShot File Error, Please choose again"); } } if (cbx_SWCP_CompareVBF.Checked) { theVBFDir = new DirectoryInfo(this.tbx_Setting_VBFFolder.Text); FileInfo[] VBFList = theVBFDir.GetFiles(); VBFFileNameList = new string[VBFList.Length]; for (int j = 0; j < VBFList.Length; j++) { VBFFileNameList[j] = VBFList[j].Name.ToUpper(); } } if (cbx_SWCP_ExportVBF.Checked) { theVBFDir = new DirectoryInfo(this.tbx_Setting_VBFFolder.Text); FileInfo[] VBFList = theVBFDir.GetFiles(); VBFFileNameList = new string[VBFList.Length]; for (int j = 0; j < VBFList.Length; j++) { VBFFileNameList[j] = VBFList[j].Name.ToUpper(); } if (fbd_SWCP_ExportVBF.ShowDialog() == DialogResult.OK) { ExportVBFDir = new DirectoryInfo(fbd_SWCP_ExportVBF.SelectedPath); } else { throw new Exception("Please select VBF Export Folder"); } } if (tbx_Setting_EBOMExtra.Text != "") EBOM.LoadEBOMExtra(tbx_Setting_EBOMExtra.Text); if (tbx_Setting_EBOMExtra.Text != "") EBOM.LoadEBOMExtra(tbx_Setting_EBOMExtra.Text); Microsoft.Office.Interop.Excel.Application xlApp = null; Microsoft.Office.Interop.Excel.Workbook xlBook = null; Microsoft.Office.Interop.Excel.Worksheet xlSheet = null; object missing = Missing.Value; xlApp = new Microsoft.Office.Interop.Excel.Application(); xlBook = xlApp.Workbooks.Add(tbx_Setting_SWCP.Text); xlSheet = xlBook.Sheets[tbx_Setting_SWCPSheetName.Text]; int i = 2; while (IVSStructure.isValidPN(xlSheet.Cells[Convert.ToInt32(nud_Setting_SWCPTopAssyCol.Value)][i].Value)) { PartLineage PN = EBOM.GetModuleByAssyPN(xlSheet.Cells[nud_Setting_SWCPTopAssyCol.Value][i].Value); if (PN == null) { tbx_SWCP_Result.AppendText("Warning:" + xlSheet.Cells[nud_Setting_SWCPTopAssyCol.Value][i].Value + " Data NOT Found in EBOM\r\n"); xlSheet.Cells[nud_Setting_Comment_Column.Value][i].Value = "Part Number NOT Found in EBOM"; } else { tbx_SWCP_Result.AppendText("Working on " + xlSheet.Cells[nud_Setting_SWCPTopAssyCol.Value][i].Value); //ECU Address if (PN.NodeAddr != null) { xlSheet.Cells[(Convert.ToInt32(nud_Setting_EDUAddress_Column.Value))][i].Value = ("0x" + PN.NodeAddr); } tbx_SWCP_Result.AppendText("."); //Network if (PN.Protocol != null) xlSheet.Cells[Convert.ToInt32(nud_Setting_Network_Column.Value)][i].Value = PN.Protocol; tbx_SWCP_Result.AppendText("."); //SBL if (PN.SBL != null) { xlSheet.Cells[Convert.ToInt32(nud_Setting_SBL_Column.Value)][i].Value = PN.SBL.Part.ToString(); if (cbx_SWCP_CompareVBF.Checked) { string target = PN.SBL.Part.ToString().ToUpper(); if (!target.EndsWith(".VBF")) target = target + ".VBF"; if (VBFFileNameList.Contains<string>(target)) xlSheet.Cells[Convert.ToInt32(nud_Setting_SBL_Column.Value)][i].Interior.Colorindex = 4; else { if (PN.CheckFlash()) xlSheet.Cells[Convert.ToInt32(nud_Setting_SBL_Column.Value)][i].Interior.Colorindex = 3; else xlSheet.Cells[Convert.ToInt32(nud_Setting_SBL_Column.Value)][i].Interior.Colorindex = 27; } } } tbx_SWCP_Result.AppendText("."); //Hardware if (PN.Hardware != null) { xlSheet.Cells[Convert.ToInt32(nud_Setting_Hardware_Column.Value)][i].Value = PN.Hardware.Part.ToString(); xlSheet.Cells[Convert.ToInt32(nud_Setting_Hardware_Column.Value + 1)][i].Value = PN.Hardware.PID; if (cbx_SWCP_ifCompare.Checked == true) { int result = theSS.CompareData(PN.ECUAcronym, PN.Hardware.PID, PN.Hardware.Part.ToString()); if (result == 1) { xlSheet.Cells[Convert.ToInt32(nud_Setting_Hardware_Column.Value)][i].Interior.Colorindex = 4; if (xlSheet.Cells[Convert.ToInt32(nud_Setting_Hardware_Column.Value)][i].Comment != null) xlSheet.Cells[Convert.ToInt32(nud_Setting_Hardware_Column.Value)][i].Comment.Delete(); } else if (result == 2) { xlSheet.Cells[Convert.ToInt32(nud_Setting_Hardware_Column.Value)][i].Interior.Colorindex = 3; xlSheet.Cells[Convert.ToInt32(nud_Setting_Hardware_Column.Value)][i].AddComment(theSS.GetData(PN.ECUAcronym, PN.Hardware.PID)); } } } tbx_SWCP_Result.AppendText("."); //Application if (PN.Softwares != null) { for (int j = 0; j < PN.Softwares.Count; j++) { xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].Value = PN.Softwares[j].Part.ToString(); if (cbx_SWCP_ifCompare.Checked == true) { int result = theSS.CompareData(PN.ECUAcronym.ToString(), PN.Softwares[j].PID, PN.Softwares[j].Part.ToString()); if (result == 1) { xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].Interior.Colorindex = 4; if (xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].Comment != null) xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].Comment.Delete(); } else if (result == 2) { if (!PN.Softwares[j].IsFlash) xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].Interior.Colorindex = 3; else xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].Interior.Colorindex = 27; xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].AddComment(theSS.GetData(PN.ECUAcronym, PN.Softwares[j].PID)); } } else if (cbx_SWCP_CompareVBF.Checked == true) { string target = PN.Softwares[j].Part.ToString().ToUpper(); if (!target.EndsWith(".VBF")) target = target + ".VBF"; if (VBFFileNameList.Contains<string>(target)) xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].Interior.Colorindex = 4; else { if (!PN.Softwares[j].IsFlash) xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].Interior.Colorindex = 27; else xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4)][i].Interior.Colorindex = 3; } } xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4) + 1][i].Value = PN.Softwares[j].PID; xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4) + 2][i].Value = PN.Softwares[j].Type.ToString(); if (PN.Softwares[j].IsFlash) xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4) + 3][i].Value = "Y"; else xlSheet.Cells[(nud_Setting_APP_Column.Value) + (j * 4) + 3][i].Value = "N"; tbx_SWCP_Result.AppendText("."); } } tbx_SWCP_Result.AppendText("."); //Comment if (PN.Latest == false) xlSheet.Cells[Convert.ToInt32(nud_Setting_Comment_Column.Value)][i].Value = "Not Latest Version"; tbx_SWCP_Result.AppendText("Done!\r\n"); } i++; } xlApp.Visible = true; //xlBook.Save(); //xlApp.Quit(); } catch (Exception Error) { MessageBox.Show(Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }