Пример #1
0
        private AutofacConfig _autofacConfig = new AutofacConfig(); //调用配置类
        #endregion

        /// <summary>
        /// 添加资产模板
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Press(object sender, EventArgs e)
        {
            try
            {
                if (btnType.Tag == null)
                {
                    throw new Exception("请选择类别.");
                }
                decimal?price = null;

                if (!string.IsNullOrEmpty(txtPrice.Text))
                {
                    decimal p2;
                    if (!decimal.TryParse(txtPrice.Text, out p2))
                    {
                        throw new Exception("请输入正确的价格.");
                    }
                    else
                    {
                        price = p2;
                    }
                }

                AssTemplateInputDto assTemplateInputDto = new AssTemplateInputDto
                {
                    IMAGE         = ImgPicture.ResourceID,
                    NAME          = txtName.Text,
                    NOTE          = txtNote.Text,
                    PRICE         = price,
                    SPECIFICATION = txtSpe.Text,
                    TYPEID        = btnType.Tag.ToString(),
                    UNIT          = txtUnit.Text,
                    VENDOR        = txtVendor.Text
                };
                ReturnInfo returnInfo = _autofacConfig.SettingService.AddAssTemplate(assTemplateInputDto);
                if (returnInfo.IsSuccess)
                {
                    ShowResult = ShowResult.Yes;
                    Close();
                    Toast("添加成功.资产模板编号为" + returnInfo.ErrorInfo);
                }
                else
                {
                    Toast(returnInfo.ErrorInfo);
                }
            }
            catch (Exception ex)
            {
                Toast(ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// 修改资产模板
        /// </summary>
        /// <param name="inputDto">资产模板信息</param>
        /// <returns></returns>
        public ReturnInfo UpdateAssTemplate(AssTemplateInputDto inputDto)
        {
            ReturnInfo    RInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();
            //产生资产编号
            string ValidateInfo = Helper.BasicValidate(inputDto).ToString();

            sb.Append(ValidateInfo);
            if (sb.Length == 0)
            {
                try
                {
                    AssTemplate assets = _assTemplateRepository.GetById(inputDto.TEMPLATEID).FirstOrDefault();
                    if (assets != null)
                    {
                        assets.IMAGE         = inputDto.IMAGE;
                        assets.NAME          = inputDto.NAME;
                        assets.NOTE          = inputDto.NOTE;
                        assets.PRICE         = inputDto.PRICE;
                        assets.SPECIFICATION = inputDto.SPECIFICATION;
                        assets.TYPEID        = inputDto.TYPEID;
                        assets.UNIT          = inputDto.UNIT;
                        assets.VENDOR        = inputDto.VENDOR;
                        _unitOfWork.RegisterDirty(assets);
                    }

                    bool result = _unitOfWork.Commit();
                    RInfo.IsSuccess = result;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
                catch (Exception ex)
                {
                    _unitOfWork.Rollback();
                    sb.Append(ex.Message);
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
            }
            else
            {
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }
Пример #3
0
        /// <summary>
        /// 添加资产模板
        /// </summary>
        /// <param name="inputDto">资产模板信息</param>
        /// <returns></returns>
        public ReturnInfo AddAssTemplate(AssTemplateInputDto inputDto)
        {
            ReturnInfo    RInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();

            if (string.IsNullOrEmpty(inputDto.TEMPLATEID))
            {
                string MaxId = _assTemplateRepository.GetMaxId();
                string atId  = Helper.GenerateIDEx("AT", MaxId);
                //产生资产编号
                inputDto.TEMPLATEID = atId;
            }
            string ValidateInfo = Helper.BasicValidate(inputDto).ToString();

            sb.Append(ValidateInfo);
            if (sb.Length == 0)
            {
                try
                {
                    AssTemplate assets = Mapper.Map <AssTemplateInputDto, AssTemplate>(inputDto);
                    _unitOfWork.RegisterNew(assets);

                    bool result = _unitOfWork.Commit();
                    RInfo.IsSuccess = result;
                    RInfo.ErrorInfo = inputDto.TEMPLATEID;
                    return(RInfo);
                }
                catch (Exception ex)
                {
                    _unitOfWork.Rollback();
                    sb.Append(ex.Message);
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
            }
            else
            {
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }