//新增图号 private void AddDrawing() { #region 【1】(新增)封装属性并保存到模型中 //1-封装图号对象 DrawingModel objDrawing = new DrawingModel() { DrawingClassId = this.cboDrawingClass.SelectedValue == null ? null : this.cboDrawingClass.SelectedValue.ToString(), DrawingCode = this.txtDrawingCode.Text.Trim(), MaterialName = this.txtMaterialName.Text.Trim(), MaterialSpec = this.txtMaterialSpec.Text.Trim(), Unit = this.cboUnit.SelectedValue == null ? null : this.cboUnit.SelectedValue.ToString(), PurchaseTypeId = this.cboPurchaseType.SelectedValue == null ? null : this.cboPurchaseType.SelectedValue.ToString(), SelectionTypeId = this.cboSelectionType.SelectedValue == null ? null : this.cboSelectionType.SelectedValue.ToString(), HeatTreatment = this.txtHeatTreatment.Text.Trim(), SurfaceTreatment = this.txtSurfaceTreatment.Text.Trim(), Revision = 1, DrawingStatusId = 0,//申请状态-0 Weight = ConvertEx.ToFloat(this.txtWeight.Text.Trim()).ToString("F2"), Brand = this.txtBrand.Text.Trim(), ReMark = this.txtReMark.Text.Trim(), DocIdModel = ConvertEx.ToInt(Globals.FileID), CreateFrom = "来自SW插件", CreateId = Globals.DEF_CreateId, CreateUser = Globals.DEF_CreateUser, CreateDate = objDrawingService.GetDBServerTime(), CreateInfo = Globals.DEF_CreateInfo }; //2-无论数据库是否保存,都将填写的内容更新到本模型属性中 swAppHelper.UpdateProperty(objDrawing); //Msg.ShowInformation("文件属性已更新并保存!"); Globals.CurrentDrawing = objDrawing;//给全局变量赋值 #endregion #region 【2】(新增)将数据提交到数据库 try { if (objDrawingService.AddDrawing(objDrawing)) { this.DialogResult = DialogResult.OK; Msg.ShowInformation("添加成功,请保存文件!"); //只允许提交一次 this.btnAddMaterial.Enabled = false; } else { Msg.ShowError("添加失败!"); } } catch (Exception ex) { Msg.ShowError(ex.Message); } #endregion }
//修改图号 private void ModifyDrawing(string drawingId) { //询问是否修改现有图号信息 if (Msg.AskQuestion("该图号信息已经存在,需要修改吗?")) { #region 【1】(修改)封装属性并保存到模型中 //1-封装图号对象 DrawingModel objDrawing = new DrawingModel() { DrawingId = drawingId, DrawingClassId = this.cboDrawingClass.SelectedValue == null ? null : this.cboDrawingClass.SelectedValue.ToString(), DrawingCode = this.txtDrawingCode.Text.Trim(), MaterialName = this.txtMaterialName.Text.Trim(), MaterialSpec = this.txtMaterialSpec.Text.Trim(), Unit = this.cboUnit.SelectedValue == null ? null : this.cboUnit.SelectedValue.ToString(), PurchaseTypeId = this.cboPurchaseType.SelectedValue == null ? null : this.cboPurchaseType.SelectedValue.ToString(), SelectionTypeId = this.cboSelectionType.SelectedValue == null ? null : this.cboSelectionType.SelectedValue.ToString(), HeatTreatment = this.txtHeatTreatment.Text.Trim(), SurfaceTreatment = this.txtSurfaceTreatment.Text.Trim(), Weight = ConvertEx.ToFloat(this.txtWeight.Text.Trim()).ToString("F2"), Brand = this.txtBrand.Text.Trim(), ReMark = this.txtReMark.Text.Trim(), //修改时增加更改人信息 UpdateId = Globals.DEF_CreateId, UpdateUser = Globals.DEF_CreateUser, UpdateDate = objDrawingService.GetDBServerTime(), UpdateInfo = Globals.DEF_CreateInfo //修改时不改变原来的信息(版本、状态、文件ID等) //Revision = 1, //DrawingStatusId = 0,//申请状态-0 //DocIdModel = ConvertEx.ToInt(Globals.FileID), //CreateFrom = "来自SW插件", //CreateId = Globals.DEF_CreateId, //CreateUser = Globals.DEF_CreateUser, //CreateDate = objDrawingService.GetDBServerTime(), //CreateInfo = Globals.DEF_CreateInfo }; //2-无论数据库是否保存,都将填写的内容更新到本模型属性中 swAppHelper.UpdateProperty(objDrawing); //Msg.ShowInformation("文件属性已更新并保存!"); Globals.CurrentDrawing = objDrawing;//给全局变量赋值 #endregion #region 【2】(修改)将数据提交到数据库 try { if (objDrawingService.ModifyMaterial(objDrawing)) { this.DialogResult = DialogResult.OK; Msg.ShowInformation("修改成功,请保存文件!"); //只允许提交一次 this.btnAddMaterial.Enabled = false; } else { Msg.ShowError("修改失败!"); } } catch (Exception ex) { Msg.ShowError(ex.Message); } #endregion } else { return; } }
//新增图号(物料编码) private void AddDrawing() { #region 【1】(新增)封装属性并保存到模型中 //1-封装图号对象 MaterialModel objMaterial = new MaterialModel() { DocIdModel = ConvertEx.ToInt(Globals.FileID), MaterialId = this.txtMaterialId.Text.Trim(), IsPublic = ConvertEx.ToBoolean(this.txtIsPublic.Text.Trim()), MaterialCode = this.txtMaterialCode.Text.Trim(), FactoryCode = this.txtFactoryCode.Text.Trim(), MaterialClassId = this.txtMaterialClassId.Text.Trim(), MaterialCategoryId = this.cboMaterialCategoryId.SelectedValue.ToString(), DrawingCode = this.txtDrawingCode.Text.Trim(), MaterialName = this.txtMaterialName.Text.Trim(), MaterialSpec = this.txtMaterialSpec.Text.Trim(), MaterialType = this.txtMaterialType.Text.Trim(), Unit = this.cboUnit.SelectedValue.ToString(), Mquality = this.txtMquality.Text.Trim(), Weight = ConvertEx.ToFloat(this.txtWeight.Text.Trim()).ToString("F2"), MachiningPropertyId = this.cboMachiningProperty.SelectedValue.ToString(), PaintingColor = this.cboPaintingColor.SelectedValue == null ? null : this.cboPaintingColor.SelectedValue.ToString(), BrandId = this.cboBrandId.SelectedValue == null ? null : this.cboBrandId.SelectedValue.ToString(), ImportanceGrade = this.cboImportanceGrade.Text, DraftFeatureId = this.cboDraftFeatureId.SelectedValue == null ? null : this.cboDraftFeatureId.SelectedValue.ToString(), HeatTreatment = this.txtHeatTreatment.Text.Trim(), SurfaceTreatment = this.txtSurfaceTreatment.Text.Trim(), ReMark = this.txtReMark.Text.Trim(), Revision = 1, StatusId = 0,//申请状态-0 CreateFrom = "来自SW插件", CreateId = Globals.DEF_CreateId, CreateUser = Globals.DEF_CreateUser, CreateDate = objDrawingService.GetDBServerTime(), CreateInfo = Globals.DEF_CreateInfo }; //★★保存之前从数据库获取最新流水码★★ objMaterial.MaterialCode = objMaterialService.GetNewMaterialCode(objMaterial.MaterialClassId); //2-无论数据库是否保存,都将填写的内容更新到本模型属性中 swAppHelper.UpdateProperty(objMaterial); //Msg.ShowInformation("文件属性已更新并保存!"); Globals.CurrentMaterial = objMaterial;//给全局变量赋值 #endregion #region 【2】(新增)将数据提交到数据库 try { if (objMaterialService.AddMaterial(objMaterial)) { this.DialogResult = DialogResult.OK; Msg.ShowInformation("添加成功,请保存文件!"); //只允许提交一次 this.tsbAddMaterial.Enabled = false; } else { Msg.ShowError("添加失败!"); } } catch (Exception ex) { Msg.ShowError(ex.Message); } #endregion }