コード例 #1
0
        //新增图号
        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
        }
コード例 #2
0
        //获取当前文件的Drawing属性
        public static DrawingModel GetDrawingInfo()
        {
            DrawingModel objDrawing = new DrawingModel();
            //【1】打开指定的SW文件,并获取文件名
            ModelDoc2 swDoc      = swAppHelper.ActiveDoc();
            string    fileName   = swDoc.GetPathName();                                 //文件名
            string    configName = swDoc.ConfigurationManager.ActiveConfiguration.Name; //当前激活配置名

            if (fileName == null || fileName.Length == 0)
            {
                Msg.ShowError("无法获取文件名,请保存文件后重试!");
                return(null);
            }

            //【2】从模型中获取主要属性值
            string drawingcode      = swDoc.GetCustomInfoValue(configName, "图号");
            string materialname     = swDoc.GetCustomInfoValue(configName, "名称");
            string materialspec     = swDoc.GetCustomInfoValue(configName, "规格型号");
            string weight           = swDoc.GetCustomInfoValue(configName, "重量");
            string unit             = swDoc.GetCustomInfoValue(configName, "单位");
            string purchasetypeid   = swDoc.GetCustomInfoValue(configName, "采购类型");
            string selectiontypeid  = swDoc.GetCustomInfoValue(configName, "选型分类");
            string surfacetreatment = swDoc.GetCustomInfoValue(configName, "表面处理");
            string heattreatment    = swDoc.GetCustomInfoValue(configName, "热处理");
            string brand            = swDoc.GetCustomInfoValue(configName, "品牌");
            string remark           = swDoc.GetCustomInfoValue(configName, "备注");

            //【3】封装图号实体类对象属性
            objDrawing.FileName         = fileName;
            objDrawing.ConfigName       = configName;
            objDrawing.DrawingCode      = drawingcode;
            objDrawing.MaterialName     = materialname;
            objDrawing.MaterialSpec     = materialspec;//XorG:规格型号
            objDrawing.Weight           = weight;
            objDrawing.Unit             = unit;
            objDrawing.PurchaseTypeId   = purchasetypeid;
            objDrawing.SelectionTypeId  = selectiontypeid;
            objDrawing.SurfaceTreatment = surfacetreatment;
            objDrawing.HeatTreatment    = heattreatment;
            objDrawing.Brand            = brand;
            objDrawing.ReMark           = remark;
            return(objDrawing);
        }
コード例 #3
0
        //如果通过文件ID可以查询到图号编码等信息(图号状态是1),则返回4个字符串,否则返回空的List
        public DrawingModel GetFileDrawingInfo(string fileID)
        {
            SQLHelper.connString = Globals.connStrGroupDBName;
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" select * from code_Drawing");
            strSql.Append(" where DocIdModel={0} and DrawingStatusId=1");
            strSql.Append(" ORDER BY DrawingId DESC");
            string       sql        = string.Format(strSql.ToString(), fileID);
            DataTable    dt         = SQLHelper.GetDataSet(sql).Tables[0];
            DrawingModel objDrawing = null;

            if (dt.Rows.Count >= 1)
            {
                objDrawing = new DrawingModel()
                {
                    DrawingCode  = dt.Rows[0]["DrawingCode"].ToString(),
                    MaterialName = dt.Rows[0]["MaterialName"].ToString(),
                    MaterialSpec = dt.Rows[0]["MaterialSpec"].ToString(),
                    DocIdModel   = Convert.ToInt32(dt.Rows[0]["DocIdModel"])
                };
            }
            return(objDrawing);
        }
コード例 #4
0
        //修改图号
        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;
            }
        }