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_practices : System.Web.UI.UserControl { #region methods /// /// Method to Bind Practice Data /// private void BindPracticeData() { try { ArrayList practiceList = xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPractice), "", "", "name"); rptPractices.DataSource = practiceList; rptPractices.DataBind(); } catch (Exception ex) { exception.HandleException("Practices:", MethodBase.GetCurrentMethod().Name, ex, Session["practice"]); Response.Redirect("/error", false); } } /// /// Populate Form Values /// /// private void PopulatePageFormValues(ref oMedicalPractice _Practice) { try { txtName.Value = _Practice.name; txtDescription.Value = _Practice.description; txtQualifications.Value = _Practice.qualifications; txtTel.Value = _Practice.tel; txtFax.Value = _Practice.fax; txtMobile.Value = _Practice.mobile; txtEmail.Value = _Practice.email; txtPracNo.Value = _Practice.practiceNo; txtHPCSANo.Value = _Practice.HPCSANo; txtPostal1.Value = _Practice.postal1; txtPostal2.Value = _Practice.postal2; txtPostal3.Value = _Practice.postal3; txtPostalCode.Value = _Practice.postalCode; txtBank.Value = _Practice.bank; txtBranch.Value = _Practice.branch; txtBranchCode.Value = _Practice.branchCode; txtAccountNo.Value = _Practice.accountNo; txtAccountType.Value = _Practice.accountType; txtIncNumber.Value = _Practice.incNum; chkASTPaymentExVat.Checked = _Practice.isAstPaymentExVat; txtVatRate.Value = _Practice.vatRate.ToString(); } catch (Exception ex) { exception.HandleException("Practices:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Save Form Values /// /// private void SavePageFormValues(ref oMedicalPractice _Practice) { try { _Practice.name = txtName.Value; _Practice.description = txtDescription.Value; _Practice.qualifications = txtQualifications.Value; _Practice.tel = txtTel.Value; _Practice.fax = txtFax.Value; _Practice.mobile = txtMobile.Value; _Practice.email = txtEmail.Value; _Practice.practiceNo = txtPracNo.Value; _Practice.HPCSANo = txtHPCSANo.Value; _Practice.postal1 = txtPostal1.Value; _Practice.postal2 = txtPostal2.Value; _Practice.postal3 = txtPostal3.Value; _Practice.postalCode = txtPostalCode.Value; _Practice.bank = txtBank.Value; _Practice.branch = txtBranch.Value; _Practice.branchCode = txtBranchCode.Value; _Practice.accountNo = txtAccountNo.Value; _Practice.accountType = txtAccountType.Value; _Practice.incNum = txtIncNumber.Value; _Practice.isAstPaymentExVat = chkASTPaymentExVat.Checked; int vatRate = 0; if (!int.TryParse(txtVatRate.Value, out vatRate)) throw new Exception("Invalid VAT Rate."); else _Practice.vatRate = vatRate; } catch (Exception ex) { exception.HandleException("Practices:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Method to Toggle Panels /// /// private void TogglePanels(string panelName) { switch (panelName) { case "pnlPracticePage": pnlPracticePage.Visible = true; pnlPracticeList.Visible = false; break; case "pnlPracticeList": pnlPracticePage.Visible = false; pnlPracticeList.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) { BindPracticeData(); } } catch (Exception ex) { exception.HandleException("Practices:", MethodBase.GetCurrentMethod().Name, ex, Session["practice"]); Response.Redirect("/error", false); } } /// /// New Practice Click /// /// /// protected void btnNewPractice_Click(object sender, EventArgs e) { try { //show Content Specific TogglePanels("pnlPracticePage"); Session["PracticeId"] = 0; utils.disposeSession("Practice"); oMedicalPractice Practice = new oMedicalPractice(); PopulatePageFormValues(ref Practice); } catch (Exception ex) { exception.HandleException("Practices:", MethodBase.GetCurrentMethod().Name, ex, Session["practice"]); Response.Redirect("/error", false); } } /// /// Edit the Practice page /// /// /// protected void lnkEdit_Click(object sender, EventArgs e) { oMedicalPractice _Practice = new oMedicalPractice(); ArrayList catList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton)) { // int recId = int.Parse(((LinkButton)sender).CommandArgument); if (recId > 0) { Session["PracticeId"] = recId; //get cat catList = xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPractice), "recId", recId.ToString()); //enumerate list foreach (oMedicalPractice cat in catList) { //assign object _Practice = cat; //populate page form PopulatePageFormValues(ref _Practice); Session["Practice"] = _Practice; break; } //show Practice Form TogglePanels("pnlPracticePage"); } } } catch (Exception ex) { exception.HandleException("Practices:", MethodBase.GetCurrentMethod().Name, ex, Session["practice"]); Response.Redirect("/error", false); } } /// /// Remove the Practice /// /// /// 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(oMedicalPractice))) { //rebind pages grid BindPracticeData(); pnlResult.Visible = true; //display successful result lblResult.Text = "the selected Practice was deleted successfully."; } } } catch (Exception ex) { exception.HandleException("Practices:", MethodBase.GetCurrentMethod().Name, ex, Session["practice"]); Response.Redirect("/error", false); } } /// /// Cancel /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { Session["PracticeId"] = 0; utils.disposeSession("Practice"); BindPracticeData(); //show cat list TogglePanels("pnlPracticeList"); } catch (Exception ex) { exception.HandleException("Practices:", MethodBase.GetCurrentMethod().Name, ex, Session["practice"]); Response.Redirect("/error", false); } } /// /// Save Click /// /// /// protected void btnSave_Click(object sender, EventArgs e) { oMedicalPractice Practice = new oMedicalPractice(); try { if (utils.verifySession("Practice"))//update mode { Practice = (oMedicalPractice)Session["Practice"]; //save form values SavePageFormValues(ref Practice); if (xData.UpdateTyped("recId", Practice.recId.ToString(), typeof(oMedicalPractice), Practice)) { Session["PracticeId"] = Practice.recId; Session["Practice"] = Practice; BindPracticeData(); pnlResult.Visible = true; lblResult.Text = "your changes were updated successfully."; } } else { if (!xData.VerifyExists("recId", typeof(oMedicalPractice), "email", txtEmail.Value)) { //save form values SavePageFormValues(ref Practice); Practice.recId = xData.SaveTyped("recId", typeof(oMedicalPractice), Practice); if (Practice.recId > 0) { Session["PracticeId"] = Practice.recId; Session["Practice"] = Practice; BindPracticeData(); pnlResult.Visible = true; lblResult.Text = "your Practice was created successfully."; } } else { pnlResult.Visible = true; lblResult.Text = "An Practice with this email already exists on the system"; } } } catch (Exception ex) { exception.HandleException("Practices:", MethodBase.GetCurrentMethod().Name, ex, Session["practice"]); Response.Redirect("/error", false); } } #endregion }