Exemplo n.º 1
0
 public List<Loans> BindLoansData()
 {
     LoansBLL bll = new LoansBLL();
     List<Loans> lst = bll.GetLoans();
     PopulateLoanGrid = lst;
     return lst;
 }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        private void BindLoansTab(List<Loans> lst = null)
        {
            if (lst == null)
            {
                LoansBLL bll = new LoansBLL();
                lst = bll.GetLoans();
            }

            //grdLoans.DataSource = lst;
            //grdLoans.DataBind();
        }
Exemplo n.º 4
0
        protected void grdQuotesAndTrades_FilterCheckListItemsRequested(object sender, GridFilterCheckListItemsRequestedEventArgs e)
        {
            DataTable data = new DataTable();

            switch (e.Column.DataField)
            {
                case "LoanName":
                    data.Columns.Add("CodeName");
                    LoansBLL loansBLL = new LoansBLL();
                    List<Loans> loans = loansBLL.GetLoans();

                    for (int i = 0; i < loans.Count - 1; i++)
                    {
                        data.Rows.Add(loans[i].CodeName);
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "CodeName";
                    e.ListBox.DataTextField = "CodeName";
                    e.ListBox.DataValueField = "CodeName";
                    e.ListBox.DataBind();

                    break;
                default:
                    break;
            }
        }
Exemplo n.º 5
0
        protected void grdLoans_FilterCheckListItemsRequested(object sender, GridFilterCheckListItemsRequestedEventArgs e)
        {
            DataTable data = new DataTable();

            switch (e.Column.DataField)
            {
                case "CodeName":
                    data.Columns.Add("CodeName");
                    LoansBLL loansBLL = new LoansBLL();
                    List<Loans> loans = loansBLL.GetLoans();

                    for (int i = 0; i <= loans.Count - 1; i++)
                    {
                        data.Rows.Add(loans[i].CodeName);
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "CodeName";
                    e.ListBox.DataTextField = "CodeName";
                    e.ListBox.DataValueField = "CodeName";
                    e.ListBox.DataBind();

                    break;
                case "Borrower":
                    data = new DataTable();
                    data.Columns.Add("Borrower");

                    BorrowersBL borrowerBL = new BorrowersBL();
                    List<Borrower> borrower = borrowerBL.GetBorrowers();
                    for (int i = 0; i < borrower.Count - 1; i++)
                    {
                        data.Rows.Add(borrower[i].Name);
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "Borrower";
                    e.ListBox.DataTextField = "Borrower";
                    e.ListBox.DataValueField = "Borrower";
                    e.ListBox.DataBind();
                    break;
                case "Country":
                    data = new DataTable();
                    data.Columns.Add("Country");

                    CountryBL CountryBL = new CountryBL();
                    List<tblCountry> country = CountryBL.GetCountry();
                    for (int i = 0; i < country.Count - 1; i++)
                    {
                        data.Rows.Add(country[i].Name);
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "Country";
                    e.ListBox.DataTextField = "Country";
                    e.ListBox.DataValueField = "Country";
                    e.ListBox.DataBind();
                    break;
                case "CreditRating":
                    data = new DataTable();
                    data.Columns.Add("CreditRating");

                    CreditRatingsBL CreditRatingsBL = new CreditRatingsBL();
                    List<CreditRating> CreditRating = CreditRatingsBL.GetRatings();
                    for (int i = 0; i < CreditRating.Count - 1; i++)
                    {
                        data.Rows.Add(CreditRating[i].Rating);
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "CreditRating";
                    e.ListBox.DataTextField = "CreditRating";
                    e.ListBox.DataValueField = "CreditRating";
                    e.ListBox.DataBind();
                    break;
                case "Sector":
                    data = new DataTable();
                    data.Columns.Add("Sector");

                    LoansBLL loansBll = new LoansBLL();
                    List<Sectors> sector = loansBll.GetSector();

                    for (int i = 0; i < sector.Count; i++)
                    {
                        if (sector[i] != null)
                        {
                            data.Rows.Add(sector[i].Sector);
                        }
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "Sector";
                    e.ListBox.DataTextField = "Sector";
                    e.ListBox.DataValueField = "Sector";
                    e.ListBox.DataBind();
                    break;
                case "PP":
                    data = new DataTable();
                    data.Columns.Add("PP");

                    loansBll = new LoansBLL();
                    List<PP> pp = loansBll.GetPP();

                    for (int i = 0; i < pp.Count; i++)
                    {
                        if (pp[i] != null)
                        {
                            data.Rows.Add(pp[i].pp);
                        }
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "PP";
                    e.ListBox.DataTextField = "PP";
                    e.ListBox.DataValueField = "PP";
                    e.ListBox.DataBind();
                    break;
                case "FixedOrFloating":
                    data = new DataTable();
                    data.Columns.Add("FixedOrFloating");

                    loansBll = new LoansBLL();
                    List<BLL.FixedOrFloating> fof = loansBll.GetFixedFloating();

                    for (int i = 0; i < fof.Count; i++)
                    {
                        if (fof[i] != null)
                        {
                            data.Rows.Add(fof[i].fixedorfloating);
                        }
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "FixedOrFloating";
                    e.ListBox.DataTextField = "FixedOrFloating";
                    e.ListBox.DataValueField = "FixedOrFloating";
                    e.ListBox.DataBind();
                    break;
                case "Notional":
                    data = new DataTable();
                    data.Columns.Add("Notional");

                    loansBll = new LoansBLL();
                    List<BLL.Notional> notional = loansBll.GetNotional();

                    for (int i = 0; i < notional.Count; i++)
                    {
                        if (notional[i] != null)
                        {
                            data.Rows.Add(notional[i].notional);
                        }
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "Notional";
                    e.ListBox.DataTextField = "Notional";
                    e.ListBox.DataValueField = "Notional";
                    e.ListBox.DataBind();
                    break;
                case "Margin":
                    data = new DataTable();
                    data.Columns.Add("Margin");

                    loansBll = new LoansBLL();
                    List<BLL.Margin> margin = loansBll.GetMargin();

                    for (int i = 0; i < margin.Count; i++)
                    {
                        if (margin[i] != null)
                        {
                            data.Rows.Add(margin[i].margin);
                        }
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "Margin";
                    e.ListBox.DataTextField = "Margin";
                    e.ListBox.DataValueField = "Margin";
                    e.ListBox.DataBind();
                    break;
                case "Currency":
                    data = new DataTable();
                    data.Columns.Add("Currency");

                    CurrenciesBL currencyBL = new CurrenciesBL();
                    List<Currency> currency = currencyBL.GetCurrency();

                    for (int i = 0; i < currency.Count; i++)
                    {
                        if (currency[i].Currancy != null)
                        {
                            data.Rows.Add(currency[i].Currancy);
                        }
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "Currency";
                    e.ListBox.DataTextField = "Currency";
                    e.ListBox.DataValueField = "Currency";
                    e.ListBox.DataBind();
                    break;
                case "CouponFrequency":
                    data = new DataTable();
                    data.Columns.Add("CouponFrequency");

                    loansBll = new LoansBLL();
                    List<BLL.CouponFrequency> couponFreq = loansBll.GetCouponFrequency();

                    for (int i = 0; i < couponFreq.Count; i++)
                    {
                        if (couponFreq[i] != null)
                        {
                            data.Rows.Add(couponFreq[i].coupon);
                        }
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "CouponFrequency";
                    e.ListBox.DataTextField = "CouponFrequency";
                    e.ListBox.DataValueField = "CouponFrequency";
                    e.ListBox.DataBind();
                    break;
                case "FacilitySize":
                    data = new DataTable();
                    data.Columns.Add("FacilitySize");

                    loansBll = new LoansBLL();
                    List<BLL.FacilitySize> facility = loansBll.GetFacilitySize();

                    for (int i = 0; i < facility.Count; i++)
                    {
                        if (facility[i] != null)
                        {
                            data.Rows.Add(facility[i].facility);
                        }
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "FacilitySize";
                    e.ListBox.DataTextField = "FacilitySize";
                    e.ListBox.DataValueField = "FacilitySize";
                    e.ListBox.DataBind();
                    break;
                case "CreditRatingModys":
                    data = new DataTable();
                    data.Columns.Add("CreditRatings");

                    loansBll = new LoansBLL();

                    List<CreditRating> creditRatingModdys = loansBll.GetCreditRatingModdys();
                    for (int i = 0; i < creditRatingModdys.Count; i++)
                    {
                        data.Rows.Add(creditRatingModdys[i].Rating);
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "CreditRatings";
                    e.ListBox.DataTextField = "CreditRatings";
                    e.ListBox.DataValueField = "CreditRatings";
                    e.ListBox.DataBind();

                    break;
                case "CreditRatingSPs":
                    data = new DataTable();
                    data.Columns.Add("CreditRatings");

                    loansBll = new LoansBLL();

                    List<CreditRating> creditRatingSPs = loansBll.GetCreditRatingSP();
                    for (int i = 0; i < creditRatingSPs.Count; i++)
                    {
                        data.Rows.Add(creditRatingSPs[i].Rating);
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "CreditRatings";
                    e.ListBox.DataTextField = "CreditRatings";
                    e.ListBox.DataValueField = "CreditRatings";
                    e.ListBox.DataBind();

                    break;
                case "CreditRatingFitch":
                    data = new DataTable();
                    data.Columns.Add("CreditRatings");

                    loansBll = new LoansBLL();

                    List<CreditRating> creditRatingFitch = loansBll.GetCreditRatingFitch();
                    for (int i = 0; i < creditRatingFitch.Count; i++)
                    {
                        data.Rows.Add(creditRatingFitch[i].Rating);
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "CreditRatings";
                    e.ListBox.DataTextField = "CreditRatings";
                    e.ListBox.DataValueField = "CreditRatings";
                    e.ListBox.DataBind();

                    break;
                case "CreditRatingING":
                    data = new DataTable();
                    data.Columns.Add("CreditRatings");

                    loansBll = new LoansBLL();

                    List<CreditRating> creditRatingING = loansBll.GetCreditRatingING();
                    for (int i = 0; i < creditRatingING.Count; i++)
                    {
                        data.Rows.Add(creditRatingING[i].Rating);
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "CreditRatings";
                    e.ListBox.DataTextField = "CreditRatings";
                    e.ListBox.DataValueField = "CreditRatings";
                    e.ListBox.DataBind();

                    break;
                //case "NoOfAmortisation":
                //    data = new DataTable();
                //    data.Columns.Add("NoOfAmortrization");

                //    loansBll = new LoansBLL();
                //    List<BLL.NoOfAmortrization> noOfAmort = loansBll.GetNoOfAmortrization();

                //    for (int i = 0; i < noOfAmort.Count; i++)
                //    {
                //        if (noOfAmort[i] != null)
                //        {
                //            data.Rows.Add(noOfAmort[i].noofAmort);
                //        }
                //    }

                //    e.ListBox.DataSource = data;
                //    e.ListBox.DataKeyField = "noofAmort";
                //    e.ListBox.DataTextField = "noofAmort";
                //    e.ListBox.DataValueField = "noofAmort";
                //    e.ListBox.DataBind();
                //    break;
                case "StructureID":
                    data = new DataTable();
                    data.Columns.Add("StructureID");

                    loansBll = new LoansBLL();
                    List<BLL.StructureID> structure = loansBll.GetStructureID();

                    for (int i = 0; i < structure.Count; i++)
                    {
                        if (structure[i] != null)
                        {
                            data.Rows.Add(structure[i].structureID);
                        }
                    }

                    e.ListBox.DataSource = data;
                    e.ListBox.DataKeyField = "StructureID";
                    e.ListBox.DataTextField = "StructureID";
                    e.ListBox.DataValueField = "StructureID";
                    e.ListBox.DataBind();
                    break;
                default:
                    break;
            }

            //// sector

            //data = new DataTable();
            //data.Columns.Add("CreditRating");

            //CreditRatingsBL CreditRatingsBL = new CreditRatingsBL();
            //List<CreditRating> CreditRating = CreditRatingsBL.GetRatings();
            //for (int i = 0; i < CreditRating.Count - 1; i++)
            //{
            //    data.Rows.Add(CreditRating[i].Rating);
            //}

            //e.ListBox.DataSource = data;
            //e.ListBox.DataKeyField = "CreditRating";
            //e.ListBox.DataTextField = "CreditRating";
            //e.ListBox.DataValueField = "CreditRating";
            //e.ListBox.DataBind();
        }
        protected void ExportToCSV()
        {
            string csv_file_path = Server.MapPath("~/Temp/tempfile1.csv");
            if (ddlImportType.SelectedValue == "Loan")
            {
                LoansBLL bll = new LoansBLL();

                var loanList = bll.GetLoans().Select(x => new { LoanName = x.CodeName, Borrower = x.Borrower, Country = x.Country, Sector = x.Sector, SigingDate = x.Signing_Date, MaturityDate = x.Maturity_Date, FixedOrFloating = x.FixedOrFloating, Margin = x.Margin, Currency = x.Currency, CouponFrequency = x.CouponFrequency, FacilitySize = x.FacilitySize, Bilateral = x.Bilateral, Amortizing = x.Amortizing, CouponDate = x.CouponDate, Notional = x.Notional, AmortisationsStartPoint = x.AmortisationsStartPoint, NoOfAmortisationPoint = x.NoOfAmortisationPoint, StructureID = x.StructureID, PP = x.PP, FixedFloating = x.Fixed_Floating, CreditRatingModys = x.CreditRatingModys, CreditRatingSPs = x.CreditRatingSPs, CreditRatingFitch = x.CreditRatingFitch, CreditRatingING = x.CreditRatingING, Gurantor = x.Gurantor, Grid = x.Grid, SummitCreditEntity = x.SummitCreditEntity });
                List<LoanTable> loanTable = new List<LoanTable>();
                foreach (var item in loanList)
                {
                    loanTable.Add(new LoanTable(item.LoanName, item.Borrower, item.Country, Convert.ToDateTime(item.SigingDate), Convert.ToDateTime(item.MaturityDate), item.FixedOrFloating, item.Margin, item.Currency, item.CouponFrequency, item.FacilitySize, Convert.ToBoolean(item.Bilateral), item.Amortizing, Convert.ToDateTime(item.CouponDate), item.Notional, item.AmortisationsStartPoint, Convert.ToInt16(item.NoOfAmortisationPoint), item.StructureID, item.PP, item.FixedFloating, item.CreditRatingModys, item.CreditRatingSPs, item.CreditRatingFitch, item.CreditRatingING, item.Gurantor, item.Grid, item.SummitCreditEntity));
                }

                BLL.CsvExport<LoanTable> exportHelper = new CsvExport<LoanTable>(loanTable);

                exportHelper.ExportToFile(csv_file_path);

                LogActivity("Loans Exported", "Export the Loans", string.Empty);
            }
            else if (ddlImportType.SelectedValue == "Quotes")
            {
                QuotesAndTradesBLL bll = new QuotesAndTradesBLL();

                var quotesList = bll.GetQuotesAndTrades().Select(x => new { LoanName = x.LoanName, TimeStamp = x.TimeStamp, CounterParty = x.CounterParty, BidPrice = x.BidPrice, OfferPrice = x.OfferPrice, BidSpread = x.BidSpread, OfferSpread = x.OfferSpread, Traded = x.Traded, MarketValue = x.MarketValue, Country = x.Country, AverageLife = x.AverageLife, AvgLifeDisc = x.AvgLifeDisc, AvgLifeRiskDisc = x.AvgLifeRiskDisc, AvgLifeNonDisc = x.AvgLifeNonDisc, SettlementDate = x.SettlementDate, Margin = x.Margin });
                List<HistoricalQuote> quotes = new List<HistoricalQuote>();

                foreach (var item in quotesList)
                {
                    quotes.Add(new HistoricalQuote(item.LoanName, Convert.ToDateTime(item.TimeStamp.Value), item.CounterParty, Convert.ToDecimal(item.BidPrice), Convert.ToDecimal(item.OfferPrice), Convert.ToDecimal(item.BidSpread), Convert.ToDecimal(item.OfferSpread), Convert.ToBoolean(item.Traded), Convert.ToDecimal(item.MarketValue), item.Country, Convert.ToDecimal(item.AverageLife), Convert.ToDecimal(item.AvgLifeDisc), Convert.ToDecimal(item.AvgLifeRiskDisc), Convert.ToDecimal(item.AvgLifeNonDisc), Convert.ToDateTime(item.SettlementDate), item.Margin));
                }
                BLL.CsvExport<HistoricalQuote> exportHelper = new CsvExport<HistoricalQuote>(quotes);

                exportHelper.ExportToFile(csv_file_path);

                LogActivity("QuotesAndTrades Exported", "Export the quotesAndtrades", string.Empty);
            }
            else if (ddlImportType.SelectedValue == "EUR Curve")
            {
                EURCurvesBL bll = new EURCurvesBL();
                var list = bll.GetEURCurve().Select(x => new { UploadDate = x.UploadDate, SummitGenDate = x.SummitGenDate, CCY = x.CCY, Index = x.CurveIndex, Days = x.Days, Rate = x.Rate, DiscFreq = x.DiscFreq });

                List<EURCurveTable> eurTable = new List<EURCurveTable>();
                foreach (var item in list)
                {
                    eurTable.Add(new EURCurveTable(Convert.ToDateTime(item.UploadDate), Convert.ToDateTime(item.SummitGenDate), item.CCY, item.Index, Convert.ToInt16(item.Days), Convert.ToDecimal(item.Rate), Convert.ToDecimal(item.DiscFreq)));
                }
                BLL.CsvExport<EURCurveTable> exportHelper = new CsvExport<EURCurveTable>(eurTable);
                exportHelper.ExportToFile(csv_file_path);
                LogActivity("EURCurve Exported", "Export the EURCurve", string.Empty);
            }
            else if (ddlImportType.SelectedValue == "US Curve")
            {
                USDCurveBL bll = new USDCurveBL();
                var list = bll.GetUSCurve().Select(x => new { UploadDate = x.UploadDate, SummitGenDate = x.SummitGenDate, CCY = x.CCY, Index = x.CurveIndex, Days = x.Days, Rate = x.Rate, DiscFreq = x.DiscFreq });

                List<USDCurveTable> eurTable = new List<USDCurveTable>();
                foreach (var item in list)
                {
                    eurTable.Add(new USDCurveTable(Convert.ToDateTime(item.UploadDate), Convert.ToDateTime(item.SummitGenDate), item.CCY, item.Index, Convert.ToInt16(item.Days), Convert.ToDecimal(item.Rate), Convert.ToDecimal(item.DiscFreq)));
                }
                BLL.CsvExport<USDCurveTable> exportHelper = new CsvExport<USDCurveTable>(eurTable);
                exportHelper.ExportToFile(csv_file_path);
                LogActivity("USCurve Exported", "Export the USCurve", string.Empty);
            }

            FileInfo file = new FileInfo(csv_file_path);

            if (file.Exists)
            {
                ShowMessage("Message", "Data has been exported successfully");
                Response.Clear();
                Response.ClearHeaders();
                Response.ClearContent();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.ContentType = "text/plain";
                Response.Flush();
                Response.TransmitFile(file.FullName);
                Response.End();
            }
        }
        protected void btnRemoveLoan_Click(object sender, EventArgs e)
        {
            LoansBLL bll = new LoansBLL();
            bool result = bll.RemoveAllLoans();
            if (result)
            {
                // all loans
                List<Loans> allLoans = bll.GetLoans();

                // check to see if the loan has been added or updated
                ApplicationHub.RefreshLoans(allLoans);

                ShowMessage("Message", "All loans deleted successfully");
                LogActivity("Delete All Loans", "Remove all the quotes", string.Empty);
            }
            else
            {
                LogActivity("Delete All Loans(Unsuccessfull)", "Remove all the quotes", string.Empty);
                lblRemoveLoanMessage.Text = "Unable to delete the loans";
            }
        }