ASP.NET Page /PracticalPhysics/Default.aspx.cs (C#)
1: using System;  
2: using System.Collections.Generic;  
3: using System.Data;  
4: using System.IO;  
5: using System.Linq;  
6: using System.Web;  
7: using System.Web.UI;  
8: using System.Web.UI.WebControls;  
9: using PracticalPhysicsLogic;  
10:   
11: namespace QuiznetOnline.Web.UI  
12: {  
13:     public partial class PracticalPhysics_Default : System.Web.UI.Page  
14:     {  
15:         protected void Page_Load(object sender, EventArgs e)  
16:         {  
17:   
18:         }  
19:   
20:         private void LoadProducts()  
21:         {  
22:             Products products = new Products();  
23:             lstProducts.DataSource = products.GetProducts();  
24:             lstProducts.DataTextField = "ProductName";  
25:             lstProducts.DataValueField = "ProductID";  
26:             lstProducts.DataBind();  
27:   
28:             lstProducts.Items.Insert(0, new ListItem("Please select a product", "0"));  
29:         }  
30:   
31:         protected void btnLogin_Click(object sender, EventArgs e)  
32:         {  
33:             ConnecionToken connToken = ConnecionToken.Instance;  
34:             connToken.Password = txtPassword.Text;  
35:             connToken.UserID = txtUserName.Text;  
36:   
37:             Security security=new Security();  
38:   
39:             try  
40:             {  
41:                 security.ValidateUser(txtUserName.Text, txtPassword.Text);  
42:   
43:                 panelMain.Visible = true;  
44:                 panelLogin.Visible = false;  
45:   
46:                 LoadProducts();  
47:                 LoadGridFiles();  
48:             }  
49:             catch(Exception ex)  
50:             {  
51:                 lblStatus.Text = ex.Message;  
52:                 panelMain.Visible = false;  
53:                 panelLogin.Visible = true;  
54:             }  
55:         }  
56:   
57:         private void LoadGridFiles()  
58:         {  
59:             Results results = new Results();  
60:             List<Results> Files = results.ReadResultsFiles(Server.MapPath("./"), Request.ServerVariables["URL"].Replace("Default.aspx", ""), txtUserName.Text);  
61:   
62:             grdFiles.DataSource = Files;  
63:             grdFiles.DataBind();  
64:         }  
65:   
66:         protected void btnSubmit_Click(object sender, EventArgs e)  
67:         {  
68:             string str_startdate = startdatepicker.Value == string.Empty ? null : startdatepicker.Value;  
69:             string str_enddate = enddatepicker.Value == string.Empty ? null : enddatepicker.Value;  
70:   
71:             DateTime? startdate = str_startdate == null ? (DateTime?)null : Convert.ToDateTime(str_startdate);  
72:             DateTime? enddate = str_enddate == null ? (DateTime?)null : ((Convert.ToDateTime(str_enddate)).AddHours(24)).AddSeconds(-1);  
73:   
74:             Results results=new Results();  
75:   
76:   
77:             DataTable tbl=results.QueryResults(lstProducts.SelectedItem.Value == "0" ? null : lstProducts.SelectedItem.Text, txtSerialNumber.Text == string.Empty ? null : txtSerialNumber.Text, startdate, enddate);  
78:   
79:             if (tbl.Rows.Count > 0)  
80:             {  
81:                 results.SaveResult(Server.MapPath(""), txtUserName.Text, tbl);  
82:                 LoadGridFiles();  
83:             }  
84:         }  
85:   
86:         protected void grdFiles_RowDeleting(object sender, GridViewDeleteEventArgs e)  
87:         {  
88:             HyperLink hyper = (HyperLink) grdFiles.Rows[e.RowIndex].Cells[2].Controls[1];  
89:             TextBox WindowsLocation = (TextBox)grdFiles.Rows[e.RowIndex].Cells[2].FindControl("txtwindowsLocation");  
90:   
91:             File.Delete(WindowsLocation.Text);  
92:   
93:             LoadGridFiles();  
94:         }  
95:     }  
96: }

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.