protected void rgAdminListSymptom_InsertCommand(object source, GridCommandEventArgs e)
    {
        GridEditableItem dataItem = (GridEditableItem)e.Item;

        int symptomId = 0;

        TextBox txtSymptom = (TextBox)dataItem["Symptom"].Controls[0];
        TextBox txtDescription = (TextBox)dataItem["Description"].Controls[0];

        if (txtSymptom.Text == string.Empty || txtDescription.Text == string.Empty)
        {
            ShowAlertMessage("Please enter the symptom and description to add!");
        }
        else
        {
            int IsSaved = new AdministrationBAL().InsertSymptom(symptomId, txtSymptom.Text, txtDescription.Text);
            if (IsSaved < 0)
                ShowAlertMessage("Entered Symptom is already exists!");
            else
            {
                ShowAlertMessage("New Symptom Saved successfully!");
            }
        }
        BindSymptom(false);
    }
    protected void rgAdminListDepartment_InsertCommand(object source, GridCommandEventArgs e)
    {
        GridEditableItem dataItem = (GridEditableItem)e.Item;

        int departmentId = 0;

        TextBox txtDepartmentName = (TextBox)dataItem["DepartmentName"].Controls[0];
        TextBox txtDescription = (TextBox)dataItem["Description"].Controls[0];

        if (txtDepartmentName.Text == string.Empty || txtDescription.Text == string.Empty)
        {
            ShowAlertMessage("Please enter the department and description to add!");
        }
        else
        {
            int IsSaved = new AdministrationBAL().InsertDepartment(departmentId, txtDepartmentName.Text, txtDescription.Text);
            if (IsSaved < 0)
                ShowAlertMessage("Entered Department is already exists!");
            else
            {
                ShowAlertMessage("New Department Saved successfully!");
            }
        }
        BindDepartment(false);
    }
    private void BindAppointment(bool isBind)
    {
        DataTable dtAppointmentView = new AdministrationBAL().GetAppointmentview();

        foreach (DataRow drAppointmentView in dtAppointmentView.Rows)
        {
            if (!string.IsNullOrEmpty(drAppointmentView["ScheduleAddress"].ToString()))
                drAppointmentView["ScheduleAddress"] = drAppointmentView["ScheduleAddress"].ToString().Replace("\r\n\r\n", "\n").Replace("\r\n", "\n").Replace("\n\n", "\n").Replace("\n", ", \n");
            else
            {
                StringBuilder ScheduleAddress = new StringBuilder();

                ScheduleAddress.AppendLine(drAppointmentView["OrganizationName"].ToString());
                ScheduleAddress.AppendLine((!string.IsNullOrEmpty(drAppointmentView["AddressLine2"].ToString())) ? " \n" + drAppointmentView["AddressLine1"].ToString() + " \n" + drAppointmentView["AddressLine2"].ToString() : " \n" + drAppointmentView["AddressLine1"].ToString());
                ScheduleAddress.AppendLine((!string.IsNullOrEmpty(drAppointmentView["CityName"].ToString())) ? " \n" + drAppointmentView["CityName"].ToString() : string.Empty);
                ScheduleAddress.AppendLine((!string.IsNullOrEmpty(drAppointmentView["StateName"].ToString())) ? " \n" + drAppointmentView["StateName"].ToString() : string.Empty);
                ScheduleAddress.AppendLine((!string.IsNullOrEmpty(drAppointmentView["CountryName"].ToString())) ? " \n" + drAppointmentView["CountryName"].ToString() : string.Empty);
                ScheduleAddress.AppendLine((!string.IsNullOrEmpty(drAppointmentView["PostalCode"].ToString())) ? " \nPostalCode:" + drAppointmentView["PostalCode"].ToString() : string.Empty);
                ScheduleAddress.AppendLine((!string.IsNullOrEmpty(drAppointmentView["Phone"].ToString())) ? " \nPhone: " + drAppointmentView["Phone"].ToString() : string.Empty);

                drAppointmentView["ScheduleAddress"] = ScheduleAddress.ToString();
            }

            drAppointmentView["CreatedOn"] = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Convert.ToDateTime(drAppointmentView["CreatedOn"]), "India Standard Time");

        }
        dtAppointmentView.AcceptChanges();

        rgAdminAppointmentView.DataSource = dtAppointmentView;

        if (!isBind)
            rgAdminAppointmentView.DataBind();
    }
    private void BindPatientSearch(bool isBind )
    {
        DataTable dtPatientSearch = new AdministrationBAL().GetSearchCount();

        rgAdminPatientSearchView.DataSource = dtPatientSearch;

        if(!isBind)
        rgAdminPatientSearchView.DataBind();
    }
    protected void rgAdminListDiagnosis_DeleteCommand(object source, GridCommandEventArgs e)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        int diagnosisId =Convert.ToInt32(dataItem.GetDataKeyValue("DiagnosisId").ToString());
        bool IsDeleted = Convert.ToBoolean(dataItem["IsDeleted"].Text);

        int isDeleted = new AdministrationBAL().DeleteDepartmentDiagnosisSymptomByDirectId(diagnosisId, diagnosisType);// for diagnosis type is 1

        BindDiagnosis(false);
        if (isDeleted > 0)
        {
            ShowAlertMessage("Deleted Successfully!");
        }
    }
    private void BindIndividualSMSSearch(bool isBind)
    {
        DataTable dtIndividualSMS = new AdministrationBAL().GetSMSIndividual();

        foreach (DataRow dr in dtIndividualSMS.Rows)
        {
            dr["CreatedOn"] = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Convert.ToDateTime(dr["CreatedOn"]), "India Standard Time");
        }
        dtIndividualSMS.AcceptChanges();

        rgSMSIndividual.DataSource = dtIndividualSMS;

        if (!isBind)
            rgSMSIndividual.DataBind();
    }
    private void BindPatientSearch(bool isBind)
    {
        DataTable dtRemainderSMS = new AdministrationBAL().GetRemainderSMS();

        foreach (DataRow dr in dtRemainderSMS.Rows)
        {
            dr["Sent On"] = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Convert.ToDateTime(dr["Sent On"]), "India Standard Time");
        }
        dtRemainderSMS.AcceptChanges();

        rgRemainderSMS.DataSource = dtRemainderSMS;

        if (!isBind)
            rgRemainderSMS.DataBind();
    }
    protected void lnkActivation_OnUpdate(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument.ToString().Length > 0)
        {
            string[] cmd = e.CommandArgument.ToString().Split(',');

            int id = Convert.ToInt32(cmd[0]);
            int type = Convert.ToInt32(cmd[1]);

            string message = new AdministrationBAL().ActivateLoginById(id, type);

            BindLoginDetail(false);

            ShowAlertMessage(message + " Successfully!");
        }
    }
 protected void btnAddNewSymptom_Click(object sender, EventArgs e)
 {
     if (txtSymptom.Text != string.Empty && txtDescriptionSymptom.Text != string.Empty)
     {
         int isSaved = new AdministrationBAL().InsertSymptom(0, txtSymptom.Text, txtDescriptionSymptom.Text);
         if (isSaved < 0)
         {
             cvNewSymptom.IsValid = false;
         }
     }
     else
     {
         cvEmptySymptom.IsValid = false;
     }
     txtSymptom.Text = "";
     txtDescriptionSymptom.Text = "";
     BindSymptom();
 }
 protected void btnAddNewDiagnosis_Click(object sender, EventArgs e)
 {
     if (txtDiagnosis.Text != string.Empty && txtDescriptionDiagnosis.Text != string.Empty)
     {
         int isSaved = new AdministrationBAL().InsertDiagnosis(0, txtDiagnosis.Text, txtDescriptionDiagnosis.Text);
         if (isSaved < 0)
         {
             cvNewDiagnosis.IsValid = false;
         }
     }
     else
     {
         cvEmptyDiagnosis.IsValid = false;
     }
     txtDiagnosis.Text = "";
     txtDescriptionDiagnosis.Text = "";
     BindDiagnosis();
 }
    protected void btnAddTreatment_Click(object sender, EventArgs e)
    {
        string[] treatment = null;

        if (rtbtreatment.Text.Trim() != string.Empty)
        {
            if (ddlDepartment.SelectedIndex > 0)
            {
                int i = 0;
                int IsSaved = 0;

                treatment = rtbtreatment.Text.ToString().Split(',');

                for ( ; i < treatment.Length; i++)
                {
                    IsSaved = new AdministrationBAL().InsertTreatment(Convert.ToInt32(ddlDepartment.SelectedItem.Value), treatment[i].ToString().Trim());

                    if (IsSaved < 0 )
                    {
                        ShowAlertMessage("Entered treatment (" + treatment[i].ToString() +") already exists!");
                        break;
                    }
                    else
                        continue;
                }
                if ((i == treatment.Length) && IsSaved > 0)
                {
                    ShowAlertMessage("New treatment saved successfully!");
                    rtbtreatment.Text = "";
                    LoadSelectedTreatment();
                }
            }
            else
            {
                cvAddTreatment.ErrorMessage = "Please select one department to map these treatment(s)!";
                cvAddTreatment.IsValid = false;
                return;
            }
        }
        else
        {
            cvAddTreatment.ErrorMessage = "Please enter treatment(s) to add!";
            cvAddTreatment.IsValid = false;
            return;
        }
    }
    private void BindSymptom(bool IsRebind)
    {
        DataTable dtSymptom = new AdministrationBAL().GetSymptom();
        rgAdminListSymptom.DataSource = dtSymptom;

        if (!IsRebind)
            rgAdminListSymptom.DataBind();
    }
    private void BindDiagnosis(bool IsRebind)
    {
        DataTable dtDiagnosis = new AdministrationBAL().GetDiagnosis();
        rgAdminListDiagnosis.DataSource = dtDiagnosis;

        if (!IsRebind)
            rgAdminListDiagnosis.DataBind();
    }
    private void LoadSelectedTreatment()
    {
        lblInfo.Visible = false;
        lblInfoSymptom.Visible = false;
        btnSaveSymptom.Visible = false;
        btnSave.Visible = false;

        rlbTreatmentList.Items.Clear();
        int departmentId = Convert.ToInt32(ddlDepartment.SelectedItem.Value);

        DataTable dtTreatment = new AdministrationBAL().GetTreatmentByDepartmentId(departmentId);
        rlbTreatmentList.DataSource = dtTreatment;
        rlbTreatmentList.DataTextField = "Diagnosis";
        rlbTreatmentList.DataValueField = "DiagnosisId";
        rlbTreatmentList.DataBind();

        SortTreatment();
    }
 protected void btnDeleteTreatment_Click(object sender, EventArgs e)
 {
     if (rlbTreatmentList.SelectedItems.Count > 0)
     {
         foreach (RadListBoxItem list in rlbTreatmentList.SelectedItems)
         {
             if (list.Selected)
             {
                 int isDeleted = new AdministrationBAL().DeleteDepartmentDiagnosisSymptomByDirectId(Convert.ToInt32(list.Value), 1); //for diagnosis type is 1
                 LoadSelectedTreatment();
             }
         }
     }
     else
     {
         cvDeleteTreatment.ErrorMessage = "Please select a treatment from the treatment list to delete.";
         cvDeleteTreatment.IsValid = false;
     }
 }
 protected void btnDeleteSymptom_Click(object sender, EventArgs e)
 {
     if (rlbSymptomList.SelectedItems.Count > 0)
     {
         foreach (RadListBoxItem list in rlbSymptomList.SelectedItems)
         {
             if (list.Selected)
             {
                 int isDeleted = new AdministrationBAL().DeleteDepartmentDiagnosisSymptomByDirectId(Convert.ToInt32(list.Value), 2); //for symptoms type is 2
             }
         }
     }
     else
     {
         cvDeleteSymptom.ErrorMessage = "Please select a symptom from Symptoms list to delete.";
         cvDeleteSymptom.IsValid = false;
     }
     BindSymptom();
 }
    protected void btnDeleteDiagnosis_Click(object sender, EventArgs e)
    {
        if (rlbDiagnosisList.SelectedItems.Count > 0)
        {
            foreach (RadListBoxItem list in rlbDiagnosisList.SelectedItems)
            {
                if (list.Selected)
                {
                    int isDeleted = new AdministrationBAL().DeleteDepartmentDiagnosisSymptomByDirectId(Convert.ToInt32(list.Value), 1); //for diagnosis type is 1
                }
            }
        }
        else
        {
            cvDeleteDiagnosis.ErrorMessage = "Please select a diagnosis from Diagnosis list to delete.";
            cvDeleteDiagnosis.IsValid = false;
        }
        rlbSelectedSymptomList.Items.Clear();
        rlbSelectedDiagnosisList.Items.Clear();

        BindDiagnosis();
    }
    private void BindDepartment(bool IsRebind)
    {
        DataTable dtDepartment = new AdministrationBAL().GetDepartment();
        rgAdminListDepartment.DataSource = dtDepartment;

        if (!IsRebind)
            rgAdminListDepartment.DataBind();
    }
    private DataTable GetAccountType(int LoginId)
    {
        DataTable dtAccountType = new AdministrationBAL().GetAccountTypeByLoginView();

        DataRow[] dr = dtAccountType.Select("LoginId=" + LoginId.ToString());

        DataTable dtvalid = dtAccountType.Clone();

        dtvalid = dr.CopyToDataTable();

        return dtvalid;
    }
    private void BindHospital(bool IsRebind)
    {
        DataTable dtDepartment = new AdministrationBAL().GetHospital();

        dtDepartment.Columns.Add("Address", typeof(string));
        foreach (DataRow dr in dtDepartment.Rows)
        {
            if (!string.IsNullOrEmpty(dr["AddressLine"].ToString()))
                dr["Address"] += dr["AddressLine"].ToString();

            if (!string.IsNullOrEmpty(dr["CityName"].ToString()))
                dr["Address"] += ", " + dr["CityName"].ToString();

            if (!string.IsNullOrEmpty(dr["StateName"].ToString()))
                dr["Address"] += ", " + dr["StateName"].ToString();

            if (!string.IsNullOrEmpty(dr["CountryName"].ToString()))
                dr["Address"] += ", " + dr["CountryName"].ToString();

            if (!string.IsNullOrEmpty(dr["PostalCode"].ToString()))
                dr["Address"] += ", " + dr["PostalCode"].ToString();

        }
        dtDepartment.AcceptChanges();

        rgAdminHospitalList.DataSource = dtDepartment;

        if (!IsRebind)
            rgAdminHospitalList.DataBind();
    }
    protected void rgAdminHospitalList_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
    {
        GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
        string mobileId = dataItem.GetDataKeyValue("Mobile").ToString();

        DataTable dtDepartment = new AdministrationBAL().GetExistingHospital(mobileId);

        dtDepartment.Columns.Add("Address", typeof(string));
        foreach (DataRow dr in dtDepartment.Rows)
        {
            if (!string.IsNullOrEmpty(dr["AddressLine"].ToString()))
                dr["Address"] += dr["AddressLine"].ToString();

            if (!string.IsNullOrEmpty(dr["CityName"].ToString()))
                dr["Address"] += ", " + dr["CityName"].ToString();

            if (!string.IsNullOrEmpty(dr["StateName"].ToString()))
                dr["Address"] += ", " + dr["StateName"].ToString();

            if (!string.IsNullOrEmpty(dr["CountryName"].ToString()))
                dr["Address"] += ", " + dr["CountryName"].ToString();

            if (!string.IsNullOrEmpty(dr["PostalCode"].ToString()))
                dr["Address"] += ", " + dr["PostalCode"].ToString();

        }
        dtDepartment.AcceptChanges();
        e.DetailTableView.DataSource = dtDepartment;

        //if (!IsRebind)
           // rgAdminHospitalList.DataBind();
    }
    private DataTable GetLoginTable(int LoginId, int AccountTypeId)
    {
        DataTable dtLoginView =  new AdministrationBAL().GetLoginTypeById();

        DataRow[] drLogin = dtLoginView.Select("LoginId=" + LoginId.ToString() + " AND " + "Type=" + AccountTypeId.ToString());

        DataTable dtLogin = null;
        if (drLogin.Length > 0)
        {
            dtLogin = dtLoginView.Clone();

            dtLogin = drLogin.CopyToDataTable();
        }
        else
            dtLogin = dtLoginView.Clone();

        return dtLogin;
    }
    private void BindAppointment(bool isBind)
    {
        DataTable dtDeletedDoctorView = new AdministrationBAL().NoProfile();

        rgAdminNoProfileView.DataSource = dtDeletedDoctorView;

        if (!isBind)
            rgAdminNoProfileView.DataBind();
    }
    protected void btnDeleteDepartment_Click(object sender, EventArgs e)
    {
        if (ddlDepartment.SelectedIndex > 0)
        {
            int isDeleted = new AdministrationBAL().DeleteDepartmentDiagnosisSymptomByDirectId(Convert.ToInt32(ddlDepartment.SelectedValue), 0); //for department type is 0
        }
        else
        {
            cvDeleteDepartment.ErrorMessage = "Please select one department from Department list to delete.";
            cvDeleteDepartment.IsValid = false;
        }
        rlbSelectedSymptomList.Items.Clear();
        rlbSelectedDiagnosisList.Items.Clear();
        rlbTreatmentList.Items.Clear();

        BindDepartment();
    }