protected void Page_Load(object sender, EventArgs e) { txtBoxes.Add(txtFname); txtBoxes.Add(txtPhoneNumber); txtBoxes.Add(txtStreet); txtBoxes.Add(txtCity); txtBoxes.Add(txtState); txtBoxes.Add(txtZip); if (!IsPostBack) { int custIDSession; //if they are requesting the page for the first time, make sure they are logged in if (Session["CustID"] != null) { custIDSession = (int)Session["CustID"]; Objects.Customer currentCustomer = new Objects.Customer(); currentCustomer = Tools.CheathamCustomerDB.GetCustomer(custIDSession); txtFname.Text = currentCustomer.Name; txtPhoneNumber.Text = currentCustomer.PhoneNumber; txtStreet.Text = currentCustomer.Address; txtCity.Text = currentCustomer.City; txtState.Text = currentCustomer.State; txtZip.Text = currentCustomer.Zip.ToString(); txtHeader.Text = "Welcome, " + currentCustomer.Name + "."; Session["Customer"] = currentCustomer; } else { //Invalid Session Response.Redirect("login.aspx"); } } }
private void TextBoxSwitch() //Fix this shit { //If boxes are editable, save the content. if (txtFname.ReadOnly == false) { bool hasValue = true; foreach (TextBox textbox in txtBoxes) { textbox.ReadOnly = true; if (textbox.Text == "") { hasValue = false;// I have no faith this will actually work... fix later } } if (hasValue) { btnEdit.Text = "Edit"; btnEdit.CssClass = "btn btn-outline-dark btn-sm"; Objects.Customer updateCustomer = new Objects.Customer(); updateCustomer = (Objects.Customer)Session["Customer"]; updateCustomer.AccountNumber = 755445;// <------------------------------------Replace with session variable updateCustomer.Name = txtFname.Text; updateCustomer.PhoneNumber = txtPhoneNumber.Text; updateCustomer.Address = txtStreet.Text; updateCustomer.City = txtCity.Text; updateCustomer.State = txtState.Text; updateCustomer.Zip = Convert.ToInt32(txtZip.Text); Session["Customer"] = updateCustomer; bool hasUpdated = false; hasUpdated = Tools.CheathamCustomerDB.UpdateCustomer(updateCustomer);//SQLDB UPDATE if (hasUpdated) { txtHeader.Text = "Welcome, " + updateCustomer.Name + "."; txtHeader.CssClass = "h4"; } else { txtHeader.Text = "Database error"; txtHeader.CssClass = "alert alert-danger"; } } else { this.TextBoxSwitch(); txtHeader.Text = "Customer information cannot be empty"; txtHeader.CssClass = "alert alert-warning"; } } else//Boxes are not editable. Make them editable to update content. { foreach (TextBox textbox in txtBoxes) { textbox.ReadOnly = false; } btnEdit.Text = "Save"; btnEdit.CssClass = "btn btn-success btn-sm"; } }