<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage"
Language="C#" Debug="true" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile"
%>
<%@ Import Namespace="System" %>
<%@ Import
Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"
%>
<%@ Import Namespace="System.Net" %>
<%@ Import
Namespace="System.Text" %>
<%@ Import Namespace="System.IO"
%>
<%@ Import Namespace="System.Web.Mobile" %>
<script
runat="server" language="C#">
public String str;
public
string strConn =@"Provider=
Microsoft.Jet.OLEDB.4.0;Data
Source=C:\inetpub\wwwroot\Prsnlmob\db1.mdb;";
private char[] separator =
{','} ;
protected OleDbConnection oleDbConnection1;
protected
OleDbCommand oleDbCommand1;
protected OleDbCommand
oleDbCommand2;
private string strUserName;
private void
Page_Load(object sender, System.EventArgs e)
{
oleDbConnection1
= new OleDbConnection(strConn);
oleDbCommand1 = new
OleDbCommand();
oleDbCommand2 = new OleDbCommand();
if
(!IsPostBack)
{
strUserName =
Context.User.Identity.Name;
Label1.Text = strUserName;
TextBox1.Text =
GetSymbolsForUser();
FillQuotes(TextBox1.Text);
}
}
private
void Command1_Click(object sender, System.EventArgs
e)
{
//Signout
MobileFormsAuthentication.SignOut();
RedirectToMobilePage("login.aspx");
}
private
void FillQuotes(string strSymbols)
{
//this function will fetch stock
quotes for each stock symbol specified by the user and populate the data in a
datatable. The data is finally bound to an ObjectList.
HttpWebRequest
req;
HttpWebResponse res;
StreamReader sr;
string
strResult;
string[] temp;
string[] temp1;
string
strcurindex;
string fullpath ;
DataSet ds = new
DataSet();
ds.Tables.Add("tblStk");
DataColumn SymbolColumn = new
DataColumn();
SymbolColumn.DataType =
System.Type.GetType("System.String");
SymbolColumn.AllowDBNull = true;
SymbolColumn.Caption = "Symbol";
SymbolColumn.ColumnName =
"StkSymbol";
SymbolColumn.DefaultValue = "MSFT";
// Add the column
to the table.
ds.Tables["tblStk"].Columns.Add(SymbolColumn );
//get stock quote for each row
DataColumn PriceColumn = new
DataColumn();
PriceColumn.DataType =
System.Type.GetType("System.Decimal");
PriceColumn.AllowDBNull = true;
PriceColumn.Caption = "Price";
PriceColumn.ColumnName = "StkPrice";
PriceColumn.DefaultValue = 0;
// Add the column to the table.
ds.Tables["tblStk"].Columns.Add(PriceColumn);
temp =
strSymbols.Split(separator) ;
if (temp.Length > 0)
{
for(int
i=0;i<temp.Length;i++)
{
fullpath =
@"http://quote.yahoo.com/d/quotes.csv?s="+ temp[i]
+"&f=sl1d1t1c1ohgvj1pp2owern&e=.csv";
try
{
req =
(HttpWebRequest) WebRequest.Create(fullpath);
res = (HttpWebResponse)
req.GetResponse();
sr = new StreamReader(res.GetResponseStream(),
Encoding.ASCII);
strResult =
sr.ReadLine();
sr.Close();
temp1 = strResult.Split(separator)
;
if(temp1.Length >1)
{
//only the relevant portion
.
strcurindex = temp1[1] ;
DataRow myRow =
ds.Tables["tblStk"].NewRow();
myRow[0] = temp[i];
myRow[1] =
Convert.ToDecimal(strcurindex);
ds.Tables["tblStk"].Rows.Add(myRow);
}
}
catch(Exception
)
{
}
}
ObjectList1.DataSource =
ds.Tables["tblStk"].DefaultView;
ObjectList1.DataBind();
ObjectList1.TableFields="StkSymbol;StkPrice";
}
}
private void Command2_Click(object sender,
System.EventArgs e)
{
//the following code will update the Stock
Symbol preferences as specified by the user.
oleDbCommand2.Connection =
oleDbConnection1;
oleDbCommand2.CommandText = "UPDATE tblStock SET
StockSymbols = ? WHERE (UserId = ?)";
oleDbCommand2.Parameters.Add(new
System.Data.OleDb.OleDbParameter("StockSymbols",
System.Data.OleDb.OleDbType.VarWChar, 255,
"StockSymbols"));
oleDbCommand2.Parameters.Add(new
System.Data.OleDb.OleDbParameter("Original_UserId",
System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "UserId",
System.Data.DataRowVersion.Original,
null));
oleDbCommand2.Parameters[0].Value =
TextBox1.Text;
oleDbCommand2.Parameters[1].Value =
Context.User.Identity.Name;
oleDbConnection1.Open();
oleDbCommand2.ExecuteNonQuery();
oleDbConnection1.Close();
FillQuotes(GetSymbolsForUser());
}
private
void Command3_Click(object sender, System.EventArgs e)
{
//Refresh the
stock quotes
FillQuotes(GetSymbolsForUser());
}
private
string GetSymbolsForUser()
{
//Fetch the preferences specified by the
user from the database
oleDbCommand1.Connection =
oleDbConnection1;
oleDbCommand1.CommandText = "SELECT StockSymbols, UserId
FROM tblStock WHERE (UserId =
?)";
this.oleDbCommand1.Parameters.Add(new
System.Data.OleDb.OleDbParameter("UserId", System.Data.OleDb.OleDbType.VarWChar,
50, "UserId"));
oleDbCommand1.Parameters[0].Value =
Context.User.Identity.Name;
oleDbConnection1.Open();
string strSymbols
=
(string)oleDbCommand1.ExecuteScalar();
oleDbConnection1.Close();
return
strSymbols;
}
</script>
<mobile:Form id = "Form1"
runat="server">
<mobile:Label id="Label1"
runat="server">Label</mobile:Label>
<mobile:TextBox
id="TextBox1" runat="server"></mobile:TextBox>
<mobile:Command
id="Command2" runat="server" onClick="Command2_Click">Update Stock
Symbols</mobile:Command>
<mobile:Command id="Command3"
runat="server" onClick="Command3_Click">Refresh
Quotes</mobile:Command>
<mobile:ObjectList id="ObjectList1"
runat="server" LabelStyle-StyleReference="title"
CommandStyle-StyleReference="subcommand"></mobile:ObjectList>
<mobile:Command
id="Command1" runat="server"
OnClick="Command1_Click">Logout</mobile:Command>
</mobile:Form>
<?xml version="1.0" encoding="utf-8"
?>
<configuration>
<system.web>
<compilation defaultLanguage="c#"
debug="true"/>
<customErrors mode="Off" />
<authentication mode="Forms" >
<forms loginUrl="login.aspx"
name=".ASPXCOOKIEAUTH"
path="/">
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
<trace enabled="false"
requestLimit="10" pageOutput="false" traceMode="SortByTime"
localOnly="true"/>
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data
source=127.0.0.1;user id=sa;password=" cookieless="true" timeout="20"
/>
<globalization requestEncoding="utf-8"
responseEncoding="utf-8" />
<httpRuntime
useFullyQualifiedRedirectUrl="true" />
<mobileControls
cookielessDataDictionaryType="System.Web.Mobile.CookielessData"
/>
<deviceFilters>
<filter name="isHTML32"
compare="PreferredRenderingType" argument="html32" />
<filter
name="isWML11" compare="PreferredRenderingType" argument="wml11"
/>
<filter name="is
CHTML10" compare="PreferredRenderingType"
argument="chtml10" />
<filter name="isGoAmerica" compare="Browser"
argument="Go.Web" />
<filter name="isMME" compare="Browser"
argument="Microsoft Mobile Explorer" />
<filter name="isMyPalm"
compare="Browser" argument="MyPalm" />
<filter name="isPocketIE"
compare="Browser" argument="Pocket IE" />
<filter name="isUP3x"
compare="Type" argument="Phone.com 3.x Browser" />
<filter
name="isUP4x" compare="Type" argument="Phone.com 4.x Browser"
/>
<filter name="isEricssonR380" compare="Type" argument="Ericsson
R380" />
<filter name="isNokia7110" compare="Type" argument="Nokia
7110" />
<filter name="prefersGIF" compare="PreferredImageMIME"
argument="image/gif" />
<filter name="prefersWBMP"
compare="PreferredImageMIME" argument="image/vnd.wap.wbmp"
/>
<filter name="supportsColor" compare="IsColor" argument="true"
/>
<filter name="supportsCookies" compare="Cookies" argument="true"
/>
<filter name="supportsJavaScript" compare="Javascript"
argument="true" />
<filter name="supportsVoiceCalls"
compare="CanInitiateVoiceCall" argument="true" />
</deviceFilters>
</system.web>
</configuration>