/// <summary> /// /// </summary> /// <param name="from">Variant to pull data from</param> /// <param name="to">Variant to update</param> /// <param name="_overwrite">Type of Overwrite</param> /// <param name="Force">Will force Alternate variants to fitted and apply data.</param> public void SyncVariants(string from, string[] Destinations, string _overwrite, bool Force) { Overwrite = _overwrite; foreach (string to in Destinations) { Var_Type VariantList = new Var_Type(); //Get variant info based on From variable. if (from == "Base") { VariantList.VarName = from; GetBaseVariants(ref VariantList); } else { VariantList.VarName = from.ToUpper(); Get_Variants(ref VariantList); } //Make sure variant data was loaded. if (VariantList == null) { return; } if (VariantList.Components.Count == 0) { MessageBox.Show("No component variations found."); return; } //Set variant info based on To variable. if (to == "Base") { SetBaseDesign(VariantList); } else { SetVariant(VariantList, to.ToUpper(), Force); } } MessageBox.Show("Process Complete."); }
/// <summary> /// Set parameter data in the provided variant. /// </summary> /// <param name="VarList">Parameter data.</param> /// <param name="VarName">Name of variant to modify.</param> /// <param name="Force">Force alternate variants to fitted.</param> void SetVariant(Var_Type VarList, string VarName, bool Force) { try { IProject project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject; IProjectVariant Variant; IComponentVariation CompVariant; IParameterVariation ParamVariant; if (project == null) { return; } project.DM_BeginUpdate(); string RefDes; for (int i = 0; i < project.DM_ProjectVariantCount(); i++) { Variant = project.DM_ProjectVariants(i); //Find variant that matches the one provided. if (project.DM_ProjectVariants(i).DM_Description().ToUpper() == VarName) { Progress.Maximum = (Variant.DM_VariationCount() + VarList.Components.Count); Progress.Value = 0; UpdateLabel("Updating " + VarName + " Variants"); for (int j = 0; j < Variant.DM_VariationCount(); j++) { //Remove alternate variants if Force is true. if (Variant.DM_Variations(j).DM_VariationKind() == TVariationKind.eVariation_Alternate && Force) { Variant.DM_RemoveComponentVariation(j); j--; } else { CompVariant = Variant.DM_Variations(j); RefDes = CompVariant.DM_PhysicalDesignator(); //Make sure there is parameter data for this component variant. if (VarList.Components.ContainsKey(CompVariant.DM_PhysicalDesignator())) { for (int k = 0; k < CompVariant.DM_VariationCount(); k++) { if (CompVariant.DM_VariationKind() != TVariationKind.eVariation_NotFitted) { ParamVariant = CompVariant.DM_Variations(k); //Update parameter data. if ("PE_ENG" == ParamVariant.DM_ParameterName().ToUpper() || ParamVariant.DM_ParameterName().ToUpper() == "PE_FLT") { if (VarList.Components[CompVariant.DM_PhysicalDesignator()].ContainsKey(ParamVariant.DM_ParameterName().ToUpper())) { if (VarList.Components[CompVariant.DM_PhysicalDesignator()][ParamVariant.DM_ParameterName().ToUpper()] != CompVariant.DM_PhysicalDesignator()) { if (OverwriteValue(ParamVariant.DM_VariedValue(), VarList.Components[CompVariant.DM_PhysicalDesignator()][ParamVariant.DM_ParameterName().ToUpper()], CompVariant.DM_PhysicalDesignator(), ParamVariant.DM_ParameterName().ToUpper())) { ParamVariant.DM_SetVariedValue(VarList.Components[CompVariant.DM_PhysicalDesignator()][ParamVariant.DM_ParameterName().ToUpper()] + "_$"); VarList.Components[CompVariant.DM_PhysicalDesignator()].Saved = true; } } } } //else //{ // ParamVariant.DM_SetVariedValue(VarList.Components[CompVariant.DM_PhysicalDesignator()][ParamVariant.DM_ParameterName().ToUpper()] + "_$"); // VarList.Components[CompVariant.DM_PhysicalDesignator()].Saved = true; //} } } if (!VarList.Components[CompVariant.DM_PhysicalDesignator()].Saved) { CreateCompVar(ref CompVariant, VarList.Components[CompVariant.DM_PhysicalDesignator()]); VarList.Components[CompVariant.DM_PhysicalDesignator()].Saved = true; } } } Progress.Value += 1; } IComponentVariation tmpCompVar; foreach (string CompRef in VarList.Components.Keys) { //Add component variants that havent already been modified. if (!VarList.Components[CompRef].Saved) { tmpCompVar = null; tmpCompVar = project.DM_ProjectVariants(i).DM_AddComponentVariation(); tmpCompVar.DM_SetVariationKind(TVariationKind.eVariation_None); CreateCompVar(ref tmpCompVar, VarList.Components[CompRef], CompRef); VarList.Components[CompRef].Saved = true; } Progress.Value += 1; UpdateLabel("Updating " + VarName + " Variants"); } } } project.DM_EndUpdate(); } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }
/// <summary> /// Updates base design parameters based on provided data. /// </summary> /// <param name="VarList">Parameter data</param> void SetBaseDesign(Var_Type VarList) { try { string RefDes; IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace; IDXPProject CurrentProject; int LogicalDocumentCount; int LoopIterator; IDXPDocument CurrentSheet; CurrentProject = CurrentWorkspace.DM_FocusedProject(); LogicalDocumentCount = CurrentProject.DM_LogicalDocumentCount(); ISch_ServerInterface SchServer = SCH.GlobalVars.SchServer; IClient Client = DXP.GlobalVars.Client; IServerDocument ServerDoc; IDXPDocument ActiveDoc = DXP.GlobalVars.DXPWorkSpace.DM_FocusedDocument(); //Save current open document so it can be reopened after process is done. Progress.Maximum = LogicalDocumentCount; Progress.Value = 0; UpdateLabel("Updating Variants"); bool DocOpened = false; //Iterate through all documents looking for scheatic docs. for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++) { CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1); if (CurrentSheet.DM_DocumentKind() == "SCH") { //Open document if not already open. DocOpened = false; if (Client.IsDocumentOpen(CurrentSheet.DM_FullPath())) { ServerDoc = Client.GetDocumentByPath(CurrentSheet.DM_FullPath()); DocOpened = true; } else { ServerDoc = Client.OpenDocument("SCH", CurrentSheet.DM_FullPath()); } //Client.ShowDocument(ServerDoc); ISch_Lib SchDoc; SchDoc = SchServer.LoadSchDocumentByPath(CurrentSheet.DM_FullPath()) as ISch_Lib; ISch_Iterator LibraryIterator, PIterator; ISch_Component Component; ISch_Parameter Param; VarParam <string, string> CompVars = new VarParam <string, string>(); if (SchDoc == null) { return; } //Iterate theough all components on the schematic. LibraryIterator = SchDoc.SchIterator_Create(); LibraryIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent)); Component = LibraryIterator.FirstSchObject() as ISch_Component; while (Component != null) { RefDes = Component.GetState_SchDesignator().GetState_Text(); if (VarList.Components.ContainsKey(Component.GetState_SchDesignator().GetState_Text())) { if (VarList.Components[Component.GetState_SchDesignator().GetState_Text()].Saved == false) { Component.UpdatePart_PreProcess(); CompVars = VarList.Components[Component.GetState_SchDesignator().GetState_Text()]; //Iterate theough all parameters in the component. PIterator = Component.SchIterator_Create(); PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eParameter)); Param = PIterator.FirstSchObject() as ISch_Parameter; while (Param != null) { if (Param.GetState_Name() != null) { if (Param.GetState_Name().ToUpper() != null) { //Set parameter data in component if it is in the provided parameter data. //Param = null; if (CompVars.ContainsKey(Param.GetState_Name().ToUpper())) { if (Param.GetState_Text() == "x") { Param.SetState_Text(CompVars[Param.GetState_Name().ToUpper()]); } else if (OverwriteValue(Param.GetState_Text().ToUpper(), CompVars[Param.GetState_Name().ToUpper()], Component.GetState_SchDesignator().GetState_Text(), Param.GetState_Name().ToUpper())) { Param.SetState_Text(CompVars[Param.GetState_Name().ToUpper()]); } } } } Param = PIterator.NextSchObject() as ISch_Parameter; } Component.UpdatePart_PostProcess(); VarList.Components[Component.GetState_SchDesignator().GetState_Text()].Saved = true; } } Component = LibraryIterator.NextSchObject() as ISch_Component; } if (ServerDoc.GetModified()) { ServerDoc.DoFileSave(""); } if (!DocOpened) { Client.CloseDocument(ServerDoc); } ServerDoc = null; } Progress.Value += 1; UpdateLabel("Updating Variants"); } Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath())); return; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }
/// <summary> /// Get parameter data from the base design. /// </summary> /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param> public void GetBaseVariants(ref Var_Type VarList) { try { IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace; IDXPProject CurrentProject; int LogicalDocumentCount; int LoopIterator; IDXPDocument CurrentSheet; CurrentProject = CurrentWorkspace.DM_FocusedProject(); LogicalDocumentCount = CurrentProject.DM_LogicalDocumentCount(); ISch_ServerInterface SchServer = SCH.GlobalVars.SchServer; IClient Client = DXP.GlobalVars.Client; IServerDocument ServerDoc; IDXPDocument ActiveDoc = DXP.GlobalVars.DXPWorkSpace.DM_FocusedDocument(); //Save current open document so it can be reopened after process is done. VarParam <string, string> Parameters = new VarParam <string, string>(); string RefDes; bool DocOpened = false; Progress.Value = 0; Progress.Maximum = LogicalDocumentCount; UpdateLabel("Loading Variants"); //iterate through project documents. for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++) { CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1); //Check for schematic documents. if (CurrentSheet.DM_DocumentKind() == "SCH") { DocOpened = false; //Open documents if (Client.IsDocumentOpen(CurrentSheet.DM_FullPath())) { ServerDoc = Client.GetDocumentByPath(CurrentSheet.DM_FullPath()); DocOpened = true; } else { ServerDoc = Client.OpenDocument("SCH", CurrentSheet.DM_FullPath()); } //Client.ShowDocument(ServerDoc); ISch_Lib SchDoc; SchDoc = SchServer.LoadSchDocumentByPath(CurrentSheet.DM_FullPath()) as ISch_Lib; ISch_Iterator LibraryIterator, PIterator; ISch_Component Component; ISch_Parameter Param; if (SchDoc == null) { return; } //Iterate theough all components on the schematic. LibraryIterator = SchDoc.SchIterator_Create(); LibraryIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent)); Component = LibraryIterator.FirstSchObject() as ISch_Component; while (Component != null) { if (Component.GetState_SchDesignator().GetState_Text().Contains("?")) { MessageBox.Show("Detected and un-annotated refdes. Please Annotate the project and try again."); VarList = null; return; } RefDes = Component.GetState_SchDesignator().GetState_Text(); Parameters = new VarParam <string, string>(); //Iterate theough all parameters in the component. PIterator = Component.SchIterator_Create(); PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eParameter)); Param = PIterator.FirstSchObject() as ISch_Parameter; while (Param != null) { if (Param.GetState_Name() != null) { //Store specific parameter data. if ("PE_ENG" == Param.GetState_Name().ToUpper() || Param.GetState_Name().ToUpper() == "PE_FLT") { if (Param.GetState_Text() != "x") { Parameters.Add(Param.GetState_Name().ToUpper(), Param.GetState_CalculatedValueString()); } } } Param = PIterator.NextSchObject() as ISch_Parameter; } //Add stored parameter data to VarList. if (Parameters.Count > 0) { if (!VarList.Components.ContainsKey(RefDes)) { VarList.Components.Add(RefDes, Parameters); } } Component = LibraryIterator.NextSchObject() as ISch_Component; } //if (ServerDoc.GetModified()) // ServerDoc.DoFileSave(""); //Close opend documents. if (!DocOpened) { Client.CloseDocument(ServerDoc); } ServerDoc = null; } Progress.Value += 1; UpdateLabel("Loading Variants"); } Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath())); return; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }
/// <summary> /// Get parameter data from an existing variant. /// </summary> /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param> public void Get_Variants(ref Var_Type VarList) { try { IProject project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject; IProjectVariant Variant; IComponentVariation CompVariant; IParameterVariation ParamVariant; VarParam <string, string> Parameters = new VarParam <string, string>(); string RefDes; int l = 0; for (int i = 0; i < project.DM_ProjectVariantCount(); i++) { l++; Variant = project.DM_ProjectVariants(i); //Find the variant that matches the one provided. if (project.DM_ProjectVariants(i).DM_Description().ToUpper() == VarList.VarName) { Progress.Maximum = Variant.DM_VariationCount(); Progress.Value = 0; UpdateLabel("Loading Variants"); for (int j = 0; j < Variant.DM_VariationCount(); j++) { CompVariant = Variant.DM_Variations(j); RefDes = CompVariant.DM_PhysicalDesignator(); //checking to make sure all components have a refdes assigned. if (RefDes.Contains("?")) { MessageBox.Show("Detected an un-annotated refdes. Please Annotate the project and try again."); VarList = null; return; } Parameters = new VarParam <string, string>(); //Iterate through all parameters for current component variant. for (int k = 0; k < CompVariant.DM_VariationCount(); k++) { if (CompVariant.DM_VariationKind() != TVariationKind.eVariation_NotFitted) { ParamVariant = CompVariant.DM_Variations(k); //Get values of matching parameters. if ("PE_ENG" == ParamVariant.DM_ParameterName().ToUpper() || ParamVariant.DM_ParameterName().ToUpper() == "PE_FLT") { string tmpVarValue = ParamVariant.DM_VariedValue() == null ? "x" : ParamVariant.DM_VariedValue(); Parameters.Add(ParamVariant.DM_ParameterName().ToUpper(), tmpVarValue); if (!tmpVarValue.EndsWith("_$")) { ParamVariant.DM_SetVariedValue(tmpVarValue + "_$"); } } } } l++; //Save collected data to VarList. if (Parameters.Count > 0) { VarList.Components.Add(RefDes, Parameters); } Progress.Value += 1; UpdateLabel("Loading Variants"); } } } } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }
private void btnImport_Click(object sender, EventArgs e) { try { //TODO: need to support hierarchy string Path = txtPath.Text; if (Path == "") { MessageBox.Show("Missing file path."); return; } Var_Type Variants = GetPEData(Path); //Get data from excel. if (Variants == null) { return; } //Verify data was collected. if (Variants.Components.Count == 0) { MessageBox.Show("There were no PE_FLT or PE_ENG changes detected."); return; } //Disabled for now. #region Set Base Design //IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace; //IDXPProject CurrentProject; //int LogicalDocumentCount; //int LoopIterator; //IDXPDocument CurrentSheet; //CurrentProject = CurrentWorkspace.DM_FocusedProject(); //LogicalDocumentCount = CurrentProject.DM_LogicalDocumentCount(); //ISch_ServerInterface SchServer = SCH.GlobalVars.SchServer; //IClient Client = DXP.GlobalVars.Client; //IServerDocument ServerDoc; //IDXPDocument ActiveDoc = DXP.GlobalVars.DXPWorkSpace.DM_FocusedDocument(); //Save current open document so it can be reopened after process is done. //bool DocOpened = false; //for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++) //{ // CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1); // if (CurrentSheet.DM_DocumentKind() == "SCH") // { // DocOpened = false; // if (Client.IsDocumentOpen(CurrentSheet.DM_FullPath())) // { // ServerDoc = Client.GetDocumentByPath(CurrentSheet.DM_FullPath()); // DocOpened = true; // } // else // ServerDoc = Client.OpenDocument("SCH", CurrentSheet.DM_FullPath()); // //Client.ShowDocument(ServerDoc); // ISch_Lib SchDoc; // SchDoc = SchServer.LoadSchDocumentByPath(CurrentSheet.DM_FullPath()) as ISch_Lib; // ISch_Iterator LibraryIterator, PIterator; // ISch_Component Component; // ISch_Parameter Param; // VarParam<string, string> CompVars = new VarParam<string, string>(); // if (SchDoc == null) // return; // //Iterate theough all components on the schematic. // LibraryIterator = SchDoc.SchIterator_Create(); // LibraryIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent)); // Component = LibraryIterator.FirstSchObject() as ISch_Component; // while (Component != null) // { // if (Variants.Components.ContainsKey(Component.GetState_DesignItemId())) // { // Component.UpdatePart_PreProcess(); // CompVars = Variants.Components[Component.GetState_DesignItemId()]; // //Iterate theough all parameters in the component. // PIterator = Component.SchIterator_Create(); // PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eParameter)); // Param = PIterator.FirstSchObject() as ISch_Parameter; // while (Param != null) // { // if (Param.GetState_Name() != null) // if ("PE_ENG" == Param.GetState_Name() || Param.GetState_Name() == "PE_FLT") // { // Param.SetState_Text(CompVars[Param.GetState_Name()]); // } // Param = PIterator.NextSchObject() as ISch_Parameter; // } // Component.UpdatePart_PostProcess(); // } // Component = LibraryIterator.NextSchObject() as ISch_Component; // } // if (ServerDoc.GetModified()) // ServerDoc.DoFileSave(""); // if (!DocOpened) // Client.CloseDocument(ServerDoc); // ServerDoc = null; // } //} //Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath())); #endregion #region Set Var_PE IProject project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject; IProjectVariant Variant; IComponentVariation CompVariant; IParameterVariation ParamVariant; CheckParams(); //Stores the library reference value for each refdes. ComponentList <string, string> CompList = GetComponents(); //Get list of components in the design. //GetComponents() will return null if there is an error. if (CompList == null) { MessageBox.Show("Error getting a list of components. Please check design and try again.", "Component List Error", MessageBoxButtons.OK); return; } string RefDes; for (int i = 0; i < project.DM_ProjectVariantCount(); i++) { Variant = project.DM_ProjectVariants(i); //Update Var_PE data only. if (project.DM_ProjectVariants(i).DM_Description().ToUpper() == "VAR_PE") { pbProgress.Maximum = Variant.DM_VariationCount(); pbProgress.Value = 0; UpdateLabel("Updating Existing Variants"); //PCB.IPCB_Component.GetState_ChannelOffset() //EDP.IProject.DM_ChannelDesignatorFormat() //EDP.IProject.DM_ChannelRoomLevelSeperator() //EDP.IPart.DM_ChannelOffset() //EDP.IDocument.DM_ChannelIndex() //EDP.IDocument.DM_ChannelPrefix() for (int j = 0; j < Variant.DM_VariationCount(); j++) { CompVariant = Variant.DM_Variations(j); RefDes = CompVariant.DM_PhysicalDesignator(); //Check that there is data in the Variants list for current refdes. if (CompList.ContainsKey(RefDes)) { if (Variants.Components.ContainsKey(CompList[RefDes])) { for (int k = 0; k < CompVariant.DM_VariationCount(); k++) { if (CompVariant.DM_VariationKind() != TVariationKind.eVariation_NotFitted) { ParamVariant = CompVariant.DM_Variations(k); //Update component variant parameter data. if ("PE_ENG" == ParamVariant.DM_ParameterName().ToUpper() || ParamVariant.DM_ParameterName().ToUpper() == "PE_FLT") //Verify a parameter we want. { if (CompList.ContainsKey(RefDes)) { if (Variants.Components.ContainsKey(CompList[RefDes])) { if (Variants.Components[CompList[RefDes]].ContainsKey(ParamVariant.DM_ParameterName().ToUpper())) //Make sure the parameter value is in our list of data. //if (Variants.Components[CompList[RefDes]][ParamVariant.DM_ParameterName()] != CompVariant.DM_PhysicalDesignator()) //I dont know what this is for. //if (Variants.Components[CompList[RefDes]][ParamVariant.DM_ParameterName().ToUpper()] != "x") //Make sure the parameter data is not 'x' { ParamVariant.DM_SetVariedValue(Variants.Components[CompList[RefDes]][ParamVariant.DM_ParameterName().ToUpper()] + "_$"); } } } } } } if (CompList.ContainsKey(RefDes)) { CompList.Remove(RefDes); } } } pbProgress.Value = j; UpdateLabel("Updating Existing Variants"); } IComponentVariation tmpCompVar; pbProgress.Maximum = CompList.Count; pbProgress.Value = 0; UpdateLabel("Creating New Variants"); project.DM_BeginUpdate(); //Create new variants. foreach (string CompRef in CompList.Keys) { if (Variants.Components.ContainsKey(CompList[CompRef])) { tmpCompVar = project.DM_ProjectVariants(i).DM_AddComponentVariation(); tmpCompVar.DM_SetVariationKind(TVariationKind.eVariation_None); CreateCompVar(ref tmpCompVar, Variants.Components[CompList[CompRef]], CompRef); Variants.Components[CompList[CompRef]].Saved = true; } pbProgress.Value++; UpdateLabel("Creating New Variants"); } project.DM_EndUpdate(); } } #endregion return; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } finally { this.Close(); MessageBox.Show("Process Complete"); } }
/// <summary> /// Load parameter data from excel doc. /// </summary> /// <param name="Path">Path to excel doc.</param> /// <returns></returns> Var_Type GetPEData(string Path) { pbProgress.Value = 0; UpdateLabel("Opening Excel Doc"); Excel.Application xlApp; Excel.Workbook xlWorkBook = null; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; if (Path == "") { return(null); } xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(Path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Var_Type Output = new Var_Type(); VarParam <string, string> tmpParams; string PE_Flt, PE_Eng, LibRef; try { Output.VarName = "ModBOM"; pbProgress.Maximum = 3; UpdateLabel("Getting Column Headers"); //Get column letters for specific column names. PE_Eng = GetColumn("PE_ENG", ref xlWorkSheet); pbProgress.Value = 1; UpdateLabel("Getting Column Headers"); PE_Flt = GetColumn("PE_FLT", ref xlWorkSheet); pbProgress.Value = 2; UpdateLabel("Getting Column Headers"); LibRef = GetColumn("LIBREF", ref xlWorkSheet); pbProgress.Value = 3; UpdateLabel("Getting Column Headers"); if (PE_Eng == "" || PE_Flt == "" || LibRef == "") { MessageBox.Show("One or more parameters are missing from the BOM. Please try again with a different BOM."); xlWorkBook.Close(false, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); return(null); } int Row = 2; int cnt = 0; while (xlWorkSheet.Range[LibRef + Row].Value2 != null) { Row++; cnt++; } pbProgress.Maximum = cnt; pbProgress.Value = 0; UpdateLabel("Reading Data"); Row = 2; //Read parameter data. while (xlWorkSheet.Range[LibRef + Row].Value2 != null) { //if (xlWorkSheet.Range[PE_Flt + Row].Value2.ToString() != "x" || xlWorkSheet.Range[PE_Eng + Row].Value2.ToString() != "x") //{ if (Output.Components.ContainsKey(xlWorkSheet.Range[LibRef + Row].Value2.ToString())) { MessageBox.Show("Multiple library references for " + xlWorkSheet.Range[LibRef + Row].Value2.ToString() + " in this BOM. First instance is used."); } else { if (xlWorkSheet.Range[PE_Flt + Row].Value2 == null) { xlWorkSheet.Range[PE_Flt + Row].Value2 = "x"; } if (xlWorkSheet.Range[PE_Eng + Row].Value2 == null) { xlWorkSheet.Range[PE_Eng + Row].Value2 = "x"; } if (xlWorkSheet.Range[PE_Flt + Row].Value2.ToString() == "x") { xlWorkSheet.Range[PE_Flt + Row].Value2 = "z"; } if (xlWorkSheet.Range[PE_Eng + Row].Value2.ToString() == "x") { xlWorkSheet.Range[PE_Eng + Row].Value2 = "z"; } tmpParams = new VarParam <string, string>(); tmpParams.Add(new KeyValuePair <string, string>("PE_ENG", xlWorkSheet.Range[PE_Eng + Row].Value2.ToString().Replace("'", ""))); tmpParams.Add(new KeyValuePair <string, string>("PE_FLT", xlWorkSheet.Range[PE_Flt + Row].Value2.ToString().Replace("'", ""))); Output.Components.Add(new KeyValuePair <string, VarParam <string, string> >(xlWorkSheet.Range[LibRef + Row].Value2.ToString(), tmpParams)); } //} Row++; pbProgress.Value++; UpdateLabel("Reading Data"); } //xlWorkBook.Close(false, misValue, misValue); //xlApp.Quit(); //releaseObject(xlWorkSheet); //releaseObject(xlWorkBook); //releaseObject(xlApp); //return Output; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); Output = null; } xlWorkBook.Close(false, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); return(Output); }