コード例 #1
0
        /// <summary>
        /// 添加消费明细
        /// </summary>
        /// <param name="entity">消费明细对象</param>
        public ReturnInfo CreateRB_Rows(RB_RowsInputDto entity)
        {
            ReturnInfo    RInfo        = new ReturnInfo();
            StringBuilder sb           = new StringBuilder();
            string        ValidateInfo = Helper.ValidateRB_RowsInputDto(entity);

            sb.Append(ValidateInfo);
            if (string.IsNullOrEmpty(ValidateInfo))
            {
                try
                {
                    RB_Rows r = Mapper.Map <RB_RowsInputDto, RB_Rows>(entity);
                    r.R_CreateDate = DateTime.Now;
                    _unitOfWork.RegisterNew(r);
                    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);
            }
        }
コード例 #2
0
 /// <summary>
 /// 创建消费记录
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSave_Press(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(RBCC))     //判断成本中心是否已经选择
         {
             throw new Exception("请选择成本中心!");
         }
         else
         {
             RBInputDto RB = new RBInputDto(); //定义一个新的报销单
             RB.CC_ID   = RBCC;                //成本中心编号
             RB.RB_Note = this.TxtNote.Text;   //报销单备注
             //将选中的消费记录行项添加到报销单中
             foreach (ListViewRow Row in listRBRowData.Rows)
             {
                 frmRBCreateLayout layout = Row.Control as frmRBCreateLayout;
                 //如果当前行项消费记录被选中
                 if (layout.checkNum() == 1)
                 {
                     //把选中行的消费记录行项的数据添加到报销单中
                     int             RID      = layout.getID();
                     RB_RowsDto      RBRow    = AutofacConfig.rBService.GetRowByRowID(RID);
                     RB_RowsInputDto NewRBRow = new RB_RowsInputDto();
                     NewRBRow.R_ID          = RBRow.R_ID;          //消费记录编号
                     NewRBRow.R_TypeID      = RBRow.R_TypeID;      //消费类型编号
                     NewRBRow.R_Amount      = RBRow.R_Amount;      //消费记录金额
                     NewRBRow.R_Note        = RBRow.R_Note;        //消费记录日期
                     NewRBRow.R_ConsumeDate = RBRow.R_ConsumeDate; //消费日期
                     RB.RB_Rows.Add(NewRBRow);
                 }
             }
             RB.RB_CreateUser = Client.Session["U_ID"].ToString();               //创建用户
             ReturnInfo r = AutofacConfig.rBService.CreateRB(RB);
             if (r.IsSuccess == true)
             {
                 //如果数据库添加报销记录成功
                 this.ShowResult = ShowResult.Yes;
                 this.Close();
                 Toast("报销提交成功!");
             }
             else
             {
                 throw new Exception(r.ErrorInfo);
             }
         }
     }
     catch (Exception ex)
     {
         Toast(ex.Message);
     }
 }
コード例 #3
0
        /// <summary>
        /// 更新消费明细
        /// </summary>
        /// <param name="entity">消费明细对象</param>
        public ReturnInfo UpdateRB_Rows(RB_RowsInputDto entity)
        {
            ReturnInfo    RInfo        = new ReturnInfo();
            StringBuilder sb           = new StringBuilder();
            string        ValidateInfo = Helper.ValidateRB_RowsInputDto(entity);

            sb.Append(ValidateInfo);
            if (string.IsNullOrEmpty(ValidateInfo))
            {
                RB_Rows r = _rbrowsRepository.GetByID(entity.R_ID).FirstOrDefault();
                try
                {
                    if (r != null)
                    {
                        r.R_Amount      = entity.R_Amount;
                        r.R_ConsumeDate = entity.R_ConsumeDate;
                        r.R_Note        = entity.R_Note;
                        r.R_TypeID      = entity.R_TypeID;
                        r.RB_ID         = entity.RB_ID;
                        _unitOfWork.RegisterDirty(r);
                        bool result = _unitOfWork.Commit();
                        RInfo.IsSuccess = result;
                        RInfo.ErrorInfo = sb.ToString();
                        return(RInfo);
                    }
                    else
                    {
                        RInfo.IsSuccess = false;
                        RInfo.ErrorInfo = "找不到该消费明细!";
                        return(RInfo);
                    }
                }
                catch (Exception ex)
                {
                    _unitOfWork.RegisterClean(r);
                    _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);
            }
        }
