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) { } }
protected void Import() { try { string filename = Path.GetFileName(fuFile.FileName); string csv_file_path = Server.MapPath("~/Temp/tempfile.csv"); //fuFile.SaveAs(csv_file_path); DataTable csvData = null; List<string> columnNames = null; if (ddlImportType.SelectedValue != "EUR Curve" || ddlImportType.SelectedValue != "US Curve") { csvData = CSVHelper.GetDataTabletFromCSVFile(csv_file_path, GetDelimeters()); // Get Header column names list columnNames = csvData.Columns.Cast<DataColumn>().Select(c => c.ColumnName).ToList(); LogActivity("File Uploaded", "Upload the file to import loan/quotesAndtrades", string.Empty); } if (ddlImportType.SelectedValue == "Loan") { //ExtractLoanList(csvData, columnNames); List<Loans> importedList = ExtractLoanList(csvData, columnNames); // ExtractLoanList(csvData, columnNames); // Save it to database ApplicationHub.RefreshLoans(importedList); LogActivity("Loans Imported", "Import the loans", string.Empty); } else if (ddlImportType.SelectedValue == "Quotes") { List<QuotesAndTrades> importedList = ExtractQuotesAndTradesList(csvData, columnNames); // Save it to database if (importedList.Count > 0) { QuotesAndTradesBLL bll = new QuotesAndTradesBLL(); bll.AddImportedQuotesAndTrades(importedList); ApplicationHub.RefreshQuotesAndTrade(importedList); LogActivity("QuotesAndTrades Imported", "Import the quotesAndtrades", string.Empty); } else { RadWindowManager1.RadAlert("No Data found", 330, 180, "realedge associates", "alertCallBackFn"); return; } } else if (ddlImportType.SelectedValue == "Counterparties") { List<CounterParty> importedList = ExtractCounterPartyList(csvData, columnNames); if (importedList.Count > 0) { CounterPartyBL bll = new CounterPartyBL(); bll.AddImportedQuotesAndTrades(importedList); LogActivity("Counterparties Imported", "Counterparties", string.Empty); } else { RadWindowManager1.RadAlert("No Data found", 330, 180, "realedge associates", "alertCallBackFn"); return; } } else if (ddlImportType.SelectedValue == "EUR Curve") { //importdatafromexcel(csv_file_path); List<EURCurve> importedList = ExtractEURCurveList(csvData, columnNames); if (importedList.Count > 0) { EURCurvesBL bll = new EURCurvesBL(); bll.UpdateCurve(); bll.ImportEURCurves(importedList); LogActivity("EURCurves Imported", "EURCurves", string.Empty); } else { RadWindowManager1.RadAlert("No Data found", 330, 180, "realedge associates", "alertCallBackFn"); return; } } else if (ddlImportType.SelectedValue == "US Curve") { List<USDCurve> importedList = ExtractUSDCurveList(csvData, columnNames); if (importedList.Count > 0) { USDCurveBL bll = new USDCurveBL(); bll.UpdateCurve(); bll.ImportUSDCurves(importedList); LogActivity("USDCurve Imported", "USDCurves", string.Empty); } else { RadWindowManager1.RadAlert("No Data found", 330, 180, "realedge associates", "alertCallBackFn"); return; } } //ShowMessage("Message", "Data has been imported successfully"); RadWindowManager1.RadAlert("Data has been imported successfully", 330, 180, "realedge associates", "alertCallBackFn"); } catch (Exception ex) { LogActivity("File Upload(Unsuccessfull)", "Unable to upload the file", ex.Message); //lblImportStatus.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; RadWindowManager1.RadAlert("Data import failed", 330, 180, "realedge associates", "alertCallBackFn"); } }