public FrmKCJSB265(Drawing drawing, ModuleTree tree) : this() { objKCJSB265 = (KCJSB265)objKCJSB265Service.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); if (objKCJSB265 == null) { return; } this.Text = drawing.ODPNo + " / Item: " + drawing.Item + " / Module: " + tree.Module + " - " + tree.CategoryName; Category objCategory = objCategoryService.GetCategoryByCategoryId(tree.CategoryId.ToString()); pbModelImage.Image = objCategory.ModelImage.Length == 0 ? Image.FromFile("NoPic.png") : (Image) new SerializeObjectToString().DeserializeObject(objCategory.ModelImage); FillData(); }
public int EditModel(IModel model) { KCJSB265 objModel = (KCJSB265)model; //编写带参数的SQL语句 StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("Update KCJSB265 set Length=@Length,ExRightDis=@ExRightDis,ExLength=@ExLength,ExWidth=@ExWidth,ExHeight=@ExHeight,"); sqlBuilder.Append("FCType=@FCType,FCSide=@FCSide,FCSideLeft=@FCSideLeft,FCSideRight=@FCSideRight,FCBlindNo=@FCBlindNo,"); sqlBuilder.Append("SSPType=@SSPType,Gutter=@Gutter,GutterWidth=@GutterWidth,ANSUL=@ANSUL,ANSide=@ANSide,ANDetector=@ANDetector,"); sqlBuilder.Append("MARVEL=@MARVEL,Japan=@Japan where KCJSB265Id=@KCJSB265Id"); //定义参数数组 SqlParameter[] param = new SqlParameter[] { new SqlParameter("@Length", objModel.Length), new SqlParameter("@ExRightDis", objModel.ExRightDis), new SqlParameter("@ExLength", objModel.ExLength), new SqlParameter("@ExWidth", objModel.ExWidth), new SqlParameter("@ExHeight", objModel.ExHeight), new SqlParameter("@FCType", objModel.FCType), new SqlParameter("@FCSide", objModel.FCSide), new SqlParameter("@FCSideLeft", objModel.FCSideLeft), new SqlParameter("@FCSideRight", objModel.FCSideRight), new SqlParameter("@FCBlindNo", objModel.FCBlindNo), new SqlParameter("@SSPType", objModel.SSPType), new SqlParameter("@Gutter", objModel.Gutter), new SqlParameter("@GutterWidth", objModel.GutterWidth), new SqlParameter("@ANSUL", objModel.ANSUL), new SqlParameter("@ANSide", objModel.ANSide), new SqlParameter("@ANDetector", objModel.ANDetector), new SqlParameter("@MARVEL", objModel.MARVEL), new SqlParameter("@Japan", objModel.Japan), new SqlParameter("@KCJSB265Id", objModel.KCJSB265Id) }; try { return(SQLHelper.Update(sqlBuilder.ToString(), param)); } catch (SqlException ex) { throw new Exception("数据库操作出现异常:" + ex.Message); } catch (Exception ex) { throw ex; } }
public IModel GetModelByWhereSql(string whereSql) { string sql = "select KCJSB265Id,ModuleTreeId,Length,ExRightDis,ExLength,ExWidth,ExHeight," + "FCType,FCSide,FCSideLeft,FCSideRight,FCBlindNo,SSPType,Gutter,GutterWidth," + "ANSUL,ANSide,ANDetector,MARVEL,Japan from KCJSB265"; sql += whereSql; SqlDataReader objReader = SQLHelper.GetReader(sql); KCJSB265 objModel = null; if (objReader.Read()) { objModel = new KCJSB265() { KCJSB265Id = Convert.ToInt32(objReader["KCJSB265Id"]), ModuleTreeId = Convert.ToInt32(objReader["ModuleTreeId"]), //最好不要用=null去判断,提示类型转换错误 Length = objReader["Length"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["Length"]), ExRightDis = objReader["ExRightDis"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["ExRightDis"]), ExLength = objReader["ExLength"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["ExLength"]), ExWidth = objReader["ExWidth"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["ExWidth"]), ExHeight = objReader["ExHeight"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["ExHeight"]), FCType = objReader["FCType"].ToString().Length == 0 ? "" : objReader["FCType"].ToString(), FCSide = objReader["FCSide"].ToString().Length == 0 ? "" : objReader["FCSide"].ToString(), FCSideLeft = objReader["FCSideLeft"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["FCSideLeft"]), FCSideRight = objReader["FCSideRight"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["FCSideRight"]), FCBlindNo = objReader["FCBlindNo"].ToString().Length == 0 ? 0 : Convert.ToInt32(objReader["FCBlindNo"]), SSPType = objReader["SSPType"].ToString().Length == 0 ? "" : objReader["SSPType"].ToString(), Gutter = objReader["Gutter"].ToString().Length == 0 ? "" : objReader["Gutter"].ToString(), GutterWidth = objReader["GutterWidth"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["GutterWidth"]), ANSUL = objReader["ANSUL"].ToString().Length == 0 ? "" : objReader["ANSUL"].ToString(), ANSide = objReader["ANSide"].ToString().Length == 0 ? "" : objReader["ANSide"].ToString(), ANDetector = objReader["ANDetector"].ToString().Length == 0 ? "" : objReader["ANDetector"].ToString(), MARVEL = objReader["MARVEL"].ToString().Length == 0 ? "" : objReader["MARVEL"].ToString(), Japan = objReader["Japan"].ToString().Length == 0 ? "" : objReader["Japan"].ToString(), }; } objReader.Close(); return(objModel); }
public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath) { //创建项目模型存放地址 string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName; if (!Directory.Exists(itemPath)) { Directory.CreateDirectory(itemPath); } else { DialogResult result = MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } //Pack的后缀 string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6); //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack //packango后需要接收打包完成的地址,参数为后缀 string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm"; if (!File.Exists(packedAssyPath)) { packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath); } //查询参数 KCJSB265 item = (KCJSB265)objKCJSB265Service.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令 int warnings = 0; int errors = 0; suffix = "_" + suffix;//后缀 ModelDoc2 swModel = default(ModelDoc2); ModelDoc2 swPart = default(ModelDoc2); AssemblyDoc swAssy = default(AssemblyDoc); Component2 swComp; Feature swFeat = default(Feature); object configNames = null; ModelDocExtension swModelDocExt = default(ModelDocExtension); bool status = false; string compReName = string.Empty; //打开Pack后的模型 swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; swAssy = swModel as AssemblyDoc; //装配体 string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称 swModelDocExt = (ModelDocExtension)swModel.Extension; //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错 swModel.ForceRebuild3(true); //TopOnly参数设置成true,只重建顶层,不重建零件内部 /*注意SolidWorks单位是m,计算是应当/1000m * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了 * (int)不进行四舍五入,Convert.ToInt32会四舍五入 */ //-----------计算中间值,---------- int fcNo = (int)((item.Length - item.FCSideLeft - item.FCSideRight) / 499m) - item.FCBlindNo; try { //----------Top Level---------- //判断FC数量,FC侧板长度 if (item.FCBlindNo > 0) { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern3"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern3").SystemValue = item.FCBlindNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D1@Distance11").SystemValue = item.FCSideLeft / 1000m; } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern3"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //判断FC/KSA if (item.FCType == "KSA") { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5202040401-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern4"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern4").SystemValue = fcNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D1@Distance9").SystemValue = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern2"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern2").SystemValue = fcNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D1@Distance10").SystemValue = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5202040401-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //----------油网侧板---------- switch (item.FCSide) { case "LEFT": //重命名装配体内部 if (item.FCType == "KSA") { compReName = "FNCE0108[BP-" + tree.Module + "]{" + (int)(item.FCSideLeft + fcNo * 2.5m) + "}"; } else { compReName = "FNCE0108[BP-" + tree.Module + "]{" + (int)(item.FCSideLeft - 4m) + "}"; } status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 if (item.FCType == "KSA") { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft + fcNo * 2.5m) / 1000m; } else { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - 4m) / 1000m; } } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; case "RIGHT": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. //重命名装配体内部 if (item.FCType == "KSA") { compReName = "FNCE0109[BP-" + tree.Module + "]{" + (int)(item.FCSideRight + fcNo * 2.5m) + "}"; } else { compReName = "FNCE0109[BP-" + tree.Module + "]{" + (int)(item.FCSideRight - 4m) + "}"; } status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 if (item.FCType == "KSA") { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight + fcNo * 2.5m) / 1000m; } else { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - 4m) / 1000m; } } break; case "BOTH": //重命名装配体内部 if (item.FCType == "KSA") { compReName = "FNCE0108[BP-" + tree.Module + ".1]{" + (int)(item.FCSideLeft + fcNo * 1.25m) + "}"; } else { compReName = "FNCE0108[BP-" + tree.Module + "]{" + (int)(item.FCSideLeft - 2m) + "}"; } status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 if (item.FCType == "KSA") { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft + fcNo * 1.25m) / 1000m; } else { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - 2m) / 1000m; } } //重命名装配体内部 if (item.FCType == "KSA") { compReName = "FNCE0109[BP-" + tree.Module + ".2]{" + (int)(item.FCSideRight + fcNo * 1.25m) + "}"; } else { compReName = "FNCE0109[BP-" + tree.Module + "]{" + (int)(item.FCSideRight - 2m) + "}"; } status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 if (item.FCType == "KSA") { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight + fcNo * 1.25m) / 1000m; } else { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - 2m) / 1000m; } } break; default: swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; } //----------日本项目需要压缩零件---------- if (item.Japan == "YES") { //吊装垫片 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9")); swComp.SetSuppression2(0); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //排风脖颈 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. //排风滑门 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXDOOR-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. //排风腔 //重命名装配体内部 compReName = "FNCE0125[KCJSB265-" + tree.Module + "]{" + (int)item.Length + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0125-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-2"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Aufsatz-Linear austragen1").SystemValue = item.Length / 1000m; swFeat = swComp.FeatureByName("EX"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("Cut-Extrude4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 if (item.MARVEL == "YES") { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } else { //吊装垫片 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9")); swComp.SetSuppression2(2); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩 //排风脖颈 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0019-1")); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swFeat = swComp.FeatureByName("ANSUL"); if (item.ANSUL == "YES") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0020-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0047-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swFeat = swComp.FeatureByName("ANDTEC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0048-2")); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swFeat = swComp.FeatureByName("ANDTEC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //排风滑门 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXDOOR-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Distance3").SystemValue = (item.ExWidth + 20m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0018-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D2@Base-Flange1").SystemValue = (item.ExLength * 2m + 100m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0013-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D1@Sketch1").SystemValue = (item.ExLength / 2m + 10m) / 1000m; swPart.Parameter("D2@Sketch1").SystemValue = (item.ExWidth + 40m) / 1000m; //排风腔 //重命名装配体内部 compReName = "FNCE0125[KCJSB265-" + tree.Module + "]{" + (int)item.Length + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0125-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-2"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Aufsatz-Linear austragen1").SystemValue = item.Length / 1000m; swFeat = swComp.FeatureByName("EX"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("Cut-Extrude4"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch2").SystemValue = item.ExRightDis / 1000m; swPart.Parameter("D1@Sketch2").SystemValue = item.ExLength / 1000m; swPart.Parameter("D2@Sketch2").SystemValue = item.ExWidth / 1000m; if (item.ANSUL == "YES") { //侧喷 if (item.ANSide == "LEFT") { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else if (item.ANSide == "RIGHT") { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //探测器 if (item.ANDetector == "LEFT") { swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else if (item.ANDetector == "RIGHT") { swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else if (item.ANDetector == "BOTH") { swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } else { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } if (item.MARVEL == "YES") { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } //----------SSP灯板支撑条---------- if (item.SSPType == "DOME") { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m; if (item.Gutter == "YES") { swModel.Parameter("D1@Distance12").SystemValue = item.GutterWidth / 1000m; } else { swModel.Parameter("D1@Distance12").SystemValue = 0.5m / 1000m; } } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m; if (item.Gutter == "YES") { swModel.Parameter("D1@Distance2").SystemValue = item.GutterWidth / 1000m; } else { swModel.Parameter("D1@Distance2").SystemValue = 0.5m / 1000m; } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. } swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }
private void btnEditData_Click(object sender, EventArgs e) { #region 数据验证 //必填项目 if (pbModelImage.Tag.ToString().Length == 0) { return; } if (!DataValidate.IsDecimal(txtLength.Text.Trim()) || Convert.ToDecimal(txtLength.Text.Trim()) < 100m) { MessageBox.Show("请认真检查烟罩长度", "提示信息"); txtLength.Focus(); txtLength.SelectAll(); return; } //ANSUL腔 if (cobGutter.SelectedIndex == -1) { MessageBox.Show("请选择是否右ANSUL腔", "提示信息"); cobGutter.Focus(); return; } else if (cobGutter.SelectedIndex == 0 && (!DataValidate.IsDecimal(txtGutterWidth.Text.Trim()) || Convert.ToDecimal(txtGutterWidth.Text.Trim()) < 30m)) { MessageBox.Show("请认真检查ANSUL腔宽度", "提示信息");//当脖颈大于2时需要填写脖颈间距 txtGutterWidth.Focus(); txtGutterWidth.SelectAll(); return; } //脖颈 if (!DataValidate.IsDecimal(txtExLength.Text.Trim()) || Convert.ToDecimal(txtExLength.Text.Trim()) < 50m) { MessageBox.Show("请填写脖颈长度", "提示信息"); txtExLength.Focus(); txtExLength.SelectAll(); return; } if (!DataValidate.IsDecimal(txtExWidth.Text.Trim()) || Convert.ToDecimal(txtExWidth.Text.Trim()) < 50m) { MessageBox.Show("请填写脖颈宽度", "提示信息"); txtExWidth.Focus(); txtExWidth.SelectAll(); return; } if (!DataValidate.IsDecimal(txtExHeight.Text.Trim()) || Convert.ToDecimal(txtExHeight.Text.Trim()) < 20m) { MessageBox.Show("请填写脖颈高度", "提示信息"); txtExHeight.Focus(); txtExHeight.SelectAll(); return; } //ANSUL if (cobANSUL.SelectedIndex == -1) { MessageBox.Show("是否带ANSUL", "提示信息"); cobANSUL.Focus(); return; } if (cobMARVEL.SelectedIndex == -1) { MessageBox.Show("是否带MARVEL", "提示信息"); cobMARVEL.Focus(); return; } if (cobANSUL.SelectedIndex == 0) { if (cobANSide.SelectedIndex == -1) { MessageBox.Show("请选择ANSUL侧喷位置", "提示信息"); cobANSide.Focus(); return; } if (cobANDetector.SelectedIndex == -1) { MessageBox.Show("请选择ANSUL探测器进出口位置", "提示信息"); cobANDetector.Focus(); return; } } //其他配置 if (cobSSPType.SelectedIndex == -1) { MessageBox.Show("请选择SSP灯板类型", "提示信息"); cobSSPType.Focus(); return; } if (cobJapan.SelectedIndex == -1) { MessageBox.Show("请选择是否为日本项目", "提示信息"); cobJapan.Focus(); return; } //油网侧板 if (cobFCType.SelectedIndex == -1) { MessageBox.Show("请选择油网类型", "提示信息"); cobFCType.Focus(); return; } if (cobFCSide.SelectedIndex == -1) { MessageBox.Show("请选择油网侧板", "提示信息"); cobFCSide.Focus(); return; } if ((cobFCSide.SelectedIndex == 0 || cobFCSide.SelectedIndex == 2) && (!DataValidate.IsDecimal(txtFCSideLeft.Text.Trim()) || Convert.ToDecimal(txtFCSideLeft.Text.Trim()) < 10m)) { MessageBox.Show("请认真检查左油网侧板长度", "提示信息");//当脖颈大于2时需要填写脖颈间距 txtFCSideLeft.Focus(); txtFCSideLeft.SelectAll(); return; } if ((cobFCSide.SelectedIndex == 1 || cobFCSide.SelectedIndex == 2) && (!DataValidate.IsDecimal(txtFCSideRight.Text.Trim()) || Convert.ToDecimal(txtFCSideRight.Text.Trim()) < 10m)) { MessageBox.Show("请认真检查右油网侧板长度", "提示信息");//当脖颈大于2时需要填写脖颈间距 txtFCSideRight.Focus(); txtFCSideRight.SelectAll(); return; } #endregion //封装对象 KCJSB265 objKCJSB265 = new KCJSB265() { KCJSB265Id = Convert.ToInt32(pbModelImage.Tag), ANSUL = cobANSUL.Text, ANSide = cobANSide.Text.Trim().Length == 0 ? "NO" : cobANSide.Text, ANDetector = cobANDetector.Text.Trim().Length == 0 ? "NO" : cobANDetector.Text, MARVEL = cobMARVEL.Text, SSPType = cobSSPType.Text, Japan = cobJapan.Text, Gutter = cobGutter.Text, FCSide = cobFCSide.Text, FCType = cobFCType.Text, FCBlindNo = Convert.ToInt32(cobFCBlindNo.Text.Trim()), Length = Convert.ToDecimal(txtLength.Text.Trim()), ExRightDis = Convert.ToDecimal(txtExRightDis.Text.Trim()), ExLength = Convert.ToDecimal(txtExLength.Text.Trim()), ExWidth = Convert.ToDecimal(txtExWidth.Text.Trim()), ExHeight = Convert.ToDecimal(txtExHeight.Text.Trim()), GutterWidth = Convert.ToDecimal(txtGutterWidth.Text.Trim()), FCSideLeft = Convert.ToDecimal(txtFCSideLeft.Text.Trim()), FCSideRight = Convert.ToDecimal(txtFCSideRight.Text.Trim()) }; //提交修改 try { if (objKCJSB265Service.EditModel(objKCJSB265) == 1) { MessageBox.Show("制图数据修改成功", "提示信息"); this.DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }