using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using ButterfieldGardens.Web; public partial class admin_index : System.Web.UI.Page { public long iInventoryId = -1; protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] == null) { Response.Redirect("/admin/"); } if (!Request.QueryString.Get("i").Equals(null)) { iInventoryId = Convert.ToInt32(Request.QueryString.Get("i").ToString()); if (!IsPostBack) { Load_Inventory(); } } else { DisableForm(); } Navigation objNav = new Navigation(); header.InnerHtml = objNav.GetAdminHeader(); adminNav.InnerHtml = objNav.GetAdminSubNavMenu("inventory"); footer.InnerHtml = objNav.GetFooter(false, false); Page.MaintainScrollPositionOnPostBack = true; } public void Load_Inventory() { cInventoryDAO objInvDAO = new cInventoryDAO(); cInventory objInv = objInvDAO.GetInventory(Convert.ToString(iInventoryId)); if (objInv.InventoryId.Equals(-1)) { DisableForm(); return; } txtTitle.Text = objInv.InventoryTitle; txtDescription.Text = objInv.InventoryDescription; txtPrice.Text = objInv.Price; objInv.Dispose(); objInvDAO.Dispose(); } protected void SaveProperty(object sender, EventArgs e) { try { ValidateUserInput(); EditProperty(); Response.Redirect("/admin/manage-inventory.aspx"); } catch (Exception ex) { DisplayErrorMessage(ex); } } public void ValidateUserInput() { Boolean isValid = true; if (txtTitle.Text.Equals("")) { isValid = false; } if (txtDescription.Text.Equals("")) { isValid = false; } if (txtPrice.Text.Equals("")) { isValid = false; } if (isValid.Equals(false)) { throw (new Exception("All fields are required for this form. Please try again.")); } } public void EditProperty() { cInventoryDAO objInvDAO = new cInventoryDAO(); cInventory objInv = new cInventory(); objInv.InventoryId = iInventoryId; objInv.InventoryTitle = txtTitle.Text; objInv.InventoryDescription = txtDescription.Text; objInv.Price = txtPrice.Text; objInvDAO.UpdateInventory(objInv); } public void DisplaySuccessMessage() { Literal lit = new Literal(); lit.Text = "The property was successfully edited. To add another property, complete the form below."; lblNotify.Controls.Add(lit); lblNotify.CssClass = "success"; lblNotify.Visible = true; txtTitle.Text = ""; txtDescription.Text = ""; txtPrice.Text = ""; } public void DisplayErrorMessage(Exception exError) { Literal lit = new Literal(); lit.Text = exError.Message; lblNotify.Controls.Add(lit); lblNotify.CssClass = "error"; lblNotify.Visible = true; } public void DisableForm() { inventoryEditForm.Disabled = true; } }