-
Notifications
You must be signed in to change notification settings - Fork 7
/
getquoteadd.aspx.cs
316 lines (296 loc) · 14 KB
/
getquoteadd.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
using DataAccessLayer;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Analytics
{
public partial class getquoteadd : System.Web.UI.Page
{
public string Symbol
{
get
{
if (DropDownListStock.SelectedIndex >= 0)
return DropDownListStock.SelectedValue;
else
return "";
}
}
public string CompanyName
{
get
{
if (DropDownListStock.SelectedIndex >= 0)
//return (DropDownListStock.SelectedItem.Text.Split(':')[1]).Trim();
return DropDownListStock.SelectedItem.Text.Trim();
else
return "";
}
}
public string ExchangeCode
{
get
{
return textboxExch.Text.Trim();
}
}
public string ExchangeDisplay
{
get
{
return textboxExchDisp.Text.Trim();
}
}
public string InvestmentType
{
get
{
return textboxType.Text.Trim();
}
}
public string InvestmentTypeDisplay
{
get
{
return textboxTypeDisp.Text.Trim();
}
}
public string QuoteDateTime
{
get
{
return System.Convert.ToDateTime(textboxLatestDay.Text.ToString()).ToString();
}
}
public string Price
{
get
{
return textboxPrice.Text;
}
}
protected void Page_Load(object sender, EventArgs e)
{
//if (Session["EMAILID"] != null)
//{
// Master.UserID = Session["EMAILID"].ToString();
//}
//if((Session["EMAILID"] != null) && (Session["STOCKPORTFOLIONAME"] != null))
if ((Session["EMAILID"] != null))
{
//Master.Portfolio = Session["STOCKPORTFOLIONAME"].ToString();
if (!IsPostBack)
{
ViewState["FetchedData"] = null;
DropDownListStock.Items.Clear();
StockManager stockManager = new StockManager();
DataTable tableStockMaster = stockManager.getStockMaster(ddlExchange.SelectedValue.ToString());
if ((tableStockMaster != null) && (tableStockMaster.Rows.Count > 0))
{
ViewState["STOCKMASTER"] = tableStockMaster;
ListItem li = new ListItem("Select Stock or Company", "-1");
DropDownListStock.Items.Add(li);
foreach (DataRow rowitem in tableStockMaster.Rows)
{
li = new ListItem(rowitem["COMP_NAME"].ToString(), rowitem["SYMBOL"].ToString() + "." + ddlExchange.SelectedValue);//rowitem["EXCHANGE"].ToString());
DropDownListStock.Items.Add(li);
}
}
bool isAddAllowed = true;
if (Request.QueryString["addallowed"] != null)
isAddAllowed = System.Convert.ToBoolean(Request.QueryString["valuation"]);
if (isAddAllowed)
{
buttonAddStock.Enabled = true;
}
else
{
buttonAddStock.Enabled = false;
}
}
}
else
{
//Response.Write("<script language=javascript>alert('" + common.noLogin + "')</script>");
Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('" + common.noLogin + "');", true);
Response.Redirect("~/Default.aspx");
}
}
protected void buttonAddStock_Click(object sender, EventArgs e)
{
//Server.Transfer("~/addnewscript.aspx");
if (ViewState["StockMasterRowId"] != null)
{
Session["STOCKPORTFOLIOSCRIPTID"] = ViewState["StockMasterRowId"];
if (this.MasterPageFile.Contains("Site.Master"))
Response.Redirect("~/addnewscript.aspx?symbol=" + Symbol + "&date=" + QuoteDateTime + "&price=" + Price + "&companyname=" + Server.UrlEncode(CompanyName) +
"&exch=" + ddlExchange.SelectedValue);
else if (this.MasterPageFile.Contains("Site.Mobile.Master"))
Response.Redirect("~/maddnewscript.aspx?symbol=" + Symbol + "&date=" + QuoteDateTime + "&price=" + Price + "&companyname=" + Server.UrlEncode(CompanyName) +
"&exch=" + ddlExchange.SelectedValue);
else
Response.Redirect("~/maddnewscript.aspx?symbol=" + Symbol + "&date=" + QuoteDateTime + "&price=" + Price + "&companyname=" + Server.UrlEncode(CompanyName) +
"&exch=" + ddlExchange.SelectedValue);
}
}
protected void buttonGoBack_Click(object sender, EventArgs e)
{
if (this.MasterPageFile.Contains("Site.Master"))
Response.Redirect("~/openportfolio.aspx");
else if (this.MasterPageFile.Contains("Site.Mobile.Master"))
Response.Redirect("~/mopenportfolio.aspx");
else
Response.Redirect("~/mopenportfolio.aspx");
}
protected void DropDownListStock_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownListStock.SelectedValue != "-1")
{
//labelSelectedSymbol.Text = DropDownListStock.SelectedValue;
textboxSelectedSymbol.Text = DropDownListStock.SelectedValue;
Session["STOCKPORTFOLIOSCRIPTNAME"] = DropDownListStock.SelectedValue;
textboxExch.Text = ddlExchange.SelectedValue;
textboxExchDisp.Text = ddlExchange.Text;
textboxType.Text = "";//scriptRows[0]["Type"].ToString();
textboxTypeDisp.Text = "";// scriptRows[0]["TypeDisplay"].ToString();
StockManager stockManager = new StockManager();
DataTable stockTable = stockManager.SearchStock(textboxSelectedSymbol.Text.Split('.')[0], ddlExchange.SelectedValue);
if((stockTable != null) && (stockTable.Rows.Count > 0))
{
ViewState["StockMasterRowId"] = stockTable.Rows[0]["ROWID"];
}
}
else
{
textboxSelectedSymbol.Text = "Please select stock to get quote for";
}
}
protected void ButtonSearch_Click(object sender, EventArgs e)
{
if (ViewState["STOCKMASTER"] != null)
{
DataTable stockMaster = (DataTable)ViewState["STOCKMASTER"];
if ((stockMaster != null) && (stockMaster.Rows.Count > 0))
{
StringBuilder filter = new StringBuilder();
if (!(string.IsNullOrEmpty(TextBoxSearch.Text)))
filter.Append("COMP_NAME Like '%" + TextBoxSearch.Text + "%'");
DataView dv = stockMaster.DefaultView;
dv.RowFilter = filter.ToString();
if (dv.Count > 0)
{
DropDownListStock.Items.Clear();
ListItem li = new ListItem("Select Stock", "-1");
DropDownListStock.Items.Add(li);
foreach (DataRow rowitem in dv.ToTable().Rows)
{
li = new ListItem(rowitem["COMP_NAME"].ToString(), rowitem["SYMBOL"].ToString() + "." + ddlExchange.SelectedValue);//rowitem["EXCHANGE"].ToString());
DropDownListStock.Items.Add(li);
}
}
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.noSymbolFound +"')</script>");
Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('" + common.noSymbolFound + "');", true);
}
}
protected void ButtonGetQuote_Click(object sender, EventArgs e)
{
string selectedSymbol = "";
if (DropDownListStock.SelectedIndex >= 0)
{
string folderPath = Server.MapPath("~/scriptdata/");
bool bIsTestOn = true;
if (Session["IsTestOn"] != null)
{
bIsTestOn = System.Convert.ToBoolean(Session["IsTestOn"]);
}
if (Session["DATAFOLDER"] != null)
{
folderPath = Session["DATAFOLDER"].ToString();
}
selectedSymbol = DropDownListStock.SelectedValue;
selectedSymbol = textboxSelectedSymbol.Text;
//DataTable quoteTable = StockApi.globalQuote(folderPath, selectedSymbol, bIsTestOn, apiKey: Session["ApiKey"].ToString());
//will try to ALWAYS get quote from market
//DataTable quoteTable = StockApi.globalQuoteAlternate(folderPath, selectedSymbol, bIsTestOn, apiKey: Session["ApiKey"].ToString());
//DataTable quoteTable = StockApi.globalQuoteAlternate(folderPath, selectedSymbol, bIsTestModeOn:false, apiKey: Session["ApiKey"].ToString());
//column names = symbol,open,high,low,price,volume,latestDay,previousClose,change,changePercent
StockManager stockManager = new StockManager();
DataTable quoteTable = stockManager.GetQuote(selectedSymbol);
if (quoteTable != null)
{
textboxOpen.Text = quoteTable.Rows[0]["open"].ToString();
textboxHigh.Text = quoteTable.Rows[0]["high"].ToString();
textboxLow.Text = quoteTable.Rows[0]["low"].ToString();
textboxPrice.Text = quoteTable.Rows[0]["price"].ToString();
textboxVolume.Text = quoteTable.Rows[0]["volume"].ToString();
textboxLatestDay.Text = System.Convert.ToDateTime(quoteTable.Rows[0]["latestDay"].ToString()).ToString("yyyy-MM-ddThh:mm:ss");
textboxPrevClose.Text = quoteTable.Rows[0]["previousClose"].ToString();
textboxChange.Text = quoteTable.Rows[0]["change"].ToString();
textboxChangePercent.Text = quoteTable.Rows[0]["changePercent"].ToString();
}
else
{
//Response.Write("<script language=javascript>alert('" + common.noQuoteAvailable + "')</script>");
Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('" + common.noQuoteAvailable + "');", true);
}
}
else
{
//Response.Write("<script language=javascript>alert('"+ common.noStockSelectedToGetQuote +"')</script>");
Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('" + common.noStockSelectedToGetQuote + "');", true);
}
}
protected void ddlExchange_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownListStock.Items.Clear();
TextBoxSearch.Text = "";
textboxSelectedSymbol.Text = "";
StockManager stockManager = new StockManager();
DataTable tableStockMaster = stockManager.getStockMaster(ddlExchange.SelectedValue.ToString());
if ((tableStockMaster != null) && (tableStockMaster.Rows.Count > 0))
{
ViewState["STOCKMASTER"] = tableStockMaster;
ListItem li = new ListItem("Select Stock", "-1");
DropDownListStock.Items.Add(li);
foreach (DataRow rowitem in tableStockMaster.Rows)
{
li = new ListItem(rowitem["COMP_NAME"].ToString(), rowitem["SYMBOL"].ToString() + "." + ddlExchange.SelectedValue);//rowitem["EXCHANGE"].ToString());
DropDownListStock.Items.Add(li);
}
}
else
{
ViewState["STOCKMASTER"] = null;
textboxOpen.Text = "";
textboxHigh.Text = "";
textboxLow.Text = "";
textboxPrice.Text = "";
textboxVolume.Text = "";
textboxLatestDay.Text = "";
textboxPrevClose.Text = "";
textboxChange.Text = "";
textboxChangePercent.Text = "";
textboxExch.Text = "";
textboxExchDisp.Text = "";
textboxType.Text = "";//scriptRows[0]["Type"].ToString();
textboxTypeDisp.Text = "";// scriptRows[0]["TypeDisplay"].ToString();
//Response.Write("<script language=javascript>alert('" + common.noSymbolFound +"')</script>");
Page.ClientScript.RegisterStartupScript(GetType(), "myScript", "alert('" + common.noSymbolFound + "');", true);
}
}
}
}