From fb27c94b957485696aba2c1728c9d6820da55e81 Mon Sep 17 00:00:00 2001 From: caschick221 Date: Wed, 20 Mar 2024 15:33:54 -0400 Subject: [PATCH] H{ouhbibib --- .idea/config/applicationhost.config | 14 ++--- CH78/Display.aspx.cs | 90 +++++++++++++++++++++++++++++ CH78/Home.aspx.cs | 27 ++++++++- CH78/StudentDataTier.cs | 37 ++++++++++++ CH78/Web.config | 2 +- 5 files changed, 161 insertions(+), 9 deletions(-) diff --git a/.idea/config/applicationhost.config b/.idea/config/applicationhost.config index 0c9a32e..654d94b 100644 --- a/.idea/config/applicationhost.config +++ b/.idea/config/applicationhost.config @@ -155,7 +155,7 @@ - + @@ -163,7 +163,7 @@ - + @@ -171,7 +171,7 @@ - + @@ -179,7 +179,7 @@ - + @@ -187,7 +187,7 @@ - + @@ -195,7 +195,7 @@ - + @@ -203,7 +203,7 @@ - + diff --git a/CH78/Display.aspx.cs b/CH78/Display.aspx.cs index a92d31a..5a403f8 100644 --- a/CH78/Display.aspx.cs +++ b/CH78/Display.aspx.cs @@ -1,5 +1,7 @@ using System; using System.Web.UI; +using System.Data; +using System.Drawing; namespace CH78 { @@ -7,7 +9,95 @@ namespace CH78 { protected void Page_Load(object sender, EventArgs e) { + string studentID = ""; + string gender; + if (!IsPostBack) + { + // 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") + { + // do nothing + } + + 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 + StudentDataTier stuDT = new StudentDataTier(); + 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(); + // TODO complete other fields + + gender = ds.Tables[0].Rows[0]["gender_desc"].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 + + txtState.DataSource = StudentDataTier.GetStates(); + txtState.DataTextField = "FullAndAbbrev"; + txtState.DataValueField = "abbreviation"; + txtState.SelectedValue = "PA"; + txtState.DataBind(); + + 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") + { + 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 btnCancelStu_OnClick(object sender, EventArgs e) diff --git a/CH78/Home.aspx.cs b/CH78/Home.aspx.cs index 39f40c0..9b001f9 100644 --- a/CH78/Home.aspx.cs +++ b/CH78/Home.aspx.cs @@ -195,7 +195,32 @@ namespace CH78 protected void lbtnEdit_Click(object sender, CommandEventArgs e) { - + string recordToBeEdited; + Int64 mEditedRecord = 0; + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + + try + { + Session["vStudentID"] = txtStudentID.Text.Trim(); + Session["vFName"] = txtFName.Text.Trim(); + Session["vLName"] = txtLName.Text.Trim(); + + // Get the record + recordToBeEdited = (e.CommandArgument.ToString().Trim()); + + // this script will open a popup + sb.Append(""); + + // register with ClientScript + Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopupScript", sb.ToString()); + } + catch (Exception ex) + { + throw new Exception(ex.Message, ex.InnerException); + } } } } \ No newline at end of file diff --git a/CH78/StudentDataTier.cs b/CH78/StudentDataTier.cs index 15fab8e..58ebba7 100644 --- a/CH78/StudentDataTier.cs +++ b/CH78/StudentDataTier.cs @@ -66,6 +66,43 @@ namespace CH78 myConn.Close(); } } + + + public static DataSet GetStates() + { + + + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "GetAllStates"; + // adapter and dataset + SqlDataAdapter aAdapter = new SqlDataAdapter(); + aAdapter.SelectCommand = cmdString; + DataSet aDataSet = new DataSet(); + + // fill adapter + aAdapter.Fill(aDataSet); + + // return dataSet + return aDataSet; + } + catch (Exception ex) + { + throw new ArgumentException(ex.Message); + } + finally + { + myConn.Close(); + } + } public static DataSet SearchStudents(string fname, string lname, string stuID) { diff --git a/CH78/Web.config b/CH78/Web.config index a05e4d9..d8f1b02 100644 --- a/CH78/Web.config +++ b/CH78/Web.config @@ -15,7 +15,7 @@ - +