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); }
|