Exemple #1
0
        /// <summary>
        /// 成本中心验证
        /// </summary>
        /// <param name="entity">成本中心对象</param>
        public static string ValidateCCInputDto(CCInputDto entity)
        {
            //基础验证
            StringBuilder sb = BasicValidate <CCInputDto>(entity);

            //额外验证(开始小于结束)
            if (!string.IsNullOrEmpty(entity.CC_StartDate.ToString()) && !string.IsNullOrEmpty(entity.CC_EndDate.ToString()))
            {
                if (entity.CC_StartDate > entity.CC_EndDate)
                {
                    sb.Append("开始日期不能大于结束日期!");
                }
            }
            if (entity.CC_Amount < 0)
            {
                sb.Append("预算金额必须为正!");
            }
            if (!Regex.IsMatch(entity.CC_Amount.ToString(), @"^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$"))
            {
                sb.Append("预算金额格式错误,至多2位小数!");
            }
            if (!string.IsNullOrEmpty(entity.CC_LiableMan))
            {
                if (!userRepository.IsExists(entity.CC_LiableMan))
                {
                    sb.Append("责任人" + entity.CC_LiableMan + "不在用户表中!");
                }
            }
            return(sb.ToString());
        }
Exemple #2
0
        /// <summary>
        /// 添加成本中心
        /// </summary>
        /// <param name="entity">成本中心对象</param>
        public ReturnInfo AddCostCenter(CCInputDto entity)
        {
            ReturnInfo    RInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();
            string        MaxID = _costCenterRepository.GetMaxID();
            string        NowID = Helper.GenerateIDEx("CC", MaxID);

            entity.CC_ID = NowID;
            //entity.CC_IsActive= 1;
            string ValidateInfo = Helper.ValidateCCInputDto(entity);

            sb.Append(ValidateInfo);
            if (string.IsNullOrEmpty(ValidateInfo))
            {
                try
                {
                    CostCenter c = Mapper.Map <CCInputDto, CostCenter>(entity);
                    c.CC_CreateDate = DateTime.Now;
                    if (entity.CC_EndDate != null)
                    {
                        c.CC_EndDate = (DateTime)entity.CC_EndDate;
                    }
                    c.CC_IsActive = (int)IsActive.激活;
                    if (entity.CC_StartDate != null)
                    {
                        c.CC_StartDate = (DateTime)entity.CC_StartDate;
                    }
                    c.CC_UpdateDate = DateTime.Now;
                    c.CC_UsedAmount = 0;

                    string MaxID2 = _costCenterRepository.GetMaxID();
                    string NowID2 = Helper.GenerateIDEx("CC", MaxID2);
                    c.CC_ID = NowID2;
                    _unitOfWork.RegisterNew(c);
                    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);
            }
        }
 /// <summary>
 /// 保存
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtCC_Name.Text.Trim().Length <= 0)
         {
             throw new Exception("请输入成本中心名称!");
         }
         if (string.IsNullOrEmpty(type) == true)
         {
             throw new Exception("请输入类型!");
         }
         if (txtAmount.Text.Trim().Length <= 0)
         {
             throw new Exception("金额必须大于0!");
         }
         else
         {
             if (System.Text.RegularExpressions.Regex.IsMatch(txtAmount.Text.Trim(), @"^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$") == false)
             {
                 throw new Exception("金额必须为大于0的数字!");
             }
         }
         if (string.IsNullOrWhiteSpace(liableMan) == true)
         {
             throw new Exception("请输入责任人!");
         }
         if (string.IsNullOrWhiteSpace(CTempID) == true)
         {
             throw new Exception("请输入成本中心类型模板!");
         }
         if (string.IsNullOrEmpty(D_ID) == true)
         {
             throw new Exception("该责任人未分配部门,请去分配部门!");
         }
         //更新成本中心数据赋值
         CCInputDto cc = new CCInputDto();
         cc.CC_Name         = txtCC_Name.Text.Trim();
         cc.CC_TypeID       = type;
         cc.CC_StartDate    = dpkStartDate.Value;
         cc.CC_EndDate      = dpkEndDate.Value;
         cc.CC_Amount       = Convert.ToDecimal(txtAmount.Text.Trim());
         cc.CC_LiableMan    = liableMan;
         cc.CC_DepartmentID = D_ID;
         cc.CC_TemplateID   = CTempID;
         ReturnInfo result;
         if (string.IsNullOrEmpty(CCID) == false)
         {
             cc.CC_ID         = CCID;
             cc.CC_UpdateUser = Client.Session["U_ID"].ToString();
             //更新成本中心
             result = AutofacConfig.costCenterService.UpdateCostCenter(cc);
         }
         else
         {
             cc.CC_CreateUser = Client.Session["U_ID"].ToString();
             //创建成本中心
             result = AutofacConfig.costCenterService.AddCostCenter(cc);
         }
         //如果返回true,则创建或更新成本中心成功,否则失败并抛出错误
         if (result.IsSuccess == false)
         {
             throw new Exception(result.ErrorInfo);
         }
         else
         {
             ShowResult = ShowResult.Yes;
             //if (string.IsNullOrEmpty(CCID) == true)
             //{
             Close();
             //}
             Toast("成本中心提交成功!", ToastLength.SHORT);
         }
     }
     catch (Exception ex)
     {
         Toast(ex.Message, ToastLength.SHORT);
     }
 }
