using framework_business; using framework_library; using System; using System.Collections; using System.Data; using System.Reflection; using System.Web.UI; using System.Web.UI.WebControls; public partial class controls_admin_smscredit : System.Web.UI.UserControl { #region methods /// /// Method to Bind SMSCredit Data /// private void BindSMSCreditData() { try { bool exist = false; int globalCredit = 0; foreach (oCustomer customer in xData.GetTypedByCriteriaSpecific("recId", typeof(oCustomer), "isActive", "1", "", "pal_", true)) { foreach (oSMSCredit smsCredit in xData.GetTypedByCriteriaSpecific("recId", typeof(oSMSCredit), "customerCode", customer.code, "", "pal_", true)) { exist = true; globalCredit = globalCredit + smsCredit.currentBalance; break; } if (!exist) { oSMSCredit newCredit = new oSMSCredit(); newCredit.customerCode = customer.code; xData.SaveTyped("recId", typeof(oSMSCredit), newCredit, "pal_", true); } } lblGlobal.Text = "Global Credit Balance: "+globalCredit.ToString(); ArrayList smsCreditList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSMSCredit), "", "", "customerCode", "pal_", true); rptSMSCredits.DataSource = smsCreditList; rptSMSCredits.DataBind(); upSMSCredits.Update(); } catch (Exception ex) { exception.HandleException("SMSCredits:", MethodBase.GetCurrentMethod().Name, ex, Session["smsCredit"]); Response.Redirect("/error", false); } } #endregion #region events /// /// Load SMS Credits /// /// /// protected void lnkLoad_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { string customerCode = ((LinkButton)sender).CommandArgument; if (customerCode != "") { Session["customerCode"] = customerCode; foreach (oCustomer customer in xData.GetTypedByCriteriaSpecific("recId", typeof(oCustomer), "code", customerCode, "", "pal_", true)) { lblLoadTitle.Text = "Load Credits for " + customer.customer; } foreach (oSMSCredit smsCredit in xData.GetTypedByCriteriaSpecific("recId", typeof(oSMSCredit), "customerCode", customerCode, "", "pal_", true)) { lblCurrentBalance.Text = smsCredit.currentBalance.ToString(); txtThreshold.Text = smsCredit.threshold.ToString(); } upLoad.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showLoadModal", "$('#modLoad').modal('show');", true); } } } catch (Exception ex) { exception.HandleException("SMSCredits:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Page Load Event /// /// /// protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { BindSMSCreditData(); if (utils.verifySession("smsCredit")) { oSMSCredit smsCredit = (oSMSCredit)Session["smsCredit"]; } } } catch (Exception ex) { exception.HandleException("SMSCredits:", MethodBase.GetCurrentMethod().Name, ex, Session["smsCredit"]); Response.Redirect("/error", false); } } /// /// Cancel /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { utils.disposeSession("customerCode"); BindSMSCreditData(); } catch (Exception ex) { exception.HandleException("SMSCredits:", MethodBase.GetCurrentMethod().Name, ex, Session["smsCredit"]); Response.Redirect("/error", false); } } /// /// Save Click /// /// /// protected void btnSave_Click(object sender, EventArgs e) { try { if (utils.verifySession("customerCode")) { oSMSCreditLog newCreditLog = new oSMSCreditLog(); newCreditLog.customerCode = Session["customerCode"].ToString(); newCreditLog.qty = Convert.ToInt32(txtNumberOfCredits.Text); newCreditLog.reference = txtReference.Text; newCreditLog.transactionDate = DateTime.Now; newCreditLog.transactionType = (int)pNums.SMSCreditTransactionType.Loaded; newCreditLog.userId = handler.ReturnUser().recId; xData.SaveTyped("recId", typeof(oSMSCreditLog), newCreditLog, "pal_", true); } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showLoadModal", "$('#modLoad').modal('hide');", true); utils.disposeSession("customerCode"); BindSMSCreditData(); } catch (Exception ex) { exception.HandleException("SMSCredits:", MethodBase.GetCurrentMethod().Name, ex, Session["smsCredit"]); Response.Redirect("/error", false); } } /// /// history click /// /// /// protected void lnkHistory_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { string customerCode = ((LinkButton)sender).CommandArgument; if (customerCode != "") { Session["customerCode"] = customerCode; foreach (oCustomer customer in xData.GetTypedByCriteriaSpecific("recId", typeof(oCustomer), "code", customerCode, "", "pal_", true)) { lblLogTitle.Text = "SMS Credit Log for " + customer.customer; } ArrayList smsCreditLog = xData.GetTypedByCriteriaSpecific("recId", typeof(ovSMSCreditHistory), "customerCode", customerCode, "recId", "pal_", true); rptLog.DataSource = smsCreditLog; rptLog.DataBind(); upLog.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showLogModal", "$('#modLog').modal('show');", true); } } } catch (Exception ex) { exception.HandleException("SMSCredits:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// update click /// /// /// protected void lnkUpdate_Click(object sender, EventArgs e) { try { if (utils.verifySession("customerCode")) { foreach (oSMSCredit smsCredit in xData.GetTypedByCriteriaSpecific("recId",typeof(oSMSCredit),"customerCode",Session["customerCode"].ToString(),"","pal_",true)) { smsCredit.threshold = Convert.ToInt32(txtThreshold.Text); xData.UpdateTyped("recId",smsCredit.recId.ToString(),typeof(oSMSCredit),smsCredit,"pal_",true); } upLoad.Update(); BindSMSCreditData(); upSMSCredits.Update(); } } catch (Exception ex) { exception.HandleException("SMSCredits:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } #endregion }