示例#1
0
        public static void UpdateProperty(MaterialModel objMaterial)
        {
            //1.打开指定的SW文件
            ModelDoc2 swDoc = swAppHelper.ActiveDoc(Globals.FileName);
            //2.获取当前激活配置名
            string configName = swDoc.ConfigurationManager.ActiveConfiguration.Name;

            #region 封装所有的SolidWorks属性(配置+自定义)
            //获取属性值:图号、名称、型号规格、单位、热处理、表面处理、品牌、血液
            Dictionary <string, string> MyCustominfos = new Dictionary <string, string>();
            MyCustominfos.Add("Identification Nb", objMaterial.MaterialCode);
            MyCustominfos.Add("Description", objMaterial.MaterialName);
            MyCustominfos.Add("规格", objMaterial.MaterialSpec);
            MyCustominfos.Add("型号", objMaterial.MaterialType);
            MyCustominfos.Add("单位", objMaterial.Unit);
            MyCustominfos.Add("加工属性", objMaterial.MachiningPropertyId);
            MyCustominfos.Add("涂装颜色", objMaterial.PaintingColor);
            MyCustominfos.Add("品牌", objMaterial.BrandId);
            //遍历每个属性并赋值
            foreach (string key in MyCustominfos.Keys)
            {
                //删除,添加配置特定的属性
                swDoc.DeleteCustomInfo2(configName, key);
                swDoc.AddCustomInfo3(configName, key, (int)swCustomInfoType_e.swCustomInfoText, MyCustominfos[key]);
                //删除,添加自定义的属性
                swDoc.DeleteCustomInfo(key);
                swDoc.AddCustomInfo2(key, (int)swCustomInfoType_e.swCustomInfoText, MyCustominfos[key]);
            }
            #endregion

            #region 重建模型
            swDoc.ClearSelection();    //清除选择
            swDoc.ForceRebuild3(true); //重建模型Ctrl+Q
            //swDoc.ShowNamedView2("*等轴测", 7);//等轴测显示
            //swDoc.ViewZoomtofit2();//全屏显示
            //swDoc.Save();
            //swAppHelper.CloseDoc(objDoc.OriginalFileName);
            #endregion
        }
示例#2
0
        //修改图号
        private void ModifyDrawing(string drawingId)
        {
            //询问是否修改现有图号信息
            if (Msg.AskQuestion("该图号信息已经存在,需要修改吗?"))
            {
                #region 【1】(修改)封装属性并保存到模型中
                //1-封装图号对象
                MaterialModel objMaterial = new MaterialModel()
                {
                    MaterialId         = this.txtMaterialId.Text.Trim(),
                    MaterialCategoryId = this.cboMaterialCategoryId.SelectedValue.ToString(),
                    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(),
                    //修改时增加更改人信息
                    UpdateId   = Globals.DEF_CreateId,
                    UpdateUser = Globals.DEF_CreateUser,
                    UpdateDate = objDrawingService.GetDBServerTime(),
                    UpdateInfo = Globals.DEF_CreateInfo,
                    //修改时不改变原来的信息(版本、状态、文件ID等)
                    MaterialCode = this.txtMaterialCode.Text.Trim(),
                    //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
                };

                //Msg.ShowInformation(this.cboImportanceGrade.Text);
                //2-无论数据库是否保存,都将填写的内容更新到本模型属性中
                swAppHelper.UpdateProperty(objMaterial);
                //Msg.ShowInformation("文件属性已更新并保存!");
                Globals.CurrentMaterial = objMaterial;//给全局变量赋值
                #endregion

                #region 【2】(修改)将数据提交到数据库
                try
                {
                    if (objMaterialService.ModifyMaterial(objMaterial))
                    {
                        this.DialogResult = DialogResult.OK;
                        Msg.ShowInformation("修改成功,请保存文件!");
                        //只允许提交一次
                        this.tsbAddMaterial.Enabled = false;
                    }
                    else
                    {
                        Msg.ShowError("修改失败!");
                    }
                }
                catch (Exception ex)
                {
                    Msg.ShowError(ex.Message);
                }
                #endregion
            }
            else
            {
                return;
            }
        }
示例#3
0
        //新增图号(物料编码)
        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
        }