Exemple #4
0
        /// <summary>
        /// 更新成本中心
        /// </summary>
        /// <param name="entity">成本中心对象</param>
        public ReturnInfo UpdateCostCenter(CCInputDto entity)
        {
            ReturnInfo    RInfo        = new ReturnInfo();
            StringBuilder sb           = new StringBuilder();
            string        ValidateInfo = Helper.ValidateCCInputDto(entity);

            if (string.IsNullOrEmpty(ValidateInfo))
            {
                CostCenter cc = _costCenterRepository.GetByID(entity.CC_ID).FirstOrDefault();
                if (cc != null)
                {
                    try
                    {
                        #region 如果字段非空或0,则更新对应字段
                        cc.CC_UpdateDate = DateTime.Now;
                        if (entity.CC_Amount > 0)
                        {
                            cc.CC_Amount = entity.CC_Amount;
                        }
                        if (entity.CC_DepartmentID != null)
                        {
                            cc.CC_DepartmentID = entity.CC_DepartmentID;
                        }
                        if (entity.CC_EndDate != null)
                        {
                            cc.CC_EndDate = (DateTime)entity.CC_EndDate;
                        }
                        //cc.CC_IsActive = entity.CC_IsActive;
                        if (entity.CC_LiableMan != null)
                        {
                            cc.CC_LiableMan = entity.CC_LiableMan;
                        }
                        if (entity.CC_Name != null)
                        {
                            cc.CC_Name = entity.CC_Name;
                        }
                        if (entity.CC_StartDate != null)
                        {
                            cc.CC_StartDate = (DateTime)entity.CC_StartDate;
                        }
                        if (entity.CC_TemplateID != null)
                        {
                            cc.CC_TemplateID = entity.CC_TemplateID;
                        }
                        if (entity.CC_TypeID != null)
                        {
                            cc.CC_TypeID = entity.CC_TypeID;
                        }
                        if (entity.CC_UpdateUser != null)
                        {
                            cc.CC_UpdateUser = entity.CC_UpdateUser;
                        }
                        #endregion
                        _unitOfWork.RegisterDirty(cc);
                        bool result = _unitOfWork.Commit();
                        RInfo.IsSuccess = result;
                        RInfo.ErrorInfo = sb.ToString();
                        return(RInfo);
                    }
                    catch (Exception ex)
                    {
                        _unitOfWork.RegisterClean(cc);
                        _unitOfWork.Rollback();
                        sb.Append(ex.Message);
                        RInfo.IsSuccess = false;
                        RInfo.ErrorInfo = sb.ToString();
                        return(RInfo);
                    }
                }
                else
                {
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = "找不到该成本中心!";
                    return(RInfo);
                }
            }
            else
            {
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }