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_medical_tariffs : System.Web.UI.UserControl { #region methods /// /// Method to Bind Tariff Data /// private void BindTariffData() { try { ArrayList TariffList = xData.GetTypedByCriteriaSpecific("recId", typeof(oTariffPlan), "", "", "name"); rptTariffs.DataSource = TariffList; rptTariffs.DataBind(); } catch (Exception ex) { exception.HandleException("tariffs", MethodBase.GetCurrentMethod().Name, ex, Session["Tariff"]); Response.Redirect("/error", false); } } /// /// Populate Form Values /// /// private void PopulatePageFormValues(ref oTariffPlan _Tariff) { try { txtName.Value = _Tariff.name; txtCode.Value = _Tariff.code; txtNotes.Value = _Tariff.notes; ddLiability.SelectedValue = _Tariff.liableIndicator.ToString(); chkClaimActive.Checked = _Tariff.claimActivated; txtIHPercent.Value = _Tariff.iHPercent.ToString(); txtOHPercent.Value = _Tariff.oHPercent.ToString(); } catch (Exception ex) { exception.HandleException("tariffs", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Save Form Values /// /// private void SavePageFormValues(ref oTariffPlan _Tariff) { try { _Tariff.name = txtName.Value; _Tariff.code = txtCode.Value; _Tariff.notes = txtNotes.Value; _Tariff.liableIndicator = int.Parse(ddLiability.SelectedValue); _Tariff.claimActivated = chkClaimActive.Checked; _Tariff.iHPercent = decimal.Parse(txtIHPercent.Value); _Tariff.oHPercent = decimal.Parse(txtOHPercent.Value); } catch (Exception ex) { exception.HandleException("tariffs", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Method to Toggle Panels /// /// private void TogglePanels(string panelName) { switch (panelName) { case "pnlTariffPage": pnlTariffPage.Visible = true; pnlTariffList.Visible = false; break; case "pnlTariffList": pnlTariffPage.Visible = false; pnlTariffList.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) { BindTariffData(); } } catch (Exception ex) { exception.HandleException("tariffs", MethodBase.GetCurrentMethod().Name, ex, Session["Tariff"]); Response.Redirect("/error", false); } } /// /// New Tariff Click /// /// /// protected void btnNewTariff_Click(object sender, EventArgs e) { try { //show Content Specific TogglePanels("pnlTariffPage"); Session["TariffId"] = 0; utils.disposeSession("Tariff"); oTariffPlan Tariff = new oTariffPlan(); PopulatePageFormValues(ref Tariff); txtCode.Disabled = false; } catch (Exception ex) { exception.HandleException("tariffs", MethodBase.GetCurrentMethod().Name, ex, Session["Tariff"]); Response.Redirect("/error", false); } } /// /// Edit the Tariff page /// /// /// protected void lnkEdit_Click(object sender, EventArgs e) { oTariffPlan _Tariff = new oTariffPlan(); ArrayList catList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton)) { // int recId = int.Parse(((LinkButton)sender).CommandArgument); if (recId > 0) { Session["TariffId"] = recId; //get cat catList = xData.GetTypedByCriteriaSpecific("recId", typeof(oTariffPlan), "recId", recId.ToString()); //enumerate list foreach (oTariffPlan cat in catList) { //assign object _Tariff = cat; //populate page form PopulatePageFormValues(ref _Tariff); Session["Tariff"] = _Tariff; break; } txtCode.Disabled = true; //show Tariff Form TogglePanels("pnlTariffPage"); } } } catch (Exception ex) { exception.HandleException("tariffs", MethodBase.GetCurrentMethod().Name, ex, Session["Tariff"]); Response.Redirect("/error", false); } } /// /// Remove the Tariff /// /// /// protected void lnkRemove_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { // int recId = int.Parse(((LinkButton)sender).CommandArgument); foreach (oTariffPlan plan in xData.GetTypedByCriteriaSpecific("recId", typeof(oTariffPlan), "recId", recId.ToString())) { //Delete cat if (xData.DeleteTyped("recId", recId.ToString(), typeof(oTariffPlan))) { //remove rates xData.DeleteTyped("planCode", plan.code, typeof(oTariffRate)); //rebind pages grid BindTariffData(); pnlResult.Visible = true; //display successful result lblResult.Text = "the selected tariff was deleted successfully."; } } } } catch (Exception ex) { exception.HandleException("tariffs", MethodBase.GetCurrentMethod().Name, ex, Session["Tariff"]); Response.Redirect("/error", false); } } /// /// Cancel /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { Session["TariffId"] = 0; utils.disposeSession("Tariff"); BindTariffData(); //show cat list TogglePanels("pnlTariffList"); } catch (Exception ex) { exception.HandleException("tariffs", MethodBase.GetCurrentMethod().Name, ex, Session["Tariff"]); Response.Redirect("/error", false); } } /// /// Save Click /// /// /// protected void btnSave_Click(object sender, EventArgs e) { oTariffPlan Tariff = new oTariffPlan(); try { if (utils.verifySession("Tariff"))//update mode { Tariff = (oTariffPlan)Session["Tariff"]; //save form values SavePageFormValues(ref Tariff); if (xData.UpdateTyped("recId", Tariff.recId.ToString(), typeof(oTariffPlan), Tariff)) { Session["TariffId"] = Tariff.recId; Session["Tariff"] = Tariff; BindTariffData(); pnlResult.Visible = true; lblResult.Text = "your changes were updated successfully."; } } else { if (!xData.VerifyExists("recId", typeof(oTariffPlan), "code", txtCode.Value)) { //save form values SavePageFormValues(ref Tariff); Tariff.recId = xData.SaveTyped("recId", typeof(oTariffPlan), Tariff); if (Tariff.recId > 0) { xData.CreateRatesForPlan(Tariff.code); Session["TariffId"] = Tariff.recId; Session["Tariff"] = Tariff; BindTariffData(); pnlResult.Visible = true; lblResult.Text = "your Tariff was created successfully."; txtCode.Disabled = true; } } else { pnlResult.Visible = true; lblResult.Text = "A Tariff with this code already exists on the system"; } } } catch (Exception ex) { exception.HandleException("tariffs", MethodBase.GetCurrentMethod().Name, ex, Session["Tariff"]); Response.Redirect("/error", false); } } #endregion }