/// <summary> /// 修改SSPTBD的制图参数 /// </summary> /// <param name="models"></param> /// <returns></returns> public int EditModel(IModel models) { SSPTBD objModel = (SSPTBD)models; //编写带参数的SQL语句 StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("Update SSPTBD set Length=@Length,LeftType=@LeftType,RightType=@RightType,LeftLength=@LeftLength,RightLength=@RightLength,"); sqlBuilder.Append("MPanelNo=@MPanelNo,LightType=@LightType where SSPTBDId=@SSPTBDId"); //定义参数数组 SqlParameter[] param = new SqlParameter[] { new SqlParameter("@Length", objModel.Length), new SqlParameter("@LeftLength", objModel.LeftLength), new SqlParameter("@RightLength", objModel.RightLength), new SqlParameter("@LeftType", objModel.LeftType), new SqlParameter("@RightType", objModel.RightType), new SqlParameter("@MPanelNo", objModel.MPanelNo), new SqlParameter("@LightType", objModel.LightType), new SqlParameter("@SSPTBDId", objModel.SSPTBDId) }; try { return(SQLHelper.Update(sqlBuilder.ToString(), param)); } catch (SqlException ex) { throw new Exception("数据库操作出现异常:" + ex.Message); } catch (Exception ex) { throw ex; } }
/// <summary> /// 根据条件查找SSPTBD /// </summary> /// <param name="whereSql"></param> /// <returns></returns> public IModel GetModelByWhereSql(string whereSql) { string sql = "select SSPTBDId,ModuleTreeId,Length,LeftType,RightType,LeftLength,RightLength,MPanelNo,LightType from SSPTBD"; sql += whereSql; SqlDataReader objReader = SQLHelper.GetReader(sql); SSPTBD objModel = null; if (objReader.Read()) { objModel = new SSPTBD() { SSPTBDId = Convert.ToInt32(objReader["SSPTBDId"]), ModuleTreeId = Convert.ToInt32(objReader["ModuleTreeId"]), //最好不要用=null去判断,提示类型转换错误 Length = objReader["Length"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["Length"]), LeftType = objReader["LeftType"].ToString().Length == 0 ? "" : objReader["LeftType"].ToString(), RightType = objReader["RightType"].ToString().Length == 0 ? "" : objReader["RightType"].ToString(), LeftLength = objReader["LeftLength"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["LeftLength"]), RightLength = objReader["RightLength"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["RightLength"]), MPanelNo = objReader["MPanelNo"].ToString().Length == 0 ? 0 : Convert.ToInt32(objReader["MPanelNo"]), LightType = objReader["LightType"].ToString().Length == 0 ? "" : objReader["LightType"].ToString() }; } objReader.Close(); return(objModel); }
public FrmSSPTBD(Drawing drawing, ModuleTree tree) : this() { objSSPTBD = (SSPTBD)objSSPTBDService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); if (objSSPTBD == 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(); }
private void btnEditData_Click(object sender, EventArgs e) { //必填项目 if (pbModelImage.Tag.ToString().Length == 0) { return; } if (!DataValidate.IsDecimal(txtLength.Text.Trim()) || Convert.ToDecimal(txtLength.Text.Trim()) < 200m) { MessageBox.Show("请认真检查总长", "提示信息"); txtLength.Focus(); txtLength.SelectAll(); return; } if (!DataValidate.IsDecimal(txtLeftLength.Text.Trim()) || Convert.ToDecimal(txtLeftLength.Text.Trim()) < 30m) { MessageBox.Show("请认真检查UL长度", "提示信息"); txtLeftLength.Focus(); txtLeftLength.SelectAll(); return; } if (!DataValidate.IsDecimal(txtRightLength.Text.Trim()) || Convert.ToDecimal(txtRightLength.Text.Trim()) < 30m) { MessageBox.Show("请认真检查UR长度", "提示信息"); txtRightLength.Focus(); txtRightLength.SelectAll(); return; } if (cobLeftType.SelectedIndex == -1) { MessageBox.Show("请选择左灯板类型", "提示信息"); cobLeftType.Focus(); return; } if (cobRightType.SelectedIndex == -1) { MessageBox.Show("请选择右灯板类型", "提示信息"); cobRightType.Focus(); return; } if (cobMPanelNo.SelectedIndex == -1) { MessageBox.Show("请选择M型水洗挡板数量", "提示信息"); cobMPanelNo.Focus(); return; } if (cobLightType.SelectedIndex == -1) { MessageBox.Show("请选择烟罩是否带UV", "提示信息"); cobLightType.Focus(); return; } //封装对象 SSPTBD objSSPTBD = new SSPTBD() { SSPTBDId = Convert.ToInt32(pbModelImage.Tag), LeftType = cobLeftType.Text, RightType = cobRightType.Text, Length = Convert.ToDecimal(txtLength.Text.Trim()), LeftLength = Convert.ToDecimal(txtLeftLength.Text.Trim()), RightLength = Convert.ToDecimal(txtRightLength.Text.Trim()), MPanelNo = Convert.ToInt32(cobMPanelNo.Text), LightType = cobLightType.Text }; //提交修改 try { if (objSSPTBDService.EditModel(objSSPTBD) == 1) { MessageBox.Show("制图数据修改成功", "提示信息"); this.DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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); } //查询参数 SSPTBD item = (SSPTBD)objSSPTBDService.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 supportNo = item.MPanelNo * 2 - 1;//计算支撑板数量 if (item.LeftType == "Z" && item.RightType == "Z") { supportNo = supportNo * 2 + 8; } else if (item.LeftType == "W" && item.RightType == "W") { supportNo = supportNo * 2 + 4; } else if ((item.LeftType == "Z" && item.RightType == "W") || (item.LeftType == "W" && item.RightType == "Z")) { supportNo = supportNo * 2 + 6; } try { //----------Top Level---------- swModel.Parameter("D1@LocalLPattern3").SystemValue = supportNo; //----------边缘Z板---------- swModel.Parameter("D1@Distance16").SystemValue = (item.MPanelNo * 2m - 1m) * 500m / 1000m; //左边 if (item.LeftType == "Z") { //重命名装配体内部 compReName = "FNCM0010[SSPDZ-" + tree.Module + ".L]{" + (int)(item.Length - 10m) + "}(" + (int)item.LeftLength + ")"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCM0010-L[SSPDZ-]{}()-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(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = (item.Length - 270m) / 1000m; swPart.Parameter("D1@Skizze1").SystemValue = item.LeftLength / 1000m; swFeat = swComp.FeatureByName("LED"); if (item.LightType == "LED60") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } //重命名装配体内部 compReName = "FNCM0008[SSPDW-" + tree.Module + ".L]{" + (int)(item.Length - 10m) + "}(500)"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCM0008-L[SSPDW-]{}()-11") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-11" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-11"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = (item.Length - 270m) / 1000m; swPart.Parameter("D1@Skizze1").SystemValue = 499.5m / 1000m; swFeat = swComp.FeatureByName("LED"); if (item.LightType == "LED60") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCM0010-L[SSPDZ-]{}()-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. //重命名装配体内部 compReName = "FNCM0008[SSPDW-" + tree.Module + ".L]{" + (int)(item.Length - 10m) + "}(" + (int)item.LeftLength + ")"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCM0008-L[SSPDW-]{}()-11") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-11" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-11"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = (item.Length - 270m) / 1000m; swPart.Parameter("D1@Skizze1").SystemValue = item.LeftLength / 1000m; swFeat = swComp.FeatureByName("LED"); if (item.LightType == "LED60") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } //右边 if (item.RightType == "Z") { //重命名装配体内部 compReName = "FNCM0010[SSPDZ-" + tree.Module + ".R]{" + (int)(item.Length - 10m) + "}(" + (int)item.RightLength + ")"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCM0010-R[SSPDZ-]{}()-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(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = (item.Length - 270m) / 1000m; swPart.Parameter("D1@Skizze1").SystemValue = item.RightLength / 1000m; swFeat = swComp.FeatureByName("LED"); if (item.LightType == "LED60") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } //重命名装配体内部 compReName = "FNCM0008[SSPDW-" + tree.Module + ".R]{" + (int)(item.Length - 10m) + "}(500)"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCM0008-R[SSPDW-]{}()-12") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-12" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-12"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = (item.Length - 270m) / 1000m; swPart.Parameter("D1@Skizze1").SystemValue = 499.5m / 1000m; swFeat = swComp.FeatureByName("LED"); if (item.LightType == "LED60") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCM0010-R[SSPDZ-]{}()-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. //重命名装配体内部 compReName = "FNCM0008[SSPDW-" + tree.Module + ".R]{" + (int)(item.Length - 10m) + "}(" + (int)item.RightLength + ")"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCM0008-R[SSPDW-]{}()-12") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-12" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-12"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = (item.Length - 270m) / 1000m; swPart.Parameter("D1@Skizze1").SystemValue = item.RightLength / 1000m; swFeat = swComp.FeatureByName("LED"); if (item.LightType == "LED60") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } //----------标准M板---------- //重命名装配体内部 compReName = "FNCM0009[SSPDM-" + tree.Module + "]{" + (int)(item.Length - 10m) + "}(500)"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCM0009[SSPDM-]{}-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(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = (item.Length - 270m) / 1000m; swPart.Parameter("D1@Skizze1").SystemValue = 499.5m / 1000m; swFeat = swComp.FeatureByName("LED"); if (item.LightType == "LED60") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } //----------标准W板---------- if (item.MPanelNo == 1) { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCM0008[SSPDW-]{}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { //重命名装配体内部 compReName = "FNCM0008[SSPDW-" + tree.Module + "]{" + (int)(item.Length - 10m) + "}(500)"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCM0008[SSPDW-]{}-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(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = (item.Length - 270m) / 1000m; swPart.Parameter("D1@Skizze1").SystemValue = 499.5m / 1000m; swFeat = swComp.FeatureByName("LED"); if (item.LightType == "LED60") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } swFeat = swAssy.FeatureByName("LocalLPattern2"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern2").SystemValue = item.MPanelNo; swModel.Parameter("D1@LocalLPattern1").SystemValue = item.MPanelNo - 1; } swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }