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_loyaltystores : System.Web.UI.UserControl
{
#region methods
///
/// Method to Bind Store Data
///
private void BindStoreData()
{
try
{
ArrayList storeList = xData.GetTypedByCriteriaSpecific("recId", typeof(oLoyaltyStore), "isActive", "1", "");
rptLoyaltyStores.DataSource = storeList;
rptLoyaltyStores.DataBind();
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Populate Form Values
///
///
private void PopulatePageFormValues(ref oLoyaltyStore _store)
{
try
{
txtName.Value = _store.storeName;
txtCode.Value = _store.storeCode;
chkActive.Checked = _store.isActive;
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
///
/// Save Form Values
///
///
private void SavePageFormValues(ref oLoyaltyStore _store)
{
try
{
_store.storeName = txtName.Value;
_store.storeCode = txtCode.Value;
_store.isActive = chkActive.Checked;
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
///
/// Method to Toggle Panels
///
///
private void TogglePanels(string panelName)
{
switch (panelName)
{
case "pnlStorePage":
pnlStorePage.Visible = true;
pnlStoreList.Visible = false;
break;
case "pnlStoreList":
pnlStorePage.Visible = false;
pnlStoreList.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)
{
BindStoreData();
}
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// New store Click
///
///
///
protected void btnNewStore_Click(object sender, EventArgs e)
{
try
{
//show Content Specific
TogglePanels("pnlStorePage");
Session["storeId"] = 0;
utils.disposeSession("store");
oLoyaltyStore store = new oLoyaltyStore();
PopulatePageFormValues(ref store);
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Edit the store page
///
///
///
protected void lnkEdit_Click(object sender, EventArgs e)
{
oLoyaltyStore _store = new oLoyaltyStore();
ArrayList storeList = new ArrayList();
try
{
if (sender.GetType() == typeof(LinkButton))
{
int recId = int.Parse(((LinkButton)sender).CommandArgument);
if (recId > 0)
{
Session["storeId"] = recId;
//get store
storeList = xData.GetTypedByCriteriaSpecific("recId", typeof(oLoyaltyStore), "recId", recId.ToString());
//enumerate list
foreach (oLoyaltyStore store in storeList)
{
//assign object
_store = store;
//populate page form
PopulatePageFormValues(ref _store);
Session["store"] = _store;
break;
}
//show store Form
TogglePanels("pnlStorePage");
}
}
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Remove the Store
///
///
///
protected void lnkRemove_Click(object sender, EventArgs e)
{
try
{
if (sender.GetType() == typeof(LinkButton))
{
int recId = int.Parse(((LinkButton)sender).CommandArgument);
//Delete store
if (xData.DeleteTyped("recId", recId.ToString(), typeof(oLoyaltyStore)))
{
//rebind pages grid
BindStoreData();
pnlResult.Visible = true;
//display successful result
lblResult.Text = "the selected store was deleted successfully.";
}
}
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Cancel
///
///
///
protected void btnCancel_Click(object sender, EventArgs e)
{
try
{
Session["storeId"] = 0;
utils.disposeSession("store");
BindStoreData();
//show store list
TogglePanels("pnlStoreList");
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Save Click
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
oLoyaltyStore store = new oLoyaltyStore();
try
{
if (utils.verifySession("store"))//update mode
{
store = (oLoyaltyStore)Session["store"];
//save form values
SavePageFormValues(ref store);
if (xData.UpdateTyped("recId", store.recId.ToString(), typeof(oLoyaltyStore), store))
{
Session["storeId"] = store.recId;
Session["store"] = store;
BindStoreData();
pnlResult.Visible = true;
lblResult.Text = "your changes were updated successfully.";
}
}
else
{
if (!xData.VerifyExists("recId", typeof(oLoyaltyStore), "storeName", txtName.Value))
{
store.isActive = true;
//save form values
SavePageFormValues(ref store);
store.recId = xData.SaveTyped("recId", typeof(oLoyaltyStore), store);
if (store.recId > 0)
{
Session["storeId"] = store.recId;
Session["store"] = store;
BindStoreData();
pnlResult.Visible = true;
lblResult.Text = "your store was created successfully.";
}
}
else
{
pnlResult.Visible = true;
lblResult.Text = "A Store with this name already exists on the system";
}
}
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Back Button
///
///
///
protected void btnBack_Click(object sender, EventArgs e)
{
try
{
if (utils.verifySession("prevousId"))
Session["parentId"] = Session["prevousId"];
BindStoreData();
}
catch (Exception ex)
{
exception.HandleException("loyaltyStores:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
}
}
#endregion
}