分享

事务案例

 CoCO-Ebook 2013-09-25

  using (System.Transactions.TransactionScope tran = new System.Transactions.TransactionScope())
        {
            try
            {
                init();
                decimal unableDraw = 0;
                if (this.RadioButton1.Checked)
                {
                    //每月还款
                    if (loan != null)
                    {
                        decimal amount = loan.Amount;
                        if (account.AvailableBalance < amount)
                        {
                            ErrorMsg("您的帐户余额不足还款");
                            return;
                        }
                        //else if (account.AvailableBalance < amount)
                        //{
                        //    amount = account.AvailableBalance;
                        //}
                        ListingLoanLog.AddListingLoanLog(loan, amount, string.Format("(共{0}/{1}次)", c, s));
                        //if (loan.IsExperience) unableDraw += loan.Principal + loan.Interest;
                    }
                }
                else if (this.RadioButton2.Checked)
                {
                    //提前还款
                    if (account.AvailableBalance < advance)
                    {
                        ErrorMsg("您的帐户余额不足还款");
                        return;
                    }

                    decimal principal = 0;
                    bool delete = false;
                    DateTime date = DateTime.MinValue;
                    s = loanList.Length;
                    for (int i = 0; i < loanList.Length; i++)
                    {
                        ListingLoan ll = loanList[i];
                        if (date == DateTime.MinValue) date = ll.CreationDate.Date.AddMonths(-1);
                        if (delete)
                        {
                            //if (loan.IsExperience) unableDraw += loan.Principal + loan.Interest;
                            ll.Delete();
                            continue;
                        }
                        if (ll.StatusId == LoanStatus.未还.GetHashCode() || ll.StatusId == LoanStatus.部分已还.GetHashCode())
                        {
                            if (ll.CreationDate.Date < DateTime.Today)
                            {
                                advance -= ll.Amount;
                                ListingLoanLog.AddListingLoanLog(ll, true, string.Format("(共{0}/{1}次)", i + 1, s));
                                //if (loan.IsExperience) unableDraw += loan.Principal + loan.Interest;
                            }
                            else
                            {
                                //if (loan.IsExperience) unableDraw += loan.Principal + loan.Interest;
                                / .Amount = ll.Amount - advance;
                                / .RemnantPrincipal = ll.ListAmount - principal;
                                / .RemnantInterest = advance - (ll.ListAmount - principal);
                                ll.Amount = 0;
                                ll.Principal = ll.ListAmount - principal;
                                ll.Interest = advance - ll.Principal;
                                ll.RemnantPrincipal = 0;
                                ll.RemnantInterest = 0;
                                DateTime nowDate = DateTime.Now;
                                / .CreationDate = nowDate;
                                ll.PaymentDate = nowDate;
                                ll.PayAmount += advance;
                                ll.StatusId = LoanStatus.提前.GetHashCode();
                                ListingLoanLog.AddListingLoanLog(ll, advance, ll.PaymentDate.Date > date.AddDays(15), string.Format("(共{0}/{0}次)", i + 1));
                                ll.Update();
                                delete = true;
                            }
                        }
                        principal += ll.Principal;
                    }
                }
                //if (unableDraw > 0) Account.ApproveUnableDraw(userId, 0 - unableDraw);
                tran.Complete();

            }
            catch (Exception ex)
            {
                tran.Dispose();
                throw new Exception(ex.Message, ex);
            }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多