Interaction logic for AddGroupSession.xaml
Inheritance: System.Windows.Window
コード例 #1
0
        private void Select_AppointmentType(object sender, RoutedEventArgs e)
        {
            try
            {
                if (AMPM_Start.SelectedValue.ToString() == "PM" && Convert.ToInt32(BeginHour) != 12)
                {
                    BeginHour = (Convert.ToInt32(BeginHour) + 12).ToString();
                }
                if (AMPM_End.SelectedValue.ToString() == "PM" && Convert.ToInt32(EndHour) != 12)
                {
                    EndHour = (Convert.ToInt32(EndHour) + 12).ToString();
                }
                if (AMPM_Start.SelectedValue.ToString() == "AM" && Convert.ToInt32(BeginHour) == 12)
                {
                    BeginHour = (Convert.ToInt32(BeginHour) - 12).ToString();
                }
                if (AMPM_End.SelectedValue.ToString() == "AM" && Convert.ToInt32(EndHour) == 12)
                {
                    EndHour = (Convert.ToInt32(EndHour) - 12).ToString();
                }

                DateTime help             = Convert.ToDateTime(DateRecieved.ToString());
                DateTime startDateTime    = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(BeginHour), Convert.ToInt32(BeginMinute), 0);
                DateTime endDateTime      = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(EndHour), Convert.ToInt32(EndMinute), 0);
                DateTime expenseDueDate   = startDateTime.AddDays(30);
                string[] separators       = new string[] { ", " };
                string   staff            = Staff.SelectedValue.ToString();
                string   cancellationType = "Not Cxl";
                switch (CancellationType.SelectedIndex)
                {
                case 0:
                    cancellationType = "Not Cxl";
                    break;

                case 1:
                    cancellationType = "No Show";
                    break;

                case 2:
                    cancellationType = "Late Cxl";
                    break;

                case 3:
                    cancellationType = "Cxl";
                    break;

                default:
                    cancellationType = "Not Cxl";
                    break;
                }
                Models.FCS_DBModel db = new Models.FCS_DBModel();
                string[]           words = staff.Split(separators, StringSplitOptions.None);
                string             FName = words[0]; string LName = words[1]; string usertitle = words[2];  string username = words[3];
                var staffID = (from dc in db.Staff
                               where dc.StaffFirstName == FName && dc.StaffLastName == LName && dc.StaffUserName == username
                               select dc.StaffID).Distinct().FirstOrDefault();
                if (TotalGroup.Count == 0)
                {
                    MessageBox.Show("Please add at least one client."); return;
                }
                if (TotalGroup.Count > 1 && (String)ApptType.SelectedItem == "Individual")
                {
                    MessageBox.Show("Individual appointment may only have one client."); return;
                }
                //individual (1st option) (ExpenseTypeID = 1 in database)
                //group (3rd option) (ExpenseTypeID = 2 in database)
                if (ApptType.SelectedIndex == 0 || ApptType.SelectedIndex == 2)
                {
                    if (ApptType.SelectedIndex == 0)
                    {
                        ExpenseTypeID = 1;
                    }
                    else
                    {
                        ExpenseTypeID = 2;
                    }
                    Models.Appointment a = new Models.Appointment();
                    a.StaffID = staffID;
                    a.AppointmentStartDate       = startDateTime;
                    a.AppointmentEndDate         = endDateTime;
                    a.AppointmentCancelationType = cancellationType;
                    db.Appointments.Add(a);
                    db.SaveChanges();

                    foreach (var item in TotalGroup)
                    {
                        AddGroupSession ags = new AddGroupSession(ExpenseTypeID, item, staffID, expenseDueDate, startDateTime, endDateTime, a.AppointmentID);
                        ags.ShowDialog();
                        ags.ExpensePaidDate.IsEnabled = false;
                        ags.FN.IsEnabled            = false;
                        ags.LN.IsEnabled            = false;
                        ags.OQ.IsEnabled            = false;
                        ags.MoneyDonation.IsEnabled = true;
                        ags.Grant.IsEnabled         = false;
                    }
                    this.Close();
                }
                //family (2nd option) (ExpenseTypeID = 3 in database)
                else if (ApptType.SelectedIndex == 1)
                {
                    ExpenseTypeID = 3;
                    foreach (var item in TotalGroup)
                    {
                        Models.Appointment a = new Models.Appointment();
                        a.StaffID = staffID;
                        a.AppointmentStartDate       = startDateTime;
                        a.AppointmentEndDate         = endDateTime;
                        a.AppointmentCancelationType = cancellationType;
                        db.Appointments.Add(a);
                        db.SaveChanges();

                        AddGroupSession ags = new AddGroupSession(ExpenseTypeID, item, staffID, expenseDueDate, startDateTime, endDateTime, a.AppointmentID);
                        ags.Show();
                        ags.ExpensePaidDate.IsEnabled = false;
                        ags.FN.IsEnabled            = false;
                        ags.LN.IsEnabled            = false;
                        ags.OQ.IsEnabled            = false;
                        ags.MoneyDonation.IsEnabled = true;
                        ags.Grant.IsEnabled         = false;
                    }
                    this.Close();
                }
            }
            catch
            {
                if (GroupGrid.Items.Count == 0)
                {
                    MessageBox.Show("Please select atleast one client prior to clicking on Select Appointment Type");
                }
                else if (Staff.SelectedIndex == -1)
                {
                    MessageBox.Show("Please select a Therapist prior to clicking Select on Appointment Type");
                }
                else if (DateRecieved.Text.Equals("") || DateRecieved == null)
                {
                    MessageBox.Show("Please select a Date prior to clicking Select Appointment Type");
                }
                else
                {
                    MessageBox.Show("Something went wrong. Please check the fields and try again.");
                }
            }
        }
