public IModel GetModelByWhereSql(string whereSql) { string sql = "select BCJ300Id,ModuleTreeId,Length,SidePanel,SuType,SuDis from BCJ300"; sql += whereSql; SqlDataReader objReader = SQLHelper.GetReader(sql); BCJ300 objModel = null; if (objReader.Read()) { objModel = new BCJ300() { BCJ300Id = Convert.ToInt32(objReader["BCJ300Id"]), ModuleTreeId = Convert.ToInt32(objReader["ModuleTreeId"]), //最好不要用=null去判断,提示类型转换错误 Length = objReader["Length"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["Length"]), SuDis = objReader["SuDis"].ToString().Length == 0 ? 0 : Convert.ToDecimal(objReader["SuDis"]), SidePanel = objReader["SidePanel"].ToString().Length == 0 ? "" : objReader["SidePanel"].ToString(), SuType = objReader["SuType"].ToString().Length == 0 ? "" : objReader["SuType"].ToString(), }; } objReader.Close(); return(objModel); }
public int EditModel(IModel model) { BCJ300 objModel = (BCJ300)model; //编写带参数的SQL语句 StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("Update BCJ300 set Length=@Length,SidePanel=@SidePanel,SuType=@SuType,SuDis=@SuDis where BCJ300Id=@BCJ300Id"); //定义参数数组 SqlParameter[] param = new SqlParameter[] { new SqlParameter("@Length", objModel.Length), new SqlParameter("@SidePanel", objModel.SidePanel), new SqlParameter("@SuType", objModel.SuType), new SqlParameter("@SuDis", objModel.SuDis), new SqlParameter("@BCJ300Id", objModel.BCJ300Id) }; try { return(SQLHelper.Update(sqlBuilder.ToString(), param)); } catch (SqlException ex) { throw new Exception("数据库操作出现异常:" + ex.Message); } catch (Exception ex) { throw ex; } }
public FrmBCJ300(Drawing drawing, ModuleTree tree) : this() { objBCJ300 = (BCJ300)objBCJ300Service.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); if (objBCJ300 == 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) { #region 数据验证 //必填项目 if (pbModelImage.Tag.ToString().Length == 0) { return; } if (!DataValidate.IsDecimal(txtLength.Text.Trim()) || Convert.ToDecimal(txtLength.Text.Trim()) < 90m) { MessageBox.Show("请认真检查CJ腔长度", "提示信息"); txtLength.Focus(); txtLength.SelectAll(); return; } if (cobSidePanel.SelectedIndex == -1) { MessageBox.Show("请选择CJ腔侧板", "提示信息"); cobSidePanel.Focus(); return; } if (cobSuType.SelectedIndex == -1) { MessageBox.Show("请选择脖颈方向", "提示信息"); cobSuType.Focus(); return; } if (!DataValidate.IsDecimal(txtSuDis.Text.Trim()) || Convert.ToDecimal(txtSuDis.Text.Trim()) < 50m) { MessageBox.Show("请认真检查脖颈距离右端面距离", "提示信息"); txtSuDis.Focus(); txtSuDis.SelectAll(); return; } #endregion //封装对象 BCJ300 objBCJ300 = new BCJ300() { BCJ300Id = Convert.ToInt32(pbModelImage.Tag), SidePanel = cobSidePanel.Text, SuType = cobSuType.Text, Length = Convert.ToDecimal(txtLength.Text.Trim()), SuDis = Convert.ToDecimal(txtSuDis.Text.Trim()), }; //提交修改 try { if (objBCJ300Service.EditModel(objBCJ300) == 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); } //查询参数 BCJ300 item = (BCJ300)objBCJ300Service.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 cjNo = (int)((item.Length - 40m) / 30m);//天花烟罩马蹄形CJ孔阵列距离为30 decimal firstCjDis = (item.Length - 30m * cjNo) / 2; if (firstCjDis < 15m) { cjNo--; firstCjDis = firstCjDis + 15m; } try { //----------Top Level---------- //----------脖颈---------- if (item.SuType == "UP") { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0010-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201990413-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0010-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201990413-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. } //----------侧板---------- switch (item.SidePanel) { case "LEFT": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0003-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0004-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; case "RIGHT": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0003-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0004-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. break; case "MIDDLE": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0003-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0004-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. break; default: swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0003-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0004-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0014-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; } //----------CJ腔主体---------- //重命名装配体内部 compReName = "FNCJ0015[BCJ300-" + tree.Module + "]{" + (int)item.Length + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCJ0015-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"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = item.Length / 1000m; swPart.Parameter("D1@LPattern1").SystemValue = cjNo + 1; swPart.Parameter("D3@Skizze17").SystemValue = firstCjDis / 1000m; swPart.Parameter("D4@Skizze16").SystemValue = item.SuDis / 1000m; } //----------其他零件---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCJ0016-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D2@Sketch1").SystemValue = (item.Length - 10m) / 1000m; swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }