using framework_business; using framework_library; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class controls_admin_productBrands : System.Web.UI.UserControl { #region methods /// /// Method to Bind Brand Data /// private void BindBrandData() { try { ArrayList catList = xData.GetTypedByCriteriaSpecific("recId", typeof(oProductBrand), "isActive", "1", "sequence"); rptProductBrands.DataSource = catList; rptProductBrands.DataBind(); } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Method to Bind the slide Order Drop down /// private void BindSequence() { try { for (int i = 0; i < 20; i++) { //append sequence item ddSequence.Items.Add(new ListItem(i.ToString(), i.ToString())); } } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Populate Form Values /// /// private void PopulatePageFormValues(ref oProductBrand _Brand) { try { txtBrand.Value = _Brand.brand; if (_Brand.sequence > 0) ddSequence.SelectedValue = _Brand.sequence.ToString(); } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Save Form Values /// /// private void SavePageFormValues(ref oProductBrand _Brand) { try { _Brand.brand = txtBrand.Value; _Brand.sequence = int.Parse(ddSequence.SelectedValue); } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Method to Toggle Panels /// /// private void TogglePanels(string panelName) { switch (panelName) { case "pnlBrandPage": pnlBrandPage.Visible = true; pnlBrandList.Visible = false; break; case "pnlBrandList": pnlBrandPage.Visible = false; pnlBrandList.Visible = true; break; } //clear result pnlResult.Visible = false; } #endregion #region events /// /// Page Load Event /// /// /// protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { BindBrandData(); BindSequence(); } } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// New Brand Click /// /// /// protected void btnNewBrand_Click(object sender, EventArgs e) { try { //show Content Specific TogglePanels("pnlBrandPage"); Session["BrandId"] = 0; utils.disposeSession("Brand"); oProductBrand Brand = new oProductBrand(); PopulatePageFormValues(ref Brand); } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit the Brand page /// /// /// protected void lnkEdit_Click(object sender, EventArgs e) { oProductBrand _Brand = new oProductBrand(); ArrayList catList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton)) { // int recId = int.Parse(((LinkButton)sender).CommandArgument); if (recId > 0) { Session["BrandId"] = recId; //get cat catList = xData.GetTypedByCriteriaSpecific("recId", typeof(oProductBrand), "recId", recId.ToString()); //enumerate list foreach (oProductBrand cat in catList) { //assign object _Brand = cat; //populate page form PopulatePageFormValues(ref _Brand); Session["Brand"] = _Brand; break; } //show Brand Form TogglePanels("pnlBrandPage"); } } } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Remove the Brand /// /// /// protected void lnkRemove_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { // int recId = int.Parse(((LinkButton)sender).CommandArgument); //Delete cat if (xData.DeleteTyped("recId", recId.ToString(), typeof(oProductBrand))) { //rebind pages grid BindBrandData(); pnlResult.Visible = true; //display successful result lblResult.Text = "the selected Brand was deleted successfully."; } } } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { Session["BrandId"] = 0; utils.disposeSession("Brand"); BindBrandData(); //show cat list TogglePanels("pnlBrandList"); } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Click /// /// /// protected void btnSave_Click(object sender, EventArgs e) { oProductBrand Brand = new oProductBrand(); try { if (utils.verifySession("Brand"))//update mode { Brand = (oProductBrand)Session["Brand"]; //save form values SavePageFormValues(ref Brand); if (xData.UpdateTyped("recId", Brand.recId.ToString(), typeof(oProductBrand), Brand)) { Session["BrandId"] = Brand.recId; Session["Brand"] = Brand; BindBrandData(); pnlResult.Visible = true; lblResult.Text = "your changes were updated successfully."; } } else { if (!xData.VerifyExists("recId", typeof(oProductBrand), "Brand", txtBrand.Value)) { Brand.isActive = true; //save form values SavePageFormValues(ref Brand); Brand.recId = xData.SaveTyped("recId", typeof(oProductBrand), Brand); if (Brand.recId > 0) { Session["BrandId"] = Brand.recId; Session["Brand"] = Brand; BindBrandData(); pnlResult.Visible = true; lblResult.Text = "your Brand was created successfully."; } } else { pnlResult.Visible = true; lblResult.Text = "A Brand with this name already exists on the system"; } } } catch (Exception ex) { exception.HandleException("productBrands:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion }