protected void btnAddNewLoan_Click(object sender, EventArgs e) { try { LoansBLL bll = new LoansBLL(); if (txtBoxAddMaturityDate.SelectedDate.ToString() != "" && txtBoxAddSigningDate.SelectedDate.ToString() != "") { DateTime dtMaturity = Convert.ToDateTime(txtBoxAddMaturityDate.SelectedDate.Value); DateTime dtSigning = Convert.ToDateTime(txtBoxAddSigningDate.SelectedDate.Value); SettingsBLL settingBL = new SettingsBLL(); Setting setting = settingBL.GetSettingyear("Loan Year Settings"); if (setting != null) { TimeSpan ts = dtMaturity - dtSigning; int differenceYear = Convert.ToInt32((ts.TotalDays) / 365); int year = Convert.ToInt16(setting.Value); if (dtMaturity.Year > dtSigning.Year && (differenceYear) > year) { lblMessage.Text = "Maturity Date is not Valid"; lblMessage.Visible = true; return; } } } else { //lblMessage.Text = "Enter the Details"; //lblMessage.Visible = true; RadWindowManager1.RadAlert("Maturity Date and Signing Date required", 300, 150, "realedge associates", "alertCallBackFn"); return; } // check to see either the loan has been added or updated bool isNewLoan = false; Loans loan = new Loans(); if (!string.IsNullOrEmpty(hfLoanID.Value)) { isNewLoan = false; loan.ID = Convert.ToInt32(hfLoanID.Value); LogActivity("Update the Loan", "Update the existing loan", string.Empty); } else { isNewLoan = true; LogActivity("New Loan Added", "Add the new loan", string.Empty); } List<RatingDetails> ratingDetails = new List<RatingDetails>(); ratingDetails = ShowCheckedNodes(tvCreditRating); foreach (var item in ratingDetails) { switch (item.agencyName) { case "Moody's": loan.CreditRatingModys = item.rating; break; case "S&P's": loan.CreditRatingSPs = item.rating; break; case "Fitch": loan.CreditRatingFitch = item.rating; break; case "ING": loan.CreditRatingING = item.rating; break; default: break; } } loan.CodeName = ddlAddLoanCode.Text; loan.Borrower = ddlBorrower.Text; loan.Sector = ddlSector.SelectedValue; //txtBoxAddSector.Text; loan.Signing_Date = txtBoxAddSigningDate.SelectedDate.Value.ToShortDateString(); loan.Maturity_Date = txtBoxAddMaturityDate.SelectedDate.Value.ToShortDateString(); loan.FixedOrFloating = ddlAddFixedOrFloating.SelectedValue; loan.Margin = txtBoxAddMargin.Text; loan.Currency = ddlAddCurrency.SelectedValue; loan.Country = ddlCountry.SelectedValue; loan.CouponFrequency = ddlAddCouponFrequency.SelectedValue; loan.Gurantor = txtGurantor.Text; loan.Grid = txtGrid.Text; loan.SummitCreditEntity = txtSummitCredit.Text; if (txtBoxFacilitySize.Text != string.Empty) { loan.FacilitySize = Convert.ToDecimal(txtBoxFacilitySize.Text).ToString("N"); } loan.Bilateral = ddlAddBilateral.SelectedValue == "Yes"; loan.Amortizing = ddlAmortizing.SelectedValue; loan.PP = txtPP.Text; // loan.CreditRating = txtCRating.Text; loan.StructureID = txtStructureID.Text; //Coupon Date and Notional are missing. if (txtCouponDate.SelectedDate != null) { loan.CouponDate = txtCouponDate.SelectedDate.Value.ToShortDateString(); } loan.Notional = Convert.ToDecimal(txtNotional.Text).ToString("N").Trim(); if (ddlAmortizing.SelectedValue == "Yes") { if (txtAmortisationsStartDate.SelectedDate != null) { loan.AmortisationsStartPoint = txtAmortisationsStartDate.SelectedDate.Value.ToShortDateString(); } if (txtAmortisations.Text != string.Empty) { loan.NoOfAmortisationPoint = Convert.ToInt16(txtAmortisations.Text); } } else { loan.Amortizing = "Yes"; DateTime cpnDT; if (txtCouponDate.SelectedDate.ToString() == string.Empty) { cpnDT = AddBusinessDays(DateTime.Now, 10); loan.AmortisationsStartPoint = cpnDT.ToShortDateString(); } else { cpnDT = Convert.ToDateTime(txtCouponDate.SelectedDate); loan.AmortisationsStartPoint = txtCouponDate.SelectedDate.Value.ToShortDateString(); } loan.NoOfAmortisationPoint = 10; LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); DateTime tradeDate = DateTime.Now; DataTable dtSchedule = loanScheduleBL.GenerateTable(15, Convert.ToInt16(loan.NoOfAmortisationPoint), Convert.ToDateTime(loan.AmortisationsStartPoint), loan.CouponFrequency.ToString(), loan.Notional.ToString(), Convert.ToDateTime(loan.Maturity_Date), Convert.ToDateTime(loan.CouponDate), Convert.ToDecimal(loan.Margin), Convert.ToString(loan.Currency), Convert.ToDateTime(tradeDate), AddBusinessDays(Convert.ToDateTime(tradeDate), 10)); Session["LoanSchedule"] = dtSchedule; } DAL.Login login = Session["LogedInUser"] as DAL.Login; loan.CreatedBy = login.Name; loan.LastEdited = DateTime.Now; switch (_operation) { case "Add": if (bll.CheckForLoanCode(ddlAddLoanCode.Text.Trim())) { bll.SaveLoan(loan); login = Session["LogedInUser"] as DAL.Login; LoanHistory loanHistory = new LoanHistory(); LoanHistoryBL historyBL = new LoanHistoryBL(); loanHistory.Action = "Add"; loanHistory.LoanName = loan.CodeName; loanHistory.UserName = login.Name; loanHistory.LastModified = DateTime.Now; historyBL.SaveHistory(loanHistory); // lblAddLoanMessage.Visible = true; on 7-1 CalculateFactors(); LoanScheduleBL loanScheduleBL = new LoanScheduleBL(); if (Session["LoanSchedule"] != null) { dt1 = (DataTable)Session["LoanSchedule"]; } foreach (DataRow dr in dt1.Rows) { LoanSchedule loanSchedule = new LoanSchedule(); loanSchedule.LoanID = loan.ID; loanSchedule.StartDate = Convert.ToDateTime(dr["StartDate"]); loanSchedule.EndDate = Convert.ToDateTime(dr["EndDate"]); loanSchedule.CoupFrac = Convert.ToDecimal(dr["CoupFrac"]); loanSchedule.Notation = Convert.ToDecimal(dr["Notation"]); loanSchedule.Amortisation = Convert.ToDecimal(dr["Amortisation"]); loanSchedule.Factor = Convert.ToDecimal(dr["Factor"]); loanSchedule.Spread = Convert.ToDecimal(dr["Spread"]); loanSchedule.AllInRate = Convert.ToDecimal(dr["AllInRate"]); loanSchedule.CouponPaymentDate = Convert.ToDateTime(dr["CouponPaymentDate"]); loanSchedule.RiskFreeDP1 = Convert.ToDecimal(dr["RiskFreeDP1"]); loanSchedule.RiskFreeDP2 = Convert.ToDecimal(dr["RiskFreeDP2"]); loanSchedule.FloatingRate = Convert.ToDecimal(dr["FloatingRate"]); loanSchedule.Interest = Convert.ToDecimal(dr["Interest"]); loanSchedule.Days = Convert.ToInt16(dr["Days"]); loanSchedule.AmortisationInt = Convert.ToDecimal(dr["AmortisationInt"]); loanSchedule.CreatedOn = DateTime.UtcNow; loanScheduleBL.SaveLoanSchedule(loanSchedule); } //lblMessage.Text = "Loan added Successfully"; //lblMessage.Visible = true; RadWindowManager1.RadAlert(ddlAddLoanCode.Text + " added Successfully", 300, 150, "realedge associates", "alertCallBackFn"); } else { InsertDuplicateLoan(); } break; case "Edit": bll.EditLoan(loan, Convert.ToInt16(Session["EditLoanID"]), 2); login = Session["LogedInUser"] as DAL.Login; LoanHistory loanHis = new LoanHistory(); LoanHistoryBL historiesBL = new LoanHistoryBL(); loanHis.Action = "Edit"; loanHis.LoanName = loan.CodeName; loanHis.UserName = login.Name; loanHis.LastModified = DateTime.Now; historiesBL.SaveHistory(loanHis); CalculateFactors(); LoanScheduleBL scheduleBL = new LoanScheduleBL(); if (Session["LoanSchedule"] != null) { dt1 = (DataTable)Session["LoanSchedule"]; } scheduleBL.EditSchedule(Convert.ToInt16(Session["EditLoanID"]), dt1); // Clear(); //lblMessage.Text = "Loan updated Successfully"; //lblMessage.Visible = true; RadWindowManager1.RadAlert(ddlAddLoanCode.Text + " updated Successfully", 300, 150, "realedge associates", "alertCallBackFn"); //lblConfirm.Text = "Are you sure you want to add this loan to database?"; //_operation = "Add"; //Session.Remove("EditLoanID"); break; default: break; } // all loans List<Loans> allLoans = bll.GetLoans(); BindLoansTab(allLoans); BindLoansData(); BindHistoricalQuotesAndTradesTab(); // check to see if the loan has been added or updated if (isNewLoan) { ApplicationHub.NewLoanAdded(loan); } else { ApplicationHub.RefreshLoans(allLoans); } hdnSaved.Value = "Y"; BindLoanCode(); } catch (Exception ex) { //lblAddLoanMessage.Visible = true; on 7-1 //lblAddLoanMessage.Text = "Loan failed to save"; on 7-1 // lblMessage.Text = "Loan failed to save"; lblMessage.Text = ex.Message; lblMessage.Text = ex.InnerException.Message; lblMessage.Visible = true; LogActivity("New Loan(Unsuccessfull)", "Unable to save the loan", ex.Message); } }
public void InsertRecord(string param, int flag) { try { string[] strSplit = param.Split(','); QuotesAndTrades model = new QuotesAndTrades(); if (!string.IsNullOrEmpty(strSplit[0].Remove(0, 10))) { model.BidPrice = Convert.ToDecimal(strSplit[0].Remove(0, 10)); } if (!string.IsNullOrEmpty(strSplit[1].Remove(0, 10))) { string strBidSpread = Convert.ToDecimal(strSplit[1].Remove(0, 10)).ToString("0.00"); model.BidSpread = Convert.ToDecimal(strBidSpread); } model.CounterParty = strSplit[2].Remove(0, 13); model.LoanName = strSplit[3].Remove(0, 9); if (!string.IsNullOrEmpty(strSplit[4].Remove(0, 11))) { model.OfferPrice = Convert.ToDecimal(strSplit[4].Remove(0, 11)); } if (!string.IsNullOrEmpty(strSplit[5].Remove(0, 12))) { string strOfferSpread = Convert.ToDecimal(strSplit[5].Remove(0, 12)).ToString("0.00"); model.OfferSpread = Convert.ToDecimal(strOfferSpread); } // model.MarketValue model.TimeStamp = DateTime.Now; if (strSplit[6].Remove(0, 9) == "true") model.Traded = true; else model.Traded = false; if (strSplit[3].Remove(0, 9) != string.Empty) { LoansBLL loanBLL = new LoansBLL(); model.Country = loanBLL.GetCoutryIDbyLoanID(strSplit[3].Remove(0, 9)); } if (!string.IsNullOrEmpty(strSplit[12].Remove(0, 10))) { string str = strSplit[12].Remove(0, 10); DateTime tradeDate = DateTime.Now; if (str.Contains('-')) { string[] strSpl = str.Split('-'); string datetime = strSpl[1] + "/" + strSpl[0] + "/" + strSpl[2] + " " + strSpl[3] + ":" + strSpl[4] + ":" + strSpl[5]; tradeDate = Convert.ToDateTime(datetime); } else tradeDate = Convert.ToDateTime(str); model.TradedDate = Convert.ToDateTime(tradeDate); } if (!string.IsNullOrEmpty(strSplit[13].Remove(0, 12))) { string avgLifeDisc = Convert.ToDecimal(strSplit[13].Remove(0, 12)).ToString("0.00"); model.AvgLifeDisc = Convert.ToDecimal(avgLifeDisc); } if (!string.IsNullOrEmpty(strSplit[14].Remove(0, 16))) { string avgLifeRiscDisc = Convert.ToDecimal(strSplit[14].Remove(0, 16)).ToString("0.00"); model.AvgLifeRiskDisc = Convert.ToDecimal(avgLifeRiscDisc); } if (!string.IsNullOrEmpty(strSplit[15].Remove(0, 15))) { string avgLifeNonDisc = Convert.ToDecimal(strSplit[15].Remove(0, 15)).ToString("0.00"); model.AvgLifeNonDisc = Convert.ToDecimal(avgLifeNonDisc); } if (!string.IsNullOrEmpty(strSplit[16].Remove(0, 15))) { DateTime settlementDate = Convert.ToDateTime(strSplit[16].Remove(0, 15)); model.SettlementDate = settlementDate; } if (!string.IsNullOrEmpty(strSplit[17].Remove(0, 7))) { string margin = Convert.ToString(strSplit[17].Remove(0, 7)); model.Margin = margin; } if (!string.IsNullOrEmpty(strSplit[18].Remove(0, 9))) { string notional = Convert.ToDecimal(Convert.ToString(strSplit[18].Remove(0, 9))).ToString("0.00"); model.MarketValue = Convert.ToDecimal(notional); } if (!string.IsNullOrEmpty(strSplit[19].Remove(0, 9))) { string averageLife = Convert.ToDecimal(Convert.ToString(strSplit[19].Remove(0, 12).Replace('}', ' '))).ToString("0.00"); model.AverageLife = Convert.ToDecimal(averageLife); } // model.CountryID = Convert.ToInt32(ddlRegionA.SelectedValue); List<QuotesAndTrades> lst = new List<QuotesAndTrades>(); lst.Add(model); QuotesAndTradesBLL bll = new QuotesAndTradesBLL(); bll.AddImportedQuotesAndTrades(lst); BindHistoricalQuotesAndTradesTab(); // broadcast that quote and trade has been added ApplicationHub.NewQuotesAndTradeAdded(model); if (string.IsNullOrEmpty(hfSelectedLoanA.Value)) { // Add the Loans as well Loans loanModel = new Loans(); //loanModel.Amortizing //loanModel.Bilateral loanModel.CodeName = strSplit[3].Remove(0, 9); //loanModel.Country loanModel.CouponFrequency = strSplit[7].Remove(0, 8); loanModel.Currency = strSplit[8].Remove(0, 9); //loanModel.FacilitySize loanModel.Margin = strSplit[9].Remove(0, 9); // loanModel.Margin = strSplit[10].Remove(0, 8); loanModel.Maturity_Date = strSplit[11].Remove(0, 8); //loanModel.Sector loanModel.Signing_Date = strSplit[12].Remove(0, 10).ToString().Trim(); // Persist in database LoansBLL loanBll = new LoansBLL(); if (loanBll.CheckForLoanCode(strSplit[3].Remove(0, 9).Trim())) { loanBll.SaveLoan(loanModel); //new loan has been added. //Broadcast it ApplicationHub.NewLoanAdded(loanModel); BindLoansTab(); ShowMessage("Message", "Quote and Loan added Successfully"); } else { int loanID = loanBll.GetLoanByCode(strSplit[3].Remove(0, 9)).ID; loanBll.EditLoan(loanModel, loanID, 1); //by nidhi for update the existing loan. DuplicateLoan duplicateLoan = new DuplicateLoan(); //loanModel.Amortizing //loanModel.Bilateral duplicateLoan.CodeName = strSplit[3].Remove(0, 9); //loanModel.Country duplicateLoan.CouponFrequency = strSplit[7].Remove(0, 8); duplicateLoan.Currency = strSplit[8].Remove(0, 9); //loanModel.FacilitySize duplicateLoan.FixedOrFloating = strSplit[9].Remove(0, 9); duplicateLoan.Margin = strSplit[10].Remove(0, 8); duplicateLoan.Maturity_Date = strSplit[11].Remove(0, 8); //loanModel.Sector duplicateLoan.Signing_Date = strSplit[12].Remove(0, 10).ToString().Trim(); loanBll.SaveDuplicateLoan(duplicateLoan); } } hdnQuoteTemp.Value = "N"; ShowMessage("Message", "Quote and Loan added Successfully"); switch (flag) { case 1: LogActivity("Quote and Loan A added", "Add the quote and trade on compact view A", string.Empty); break; case 2: LogActivity("Quote and Loan B added", "Add the quote and trade on compact view B", string.Empty); break; case 3: LogActivity("Quote and Loan C added", "Add the quote and trade on compact view C", string.Empty); break; default: break; } } catch (Exception) { } }