コード例 #4
0
ファイル: frmRBEdit.cs プロジェクト: ZDesirer/SmoONE
 /// <summary>
 /// 保存报销编辑
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSave_Press(object sender, EventArgs e)
 {
     try
     {
         RBInputDto ReimBur = new RBInputDto();
         ReimBur.RB_Rows = new List <RB_RowsInputDto>();
         ReimBur.RB_ID   = this.lblRBNO.Text;    //报销单编号
         ReimBur.CC_ID   = RBCC;                 //成本中心编号
         ReimBur.RB_Note = this.TxtNote.Text;    //备注
         //消费记录行项更改
         foreach (ListViewRow Row in listRBRowData.Rows)
         {
             //判断消费记录是否选中
             frmConsumption1Layout layout = Row.Control as frmConsumption1Layout;
             if (layout.checkNum() == 1)
             {
                 //把选中行的Row的数据添加到报销单中
                 int             RID      = layout.getID();
                 RB_RowsDto      RBRow    = AutofacConfig.rBService.GetRowByRowID(RID);
                 RB_RowsInputDto NewRBRow = new RB_RowsInputDto();
                 NewRBRow.R_ID          = RBRow.R_ID;
                 NewRBRow.R_TypeID      = RBRow.R_TypeID;
                 NewRBRow.R_Amount      = RBRow.R_Amount;
                 NewRBRow.R_Note        = RBRow.R_Note;
                 NewRBRow.R_ConsumeDate = RBRow.R_ConsumeDate;
                 ReimBur.RB_Rows.Add(NewRBRow);
             }
         }
         ReturnInfo r = AutofacConfig.rBService.UpdateRB(ReimBur);       //将报销记录更新到数据库中
         if (r.IsSuccess == true)
         {
             this.ShowResult = ShowResult.Yes;
             this.Close();
             Toast("报销提交成功!");
         }
         else
         {
             throw new Exception(r.ErrorInfo);
         }
     }
     catch (Exception ex)
     {
         Toast(ex.Message);
     }
 }
コード例 #5
0
        /// <summary>
        /// 消费记录明细验证
        /// </summary>
        /// <param name="entity">消费记录明细对象</param>
        public static string ValidateRB_RowsInputDto(RB_RowsInputDto entity)
        {
            //基础验证
            StringBuilder sb = BasicValidate <RB_RowsInputDto>(entity);

            //额外验证
            if (entity.R_Amount <= 0)
            {
                sb.Append("金额必须大于0!");
            }
            if (!Regex.IsMatch(entity.R_Amount.ToString(), @"^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$"))
            {
                sb.Append("金额格式错误,至多2位小数!");
            }
            if (entity.R_ConsumeDate != null)
            {
                if (entity.R_ConsumeDate > DateTime.Now)
                {
                    sb.Append("消费时间不能为未来时间!");
                }
            }

            return(sb.ToString());
        }
コード例 #6
0
ファイル: frmRowsCreate.cs プロジェクト: ZDesirer/SmoONE
 /// <summary>
 /// 创建消费记录
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSave_Press(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(this.txtMoney.Text))
         {
             throw new Exception("请输入消费金额!");
         }
         else
         {
             if (System.Text.RegularExpressions.Regex.IsMatch(txtMoney.Text.Trim(), @"^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$") == false)
             {
                 throw new Exception("金额必须为大于0的数字!");
             }
         }
         if (string.IsNullOrEmpty(TYPEID))
         {
             throw new Exception("请选择消费类别!");
         }
         if (string.IsNullOrEmpty(this.txtNote.Text))
         {
             throw new Exception("请输入备注!");
         }
         RB_RowsInputDto Row = new RB_RowsInputDto();
         Row.R_Amount      = decimal.Parse(this.txtMoney.Text); //消费金额
         Row.R_Note        = this.txtNote.Text;                 //明细
         Row.R_TypeID      = TYPEID;                            //消费类型
         Row.R_ConsumeDate = this.DatePicker.Value;             //消费记录日期
         if (string.IsNullOrWhiteSpace(ID) == false)
         {
             int RID = Convert.ToInt32(ID);       //将ID转换成Int类型
             Row.R_ID = Convert.ToInt32(ID);
             ReturnInfo r = AutofacConfig.rBService.UpdateRB_Rows(Row);
             if (r.IsSuccess == true)
             {
                 this.ShowResult = ShowResult.Yes;
                 this.Close();
                 Toast("消费记录修改成功");
             }
             else
             {
                 throw new Exception(r.ErrorInfo);
             }
         }
         else
         {
             Row.R_CreateUser = Client.Session["U_ID"].ToString();                //创建用户
             ReturnInfo r = AutofacConfig.rBService.CreateRB_Rows(Row);           //数据库创建消费记录
             if (r.IsSuccess == true)
             {
                 this.ShowResult = ShowResult.Yes;
                 this.Close();
                 Toast("消费记录提交成功!");
             }
             else
             {
                 throw new Exception(r.ErrorInfo);
             }
         }
     }
     catch (Exception ex)
     {
         Toast(ex.Message);
     }
 }