public int EditModel(IModel model) { UCWUVR4SDXF objModel = (UCWUVR4SDXF)model; //编写带参数的SQL语句 StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("Update UCWUVR4SDXF set Quantity=@Quantity where UCWUVR4SDXFId=@UCWUVR4SDXFId"); //定义参数数组 SqlParameter[] param = new SqlParameter[] { new SqlParameter("@Quantity", objModel.Quantity), new SqlParameter("@UCWUVR4SDXFId", objModel.UCWUVR4SDXFId) }; try { return(SQLHelper.Update(sqlBuilder.ToString(), param)); } catch (SqlException ex) { throw new Exception("数据库操作出现异常:" + ex.Message); } catch (Exception ex) { throw ex; } }
public FrmUCWUVR4SDXF(Drawing drawing, ModuleTree tree) : this() { objUCWUVR4SDXF = (UCWUVR4SDXF)objUCWUVR4SDXFService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); if (objUCWUVR4SDXF == 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(); }
/// <summary> /// 修改参数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEditData_Click(object sender, EventArgs e) { #region 数据验证 //必填项目 if (pbModelImage.Tag.ToString().Length == 0) { return; } if (!DataValidate.IsInteger(txtQuantity.Text.Trim())) { MessageBox.Show("请认真检查数量是否填错", "提示信息"); txtQuantity.Focus(); txtQuantity.SelectAll(); return; } #endregion //封装对象 UCWUVR4SDXF objUCWUVR4SDXF = new UCWUVR4SDXF() { UCWUVR4SDXFId = Convert.ToInt32(pbModelImage.Tag), Quantity = Convert.ToInt32(txtQuantity.Text) }; //提交修改 try { if (objUCWUVR4SDXFService.EditModel(objUCWUVR4SDXF) == 1) { MessageBox.Show("制图数据修改成功", "提示信息"); this.DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public IModel GetModelByWhereSql(string whereSql) { string sql = "select UCWUVR4SDXFId,ModuleTreeId,Quantity from UCWUVR4SDXF"; sql += whereSql; SqlDataReader objReader = SQLHelper.GetReader(sql); UCWUVR4SDXF objModel = null; if (objReader.Read()) { objModel = new UCWUVR4SDXF() { UCWUVR4SDXFId = Convert.ToInt32(objReader["UCWUVR4SDXFId"]), ModuleTreeId = Convert.ToInt32(objReader["ModuleTreeId"]), //最好不要用=null去判断,提示类型转换错误 Quantity = objReader["Quantity"].ToString().Length == 0 ? 0 : Convert.ToInt32(objReader["Quantity"]), }; } objReader.Close(); return(objModel); }
public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath) { //创建下料图文件夹,默认在D盘MyProjects目录下(先判断文件夹是否存在) string dxfPath = projectPath + @"\DXF-CUTLIST"; if (!Directory.Exists(dxfPath)) { Directory.CreateDirectory(dxfPath); } //创建dxf图文件夹 string newPath = dxfPath + @"\" + tree.Item + "-" + tree.Module + @"\"; if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } //拷贝文件,调用通用函数 if (!CommonFunc.CopyDxfFiles(tree.ModelPath, newPath)) { return; } //查询参数 UCWUVR4SDXF objUCWUVR4SDXF = (UCWUVR4SDXF)objUCWUVR4SDXFService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); //查询标准DxfCutlist,根据item.categoryId查询dxfCutList对象列表 List <DXFCutList> oldList = objDxfCutListService.GetDXFCutListsByCategoryId(tree.CategoryId.ToString()); Project objProject = objProjectService.GetProjectByProjectId(tree.ProjectId.ToString()); #region HoodCutList if (objProject.HoodType == "Hood") { //乘以数量,赋值moduletreeid foreach (var item in oldList) { hoodCutLists.Add(new HoodCutList() { ModuleTreeId = objUCWUVR4SDXF.ModuleTreeId, PartDescription = item.PartDescription, Length = item.Length, Width = item.Width, Thickness = item.Thickness, Quantity = item.Quantity * objUCWUVR4SDXF.Quantity,//多个 Materials = item.Materials, PartNo = item.PartNo, UserId = 1 }); } //基于事务hoodCutLists提交SQLServer if (hoodCutLists.Count == 0) { return; } try { if (objHoodCutListService.ImportCutList(hoodCutLists)) { hoodCutLists.Clear(); } } catch (Exception ex) { throw new Exception("UCWUVR4SDXF的HoodCutlist导入数据库失败" + ex.Message); } } #endregion #region CeilingCutList if (objProject.HoodType == "Ceiling") { //添加SubAssy,获得SubAssyId int subAssyId = objSubAssyService.AddSubAssy(new SubAssy() { ProjectId = objProject.ProjectId, SubAssyName = tree.Module }); //乘以数量,赋值moduletreeid foreach (var item in oldList) { ceilingCutLists.Add(new CeilingCutList() { SubAssyId = subAssyId, PartDescription = item.PartDescription, Length = item.Length, Width = item.Width, Thickness = item.Thickness, Quantity = item.Quantity * objUCWUVR4SDXF.Quantity,//多个UCP Materials = item.Materials, PartNo = item.PartNo, UserId = 1 }); } //基于事务CeilingCutLists提交SQLServer if (ceilingCutLists.Count == 0) { return; } try { if (objCeilingCutListService.ImportCutList(ceilingCutLists)) { ceilingCutLists.Clear(); } } catch (Exception ex) { throw new Exception("UCWUVR4SDXF的CeilingCutlist导入数据库失败" + ex.Message); } } #endregion }