コード例 #2
0
        private void Select_AppointmentType(object sender, RoutedEventArgs e)
        {
            try
            {
                if (AMPM_Start.SelectedValue.ToString() == "PM" && Convert.ToInt32(BeginHour) != 12)
                {
                    BeginHour = (Convert.ToInt32(BeginHour) + 12).ToString();
                }
                if (AMPM_End.SelectedValue.ToString() == "PM" && Convert.ToInt32(EndHour) != 12)
                {
                    EndHour = (Convert.ToInt32(EndHour) + 12).ToString();
                }
                if (AMPM_Start.SelectedValue.ToString() == "AM" && Convert.ToInt32(BeginHour) == 12)
                {
                    BeginHour = (Convert.ToInt32(BeginHour) - 12).ToString();
                }
                if (AMPM_End.SelectedValue.ToString() == "AM" && Convert.ToInt32(EndHour) == 12)
                {
                    EndHour = (Convert.ToInt32(EndHour) - 12).ToString();
                }

                DateTime help = Convert.ToDateTime(DateRecieved.ToString());
                DateTime startDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(BeginHour), Convert.ToInt32(BeginMinute), 0);
                DateTime endDateTime = new DateTime(help.Year, help.Month, help.Day, Convert.ToInt32(EndHour), Convert.ToInt32(EndMinute), 0);
                DateTime expenseDueDate = startDateTime.AddDays(30);
                string[] separators = new string[] { ", " };
                string staff = Staff.SelectedValue.ToString();
                string cancellationType = "Not Cxl";
                switch (CancellationType.SelectedIndex)
                {
                    case 0:
                        cancellationType = "Not Cxl";
                        break;
                    case 1:
                        cancellationType = "No Show";
                        break;
                    case 2:
                        cancellationType = "Late Cxl";
                        break;                 
                    case 3:
                        cancellationType = "Cxl";
                        break;
                    default:
                        cancellationType = "Not Cxl";
                        break;
                }
                Models.FCS_DBModel db = new Models.FCS_DBModel();
                string[] words = staff.Split(separators, StringSplitOptions.None);
                string FName = words[0]; string LName = words[1]; string usertitle = words[2];  string username = words[3];
                var staffID = (from dc in db.Staff
                               where dc.StaffFirstName == FName && dc.StaffLastName == LName && dc.StaffUserName == username
                               select dc.StaffID).Distinct().FirstOrDefault();
                if (TotalGroup.Count == 0) { MessageBox.Show("Please add at least one client."); return; }
                if (TotalGroup.Count > 1 && (String)ApptType.SelectedItem == "Individual") { MessageBox.Show("Individual appointment may only have one client."); return; }
                //individual (1st option) (ExpenseTypeID = 1 in database)
                //group (3rd option) (ExpenseTypeID = 2 in database)
                if (ApptType.SelectedIndex == 0 || ApptType.SelectedIndex == 2)
                {
                    if (ApptType.SelectedIndex == 0) { ExpenseTypeID = 1; }
                    else { ExpenseTypeID = 2; }
                    Models.Appointment a = new Models.Appointment();
                    a.StaffID = staffID;
                    a.AppointmentStartDate = startDateTime;
                    a.AppointmentEndDate = endDateTime;
                    a.AppointmentCancelationType = cancellationType;
                    db.Appointments.Add(a);
                    db.SaveChanges();

                    foreach (var item in TotalGroup)
                    {
                        AddGroupSession ags = new AddGroupSession(ExpenseTypeID, item, staffID, expenseDueDate, startDateTime, endDateTime, a.AppointmentID);
                        ags.ShowDialog();
                        ags.ExpensePaidDate.IsEnabled = false;
                        ags.FN.IsEnabled = false;
                        ags.LN.IsEnabled = false;
                        ags.OQ.IsEnabled = false;
                        ags.MoneyDonation.IsEnabled = true;
                        ags.Grant.IsEnabled = false;
                    }
                    this.Close();
                }
                //family (2nd option) (ExpenseTypeID = 3 in database)
                else if (ApptType.SelectedIndex == 1)
                {
                    ExpenseTypeID = 3;
                    foreach (var item in TotalGroup)
                    {
                        Models.Appointment a = new Models.Appointment();
                        a.StaffID = staffID;
                        a.AppointmentStartDate = startDateTime;
                        a.AppointmentEndDate = endDateTime;
                        a.AppointmentCancelationType = cancellationType;
                        db.Appointments.Add(a);
                        db.SaveChanges();

                        AddGroupSession ags = new AddGroupSession(ExpenseTypeID, item, staffID, expenseDueDate, startDateTime, endDateTime, a.AppointmentID);
                        ags.Show();
                        ags.ExpensePaidDate.IsEnabled = false;
                        ags.FN.IsEnabled = false;
                        ags.LN.IsEnabled = false;
                        ags.OQ.IsEnabled = false;
                        ags.MoneyDonation.IsEnabled = true;
                        ags.Grant.IsEnabled = false;
                    }
                    this.Close();
                }
                
            }
            catch
            {
                
                if (GroupGrid.Items.Count == 0)
                {
                    MessageBox.Show("Please select atleast one client prior to clicking on Select Appointment Type");
                }
                else if (Staff.SelectedIndex == -1)
                {
                    MessageBox.Show("Please select a Therapist prior to clicking Select on Appointment Type");
                }
                else if (DateRecieved.Text.Equals("") || DateRecieved == null)
                {
                    MessageBox.Show("Please select a Date prior to clicking Select Appointment Type");
                }
                else
                {
                    MessageBox.Show("Something went wrong. Please check the fields and try again.");
                }
            }

        }