Example #1
0
        /// <summary>
        /// 更新耗材
        /// </summary>
        /// <param name="inputDto">耗材信息</param>
        /// <returns></returns>
        public ReturnInfo UpdateConsumables(ConsumablesInputDto inputDto)
        {
            ReturnInfo    rInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();

            sb.Append(Helper.BasicValidate(inputDto).ToString());
            if (sb.Length == 0)
            {
                try
                {
                    Consumables consumable = _consumablesRepository.GetByID(inputDto.CID).FirstOrDefault();
                    if (consumable != null)
                    {
                        consumable.MODIFYDATE    = DateTime.Now;
                        consumable.IMAGE         = inputDto.IMAGE;
                        consumable.MODIFYUSER    = inputDto.MODIFYUSER;
                        consumable.NAME          = inputDto.NAME;
                        consumable.NOTE          = inputDto.NOTE;
                        consumable.SAFECEILING   = inputDto.SAFECEILING;
                        consumable.SAFEFLOOR     = inputDto.SAFEFLOOR;
                        consumable.SPECIFICATION = inputDto.SPECIFICATION;
                        consumable.SPQ           = inputDto.SPQ;
                        consumable.UNIT          = inputDto.UNIT;
                        _unitOfWork.RegisterDirty(consumable);
                    }

                    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);
            }
        }
Example #2
0
        /// <summary>
        /// 添加耗材
        /// </summary>
        /// <param name="inputDto">耗材信息</param>
        /// <returns></returns>
        public ReturnInfo AddConsumables(ConsumablesInputDto inputDto)
        {
            ReturnInfo    rInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();
            string        maxId = _consumablesRepository.GetMaxID();
            string        CId   = Helper.GenerateIDEx("C", maxId);

            inputDto.CID = CId;
            sb.Append(Helper.BasicValidate(inputDto).ToString());
            if (sb.Length == 0)
            {
                var consumable = Mapper.Map <ConsumablesInputDto, Consumables>(inputDto);
                consumable.CREATEDATE = DateTime.Now;
                consumable.MODIFYDATE = DateTime.Now;
                try
                {
                    _unitOfWork.RegisterNew(consumable);
                    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);
            }
        }
        public string UserId;                                       //用户编号


        #endregion

        /// <summary>
        /// 保存修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Press(object sender, EventArgs e)
        {
            try
            {
                //判断有效性
                int?Ceiling = null;
                if (!string.IsNullOrEmpty(txtCeiling.Text))
                {
                    int result;
                    if (int.TryParse(txtCeiling.Text, out result))
                    {
                        Ceiling = result;
                    }
                    else
                    {
                        throw new Exception("请输入正确的安全库存上限.");
                    }
                }
                int?Floor = null;
                if (!string.IsNullOrEmpty(txtFloor.Text))
                {
                    int result;
                    if (int.TryParse(txtFloor.Text, out result))
                    {
                        Floor = result;
                    }
                    else
                    {
                        throw new Exception("请输入正确的安全库存下限.");
                    }
                }
                int?SPQ = null;
                if (!string.IsNullOrEmpty(txtSPQ.Text))
                {
                    int result;
                    if (int.TryParse(txtSPQ.Text, out result))
                    {
                        SPQ = result;
                    }
                    else
                    {
                        throw new Exception("请输入正确的标准包装数量.");
                    }
                }
                ConsumablesInputDto consumablesInputDto = new ConsumablesInputDto()
                {
                    CID           = CID,
                    CREATEUSER    = UserId,
                    IMAGE         = ImgPicture.ResourceID,
                    MODIFYUSER    = UserId,
                    NAME          = txtName.Text,
                    NOTE          = txtNote.Text,
                    SAFECEILING   = Ceiling,
                    SAFEFLOOR     = Floor,
                    SPECIFICATION = txtSpe.Text,
                    SPQ           = SPQ,
                    UNIT          = txtUnit.Text
                };
                ReturnInfo returnInfo = _autofacConfig.consumablesService.UpdateConsumables(consumablesInputDto);
                if (returnInfo.IsSuccess)
                {
                    ShowResult = ShowResult.Yes;
                    Close();
                    Toast("修改成功.");
                }
                else
                {
                    Toast(returnInfo.ErrorInfo);
                }
            }
            catch (Exception ex)
            {
                Toast(ex.Message);
            }
        }