public SldBsp GetSldPrdInfoFromFile(IEdmVault5 poVault, string filePath) { IEdmFolder5 opParentFolder; //bspPrt = new SldBuy(); IEdmFile5 poFile = poVault.GetFileFromPath(filePath, out opParentFolder); if (poFile == null) { return(null); } IEdmEnumeratorVariable5 enumVar = poFile.GetEnumeratorVariable(); if (enumVar == null) { return(null); } IEdmVariableMgr5 varMgr = (IEdmVariableMgr5)poVault; if (varMgr == null) { return(null); } object tmpVar; string partType = ""; if (varMgr.GetVariable("Part Type") != null && enumVar.GetVar("Part Type", "@", out tmpVar) && tmpVar != null) { partType = tmpVar.ToString(); } if (partType == "自制件") { SldPrt prt = new SldPrt(); prt.type = 1; object route = null; if (varMgr.GetVariable("工艺路线") != null) { if (enumVar.GetVar("工艺路线", "@", out route) && route != null) { prt.route = route.ToString(); } } return(prt); } else if (partType == "标准件") { SldStd std = new SldStd(); std.type = 2; return(std); } else if (partType == "外购件") { SldBuy buy = new SldBuy(); buy.type = 3; return(buy); } else { SldBsp buy = new SldBsp(); buy.type = 4; return(buy); } }
public bool SaveBspToWorkbook(Workbook workbook, SldAsm asmPrd) { if (asmPrd.sldBspList.Count <= 0) { return(true); } int count = asmPrd.sldBspList.Count; //直接写,不用格式 Sheets sheets = workbook.Worksheets; Worksheet worksheet = null; // if (sheets.get_Item("未确定") == null) // { worksheet = (Worksheet)sheets.Add(); worksheet.Name = "错误"; //} //else //{ // worksheet = (Worksheet)sheets.get_Item("未确定"); // } if (count <= 0) { worksheet.Delete(); return(false); } List <SldBsp> .Enumerator iEnum = asmPrd.sldBspList.GetEnumerator(); int colNum = 9; object[,] dataArray = new object[count + 1, colNum]; { dataArray[0, 0] = "物料代码"; dataArray[0, 1] = "图号"; dataArray[0, 2] = "名称"; dataArray[0, 3] = "数量"; dataArray[0, 4] = "材料"; dataArray[0, 5] = "重量"; dataArray[0, 6] = "总重"; dataArray[0, 7] = "备注"; dataArray[0, 8] = "类型"; } int i = 0; while (iEnum.MoveNext()) { SldBsp bsp = iEnum.Current; dataArray[i + 1, 0] = bsp.materialNumber; dataArray[i + 1, 1] = bsp.number; dataArray[i + 1, 2] = bsp.name; dataArray[i + 1, 3] = bsp.amout == 0 ? "" : bsp.amout.ToString(); dataArray[i + 1, 4] = bsp.material; dataArray[i + 1, 5] = bsp.weight == 0 ? "" : bsp.weight.ToString(); dataArray[i + 1, 6] = bsp.totalWeight == 0 ? "" : bsp.totalWeight.ToString(); dataArray[i + 1, 7] = bsp.remark; dataArray[i + 1, 8] = bsp.type == 4 ? "未定义类型" : "未找到关联文件"; i++; } worksheet.Range["A1", worksheet.Cells[count + 1, colNum]] = dataArray; return(true); }
public void ProcessTableAnn(IEdmVault5 poVault, BomTableAnnotation swBOMTableAnn, string ConfigName, SldAsm asmPrd) { int nNumRow = 0; string ItemNumber = null; string PartNumber = null; TableAnnotation swTableAnn = (TableAnnotation)swBOMTableAnn; nNumRow = swTableAnn.RowCount; swBOMTableAnn = (BomTableAnnotation)swTableAnn; for (int j = 0; j < swTableAnn.RowCount; j++) { // //for (int i = 0; i < swTableAnn.ColumnCount;i++ ) // Console.WriteLine(swTableAnn.get_Text(j, i)); //获取类别和特有信息 if (j == swTableAnn.RowCount - 1)//最后一行为标题栏,跳过 { continue; } string filePath = ""; string compName = ""; string compConfig = ""; int compCount = swBOMTableAnn.GetComponentsCount2(j, ConfigName, out ItemNumber, out PartNumber); object[] vPtArr = swBOMTableAnn.GetComponents2(j, ConfigName); if (vPtArr != null) { for (int prIndex = 0; prIndex <= vPtArr.GetUpperBound(0); prIndex++) { Component2 swComp = (Component2)vPtArr[prIndex]; if ((swComp != null)) { //Debug.Print(" Component Name :" + swComp.Name2 + " Configuration Name : " + swComp.ReferencedConfiguration); //Debug.Print(" Component Path :" + swComp.GetPathName()); filePath = swComp.GetPathName(); compName = swComp.Name2; compConfig = swComp.ReferencedConfiguration; break; } else { continue; } } //Component2 comp2 = null; //comp2 = swBOMTableAnn.IGetComponents2(j, ConfigName, 0); //if (comp2 != null) //{ // filePath = comp2.GetPathName(); // compName = comp2.Name2; // compConfig = comp2.ReferencedConfiguration; //} } SldBsp bsp = null; if (filePath == "") { errors++; errorStr += "明细表第" + (j + 1) + "行" + swTableAnn.get_Text(j, 1) + " 未找到关联文件\n"; bsp = new SldBsp(); bsp.type = 5; } else { bsp = GetSldPrdInfoFromFile(poVault, filePath); if (bsp == null) { errors++; errorStr += "明细表第" + (j + 1) + "行" + swTableAnn.get_Text(j, 1) + " 文件:" + filePath + " 在PDM中未找到\n"; bsp = new SldBsp(); bsp.type = 5; } } bsp.path = filePath; //SldBsp bsp = new SldBsp(); swTableAnn.get_Text(j, 0); //序号 bsp.number = swTableAnn.get_Text(j, 1); //代号 bsp.name = swTableAnn.get_Text(j, 2); //名称 string amout = swTableAnn.get_Text(j, 3); int parseInt = 0; try { parseInt = int.Parse(amout); }catch (Exception) { parseInt = 0; } bsp.amout = parseInt; //数量 bsp.material = swTableAnn.get_Text(j, 4); //材料 string weight = swTableAnn.get_Text(j, 5); double parseDouble = 0.0; try { parseDouble = double.Parse(weight); } catch (Exception) { parseDouble = 0.0; } bsp.weight = parseDouble; //单重 bsp.totalWeight = bsp.weight * bsp.amout; // swTableAnn.get_Text(j, 6);//总重 bsp.remark = swTableAnn.get_Text(j, 7); //备注 //string number = swTableAnn.get_Text(j, 8);//测试 //if (bsp.number == "") bsp.number = number; if (bsp is SldPrt) { bsp.materialNumber = bsp.number == ""?"":("03." + bsp.number); asmPrd.sldPrtList.Add((SldPrt)bsp); } else if (bsp is SldStd) { asmPrd.sldStdList.Add((SldStd)bsp); } else if (bsp is SldBuy) { asmPrd.sldBuyList.Add((SldBuy)bsp); } else if (bsp is SldBsp) { asmPrd.sldBspList.Add(bsp); } } return; }