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_doctors : System.Web.UI.UserControl { #region methods /// /// Method to Bind Doctor Data /// private void BindDoctorData() { try { ArrayList DoctorList = xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalDoctor), "", "", "name"); rptDoctors.DataSource = DoctorList; rptDoctors.DataBind(); } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } /// /// Method to Bind Doctor Data /// private void BindPractices() { try { ArrayList practices = xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPractice), "", "", "name"); ddPractices.DataSource = practices; ddPractices.DataValueField = "recId"; ddPractices.DataTextField = "name"; ddPractices.DataBind(); ddPractices.Items.Insert(0, new ListItem("select a practice..", "0")); } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } /// /// Populate Form Values /// /// private void PopulatePageFormValues(ref oMedicalDoctor _Doctor) { try { txtTitle.Value = _Doctor.title; txtName.Value = _Doctor.name; txtSurname.Value = _Doctor.surname; txtInitials.Value = _Doctor.initials; txtTel.Value = _Doctor.tel; txtFax.Value = _Doctor.fax; txtMobile.Value = _Doctor.mobile; txtEmail.Value = _Doctor.email; txtBHFNo.Value = _Doctor.BHFRegNo; txtHPCSANo.Value = _Doctor.HPCSARegNo; txtPostalCode.Value = _Doctor.postalCode; txtAddress1.Value = _Doctor.address1; txtAddress2.Value = _Doctor.address2; txtAddress3.Value = _Doctor.address3; if (_Doctor.practiceId > 0) ddPractices.SelectedValue = _Doctor.practiceId.ToString(); chkMember.Checked = _Doctor.isMember; ddAssistantType.ClearSelection(); if (ddAssistantType.Items.FindByValue(_Doctor.assistantType.ToString()) != null) ddAssistantType.Items.FindByValue(_Doctor.assistantType.ToString()).Selected = true; chkIsAssistant.Checked = _Doctor.isAssistant; if (_Doctor.isMember) pnlPracticeMember.Visible = true; else pnlPracticeMember.Visible = false; if (_Doctor.isAssistant) pnlAssistant.Visible = true; else pnlAssistant.Visible = false; } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Save Form Values /// /// private void SavePageFormValues(ref oMedicalDoctor _Doctor) { try { _Doctor.name = txtName.Value; _Doctor.surname = txtSurname.Value; _Doctor.title = txtTitle.Value; _Doctor.tel = txtTel.Value; _Doctor.fax = txtFax.Value; _Doctor.mobile = txtMobile.Value; _Doctor.email = txtEmail.Value; _Doctor.initials = txtInitials.Value; _Doctor.BHFRegNo = txtBHFNo.Value; _Doctor.HPCSARegNo = txtHPCSANo.Value; _Doctor.address1 = txtAddress1.Value; _Doctor.address2 = txtAddress2.Value; _Doctor.address3 = txtAddress3.Value; _Doctor.postalCode = txtPostalCode.Value; _Doctor.isMember = chkMember.Checked; _Doctor.practiceId = int.Parse(ddPractices.SelectedValue); _Doctor.isAssistant = chkIsAssistant.Checked; _Doctor.assistantType = int.Parse(ddAssistantType.SelectedValue); } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Method to Toggle Panels /// /// private void TogglePanels(string panelName) { switch (panelName) { case "pnlDoctorPage": pnlDoctorPage.Visible = true; pnlDoctorList.Visible = false; break; case "pnlDoctorList": pnlDoctorPage.Visible = false; pnlDoctorList.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) { BindDoctorData(); BindPractices(); } } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } /// /// New Doctor Click /// /// /// protected void btnNewDoctor_Click(object sender, EventArgs e) { try { //show Content Specific TogglePanels("pnlDoctorPage"); Session["DoctorId"] = 0; utils.disposeSession("Doctor"); oMedicalDoctor Doctor = new oMedicalDoctor(); PopulatePageFormValues(ref Doctor); } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } /// /// Edit the Doctor page /// /// /// protected void lnkEdit_Click(object sender, EventArgs e) { oMedicalDoctor _Doctor = new oMedicalDoctor(); ArrayList catList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton)) { // int recId = int.Parse(((LinkButton)sender).CommandArgument); if (recId > 0) { Session["DoctorId"] = recId; //get cat catList = xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalDoctor), "recId", recId.ToString()); //enumerate list foreach (oMedicalDoctor cat in catList) { //assign object _Doctor = cat; //populate page form PopulatePageFormValues(ref _Doctor); Session["Doctor"] = _Doctor; break; } //show Doctor Form TogglePanels("pnlDoctorPage"); } } } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } /// /// Remove the Doctor /// /// /// 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(oMedicalDoctor))) { //rebind pages grid BindDoctorData(); pnlResult.Visible = true; //display successful result lblResult.Text = "the selected Doctor was deleted successfully."; } } } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } /// /// Cancel /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { Session["DoctorId"] = 0; utils.disposeSession("Doctor"); BindDoctorData(); //show cat list TogglePanels("pnlDoctorList"); } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } /// /// Save Click /// /// /// protected void btnSave_Click(object sender, EventArgs e) { oMedicalDoctor Doctor = new oMedicalDoctor(); try { if (utils.verifySession("Doctor"))//update mode { Doctor = (oMedicalDoctor)Session["Doctor"]; //save form values SavePageFormValues(ref Doctor); if (xData.UpdateTyped("recId", Doctor.recId.ToString(), typeof(oMedicalDoctor), Doctor)) { Session["DoctorId"] = Doctor.recId; Session["Doctor"] = Doctor; BindDoctorData(); pnlResult.Visible = true; lblResult.Text = "your changes were updated successfully."; } } else { if (!xData.VerifyExists("recId", typeof(oMedicalDoctor), "email", txtEmail.Value)) { //save form values SavePageFormValues(ref Doctor); Doctor.recId = xData.SaveTyped("recId", typeof(oMedicalDoctor), Doctor); if (Doctor.recId > 0) { Session["DoctorId"] = Doctor.recId; Session["Doctor"] = Doctor; BindDoctorData(); pnlResult.Visible = true; lblResult.Text = "your Doctor was created successfully."; } } else { pnlResult.Visible = true; lblResult.Text = "An Doctor with this email already exists on the system"; } } } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } /// /// Checked Changed Event /// /// /// protected void chkMember_CheckedChanged(object sender, EventArgs e) { try { if (chkMember.Checked) { pnlPracticeMember.Visible = true; } else { pnlPracticeMember.Visible = false; } } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } protected void chkIsAssistant_CheckedChanged(object sender, EventArgs e) { try { if (chkIsAssistant.Checked) { pnlAssistant.Visible = true; } else { pnlAssistant.Visible = false; } } catch (Exception ex) { exception.HandleException("Doctors:", MethodBase.GetCurrentMethod().Name, ex, Session["Doctor"]); Response.Redirect("/error", false); } } #endregion }