private void btnSave_Click(object sender, EventArgs e)
 {
     if (PEMRBusinessLogic.ActivePEMRObject != null)
     {
         if (PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_TreatmentPlan == null)
         {
             Active_VisitTiming_TreatmentPlan =
                 PEMRBusinessLogic.CreateNew_VisitTiming_TreatmentPlan(this, DB_PEMRSavingMode.SaveImmediately);
             if (Active_VisitTiming_TreatmentPlan == null)
             {
                 return;
             }
             if (PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_TreatmentPlan == null)
             {
                 PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_TreatmentPlan = new List <VisitTiming_TreatmentPlan>();
             }
             PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_TreatmentPlan.Add(Active_VisitTiming_TreatmentPlan);
             XtraMessageBox.Show("Saved Successfully", "Saved", MessageBoxButtons.OK,
                                 MessageBoxIcon.Information);
         }
         else
         {
             if (Active_VisitTiming_TreatmentPlan == null)
             {
                 return;
             }
             if (PEMRBusinessLogic.Update_VisitTiming_TreatmentPlan(this, Active_VisitTiming_TreatmentPlan))
             {
                 XtraMessageBox.Show("Saved Successfully", "Saved", MessageBoxButtons.OK,
                                     MessageBoxIcon.Information);
             }
         }
     }
 }
        private void btnAddToList_Click(object sender, EventArgs e)
        {
            if (txtTreatmentPlanDetails.EditValue == null || string.IsNullOrEmpty(txtTreatmentPlanDetails.Text) ||
                string.IsNullOrWhiteSpace(txtTreatmentPlanDetails.Text))
            {
                XtraMessageBox.Show("You should enter the Treatment Plan Details before adding", "Notice",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                    DefaultBoolean.Default);
                return;
            }

            if (spnOrderIndex.EditValue == null)
            {
                XtraMessageBox.Show("You should enter the Order Index before adding", "Notice",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                    DefaultBoolean.Default);
                return;
            }

            if (PEMRBusinessLogic.ActivePEMRObject == null)
            {
                return;
            }

            if (PEMRBusinessLogic.ActivePEMRObject != null)
            {
                Active_VisitTiming_TreatmentPlan =
                    PEMRBusinessLogic.CreateNew_VisitTiming_TreatmentPlan(this, DB_PEMRSavingMode.SaveImmediately);
                if (Active_VisitTiming_TreatmentPlan == null)
                {
                    return;
                }
                if (PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_TreatmentPlan == null)
                {
                    PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_TreatmentPlan =
                        new List <VisitTiming_TreatmentPlan>();
                }
                PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_TreatmentPlan.Add(
                    Active_VisitTiming_TreatmentPlan);
            }

            grdTreatmentPlans.DataSource =
                PEMRBusinessLogic.ActivePEMRObject.List_VisitTiming_TreatmentPlan.FindAll(
                    item => !Convert.ToInt32(item.PEMRElementStatus)
                    .Equals(Convert.ToInt32(PEMRElementStatus.Removed))).OrderBy(item => item.StepOrderIndex);
            grdTreatmentPlans.RefreshDataSource();
            ClearControls(false);
        }