You are on page 1of 6

Login Page

<% @ Page Language= "C#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <Script runat="server"> void Page_Load(Object Src, EventArgs E) { string No = ""; string Name = ""; string Lesson = ""; string Msg = ""; i f (IsPostBack) {// No = Request["txtNo"]; Name = Request["txtName"]; Lesson = Request["Lesson"]; string SQL = "Select * From "; SQL = SQL + "Where =" + "'" + No + "'" + " And ='" + Name + "'"; OleDbConnection Conn; Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"+ "Data Source="+Server.MapPath("test.mdb")); Conn.Open(); //Response.Write(SQL); OleDbCommand Comm=new OleDbCommand(SQL,Conn); OleDbDataReader dr=Comm.ExecuteReader(); i f (dr.Read()) { { Msg = "!"; } else { Conn.Close(); Response.Redirect("TEST.ASPX? Lesson="+Lesson+"&Name="+Name+"&No="+No); } } else { Msg = "!"; } Message.Text = Msg; Conn.Close(); } i f (dr[Lesson].ToString() != "-1")

} </Scr ip t> <HTML> <BODY BGCOLOR=BEIGE> <H1 ALIGN= "CENTER"></H1> <HR> <FORM METHOD="POST" RUNAT="SERVER"> <asp:DropDownList ID="Lesson" RUNAT="server"> <asp:ListItem value="ASP" selected="true">ASP</asp:ListItem> <asp:ListItem value="XML">XML</asp:ListItem> </asp:DropDownList> <P><asp:textbox id="txtName" runat="server" /></P> <P><asp:textbox id="txtNo" runat="server" /></P> <P><asp:button text="" runat="server" /></P> </FORM> <HR> <asp:label id="Message" runat="server" />

...

Score.aspx
<% @ Page Language="C#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <Script runat="server"> string Lesson; string No; string Name; OleDbDataReader dr; string SQL; OleDbConnection Conn; OleDbCommand Comm; void Page_Load(Object Src, EventArgs E) {

Lesson =Request["Lesson"]; No = Request["No"]; Name = Request["Name"]; Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"+ "Data Source="+Server.MapPath("test.mdb")); Conn.Open(); SQL = "Select * from " + Lesson; //Response.Write(SQL); Comm = new OleDbCommand(SQL,Conn); dr = Comm.ExecuteReader(); } //<60 string TestResult(string inputScore){ int Score = Convert.ToInt32(inputScore); i f (-1 == Score) } else if(Score < 60){ return "<FONT Color=Red>" + Score + "</FONT>"; } else } } </Script> <HTML> <BODY BGCOLOR="BEIGE"> <H2><HR></H2> <% int Score = 0; while (dr.Read()) { if (Request["No" + dr[""].ToString()] != null) string Ans = dr[""].ToString(); //Response.Write(Sel + Ans + "<br>"); if (Ans == Sel) { Score = Score + Convert.ToInt32(dr[""].ToString()); //Response.Write( "OK" + Score); } { string Sel = Request["No" + dr[""].ToString()]; { return Score.ToString(); { return "";

} } // DataReader Connection Conn.Close(); Conn.Open(); SQL = "Select * From "; SQL = SQL + "Where =" + "'" + No + "'" + " And ='" + Name + "'"; Comm = new OleDbCommand(SQL,Conn); OleDbDataReader drScore = Comm.ExecuteReader(); if(drScore.Read()){ if (drScore[Lesson].ToString() == "-1") { SQL = "update set " + Lesson + " = " + Score.ToString() + " where =" + "'" + No + "'" + " And ='" + Name + "'"; Conn.Close(); Conn.Open(); Comm = new OleDbCommand(SQL,Conn); Comm.ExecuteNonQuery(); } else { Response.Write ("<script>{alert('')}</script>"); } } %> <%=Name%><BR> <CENTER> <TABLE BORDER=2 BGCOLOR="#F1F1F1" WIDTH=80%> <TR BGCOLOR="#DDDDDD"><TD></TD><TD></TD></TR> <%// Conn.Close(); Conn.Open(); SQL = "Select * From "; SQL = SQL + "Where =" + "'" + No + "'" + " And ='" + Name + "'"; Comm = new OleDbCommand(SQL,Conn); drScore = Comm.ExecuteReader(); if(drScore.Read()){ %> <TR><TD>ASP</TD><TD Align=Right><%=TestResult(drScore["ASP"].ToString()) %></TD></TR> <TR><TD>XML</TD><TD Align=Right>< %=TestResult(drScore["XML"].ToString())%></TD></TR>

<% <HR>

%>

</TABLE></center> <A HREF="login.aspx?txtNo=<%=No%>&txtName=<%=Name%>">

Test.aspx

<% @ Page Language="C#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <Script runat="server"> string Lesson; string No; string Name; OleDbDataReader dr; void Page_Load(Object Src, EventArgs E) { Lesson = Request["Lesson"]; No = Request["No"]; Name = Request["Name"]; string SQL = "Select * From " + Lesson + " Order By "; OleDbConnection Conn; Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"+ "Data Source="+Server.MapPath("test.mdb")); Conn.Open(); //Response.Write(SQL); OleDbCommand Comm = new OleDbCommand(SQL,Conn); dr = Comm.ExecuteReader(); } </Script> <HTML> <BODY BGCOLOR=BEIGE> <CENTER> <H1><FONT COLOR=#6699DD></FONT></H1>

</CENTER> <H2> -- <%=Lesson%><HR></H2> <FORM Action="Score.aspx" Method="GET"> <INPUT Type="Hidden" Name="Lesson" Value=<%=Lesson%>> <INPUT Type="Hidden" Name="No" Value=<%=No%>> <INPUT Type="Hidden" Name="Name" Value=<%=Name%>> <% string TestType = ""; while (dr.Read()){ Response.Write("<B>" + dr[""].ToString() + "." + Server.HtmlEncode(dr[""].ToString()) + dr[""].ToString() + ":" + dr[""].ToString() + ")</B>"); Response.Write("<div>"); for (int i=1; i<5; i++) { { if (dr[""].ToString() == "") TestType = "Radio"; } else } Response.Write("<INPUT Type=" + TestType + " Name=No" + dr[""].ToString() + " Value=" + i +">" + Server.HtmlEncode(dr["" + i].ToString()) + "<BR>"); } Response.Write("</div>"); } %> <INPUT Type=Submit Value=" "> { TestType = "CheckBox";

You might also like