//选择正确的子节点,并给全局变量赋值 private void tsbConfirm_Click(object sender, EventArgs e) { //未选中任何节点,提示 if (tvMaterialClass.SelectedNode == null) { Msg.ShowError("未选中任何节点,无法操作!"); return; } //选中节点的ID【MaterialClassId】 string selectedNodeId = tvMaterialClass.SelectedNode.Tag.ToString().Split('_')[0]; //选中最后一层,不允许添加节点 if (selectedNodeId.Length < 4)//最后一层,位数为4位,如:1001 { Msg.ShowError("请选择最后一级节点!"); return; } //从数据库获取选中节点的完整信息 DataRow dr = objMaterialService.GetMaterialClassById(selectedNodeId); MaterialModel objMaterial = new MaterialModel() { MaterialClassId = selectedNodeId, IsPublic = ConvertEx.ToBoolean(dr["IsPublic"]), FactoryCode = ConvertEx.ToString(dr["FactoryCode"]) }; //Globals.CurrentMaterial.MaterialClassId = ConvertEx.ToInt(selectedNodeId); //Globals.CurrentMaterial.IsPublic = ConvertEx.ToBoolean(dr["IsPublic"]); //Globals.CurrentMaterial.FactoryCode = ConvertEx.ToString(dr["FactoryCode"]); if (selectedNodeId.Length == 4) { Globals.CurrentMaterial = objMaterial; this.DialogResult = DialogResult.Yes; } else { this.DialogResult = DialogResult.No; } //Msg.ShowInformation(objMaterial.MaterialClassId.ToString()); }
//新增图号(物料编码) 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 }