protected void ButtonSearch_Click(object sender, EventArgs e) { if (TextBoxSearch.Text.Length > 0) { DataTable resultTable = StockApi.symbolSearch(TextBoxSearch.Text, apiKey: Session["ApiKey"].ToString()); if (resultTable != null) { DropDownListStock.DataTextField = "Name"; DropDownListStock.DataValueField = "Symbol"; DropDownListStock.DataSource = resultTable; DropDownListStock.DataBind(); ListItem li = new ListItem("Select Stock", "-1"); DropDownListStock.Items.Insert(0, li); ViewState["GraphScript"] = "Search & Select script"; labelSelectedSymbol.Text = "Search & Select script"; } else { Response.Write("<script language=javascript>alert('" + common.noSymbolFound + "')</script>"); } } else { Response.Write("<script language=javascript>alert('" + common.noTextSearchSymbol + "')</script>"); } }
protected void ButtonSearch_Click(object sender, EventArgs e) { if (TextBoxSearch.Text.Length > 0) { //DataTable resultTable = StockApi.symbolSearch(TextBoxSearch.Text, apiKey: Session["ApiKey"].ToString()); DataTable resultTable = StockApi.symbolSearchAltername(TextBoxSearch.Text, apiKey: Session["ApiKey"].ToString()); if (resultTable != null) { DropDownListStock.Items.Clear(); DropDownListStock.DataSource = null; DropDownListStock.DataTextField = "Name"; DropDownListStock.DataValueField = "Symbol"; DropDownListStock.DataSource = resultTable; DropDownListStock.DataBind(); ListItem li = new ListItem("Select Stock", "-1"); DropDownListStock.Items.Insert(0, li); //ddlPortfolios.Items.Clear(); labelSelectedSymbol.Text = "Selected stock: "; } else { //Response.Write("<script language=javascript>alert('" + common.noSymbolFound + "')</script>"); Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('" + common.noSymbolFound + "');", true); } } else { //Response.Write("<script language=javascript>alert('" + common.noTextSearchSymbol + "')</script>"); Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('" + common.noTextSearchSymbol + "');", true); } }
public bool downloadSTOCH(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlSTOCH_Interval.SelectedValue; string Fastkperiod = textboxSTOCH_Fastkperiod.Text; string Slowkperiod = textboxSTOCH_Slowkperiod.Text; string Slowdperiod = textboxSTOCH_Slowdperiod.Text; string Slowkmatype = ddlSTOCH_Slowkmatype.SelectedValue; string Slowdmatype = ddlSTOCH_Slowdmatype.SelectedValue; if (StockApi.getSTOCHAlternate(folderPath, scriptName, day_interval: interval, fastkperiod: Fastkperiod, slowkperiod: Slowkperiod, slowdperiod: Slowdperiod, slowkmatype: Slowkmatype, slowdmatype: Slowdmatype, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { textboxMessage.Text = Environment.NewLine + "STOCH data not available for selected script."; return(false); } //if (StockApi.getSTOCH(folderPath, scriptName, day_interval: interval, fastkperiod: Fastkperiod, slowkperiod: Slowkperiod, // slowdperiod: Slowdperiod, slowkmatype: Slowkmatype, slowdmatype: Slowdmatype, // bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) //{ // textboxMessage.Text = Environment.NewLine + "STOCH data not available for selected script."; // return false; //} return(true); }
public bool downloadMACD(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlMACD_Interval.SelectedValue; string series = ddlMACD_Series.SelectedValue; string FastPeriod = textboxMACD_FastPeriod.Text; string Slowperiod = textboxMACD_SlowPeriod.Text; string SignalPeriod = textboxMACD_SignalPeriod.Text; if (StockApi.getMACDAlternate(folderPath, scriptName, day_interval: interval, seriestype: series, fastperiod: FastPeriod, slowperiod: Slowperiod, signalperiod: SignalPeriod, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { textboxMessage.Text = Environment.NewLine + "MACD data not available for selected script."; return(false); } //if (StockApi.getMACD(folderPath, scriptName, day_interval: interval, seriestype: series, fastperiod: FastPeriod, // slowperiod: Slowperiod, signalperiod: SignalPeriod, // bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) //{ // textboxMessage.Text = Environment.NewLine + "MACD data not available for selected script."; // return false; //} return(true); }
public bool downloadGetQuote(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { if (StockApi.globalQuote(folderPath, scriptName, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { Response.Write("<script language=javascript>alert('Quote data not available for selected script.')</script>"); return(false); } return(true); }
public bool downloadVWAP(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlVWAP_Interval.SelectedValue; if (StockApi.getVWAP(folderPath, scriptName, day_interval: interval, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { Response.Write("<script language=javascript>alert('VWAP data not available for selected script.')</script>"); return(false); } return(true); }
public bool downloadDaily(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string outputsize = ddlDaily_OutputSize.SelectedValue; if (StockApi.getDaily(folderPath, scriptName, outputsize: outputsize, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { Response.Write("<script language=javascript>alert('Daily data not available for selected script.')</script>"); return(false); } return(true); }
public bool downloadGetQuote(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { //if (StockApi.globalQuote(folderPath, scriptName, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) if (StockApi.globalQuoteAlternate(folderPath, scriptName, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { //Response.Write("<script language=javascript>alert('Quote data not available for selected script.')</script>"); textboxMessage.Text = Environment.NewLine + "Quote data not available for selected script"; return(false); } return(true); }
public bool downloadAdx(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlAdx_Interval.SelectedValue; string period = textboxAdx_Period.Text; if (StockApi.getADX(folderPath, scriptName, day_interval: interval, period: period, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { Response.Write("<script language=javascript>alert('ADX data not available for selected script.')</script>"); return(false); } return(true); }
protected void buttonAddKey_Click(object sender, EventArgs e) { if (textboxKey.Text.Length > 0) { string emailId = Session["EMAILID"].ToString(); string fileName = Session["PortfolioFolder"].ToString() + "\\" + emailId + ".key"; StockApi.createKey(fileName, textboxKey.Text); } else { //Response.Redirect(".\\Default.aspx"); //Response.Write("<script language=javascript>alert('Enter valid key')</script>"); Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('" + common.noValidKey + "');", true); } }
public bool downloadMACD(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlMACD_Interval.SelectedValue; string series = ddlMACD_Series.SelectedValue; string FastPeriod = textboxMACD_FastPeriod.Text; string Slowperiod = textboxMACD_SlowPeriod.Text; string SignalPeriod = textboxMACD_SignalPeriod.Text; if (StockApi.getMACD(folderPath, scriptName, day_interval: interval, seriestype: series, fastperiod: FastPeriod, slowperiod: Slowperiod, signalperiod: SignalPeriod, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { Response.Write("<script language=javascript>alert('MACD data not available for selected script.')</script>"); return(false); } return(true); }
public bool downloadSTOCH(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlSTOCH_Interval.SelectedValue; string Fastkperiod = textboxSTOCH_Fastkperiod.Text; string Slowkperiod = textboxSTOCH_Slowkperiod.Text; string Slowdperiod = textboxSTOCH_Slowdperiod.Text; string Slowkmatype = ddlSTOCH_Slowkmatype.SelectedValue; string Slowdmatype = ddlSTOCH_Slowdmatype.SelectedValue; if (StockApi.getSTOCH(folderPath, scriptName, day_interval: interval, fastkperiod: Fastkperiod, slowkperiod: Slowkperiod, slowdperiod: Slowdperiod, slowkmatype: Slowkmatype, slowdmatype: Slowdmatype, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { Response.Write("<script language=javascript>alert('STOCH data not available for selected script.')</script>"); return(false); } return(true); }
public bool downloadVWAP(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlVWAP_Interval.SelectedValue; //if (StockApi.getVWAP(folderPath, scriptName, day_interval: interval, // bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) //{ if (StockApi.getVWAPAlternate(folderPath, scriptName, time_interval: interval, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { textboxMessage.Text = Environment.NewLine + "VWAP data not available for selected script."; return(false); } //} return(true); }
public bool downloadBBands(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlBBands_Interval.SelectedValue; string period = textboxBBands_Period.Text; string series = ddlBBands_Series.SelectedValue; string nbdevUp = textboxBBands_NbdevUp.Text; string nbdevDn = textboxBBands_NbdevDn.Text; if (StockApi.getBbands(folderPath, scriptName, day_interval: interval, period: period, seriestype: series, nbdevup: nbdevUp, nbdevdn: nbdevDn, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { Response.Write("<script language=javascript>alert('Bollinger Bands data not available for selected script.')</script>"); return(false); } return(true); }
public bool downloadDaily(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string outputsize = ddlDaily_OutputSize.SelectedValue; //if (StockApi.getDaily(folderPath, scriptName, outputsize: outputsize, bIsTestModeOn: bIsTestOn, // bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) //{ //if we failed to get data from alphavantage we will try to get it from yahoo online with test flag = false if (StockApi.getDailyAlternate(folderPath, scriptName, outputsize: outputsize, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { textboxMessage.Text = Environment.NewLine + "Daily data not available for selected script."; return(false); } //} return(true); }
public bool downloadPLUS_DI(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlPlusDI_Interval.SelectedValue; string period = textboxPlusDI_Period.Text; if (StockApi.getADXAlternate(folderPath, scriptName, day_interval: interval, period: period, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString(), returnType: "PLUS_DI") == null) { textboxMessage.Text = Environment.NewLine + "PLUS_DI data not available for selected script."; return(false); } //if (StockApi.getPlusDI(folderPath, scriptName, day_interval: interval, period: period, // bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) //{ // textboxMessage.Text = Environment.NewLine + "PLUS_DI data not available for selected script."; // return false; //} return(true); }
// GET: Portfolios public async Task <IActionResult> Index() { var currentUser = await _userManager.GetUserAsync(User); var portfolioList = await _context.Portfolios.Where(m => m.AppUser == currentUser).ToListAsync(); var updatedList = new List <PortfolioIndexViewModel>(); foreach (var stock in portfolioList) { var updatedInfo = new PortfolioIndexViewModel(stock) { CurrentPrice = await StockApi.GetStockPrice(stock.Symbol) }; updatedList.Add(updatedInfo); } return(View(updatedList)); }
public async Task <IActionResult> Create(Portfolio model) { try { if (ModelState.IsValid) { var stockData = await StockApi.GetStockData(model.Symbol); var portfolio = new Portfolio { ID = model.ID, AppUser = await _userManager.GetUserAsync(User), Symbol = model.Symbol, CompanyName = stockData.CompanyName, PurchaseDateTime = model.PurchaseDateTime, AmountOfShares = model.AmountOfShares, PricePerShare = model.PricePerShare, TotalPurchasePrice = model.PricePerShare * model.AmountOfShares }; _context.Add(portfolio); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "Portfolios")); } } catch (NullReferenceException) { ModelState.AddModelError("", "Unable to locate company for that symbol. Please check spelling and try again."); } catch (DataException dex) { Console.WriteLine(dex); ModelState.AddModelError("", "Unable to save your changes. Please try again."); } catch (Exception) { ModelState.AddModelError("", "Error, Please try again."); } return(View()); }
public bool downloadRSI(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlRSI_Interval.SelectedValue; string period = textboxRSI_Period.Text; string series = ddlRSI_Series.SelectedValue; if (StockApi.getRSIalternate(folderPath, scriptName, day_interval: interval, period: period, seriestype: series, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { textboxMessage.Text = Environment.NewLine + "RSI data not available for selected script."; return(false); } //if (StockApi.getRSI(folderPath, scriptName, day_interval: interval, period: period, seriestype: series, // bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) //{ // textboxMessage.Text = Environment.NewLine + "RSI data not available for selected script."; // return false; //} return(true); }
protected void ButtonSearchPortfolio_Click(object sender, EventArgs e) { DropDownListStock.Items.Clear(); DropDownListStock.DataSource = null; ListItem li = new ListItem("Select Stock", "-1"); DropDownListStock.Items.Insert(0, li); //Session["STOCKPORTFOLIONAME"] = ddlPortfolios.SelectedValue; //Session["STOCKPORTFOLIONAME"] = ddlPortfolios.SelectedItem.Text; string[] scriptList = StockApi.getScriptFromPortfolioFile(ddlPortfolios.SelectedValue); if (scriptList != null) { foreach (string script in scriptList) { li = new ListItem(script, script); DropDownListStock.Items.Add(li); } labelSelectedSymbol.Text = "Selected stock: "; } }
public bool downloadBBands(string folderPath, string scriptName, bool bIsTestOn, bool bSaveData) { string interval = ddlBBands_Interval.SelectedValue; string period = textboxBBands_Period.Text; string series = ddlBBands_Series.SelectedValue; string nbdevUp = textboxBBands_NbdevUp.Text; string nbdevDn = textboxBBands_NbdevDn.Text; if (StockApi.getBbandsAlternate(folderPath, scriptName, day_interval: interval, period: period, seriestype: series, nbdevup: nbdevUp, nbdevdn: nbdevDn, bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) { textboxMessage.Text = Environment.NewLine + "Bollinger Bands data not available for selected script."; return(false); } //if (StockApi.getBbands(folderPath, scriptName, day_interval: interval, period: period, seriestype: series, // nbdevup: nbdevUp, nbdevdn: nbdevDn, // bIsTestModeOn: bIsTestOn, bSaveData: bSaveData, apiKey: Session["ApiKey"].ToString()) == null) //{ // textboxMessage.Text = Environment.NewLine + "Bollinger Bands data not available for selected script."; // return false; //} return(true); }
public void ShowGraph(string scriptName) { string folderPath = Server.MapPath("~/scriptdata/"); bool bIsTestOn = true; DataTable scriptData = null; DataTable tempData = null; string expression = ""; string interval = ""; string fromDate = "", toDate = ""; DataRow[] filteredRows = null; if (ViewState["FetchedData"] == null) { if (Session["IsTestOn"] != null) { bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); } if (Session["TestDataFolder"] != null) { folderPath = Session["TestDataFolder"].ToString(); } if (Request.QueryString["interval"] != null) { interval = Request.QueryString["interval"]; scriptData = StockApi.getVWAP(folderPath, scriptName, day_interval: interval, bIsTestModeOn: bIsTestOn, bSaveData: false); } ViewState["FetchedData"] = scriptData; } else { if (ViewState["FromDate"] != null) { fromDate = ViewState["FromDate"].ToString(); } if (ViewState["ToDate"] != null) { toDate = ViewState["ToDate"].ToString(); } if ((fromDate.Length > 0) && (toDate.Length > 0)) { tempData = (DataTable)ViewState["FetchedData"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { scriptData = filteredRows.CopyToDataTable(); } } else { scriptData = (DataTable)ViewState["FetchedData"]; } } if (scriptData != null) { ////time,Real Lower Band,Real Middle Band,Real Upper Band /// (chartVWAP.Series["seriesVWAP"]).XValueMember = "Date"; (chartVWAP.Series["seriesVWAP"]).XValueType = ChartValueType.Date; (chartVWAP.Series["seriesVWAP"]).YValueMembers = "VWAP"; //(chartVWAP.Series["seriesVWAP"]).ToolTip = "VWAP: Date:#VALX; Value:#VALY"; chartVWAP.ChartAreas["chartareaVWAP"].AxisX.Title = "Date"; chartVWAP.ChartAreas["chartareaVWAP"].AxisX.TitleAlignment = System.Drawing.StringAlignment.Center; chartVWAP.ChartAreas["chartareaVWAP"].AxisY.Title = "Value"; chartVWAP.ChartAreas["chartareaVWAP"].AxisY.TitleAlignment = System.Drawing.StringAlignment.Center; chartVWAP.ChartAreas["chartareaVWAP"].AxisX.LabelStyle.Format = "g"; //chartVWAP.Titles["titleVWAP"].Text = $"{"Volume Weighted Average Price - "}{scriptName}"; if (chartVWAP.Annotations.Count > 0) { chartVWAP.Annotations.Clear(); } chartVWAP.DataSource = scriptData; chartVWAP.DataBind(); } }
public void ShowGraph(string scriptName) { string folderPath = Server.MapPath("~/scriptdata/"); bool bIsTestOn = true; DataTable scriptData = null; DataTable tempData = null; string expression = ""; string interval = ""; string fastkperiod = ""; string slowkperiod = ""; string slowdperiod = ""; string slowkmatype = ""; string slowdmatype = ""; string fromDate = "", toDate = ""; DataRow[] filteredRows = null; if (ViewState["FetchedData"] == null) { if (Session["IsTestOn"] != null) { bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); } if (Session["TestDataFolder"] != null) { folderPath = Session["TestDataFolder"].ToString(); } if ((Request.QueryString["interval"] != null) && (Request.QueryString["fastkperiod"] != null) && (Request.QueryString["slowkperiod"] != null) && (Request.QueryString["slowdperiod"] != null) && (Request.QueryString["slowkmatype"] != null) && (Request.QueryString["slowdmatype"] != null)) { interval = Request.QueryString["interval"]; fastkperiod = Request.QueryString["fastkperiod"].ToString(); slowkperiod = Request.QueryString["slowkperiod"].ToString(); slowdperiod = Request.QueryString["slowdperiod"].ToString(); slowkmatype = Request.QueryString["slowkmatype"].ToString(); slowdmatype = Request.QueryString["slowdmatype"].ToString(); scriptData = StockApi.getSTOCH(folderPath, scriptName, day_interval: interval, fastkperiod: fastkperiod, slowkperiod: slowkperiod, slowdperiod: slowdperiod, slowkmatype: slowkmatype, slowdmatype: slowdmatype, bIsTestModeOn: bIsTestOn, bSaveData: false); } ViewState["FetchedData"] = scriptData; } else { if (ViewState["FromDate"] != null) { fromDate = ViewState["FromDate"].ToString(); } if (ViewState["ToDate"] != null) { toDate = ViewState["ToDate"].ToString(); } if ((fromDate.Length > 0) && (toDate.Length > 0)) { tempData = (DataTable)ViewState["FetchedData"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { scriptData = filteredRows.CopyToDataTable(); } } else { scriptData = (DataTable)ViewState["FetchedData"]; } } if (scriptData != null) { ////time,Real Lower Band,Real Middle Band,Real Upper Band /// (chartSTOCH.Series["seriesSlowK"]).XValueMember = "Date"; (chartSTOCH.Series["seriesSlowK"]).XValueType = ChartValueType.Date; (chartSTOCH.Series["seriesSlowK"]).YValueMembers = "SlowK"; //(chartSTOCH.Series["seriesSlowK"]).ToolTip = "SlowK: Date:#VALX; Value:#VALY"; chartSTOCH.ChartAreas["chartareaSlowK"].AxisX.Title = "Date"; chartSTOCH.ChartAreas["chartareaSlowK"].AxisX.TitleAlignment = System.Drawing.StringAlignment.Center; chartSTOCH.ChartAreas["chartareaSlowK"].AxisY.Title = "SlowK Value"; chartSTOCH.ChartAreas["chartareaSlowK"].AxisY.TitleAlignment = System.Drawing.StringAlignment.Center; (chartSTOCH.Series["seriesSlowD"]).XValueMember = "Date"; (chartSTOCH.Series["seriesSlowD"]).XValueType = ChartValueType.Date; (chartSTOCH.Series["seriesSlowD"]).YValueMembers = "SlowD"; //(chartSTOCH.Series["seriesSlowD"]).ToolTip = "SlowD: Date:#VALX; Value:#VALY"; chartSTOCH.ChartAreas["chartareaSlowD"].AxisX.Title = "Date"; chartSTOCH.ChartAreas["chartareaSlowD"].AxisX.TitleAlignment = System.Drawing.StringAlignment.Center; chartSTOCH.ChartAreas["chartareaSlowD"].AxisY.Title = "SlowD Value"; chartSTOCH.ChartAreas["chartareaSlowD"].AxisY.TitleAlignment = System.Drawing.StringAlignment.Center; //chartSTOCH.Titles["titleSTOCH"].Text = $"{"Stochastic Oscillator- "}{scriptName}"; if (chartSTOCH.Annotations.Count > 0) { chartSTOCH.Annotations.Clear(); } chartSTOCH.DataSource = scriptData; chartSTOCH.DataBind(); } }
public void ShowGraph(string fileName) { bool bIsTestOn = true; DataTable portfolioTable = null; DataTable valuationTable = null; DataTable indexTable = null; DataTable tempData = null; string folderPath = Server.MapPath("~/scriptdata/"); string currentFundName; string searchPath; //int markerInterval = 10; //int i = 0; double tempQty = 0; double tempCost; string fromDate = "", toDate = ""; string expression = ""; DataRow[] filteredRows = null; DataRow[] scriptRows; try { if (File.Exists(fileName)) { if (Session["IsTestOn"] != null) { bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); } if (Session["TestDataFolderMF"] != null) { folderPath = Session["TestDataFolderMF"].ToString(); } //portfolioTable = StockApi.GetValuation(folderPath, fileName, bIsTestOn); //portfolioTable = MFAPI.openMFPortfolio(folderPath, fileName); if ((ViewState["PortfolioTable"] == null) || (((DataTable)ViewState["PortfolioTable"]).Rows.Count == 0)) { portfolioTable = MFAPI.openMFPortfolio(folderPath, fileName); ViewState["PortfolioTable"] = portfolioTable; } else { portfolioTable = (DataTable)ViewState["PortfolioTable"]; } if ((ViewState["FetchedData"] == null) || (((DataTable)ViewState["FetchedData"]).Rows.Count == 0)) { //if (Session["IsTestOn"] != null) //{ // bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); //} //if (Session["TestDataFolderMF"] != null) //{ // folderPath = Session["TestDataFolderMF"].ToString(); //} valuationTable = MFAPI.GetMFValuationLine(folderPath, fileName, portfolioTable: portfolioTable); ViewState["FetchedData"] = valuationTable; gridviewPortfolioValuation.DataSource = (DataTable)ViewState["FetchedData"]; gridviewPortfolioValuation.DataBind(); } if ((System.Convert.ToInt32((ViewState["SelectedIndex"].ToString())) != ddlIndex.SelectedIndex) && (ddlIndex.SelectedIndex > 0)) { //if (Session["IsTestOn"] != null) //{ // bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); //} //if (Session["TestDataFolderMF"] != null) //{ // folderPath = Session["TestDataFolderMF"].ToString(); //} //Some index is selected by user indexTable = StockApi.getDailyAlternate(folderPath, ddlIndex.SelectedValue, bIsTestModeOn: false, bSaveData: false, apiKey: Session["ApiKey"].ToString()); ViewState["FetchedIndexData"] = indexTable; ViewState["SelectedIndex"] = ddlIndex.SelectedIndex; } //else //{ if (ViewState["FromDate"] != null) { fromDate = ViewState["FromDate"].ToString(); } if (ViewState["ToDate"] != null) { toDate = ViewState["ToDate"].ToString(); } if ((fromDate.Length > 0) && (toDate.Length > 0)) { tempData = (DataTable)ViewState["FetchedData"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { valuationTable = filteredRows.CopyToDataTable(); } tempData.Clear(); tempData = null; if (ViewState["FetchedIndexData"] != null) { tempData = (DataTable)ViewState["FetchedIndexData"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { indexTable = filteredRows.CopyToDataTable(); } } } else { valuationTable = (DataTable)ViewState["FetchedData"]; indexTable = (DataTable)ViewState["FetchedIndexData"]; } //} if (valuationTable != null) { if (chartPortfolioValuation.Annotations.Count > 0) { chartPortfolioValuation.Annotations.Clear(); } DataTable fundNameTable = portfolioTable.DefaultView.ToTable(true, "FundName"); foreach (DataRow fundNameRow in fundNameTable.Rows) { currentFundName = fundNameRow["FundName"].ToString(); scriptRows = valuationTable.Select("SCHEME_NAME='" + currentFundName + "'"); if (scriptRows.Length > 0) { if (listboxScripts.Items.FindByValue(currentFundName) == null) { ListItem li = new ListItem(currentFundName, currentFundName); listboxScripts.Items.Add(li); } if (chartPortfolioValuation.Series.FindByName(currentFundName) == null) { chartPortfolioValuation.Series.Add(currentFundName); chartPortfolioValuation.Series[currentFundName].Name = currentFundName; (chartPortfolioValuation.Series[currentFundName]).ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line; (chartPortfolioValuation.Series[currentFundName]).ChartArea = chartPortfolioValuation.ChartAreas[0].Name; chartPortfolioValuation.Series[currentFundName].Legend = chartPortfolioValuation.Legends[0].Name; chartPortfolioValuation.Series[currentFundName].LegendText = currentFundName; chartPortfolioValuation.Series[currentFundName].LegendToolTip = currentFundName; chartPortfolioValuation.Series[currentFundName].ToolTip = currentFundName + ": Date:#VALX; NAV:#VALY3; Cumulative Units:#VALY5; Current Value:#VALY (Click to see details)"; chartPortfolioValuation.Series[currentFundName].PostBackValue = currentFundName + ",#VALX,#VALY,#VALY1,#VALY2,#VALY3,#VALY4,#VALY5,#VALY6"; } tempQty = 0; tempCost = 0.00; (chartPortfolioValuation.Series[currentFundName]).Points.Clear(); foreach (DataRow itemRow in scriptRows) { (chartPortfolioValuation.Series[currentFundName]).Points.AddXY(itemRow["DATE"], itemRow["CurrentValue"]); if ((itemRow["CumulativeUnits"] != System.DBNull.Value) && ((tempQty == 0) || (tempQty != System.Convert.ToDouble(itemRow["CumulativeUnits"])))) { tempQty = System.Convert.ToDouble(itemRow["CumulativeUnits"]); (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].MarkerSize = 10; (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Diamond; //(chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].Label = itemRow["CumulativeUnits"].ToString(); } (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].PostBackValue = itemRow["SCHEME_NAME"] + "," + itemRow["DATE"] + "," + itemRow["NET_ASSET_VALUE"] + itemRow["CurrentValue"] + "," + itemRow["CumulativeUnits"] + "," + itemRow["CumulativeCost"]; } (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].MarkerSize = 10; (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Diamond; } } if (indexTable != null) { if (chartPortfolioValuation.Series.FindByName(ddlIndex.SelectedValue) == null) { chartPortfolioValuation.Series.Add(ddlIndex.SelectedValue); chartPortfolioValuation.Series[ddlIndex.SelectedValue].Name = ddlIndex.SelectedValue; (chartPortfolioValuation.Series[ddlIndex.SelectedValue]).ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line; (chartPortfolioValuation.Series[ddlIndex.SelectedValue]).ChartArea = chartPortfolioValuation.ChartAreas[0].Name; chartPortfolioValuation.Series[ddlIndex.SelectedValue].Legend = chartPortfolioValuation.Legends[0].Name; chartPortfolioValuation.Series[ddlIndex.SelectedValue].LegendText = ddlIndex.SelectedValue; chartPortfolioValuation.Series[ddlIndex.SelectedValue].LegendToolTip = ddlIndex.SelectedValue; (chartPortfolioValuation.Series[ddlIndex.SelectedValue]).YValuesPerPoint = 4; chartPortfolioValuation.Series[ddlIndex.SelectedValue].ToolTip = ddlIndex.SelectedValue + ": Date:#VALX; Close:#VALY4 (Click to see details)"; chartPortfolioValuation.Series[ddlIndex.SelectedValue].PostBackValue = ddlIndex.SelectedValue + ",#VALX,#VALY1,#VALY2,#VALY3,#VALY4"; } (chartPortfolioValuation.Series[ddlIndex.SelectedValue]).Points.DataBindXY(indexTable.Rows, "Date", indexTable.Rows, "Open,High,Low,Close"); } for (int i = 1; i < ddlIndex.Items.Count; i++) { Series tempSeries = chartPortfolioValuation.Series.FindByName(ddlIndex.Items[i].Value); if (tempSeries != null) { if (ddlIndex.SelectedValue != ddlIndex.Items[i].Value) { chartPortfolioValuation.Series.Remove(tempSeries); } } } foreach (ListItem item in listboxScripts.Items) { if (item.Value.Equals("All") && item.Selected) { foreach (Series itemSeries in chartPortfolioValuation.Series) { itemSeries.Enabled = true; } break; } else if (!item.Value.Equals("All") && (item.Selected)) { chartPortfolioValuation.Series[item.Value].Enabled = true; } else if (!item.Value.Equals("All") && (!item.Selected)) { chartPortfolioValuation.Series[item.Value].Enabled = false; } } } } } catch (Exception ex) { //Response.Write("<script language=javascript>alert('Exception while generating graph: " + ex.Message + "')</script>"); Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('Exception while generating graph:" + ex.Message + "');", true); } }
public void ShowGraph() { DataTable indexTable = null; DataTable portfolioTable = null; DataTable valuationTable = null; DataTable tempData = null; DataRow[] filteredRows = null; DataRow[] scriptRows; string fromDate = "", toDate = ""; string expression = ""; double tempQty = 0; double tempCost; string currentFundName; DataManager dataMgr = new DataManager(); string folderPath = Session["DATAFOLDER"].ToString(); if ((ViewState["PortfolioTable"] == null) || (((DataTable)ViewState["PortfolioTable"]).Rows.Count == 0)) { portfolioTable = dataMgr.openMFPortfolio(Session["EMAILID"].ToString(), Session["MFPORTFOLIONAME"].ToString(), Session["MFPORTFOLIOMASTERROWID"].ToString()); ViewState["PortfolioTable"] = portfolioTable; } else { portfolioTable = (DataTable)ViewState["PortfolioTable"]; } if ((ViewState["FetchedData"] == null) || (((DataTable)ViewState["FetchedData"]).Rows.Count == 0)) { valuationTable = dataMgr.GetValuationLineGraph(Session["MFPORTFOLIOMASTERROWID"].ToString(), Session["EMAILID"].ToString(), Session["MFPORTFOLIONAME"].ToString()); ViewState["FetchedData"] = valuationTable; gridviewPortfolioValuation.DataSource = (DataTable)ViewState["FetchedData"]; gridviewPortfolioValuation.DataBind(); } if ((System.Convert.ToInt32((ViewState["SelectedIndex"].ToString())) != ddlIndex.SelectedIndex) && (ddlIndex.SelectedIndex > 0)) { //Some index is selected by user indexTable = StockApi.getDailyAlternate(folderPath, ddlIndex.SelectedValue, bIsTestModeOn: false, bSaveData: false, apiKey: Session["ApiKey"].ToString()); ViewState["FetchedIndexData"] = indexTable; ViewState["SelectedIndex"] = ddlIndex.SelectedIndex; } if (ViewState["FromDate"] != null) { fromDate = ViewState["FromDate"].ToString(); } if (ViewState["ToDate"] != null) { toDate = ViewState["ToDate"].ToString(); } if ((fromDate.Length > 0) && (toDate.Length > 0)) { tempData = (DataTable)ViewState["FetchedData"]; expression = "DATE >= '" + fromDate + "' and DATE <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { valuationTable = filteredRows.CopyToDataTable(); } tempData.Clear(); tempData = null; if (ViewState["FetchedIndexData"] != null) { tempData = (DataTable)ViewState["FetchedIndexData"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { indexTable = filteredRows.CopyToDataTable(); } } } else { valuationTable = (DataTable)ViewState["FetchedData"]; indexTable = (DataTable)ViewState["FetchedIndexData"]; } if (valuationTable != null) { if (chartPortfolioValuation.Annotations.Count > 0) { chartPortfolioValuation.Annotations.Clear(); } DataTable fundNameTable = portfolioTable.DefaultView.ToTable(true, "FundName"); foreach (DataRow fundNameRow in fundNameTable.Rows) { currentFundName = fundNameRow["FundName"].ToString(); scriptRows = valuationTable.Select("SCHEME_NAME='" + currentFundName + "'"); if (scriptRows.Length > 0) { if (listboxScripts.Items.FindByValue(currentFundName) == null) { ListItem li = new ListItem(currentFundName, currentFundName); listboxScripts.Items.Add(li); } if (chartPortfolioValuation.Series.FindByName(currentFundName) == null) { chartPortfolioValuation.Series.Add(currentFundName); chartPortfolioValuation.Series[currentFundName].Name = currentFundName; (chartPortfolioValuation.Series[currentFundName]).ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line; (chartPortfolioValuation.Series[currentFundName]).ChartArea = chartPortfolioValuation.ChartAreas[0].Name; chartPortfolioValuation.Series[currentFundName].Legend = chartPortfolioValuation.Legends[0].Name; chartPortfolioValuation.Series[currentFundName].LegendText = currentFundName; chartPortfolioValuation.Series[currentFundName].LegendToolTip = currentFundName; chartPortfolioValuation.Series[currentFundName].ToolTip = currentFundName + ": Date:#VALX; Current Value:#VALY (Click to see details)"; chartPortfolioValuation.Series[currentFundName].PostBackValue = currentFundName + ",#VALX,#VALY1,#VALY2,#VALY3,#VALY4,#VALY5,#VALY6"; } tempQty = 0; tempCost = 0.00; (chartPortfolioValuation.Series[currentFundName]).Points.Clear(); foreach (DataRow itemRow in scriptRows) { (chartPortfolioValuation.Series[currentFundName]).Points.AddXY(itemRow["DATE"], itemRow["CurrentValue"]); if ((itemRow["CumulativeUnits"] != System.DBNull.Value) && ((tempQty == 0) || (tempQty != System.Convert.ToDouble(itemRow["CumulativeUnits"])))) { tempQty = System.Convert.ToDouble(itemRow["CumulativeUnits"]); (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].MarkerSize = 10; (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Diamond; //(chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].Label = itemRow["CumulativeUnits"].ToString(); } (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].PostBackValue = itemRow["SCHEME_NAME"] + "," + itemRow["DATE"] + "," + itemRow["NET_ASSET_VALUE"] + "," + itemRow["CurrentValue"] + "," + itemRow["CumulativeUnits"] + "," + itemRow["CumulativeCost"]; } (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].MarkerSize = 10; (chartPortfolioValuation.Series[currentFundName]).Points[(chartPortfolioValuation.Series[currentFundName]).Points.Count - 1].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Diamond; } } if (indexTable != null) { if (chartPortfolioValuation.Series.FindByName(ddlIndex.SelectedValue) == null) { chartPortfolioValuation.Series.Add(ddlIndex.SelectedValue); chartPortfolioValuation.Series[ddlIndex.SelectedValue].Name = ddlIndex.SelectedValue; (chartPortfolioValuation.Series[ddlIndex.SelectedValue]).ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line; (chartPortfolioValuation.Series[ddlIndex.SelectedValue]).ChartArea = chartPortfolioValuation.ChartAreas[0].Name; chartPortfolioValuation.Series[ddlIndex.SelectedValue].Legend = chartPortfolioValuation.Legends[0].Name; chartPortfolioValuation.Series[ddlIndex.SelectedValue].LegendText = ddlIndex.SelectedValue; chartPortfolioValuation.Series[ddlIndex.SelectedValue].LegendToolTip = ddlIndex.SelectedValue; (chartPortfolioValuation.Series[ddlIndex.SelectedValue]).YValuesPerPoint = 4; chartPortfolioValuation.Series[ddlIndex.SelectedValue].ToolTip = ddlIndex.SelectedValue + ": Date:#VALX; Close:#VALY4 (Click to see details)"; chartPortfolioValuation.Series[ddlIndex.SelectedValue].PostBackValue = ddlIndex.SelectedValue + ",#VALX,#VALY1,#VALY2,#VALY3,#VALY4"; } (chartPortfolioValuation.Series[ddlIndex.SelectedValue]).Points.DataBindXY(indexTable.Rows, "Date", indexTable.Rows, "Open,High,Low,Close"); for (int i = 1; i < ddlIndex.Items.Count; i++) { Series tempSeries = chartPortfolioValuation.Series.FindByName(ddlIndex.Items[i].Value); if (tempSeries != null) { if (ddlIndex.SelectedValue != ddlIndex.Items[i].Value) { chartPortfolioValuation.Series.Remove(tempSeries); } } } } foreach (ListItem item in listboxScripts.Items) { if (item.Value.Equals("All") && item.Selected) { foreach (Series itemSeries in chartPortfolioValuation.Series) { itemSeries.Enabled = true; } break; } else if (!item.Value.Equals("All") && (item.Selected)) { chartPortfolioValuation.Series[item.Value].Enabled = true; } else if (!item.Value.Equals("All") && (!item.Selected)) { chartPortfolioValuation.Series[item.Value].Enabled = false; } } } }
protected void buttonConvert_Click(object sender, EventArgs e) { DataTable csvColTable; DataTable csvTable; string filename; string exchangeCode; try { csvColTable = (DataTable)ViewState["CSVColData"]; csvTable = (DataTable)ViewState["CSVData"]; if ((csvColTable == null) || (csvColTable.Rows.Count <= 0) || (csvTable == null) || (csvTable.Rows.Count <= 0)) { labelMessage.Text = "Problem while fetching data from imported file. Please try importing file again."; } else { //first remove all columns that are not mapped from the csvtable foreach (DataRow row in csvColTable.Rows) { if (row["TargetCol"].ToString().Length <= 0) { csvTable.Columns.Remove(row["SourceCol"].ToString()); } } csvTable.AcceptChanges(); //ViewState["CSVData"] = csvTable; //ViewState["UploadedFileName"] = Session["PortfolioFolder"].ToString() + "\\" + FileUploadCSV.FileName; filename = ViewState["UploadedFileName"].ToString(); filename = filename.ToLower().Replace(".csv", ".xml"); if (File.Exists(filename)) { labelMessage.Text = "Data will be appended to existing file: " + filename; } //int i = 1; //while ((File.Exists(filename)) || (i <= 20)) //{ // if (i == 1) // { // filename = filename.Replace(".xml", "_" + i.ToString() + ".xml"); // } // else // { // filename = filename.Replace("_" + (i - 1).ToString() + ".xml", "_" + i + ".xml"); // } // i++; // if(i == 20) // { // labelMessage.Text = "Data will be appended to existing file:" + filename; // } //} if (ddlCountry.SelectedIndex >= 0) { exchangeCode = ddlCountry.SelectedValue; } else { exchangeCode = ".BSE"; } if (StockApi.convertTableToPortfolio(filename, csvTable, csvColTable, exchangeCode, apiKey: Session["ApiKey"].ToString())) { labelMessage.Text = "Data uploaded to file - " + filename; string folderPath = Server.MapPath("~/scriptdata/"); bool bIsTestOn = true; if (Session["DATAFOLDER"] != null) { folderPath = Session["DATAFOLDER"].ToString(); } if (Session["IsTestOn"] != null) { bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); } DataTable dt = StockApi.getPortfolioTable(folderPath, filename, false, bIsTestOn, apiKey: Session["ApiKey"].ToString()); if (dt != null) { GridViewMapped.DataSource = dt; GridViewMapped.DataBind(); ViewState["MappedData"] = dt; } } else { labelMessage.Text = "Failed to uploaded data to file - " + filename; } } } catch (Exception ex) { } }
protected void ButtonUpload_Click(object sender, EventArgs e) { try { DataTable csvTable, csvColTable; if (FileUploadCSV.HasFile) { // Get the file extension string fileExtension = System.IO.Path.GetExtension(FileUploadCSV.FileName); if (fileExtension.ToLower() != ".csv") { labelMessage.ForeColor = System.Drawing.Color.Red; labelMessage.Text = "Only text file files with .csv extension are allowed"; } else { // Get the file size int fileSize = FileUploadCSV.PostedFile.ContentLength; // If file size is greater than 2 MB if (fileSize > 2097152) { labelMessage.ForeColor = System.Drawing.Color.Red; labelMessage.Text = "File size cannot be greater than 2 MB"; } else { // Upload the file //string fileName = Session["PortfolioFolder"].ToString() + "\\" + textboxPortfolioName.Text + ".xml"; //FileUploadCSV.SaveAs(Server.MapPath("~/Uploads/" + FileUploadCSV.FileName)); ViewState["UploadedFileName"] = Session["PortfolioFolder"].ToString() + "\\" + FileUploadCSV.FileName; FileUploadCSV.SaveAs(Session["PortfolioFolder"].ToString() + "\\" + FileUploadCSV.FileName); labelMessage.ForeColor = System.Drawing.Color.Green; labelMessage.Text = "File uploaded successfully. Please map the fields below to create portfolio."; Stream receiveStream = FileUploadCSV.FileContent; StreamReader reader = null; reader = new StreamReader(receiveStream); //string fileData = reader.ReadToEnd(); //textboxMessage.Text = fileData; csvTable = StockApi.readCSV(reader); if (csvTable != null) { ViewState["CSVData"] = csvTable; ViewState["CSVGridData"] = csvTable; //if(GridViewData.Columns.Count > 0) //{ // GridViewData.Columns.Clear(); //} //foreach (DataColumn col in csvTable.Columns) //{ // BoundField newcol = new BoundField(); // newcol.DataField = col.ColumnName; // newcol.HeaderText = col.ColumnName; // GridViewData.Columns.Add(newcol); //} //GridViewData.DataSource = csvTable; //GridViewData.DataBind(); csvColTable = StockApi.readColumnsFromCSVTable(csvTable); if (csvColTable != null) { ViewState["CSVColData"] = csvColTable; ddlSourceCols.Items.Clear(); foreach (DataRow row in csvColTable.Rows) { ListItem li = new ListItem(row[0].ToString(), row[0].ToString()); ddlSourceCols.Items.Add(li); } GridViewMapping.DataSource = csvColTable; GridViewMapping.DataBind(); } else { labelMessage.ForeColor = System.Drawing.Color.Red; labelMessage.Text = "Problem while mapping source columns. Please select correct CSV file."; buttonMapSelected.Enabled = false; } buttonMapSelected.Enabled = true; } else { labelMessage.ForeColor = System.Drawing.Color.Red; labelMessage.Text = "Problem while reading data. Please select correct CSV file."; buttonMapSelected.Enabled = false; } } } } else { labelMessage.ForeColor = System.Drawing.Color.Red; labelMessage.Text = "Please select a file"; } } catch (Exception ex) { labelMessage.Text = ex.Message; } }
public void ShowGraph(string scriptName) { string folderPath = Server.MapPath("~/scriptdata/"); bool bIsTestOn = true; DataTable scriptData = null; DataTable tempData = null; string expression = ""; string outputSize = ""; string interval = ""; string fromDate = "", toDate = ""; DataRow[] filteredRows = null; if (ViewState["FetchedData"] == null) { if (Session["IsTestOn"] != null) { bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); } if (Session["TestDataFolder"] != null) { folderPath = Session["TestDataFolder"].ToString(); } if ((Request.QueryString["size"] != null) && (Request.QueryString["interval"] != null)) { outputSize = Request.QueryString["size"].ToString(); interval = Request.QueryString["interval"]; scriptData = StockApi.getIntraday(folderPath, scriptName, time_interval: interval, outputsize: outputSize, bIsTestModeOn: bIsTestOn, bSaveData: false); } ViewState["FetchedData"] = scriptData; } else { if (ViewState["FromDate"] != null) { fromDate = ViewState["FromDate"].ToString(); } if (ViewState["ToDate"] != null) { toDate = ViewState["ToDate"].ToString(); } if ((fromDate.Length > 0) && (toDate.Length > 0)) { tempData = (DataTable)ViewState["FetchedData"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { scriptData = filteredRows.CopyToDataTable(); } } else { scriptData = (DataTable)ViewState["FetchedData"]; } } if (scriptData != null) { chartintraGraph.DataSource = scriptData; chartintraGraph.DataBind(); chartintraGraph.ChartAreas[0].AxisX.LabelStyle.Format = "g"; if (checkBoxOpen.Checked) { showOpenLine(scriptData); } if (checkBoxHigh.Checked) { showHighLine(scriptData); } if (checkBoxLow.Checked) { showLowLine(scriptData); } if (checkBoxClose.Checked) { showCloseLine(scriptData); } if (checkBoxCandle.Checked) { showCandleStickGraph(scriptData); } if (checkBoxVolume.Checked) { showVolumeGraph(scriptData); } if (checkBoxGrid.Checked) { GridViewDaily.Visible = true; GridViewDaily.DataSource = scriptData; GridViewDaily.DataBind(); } } }
public void ShowGraph(string scriptName) { string folderPath = Server.MapPath("~/scriptdata/"); bool bIsTestOn = true; DataTable scriptData = null; DataTable tempData = null; string expression = ""; string interval = ""; string period = ""; string seriestype = ""; string nbdevup = ""; string nbdevdn = ""; string fromDate = "", toDate = ""; DataRow[] filteredRows = null; if (ViewState["FetchedData"] == null) { if (Session["IsTestOn"] != null) { bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]); } if (Session["TestDataFolder"] != null) { folderPath = Session["TestDataFolder"].ToString(); } if ((Request.QueryString["interval"] != null) && (Request.QueryString["period"] != null) && (Request.QueryString["seriestype"] != null) && (Request.QueryString["nbdevup"] != null) && (Request.QueryString["nbdevdn"] != null)) { interval = Request.QueryString["interval"]; period = Request.QueryString["period"]; seriestype = Request.QueryString["seriestype"]; nbdevup = Request.QueryString["nbdevup"]; nbdevdn = Request.QueryString["nbdevdn"]; scriptData = StockApi.getADX(folderPath, scriptName, day_interval: interval, period: period, bIsTestModeOn: bIsTestOn, bSaveData: false); scriptData = StockApi.getBbands(folderPath, scriptName, day_interval: interval, period: period, seriestype: seriestype, nbdevup: nbdevup, nbdevdn: nbdevdn, bIsTestModeOn: bIsTestOn, bSaveData: false); } ViewState["FetchedData"] = scriptData; } else { if (ViewState["FromDate"] != null) { fromDate = ViewState["FromDate"].ToString(); } if (ViewState["ToDate"] != null) { toDate = ViewState["ToDate"].ToString(); } if ((fromDate.Length > 0) && (toDate.Length > 0)) { tempData = (DataTable)ViewState["FetchedData"]; expression = "Date >= '" + fromDate + "' and Date <= '" + toDate + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { scriptData = filteredRows.CopyToDataTable(); } } else { scriptData = (DataTable)ViewState["FetchedData"]; } } if (scriptData != null) { ////time,Real Lower Band,Real Middle Band,Real Upper Band /// (chartBollingerBands.Series["Real Lower Band"]).XValueMember = "Date"; (chartBollingerBands.Series["Real Lower Band"]).XValueType = ChartValueType.Date; (chartBollingerBands.Series["Real Lower Band"]).YValueMembers = "Real Lower Band"; //(chartBollingerBands.Series["Real Lower Band"]).ToolTip = "Lower Band: Date:#VALX; Value:#VALY"; (chartBollingerBands.Series["Real Middle Band"]).XValueMember = "Date"; (chartBollingerBands.Series["Real Middle Band"]).XValueType = ChartValueType.Date; (chartBollingerBands.Series["Real Middle Band"]).YValueMembers = "Real Middle Band"; //(chartBollingerBands.Series["Real Middle Band"]).ToolTip = "Middle Band: Date:#VALX; Value:#VALY"; (chartBollingerBands.Series["Real Upper Band"]).XValueMember = "Date"; (chartBollingerBands.Series["Real Upper Band"]).XValueType = ChartValueType.Date; (chartBollingerBands.Series["Real Upper Band"]).YValueMembers = "Real Upper Band"; //(chartBollingerBands.Series["Real Upper Band"]).ToolTip = "Upper Band: Date:#VALX; Value:#VALY"; //chartBollingerBands.Legends.Add("Real Lower Band"); //chartBollingerBands.Legends["Real Lower Band"].Docking = System.Web.UI.DataVisualization.Charting.Docking.Top; //chartBollingerBands.Legends["Real Lower Band"].LegendStyle = System.Web.UI.DataVisualization.Charting.LegendStyle.Row; //chartBollingerBands.Legends["Real Lower Band"].BorderDashStyle = System.Web.UI.DataVisualization.Charting.ChartDashStyle.Dash; //chartBollingerBands.Legends["Real Lower Band"].BorderColor = System.Drawing.Color.Black; //chartBollingerBands.Legends.Add("Real Middle Band"); //chartBollingerBands.Legends["Real Middle Band"].Docking = System.Web.UI.DataVisualization.Charting.Docking.Top; //chartBollingerBands.Legends["Real Middle Band"].LegendStyle = System.Web.UI.DataVisualization.Charting.LegendStyle.Row; //chartBollingerBands.Legends["Real Middle Band"].BorderDashStyle = System.Web.UI.DataVisualization.Charting.ChartDashStyle.Dash; //chartBollingerBands.Legends["Real Middle Band"].BorderColor = System.Drawing.Color.Black; //chartBollingerBands.Legends.Add("Real Upper Band"); //chartBollingerBands.Legends["Real Upper Band"].Docking = System.Web.UI.DataVisualization.Charting.Docking.Top; //chartBollingerBands.Legends["Real Upper Band"].LegendStyle = System.Web.UI.DataVisualization.Charting.LegendStyle.Row; //chartBollingerBands.Legends["Real Upper Band"].BorderDashStyle = System.Web.UI.DataVisualization.Charting.ChartDashStyle.Dash; //chartBollingerBands.Legends["Real Upper Band"].BorderColor = System.Drawing.Color.Black; chartBollingerBands.ChartAreas["chartareaBollingerBands"].AxisX.Title = "Date"; chartBollingerBands.ChartAreas["chartareaBollingerBands"].AxisX.TitleAlignment = System.Drawing.StringAlignment.Center; chartBollingerBands.ChartAreas["chartareaBollingerBands"].AxisY.Title = "Value"; chartBollingerBands.ChartAreas["chartareaBollingerBands"].AxisY.TitleAlignment = System.Drawing.StringAlignment.Center; //chartBollingerBands.Titles["titleBbands"].Text = $"{"Bollinger Bands - "}{scriptName}"; //VerticalLineAnnotation VA = new VerticalLineAnnotation(); //VA.AxisX = chartBollingerBands.ChartAreas["chartareaBollingerBands"].AxisX; //VA.IsInfinitive = true; //VA.ClipToChartArea = chartBollingerBands.ChartAreas["chartareaBollingerBands"].Name; //VA.Name = "myLine"; //VA.LineColor = System.Drawing.Color.Red; //VA.LineWidth = 10; // use your numbers! //HorizontalLineAnnotation HA = new HorizontalLineAnnotation(); //VA.AxisY = chartBollingerBands.ChartAreas["chartareaBollingerBands"].AxisY; //VA.IsInfinitive = true; //VA.ClipToChartArea = chartBollingerBands.ChartAreas["chartareaBollingerBands"].Name; //VA.Name = "myLine2"; //VA.LineColor = System.Drawing.Color.Red; //VA.LineWidth = 10; // use your numbers! //chartBollingerBands.Annotations.Add(VA); //chartBollingerBands.Annotations.Add(HA); if (chartBollingerBands.Annotations.Count > 0) { chartBollingerBands.Annotations.Clear(); } chartBollingerBands.DataSource = scriptData; chartBollingerBands.DataBind(); //VA.X = chartBollingerBands.Series[0].Points.FindMinByValue("X", 0).XValue; //VA.Y = chartBollingerBands.Series[0].Points.FindMinByValue("Y1", 0).YValues[0]; ; //chartBollingerBands.ChartAreas[0].AxisX.Minimum = chartBollingerBands.Series[0].Points.FindMinByValue("X", 0).XValue; //chartBollingerBands.ChartAreas[0].AxisX.Maximum = chartBollingerBands.Series[0].Points.FindMaxByValue("X", 0).XValue; // + 1; } }
public void FillData() { DataTable tempData = null; DataTable dailyNAVSMA = null; DataTable indexTable = null; DataRow[] filteredRows = null; string expression = ""; DataManager dataMgr = new DataManager(); string folderPath = Session["DATAFOLDER"].ToString(); int smallperiod = Int32.Parse(textboxSMASmallPeriod.Text.ToString()); int longperiod = Int32.Parse(textboxSMALongPeriod.Text.ToString()); int buySpan = Int32.Parse(textboxBuySpan.Text.ToString()); int sellSpan = Int32.Parse(textboxSellSpan.Text.ToString()); string schemeCode = Request.QueryString["schemecode"].ToString(); double simulationQty = double.Parse(textboxSimulationQty.Text.ToString()); //if we were called from portfolio page then get the portfolio data for selected scheme //if (Request.QueryString["schemecode"] != null) if ((Session["MFPORTFOLIONAME"] != null) && (Session["MFPORTFOLIOMASTERROWID"] != null)) { if ((ddlShowHidePortfolio.SelectedIndex == 0) && ((ViewState["VALUATION_TABLE"] == null) || (((DataTable)ViewState["VALUATION_TABLE"]).Rows.Count == 0))) { tempData = dataMgr.GetValuationLineGraph(Session["MFPORTFOLIOMASTERROWID"].ToString(), Session["EMAILID"].ToString(), Session["MFPORTFOLIONAME"].ToString()); expression = "SCHEME_CODE = '" + schemeCode + "'"; filteredRows = tempData.Select(expression); if ((filteredRows != null) && (filteredRows.Length > 0)) { ViewState["VALUATION_TABLE"] = (DataTable)filteredRows.CopyToDataTable(); //gridviewPortfolioValuation.DataSource = (DataTable)ViewState["VALUATION_TABLE"]; //gridviewPortfolioValuation.DataBind(); } } } if ((ViewState["FetchedData"] == null) || (((DataTable)ViewState["FetchedData"]).Rows.Count == 0)) { dailyNAVSMA = dataMgr.getBacktestFromSMA(Int32.Parse(schemeCode), fromDate: ((ViewState["FromDate"] == null) || (ViewState["FromDate"].ToString().Equals(""))) ? null : ViewState["FromDate"].ToString(), toDate: ((ViewState["ToDate"] == null) || (ViewState["ToDate"].ToString().Equals(""))) ? null : ViewState["ToDate"].ToString(), smallPeriod: smallperiod, longPeriod: longperiod, buySpan: buySpan, sellSpan: sellSpan, simulationQty: simulationQty); if (dailyNAVSMA != null) { ViewState["FetchedData"] = dailyNAVSMA; //gridviewBackTestMF.DataSource = (DataTable)ViewState["FetchedData"]; //gridviewBackTestMF.DataBind(); } } if ((System.Convert.ToInt32((ViewState["SelectedIndex"].ToString())) != ddlIndex.SelectedIndex) && (ddlIndex.SelectedIndex > 0)) { //Some index is selected by user indexTable = StockApi.getDailyAlternate(folderPath, ddlIndex.SelectedValue, bIsTestModeOn: false, bSaveData: false, apiKey: Session["ApiKey"].ToString()); ViewState["FetchedIndexData"] = indexTable; ViewState["SelectedIndex"] = ddlIndex.SelectedIndex; } }