using System; using System.Web.UI; using System.Data; using System.Drawing; using System.Security.Principal; namespace CH78 { public partial class Display : Page { protected string pageType; protected void Page_Load(object sender, EventArgs e) { string studentID = ""; string gender; if (!IsPostBack) { pageType = Request.QueryString["type"].Trim().ToUpper(); // retrieve the querystring if (String.IsNullOrEmpty(Request.QueryString["ID"])) { // not the right entry point Response.Redirect("Home.aspx"); } else if (Request.QueryString["ID"].Trim().ToUpper() == "NEW") { BindDDL(); } else if (Request.QueryString["type"].Trim().ToUpper() == "VIEW") // display { GetStudent(Request.QueryString["ID"].Trim(), Request.QueryString["type"].Trim().ToUpper()); } else if (Request.QueryString["type"].Trim().ToUpper() == "EDIT") // edit { GetStudent(Request.QueryString["ID"].Trim(), Request.QueryString["type"].Trim().ToUpper()); } else // anything else { Response.Redirect("Home.aspx"); } } } public void GetStudent(string studentid, string type) { // the right record DataSet ds = new DataSet(); string gender; ds = StudentDataTier.SearchStudents("","",studentid); if (ds.Tables[0].Rows.Count > 0) { txtStuID.Text = ds.Tables[0].Rows[0]["student_id"].ToString(); txtFNAME.Text = ds.Tables[0].Rows[0]["fname"].ToString(); txtLNAME.Text = ds.Tables[0].Rows[0]["lname"].ToString(); txtMidInit.Text = ds.Tables[0].Rows[0]["midinit"].ToString(); txtDOB.Text = ds.Tables[0].Rows[0]["DOB"].ToString(); txtActBal.Text = ds.Tables[0].Rows[0]["ACCT_BAL"].ToString(); txtMajor.Text = ds.Tables[0].Rows[0]["MAJOR"].ToString(); txtCellPhone.Text = ds.Tables[0].Rows[0]["CELL_PHONE"].ToString(); txtAdr1.Text = ds.Tables[0].Rows[0]["ADDRESS_ONE"].ToString(); txtCity.Text = ds.Tables[0].Rows[0]["CITY"].ToString(); txtZip.Text = ds.Tables[0].Rows[0]["ZIP"].ToString(); txtCreds.Text = ds.Tables[0].Rows[0]["TOTALCREDITS"].ToString(); // TODO complete other fields gender = ds.Tables[0].Rows[0]["GENDER"].ToString().Trim(); // if (gender.ToUpper() == "F") // { // txtGender.SelectedItem.Text = "FEMALE"; // } // else // { // txtGender.SelectedItem.Text = "MALE"; // } txtGender.Enabled = false; //mysalary = Decimal.Parse(ds.Tables[0].Rows[0]["salary"]) //txtSalary.Text = mysalary.ToString("C") //txtSalary.Enabled = False BindDDL(); // txtState.SelectedValue = ds.Tables[0].Rows[0]["state"].ToString(); if (type.ToUpper() == "VIEW") { txtStuID.Enabled = false; txtFNAME.Enabled = false; txtLNAME.Enabled = false; btnGoStu.Visible = false; btnCancelStu.Visible = false; } else if (type.ToUpper() == "EDIT") { txtGender.Enabled = true; txtStuID.Enabled = false; btnGoStu.Visible = true; btnCancelStu.Visible = true; btnGoStu.Text = "UPDATE"; btnCancelStu.Text = "REFRESH"; btnGoStu.ForeColor = Color.Red; btnCancelStu.ForeColor = Color.Blue; } else if (type.ToUpper() == "NEW") { txtGender.Enabled = true; txtStuID.Enabled = false; btnGoStu.Visible = true; btnCancelStu.Visible = true; btnGoStu.Text = "UPDATE"; btnCancelStu.Text = "REFRESH"; btnGoStu.ForeColor = Color.Red; btnCancelStu.ForeColor = Color.Blue; } } } protected void BindDDL() { txtState.DataSource = StudentDataTier.GetStates(); txtState.DataTextField = "Name"; txtState.DataValueField = "StateID"; txtState.SelectedValue = "1"; txtState.DataBind(); txtGender.DataSource = StudentDataTier.GetGenders(); txtGender.DataTextField = "CommonName"; txtGender.DataValueField = "Gender_ID"; txtGender.SelectedValue = "0"; txtGender.DataBind(); } protected void btnCancelStu_OnClick(object sender, EventArgs e) { } protected void btnGoStu_OnClick(object sender, EventArgs e) { if (Request.QueryString["type"].Trim().ToUpper() == "VIEW") { } else if (Request.QueryString["type"].Trim().ToUpper() == "EDIT") { StudentDataTier.UpdateStudents(0, txtStuID.Text, txtFNAME.Text, txtLNAME.Text, txtMidInit.Text, DateTime.Parse(txtDOB.Text), txtGender.Text, decimal.Parse(txtActBal.Text), txtMajor.Text, txtCellPhone.Text, txtAdr1.Text, txtCity.Text, txtState.ToString(), txtZip.Text, decimal.Parse(txtCreds.Text)); } else if (Request.QueryString["type"].Trim().ToUpper() == "NEW") { StudentDataTier.UpdateStudents(1, txtStuID.Text, txtFNAME.Text, txtLNAME.Text, txtMidInit.Text, DateTime.Parse(txtDOB.Text), txtGender.Text.ToString(), decimal.Parse(txtActBal.Text), txtMajor.Text, txtCellPhone.Text, txtAdr1.Text, txtCity.Text, txtState.Text.ToString(), txtZip.Text, decimal.Parse(txtCreds.Text)); } } } }