Beispiel #1
0
        private void tableView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            AppointmentList apList1 = ((AppointmentModelController)controller).GetAppointments(doctors, dates, false);

            foreach (Control c in this.currentPanel.Controls)
            {
                if (c is DataGridView)
                {
                    foreach (Appointment t in apList1.GetAppointments())
                    {
                        if ((((DataGridView)c).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()).Contains(t.GetEndTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()).Contains(t.GetStartTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()).Contains(t.GetStartTime().ToString("M/d/yyyy")))
                        {
                            if (t.Available())
                            {
                                DialogResult dialogResult = MessageBox.Show("Are you sure?", "Delete Appointment", MessageBoxButtons.YesNo);

                                if (dialogResult == DialogResult.Yes)
                                {
                                    ((AppointmentModelController)controller).DeleteToDatabase(t);
                                    MessageBox.Show("Slot deleted!");
                                }
                                //else if (dialogResult)
                                else if (dialogResult == DialogResult.No)
                                {
                                    //do something else
                                }
                            }
                            else
                            {
                                MessageBox.Show("Slot cannot be deleted.");
                            }
                        }
                        else if ((((DataGridView)c).Rows[e.RowIndex].Cells[0].Value.ToString()).Contains(t.GetEndTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[0].Value.ToString()).Contains(t.GetStartTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[0].Value.ToString()).Contains(t.GetStartTime().ToString("M/d/yyyy")) && (((DataGridView)c).Rows[e.RowIndex].Cells[1].Value.ToString()).Contains(t.GetTitle()))
                        {
                            if (t.Available())
                            {
                                DialogResult dialogResult = MessageBox.Show("Are you sure?", "Delete Appointment", MessageBoxButtons.YesNo);
                                if (dialogResult == DialogResult.Yes)
                                {
                                    ((AppointmentModelController)controller).DeleteToDatabase(t);
                                    MessageBox.Show("Slot deleted!");
                                }
                                else if (dialogResult == DialogResult.No)
                                {
                                    //do something else
                                }
                            }
                            else
                            {
                                MessageBox.Show("Slot cannot be deleted.");
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void tableView_CellPainting_1(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex % 2 == 0 && e.ColumnIndex == 0)
            {
                e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
            }

            for (int j = 1; j < 48; j += 2)
            {
                tableView.Rows[j].Cells[0].Style.ForeColor = Color.White;

                AppointmentList apList1 = ((AppointmentModelController)controller).GetAppointments(doctors, dates, availableOnly);

                foreach (Appointment t in apList1.GetAppointments())
                {
                    String day = t.GetStartTime().ToString("ddd");

                    if (e.ColumnIndex != 0)
                    {
                        if (((e.RowIndex >= t.GetStartTime().Hour * 2 && e.RowIndex < t.GetEndTime().Hour * 2 - 1 && t.GetEndTime().Minute == 0) || (e.RowIndex >= t.GetStartTime().Hour * 2 && e.RowIndex < t.GetEndTime().Hour * 2 && t.GetEndTime().Minute == 30)) && (day.Contains("Sun") && e.ColumnIndex == 1))
                        {
                            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
                        }

                        else if (((e.RowIndex >= t.GetStartTime().Hour * 2 && (e.RowIndex < t.GetEndTime().Hour * 2 - 1 || t.GetEndTime().Hour == 0) && t.GetEndTime().Minute == 0) || (e.RowIndex >= t.GetStartTime().Hour * 2 && e.RowIndex < t.GetEndTime().Hour * 2 && t.GetEndTime().Minute == 30)) && (day.Contains("Mon") && e.ColumnIndex == 2))
                        {
                            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
                        }
                        else if (((e.RowIndex >= t.GetStartTime().Hour * 2 && (e.RowIndex < t.GetEndTime().Hour * 2 - 1 || t.GetEndTime().Hour == 0) && t.GetEndTime().Minute == 0) || (e.RowIndex >= t.GetStartTime().Hour * 2 && e.RowIndex < t.GetEndTime().Hour * 2 && t.GetEndTime().Minute == 30)) && (day.Contains("Tue") && e.ColumnIndex == 3))
                        {
                            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
                        }
                        else if (((e.RowIndex >= t.GetStartTime().Hour * 2 && (e.RowIndex < t.GetEndTime().Hour * 2 - 1 || t.GetEndTime().Hour == 0) && t.GetEndTime().Minute == 0) || (e.RowIndex >= t.GetStartTime().Hour * 2 && e.RowIndex < t.GetEndTime().Hour * 2 && t.GetEndTime().Minute == 30)) && (day.Contains("Wed") && e.ColumnIndex == 4))
                        {
                            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
                        }
                        else if (((e.RowIndex >= t.GetStartTime().Hour * 2 && (e.RowIndex < t.GetEndTime().Hour * 2 - 1 || t.GetEndTime().Hour == 0) && t.GetEndTime().Minute == 0) || (e.RowIndex >= t.GetStartTime().Hour * 2 && e.RowIndex < t.GetEndTime().Hour * 2 && t.GetEndTime().Minute == 30)) && (day.Contains("Thu") && e.ColumnIndex == 5))
                        {
                            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
                        }
                        else if (((e.RowIndex >= t.GetStartTime().Hour * 2 && (e.RowIndex < t.GetEndTime().Hour * 2 - 1 || t.GetEndTime().Hour == 0) && t.GetEndTime().Minute == 0) || (e.RowIndex >= t.GetStartTime().Hour * 2 && e.RowIndex < t.GetEndTime().Hour * 2 && t.GetEndTime().Minute == 30)) && (day.Contains("Fri") && e.ColumnIndex == 6))
                        {
                            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
                        }
                        else if (((e.RowIndex >= t.GetStartTime().Hour * 2 && (e.RowIndex < t.GetEndTime().Hour * 2 - 1 || t.GetEndTime().Hour == 0) && t.GetEndTime().Minute == 0) || (e.RowIndex >= t.GetStartTime().Hour * 2 && e.RowIndex < t.GetEndTime().Hour * 2 && t.GetEndTime().Minute == 30)) && (day.Contains("Sat") && e.ColumnIndex == 7))
                        {
                            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
                        }
                        else if (((e.RowIndex >= t.GetStartTime().Hour * 2 && (e.RowIndex < t.GetEndTime().Hour * 2 - 1 || t.GetEndTime().Hour == 0) && t.GetEndTime().Minute == 0) || (e.RowIndex >= t.GetStartTime().Hour * 2 && e.RowIndex < t.GetEndTime().Hour * 2 && t.GetEndTime().Minute == 30)) && dates.Count < 2)
                        {
                            e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public AppointmentModel()
        {
            this.appointments         = new AppointmentList();
            this.filteredAppointments = new AppointmentList();
            this.views = new List <ListView>();
            String username     = dbSettings.GetUsername();
            String password     = dbSettings.GetPassword();
            String dbname       = "udc_database";
            String myConnection = "datasource=localhost;database=" + dbname + ";port=3306;username="******";password="******"Success");
            }
            catch (Exception e) {
                Console.WriteLine("Connection Failed");
            }
        }
Beispiel #4
0
        private void tableView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            AppointmentList apList1 = ((AppointmentModelController)controller).GetAppointments(doctors, dates, false);

            foreach (Control c in this.currentPanel.Controls)
            {
                if (c is DataGridView)
                {
                    foreach (Appointment t in apList1.GetAppointments())
                    {
                        if ((((DataGridView)c).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()).Contains(t.GetEndTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()).Contains(t.GetStartTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()).Contains(t.GetStartTime().ToString("M/d/yyyy")))
                        {
                            if (t.Available())
                            {
                                t.SetAvailability(false);
                                ((AppointmentModelController)controller).UpdateDatabase(t, "Occupied");
                                MessageBox.Show("Appointment with " + t.GetTitle() + " confirmed!");
                            }
                            else
                            {
                                t.SetAvailability(true);
                                ((AppointmentModelController)controller).UpdateDatabase(t, "Available");
                                MessageBox.Show("Appointment with " + t.GetTitle() + " canceled" + ".");
                            }
                        }
                        else if ((((DataGridView)c).Rows[e.RowIndex].Cells[0].Value.ToString()).Contains(t.GetEndTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[0].Value.ToString()).Contains(t.GetStartTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[0].Value.ToString()).Contains(t.GetStartTime().ToString("M/d/yyyy")) && (((DataGridView)c).Rows[e.RowIndex].Cells[1].Value.ToString()).Contains(t.GetTitle()))
                        {
                            if (t.Available())
                            {
                                t.SetAvailability(false);
                                ((AppointmentModelController)controller).UpdateDatabase(t, "Occupied");
                                MessageBox.Show("Appointment with " + t.GetTitle() + " confirmed!!");
                            }
                            else
                            {
                                t.SetAvailability(true);
                                ((AppointmentModelController)controller).UpdateDatabase(t, "Available");
                                MessageBox.Show("Appointment with " + t.GetTitle() + " canceled" + ".");
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public void Update(List <String> doctors, List <DateTime> dates, Boolean availableOnly)
        {
            AppointmentList apList1 = ((AppointmentModelController)controller).GetAppointments(doctors, dates, availableOnly);

            this.doctors       = doctors;
            this.dates         = dates;
            this.availableOnly = availableOnly;
            int k = 1;

            if (this is CalendarView)
            {
                if (dates.Count == 1)
                {
                    this.tableView.ColumnHeadersVisible = false;
                    DataTable dt      = new DataTable();
                    DateTime  curDate = dates[0];

                    this.tableView.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.tableView_CellPainting_1);

                    dt.Columns.Add("Time");
                    dt.Columns.Add("Todo");

                    for (int i = 0; i < 24; i++)
                    {
                        dt.Rows.Add(i.ToString("00") + ":00");
                        dt.Rows.Add(i.ToString("00") + ":30");
                    }

                    tableView.DataSource = dt;

                    tableView.Columns[1].DefaultCellStyle.ForeColor = Color.White;
                    tableView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
                    tableView.Columns[0].Width    = 70;
                    tableView.Columns[1].Width    = 360;
                    tableView.Columns["Time"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    tableView.AllowUserToResizeColumns = false;
                    tableView.AllowUserToResizeRows    = false;
                    tableView.AllowUserToAddRows       = false;

                    foreach (Appointment t in apList1.GetAppointments())
                    {
                        String startTime = t.GetStartTime().ToString("HH:mm");
                        for (int i = 0; i < 48; i++)
                        {
                            if ((startTime.Equals(tableView.Rows[i].Cells[0].Value.ToString())))
                            {
                                tableView.Rows[i].Cells[k].Value           = t.GetTitle() + " | " + t.GetStartTime().ToString("M/d/yyyy") + " | " + t.GetStartTime().ToString("HH:mm") + " - " + t.GetEndTime().ToString("HH:mm");
                                tableView.Rows[i].Cells[k].Style.BackColor = t.GetColor();
                                int    j       = i + 1;
                                String endTime = (t.GetEndTime().ToString("HH:mm"));
                                while (!endTime.Equals(tableView.Rows[j].Cells[0].Value.ToString()))
                                {
                                    tableView.Rows[j].Cells[1].Style.BackColor = t.GetColor();
                                    tableView.Rows[j].Cells[1].Value           = t.GetTitle() + " | " + t.GetStartTime().ToString("M/d/yyyy") + " | " + t.GetStartTime().ToString("HH:mm") + " - " + t.GetEndTime().ToString("HH:mm");
                                    tableView.Rows[j].Cells[1].Style.ForeColor = t.GetColor();

                                    j++;

                                    if (j == 48)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                else if (dates.Count > 1)
                {
                    this.tableView.ColumnHeadersVisible = true;

                    DataTable dt = new DataTable();

                    this.tableView.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.tableView_CellPainting_1);

                    DateTime d = dates[0];

                    dt.Columns.Add("Time");

                    dt.Columns.Add(d.Day.ToString() + "-Sunday");
                    d = d.AddDays(1);
                    dt.Columns.Add(d.Day.ToString() + "-Monday");
                    d = d.AddDays(1);
                    dt.Columns.Add(d.Day.ToString() + "-Tuesday");
                    d = d.AddDays(1);
                    dt.Columns.Add(d.Day.ToString() + "-Wednesday");
                    d = d.AddDays(1);
                    dt.Columns.Add(d.Day.ToString() + "-Thursday");
                    d = d.AddDays(1);
                    dt.Columns.Add(d.Day.ToString() + "-Friday");
                    d = d.AddDays(1);
                    dt.Columns.Add(d.Day.ToString() + "-Saturday");

                    for (int i = 0; i < 24; i++)
                    {
                        dt.Rows.Add(i.ToString("00") + ":00");
                        dt.Rows.Add(i.ToString("00") + ":30");
                    }

                    tableView.DataSource = dt;


                    tableView.Columns[1].DefaultCellStyle.ForeColor = Color.White;
                    tableView.Columns[2].DefaultCellStyle.ForeColor = Color.White;
                    tableView.Columns[3].DefaultCellStyle.ForeColor = Color.White;
                    tableView.Columns[4].DefaultCellStyle.ForeColor = Color.White;
                    tableView.Columns[5].DefaultCellStyle.ForeColor = Color.White;
                    tableView.Columns[6].DefaultCellStyle.ForeColor = Color.White;
                    tableView.Columns[7].DefaultCellStyle.ForeColor = Color.White;

                    foreach (Appointment t in apList1.GetAppointments())
                    {
                        String startTime = t.GetStartTime().ToString("HH:mm");
                        for (int i = 0; i < 48; i++)
                        {
                            if ((startTime.Equals(tableView.Rows[i].Cells[0].Value.ToString())))
                            {
                                String day = t.GetStartTime().ToString("ddd");

                                while (!tableView.Columns[k].HeaderText.ToString().Contains(day) && k < 7)
                                {
                                    Console.Write(tableView.Columns[k].HeaderText.ToString());
                                    k++;
                                }

                                tableView.Rows[i].Cells[k].Value           = t.GetTitle() + " | " + t.GetStartTime().ToString("M/d/yyyy") + " | " + t.GetStartTime().ToString("HH:mm") + " - " + t.GetEndTime().ToString("HH:mm");
                                tableView.Rows[i].Cells[k].Style.BackColor = t.GetColor();
                                int    j       = i + 1;
                                String endTime = (t.GetEndTime().ToString("HH:mm"));
                                while (!endTime.Equals(tableView.Rows[j].Cells[0].Value.ToString()))
                                {
                                    tableView.Rows[j].Cells[k].Style.BackColor = t.GetColor();
                                    tableView.Rows[j].Cells[k].Value           = t.GetTitle() + " | " + t.GetStartTime().ToString("M/d/yyyy") + " | " + t.GetStartTime().ToString("HH:mm") + " - " + t.GetEndTime().ToString("HH:mm");
                                    tableView.Rows[j].Cells[k].Style.ForeColor = t.GetColor();
                                    j++;
                                    if (j == 48)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    tableView.Columns[1].DefaultCellStyle.ForeColor = Color.White;
                    tableView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
                    tableView.Columns[0].Width    = 70;
                    for (int i = 1; i < tableView.Columns.Count; i++)
                    {
                        tableView.Columns[i].Width = 100;
                    }
                    tableView.Columns["Time"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    tableView.AllowUserToResizeColumns = false;
                    tableView.AllowUserToResizeRows    = false;
                    tableView.AllowUserToAddRows       = false;
                }
            }
            else if (this is AgendaView)
            {
                tableView.AllowUserToResizeColumns = false;
                tableView.AllowUserToResizeRows    = false;
                tableView.ReadOnly = true;

                DataTable dt = new DataTable();
                dt.Columns.Add("Time");
                dt.Columns.Add("Todo");

                tableView.GridColor = Color.White;
                if (apList1.Count() == 0)
                {
                    dt.Rows.Add("No Appointments to show");
                }

                foreach (Appointment t in apList1.GetAppointments())
                {
                    dt.Rows.Add("  ");
                }

                tableView.DataSource = dt;

                int i = 0;
                foreach (Appointment t in apList1.GetAppointments())
                {
                    tableView.Rows[i].Cells[0].Value = t.GetStartTime().ToString("M/d/yyyy HH:mm") + " - " + t.GetEndTime().ToString("HH:mm");
                    tableView.Rows[i].Cells[1].Value = t.GetTitle();

                    Console.WriteLine(t.GetStartTime());

                    if (t.Available())
                    {
                        tableView.Rows[i].Cells[1].Value += " (Available)";
                    }
                    else
                    {
                        tableView.Rows[i].Cells[1].Value += " (Unavailable)";
                    }

                    tableView.Rows[i].Cells[1].Style.ForeColor = t.GetColor();

                    i++;
                }
            }
        }
Beispiel #6
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            AppointmentList apList1       = ((AppointmentModelController)controller).GetAppointments(doctors, dates, false);
            Appointment     chosenApp     = null;
            String          chosenSlotNum = null; //slot num needs to be the same
            int             year          = dateTimePicker.Value.Year;
            int             month         = dateTimePicker.Value.Month;
            int             day           = dateTimePicker.Value.Day;

            var oldStartDate = new DateTime(year, month, day, Int32.Parse(oldStartHourCB.Text), Int32.Parse(oldStartMinCB.Text), 0);
            var oldEndDate   = new DateTime(year, month, day, Int32.Parse(oldEndHourCB.Text), Int32.Parse(oldEndMinCB.Text), 0);


            Console.WriteLine("oldDate: " + oldStartDate + " - " + oldEndDate);



            if (newStartHourCB.SelectedItem == null || newStartMinCB.SelectedItem == null || newEndHourCB.SelectedItem == null || newEndMinCB.SelectedItem == null)
            {
                MessageBox.Show("Please enter a new timeslot");
            }
            else
            {
                //look for the matching appointment
                for (int i = 0; i < apList1.Count(); i++)
                {
                    Appointment a         = apList1.GetByIndex(i);
                    DateTime    tempStart = a.GetStartTime();
                    DateTime    tempEnd   = a.GetEndTime();
                    int         result1   = DateTime.Compare(tempStart, oldStartDate);
                    int         result2   = DateTime.Compare(tempEnd, oldEndDate);
                    if (result1 == 0 && result2 == 0)
                    {
                        chosenApp = a;
                        break;
                    }
                }
                Console.WriteLine("current Appoint: " + chosenApp.GetStartTime() + " - " + chosenApp.GetEndTime()); //appointment that was clicked
                chosenSlotNum = chosenApp.GetSlotNum();

                //delete
                ((AppointmentModelController)controller).DeleteToDatabase(chosenApp);

                //add but same slot num (use chosenSlotNum then set it at the end)
                Appointment app = null;

                int yearStart    = newDatePicker.Value.Year;
                int monthStart   = newDatePicker.Value.Month;
                int dayStart     = newDatePicker.Value.Day;
                int hourStart    = 0;
                int minutesStart = 0;

                if (newStartHourCB.SelectedItem.ToString()[0] == '0')
                {
                    hourStart = Int32.Parse(newStartHourCB.SelectedItem.ToString().Substring(1, 1));
                }
                else
                {
                    hourStart = Int32.Parse(newStartHourCB.SelectedItem.ToString());
                }

                if (startMinuteCB.SelectedItem.ToString()[0] == '0')
                {
                    minutesStart = Int32.Parse(newStartMinCB.SelectedItem.ToString().Substring(1, 1));
                }
                else
                {
                    minutesStart = Int32.Parse(newStartMinCB.SelectedItem.ToString());
                }

                DateTime startDate = new DateTime(yearStart, monthStart, dayStart, hourStart, minutesStart, 0);

                int yearEnd    = newDatePicker.Value.Year;
                int monthEnd   = newDatePicker.Value.Month;
                int dayEnd     = newDatePicker.Value.Day;
                int hourEnd    = 0;
                int minutesEnd = 0;

                if (endHourCB.SelectedItem.ToString()[0] == '0')
                {
                    hourEnd = Int32.Parse(newEndHourCB.SelectedItem.ToString().Substring(1, 1));
                }
                else
                {
                    hourEnd = Int32.Parse(newEndHourCB.SelectedItem.ToString());
                }

                if (endMinuteCB.SelectedItem.ToString()[0] == '0')
                {
                    minutesEnd = Int32.Parse(newEndMinCB.SelectedItem.ToString().Substring(1, 1));
                }
                else
                {
                    minutesEnd = Int32.Parse(newEndMinCB.SelectedItem.ToString());
                }

                DateTime endDate = new DateTime(yearEnd, monthEnd, dayEnd, hourEnd, minutesEnd, 0);

                if (ValidTime(startDate, endDate))
                {
                    if (recurringText.Text.ToString().Length == 0 || recurringText.Text.ToString().Equals("0"))
                    {
                        app = new Appointment(doctorName.Text, startDate, endDate);
                        app.SetSlotNumber(chosenSlotNum); //copy original slot num

                        if (app != null && !((AppointmentModelController)controller).Overlap(app))
                        {
                            ((AppointmentModelController)controller).AddToDatabase(app);
                            //MessageBox.Show("Time slot added!");
                        }
                        else
                        {
                            MessageBox.Show("Overlap task.");
                        }
                    }
                    else
                    {
                        try
                        {
                            if (Int32.Parse(recurringText.Text.ToString()) > -1)
                            {
                                DateTime tempStartDate = startDate;
                                DateTime tempEndDate   = endDate;

                                for (int i = 0; i < Int32.Parse(recurringText.Text.ToString()); i++)
                                {
                                    app = new Appointment(doctorName.Text, tempStartDate, tempEndDate);
                                    app.SetSlotNumber(chosenSlotNum); //copy original slot num


                                    if (app != null && !((AppointmentModelController)controller).Overlap(app))
                                    {
                                        ((AppointmentModelController)controller).AddToDatabase(app);
                                    }

                                    tempStartDate = tempStartDate.AddDays(7);
                                    tempEndDate   = tempEndDate.AddDays(7);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Invalid input.");
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Invalid input.");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Invalid time.");
                }



                //go back to grid view
                this.Controls.Remove(editPanel);
                this.Controls.Add(currentPanel);
                this.currentView.Update(doctors, dates, false);
                editPanel.Hide();

                MessageBox.Show("Appointment Edited");
            }
        }
Beispiel #7
0
        private void tableView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            // display dun lol (display app info) HHHAHAHAHA

            AppointmentList apList1 = ((AppointmentModelController)controller).GetAppointments(doctors, dates, false);

            foreach (Control c in this.currentPanel.Controls)
            {
                if (c is DataGridView)
                {
                    foreach (Appointment t in apList1.GetAppointments())
                    {
                        if ((((DataGridView)c).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()).Contains(t.GetEndTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()).Contains(t.GetStartTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()).Contains(t.GetStartTime().ToString("M/d/yyyy")))
                        {
                            if (t.Available())
                            {
                                save.Visible    = false;
                                editBtn.Visible = true;
                                Cancel.Visible  = true;

                                //set comboboxes
                                startHourCB.SelectedIndex = t.GetStartTime().Hour;
                                endHourCB.SelectedIndex   = t.GetEndTime().Hour;
                                String SM = t.GetStartTime().Minute.ToString();
                                if (SM.Equals("0"))
                                {
                                    startMinuteCB.SelectedIndex = 0;
                                }
                                else if (SM.Equals("30"))
                                {
                                    startMinuteCB.SelectedIndex = 1;
                                }
                                String EM = t.GetEndTime().Minute.ToString();
                                if (EM.Equals("0"))
                                {
                                    endMinuteCB.SelectedIndex = 0;
                                }
                                else if (EM.Equals("30"))
                                {
                                    endMinuteCB.SelectedIndex = 1;
                                }
                            }
                            else
                            {
                                MessageBox.Show("Slot cannot be edited.");
                            }
                        }
                        else if ((((DataGridView)c).Rows[e.RowIndex].Cells[0].Value.ToString()).Contains(t.GetEndTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[0].Value.ToString()).Contains(t.GetStartTime().ToString("HH:mm")) && (((DataGridView)c).Rows[e.RowIndex].Cells[0].Value.ToString()).Contains(t.GetStartTime().ToString("M/d/yyyy")) && (((DataGridView)c).Rows[e.RowIndex].Cells[1].Value.ToString()).Contains(t.GetTitle()))
                        {
                            if (t.Available())
                            {
                                save.Visible    = false;
                                editBtn.Visible = true;
                                Cancel.Visible  = true;

                                //set comboboxes
                                startHourCB.SelectedIndex = t.GetStartTime().Hour;
                                endHourCB.SelectedIndex   = t.GetEndTime().Hour;
                                String SM = t.GetStartTime().Minute.ToString();
                                if (SM.Equals("0"))
                                {
                                    startMinuteCB.SelectedIndex = 0;
                                }
                                else if (SM.Equals("30"))
                                {
                                    startMinuteCB.SelectedIndex = 1;
                                }
                                String EM = t.GetEndTime().Minute.ToString();
                                if (EM.Equals("0"))
                                {
                                    endMinuteCB.SelectedIndex = 0;
                                }
                                else if (EM.Equals("30"))
                                {
                                    endMinuteCB.SelectedIndex = 1;
                                }
                            }
                            else
                            {
                                MessageBox.Show("Slot cannot be edited."); //cannot edit
                            }
                        }
                    }
                }
            }
        }
        public AppointmentList GetAppointments(List <String> doctors, List <DateTime> dates, Boolean availableOnly)
        {
            DateTime        curDate;
            AppointmentList filteredAppointments = new AppointmentList();
            AppointmentList appointments         = ((AppointmentModel)this.model).GetAppointments();

            if (!availableOnly)
            {
                if (dates.Count == 1)
                {
                    curDate = dates[0].Date;

                    foreach (Appointment t in appointments.GetAppointments())
                    {
                        if ((DateTime.Compare(t.GetStartTime().Date, curDate.Date) == 0))
                        {
                            foreach (String dr in doctors)
                            {
                                if (t.GetTitle().Equals(dr))
                                {
                                    filteredAppointments.Add(t);
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (Appointment t in appointments.GetAppointments())
                    {
                        if (t.GetStartTime().Date >= dates[0].Date && t.GetStartTime().Date <= dates[1].Date)
                        {
                            foreach (String dr in doctors)
                            {
                                if (t.GetTitle().Equals(dr))
                                {
                                    filteredAppointments.Add(t);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (dates.Count == 1)
                {
                    curDate = dates[0].Date;

                    foreach (Appointment t in appointments.GetAppointments())
                    {
                        if (t.Available())
                        {
                            if ((DateTime.Compare(t.GetStartTime().Date, curDate.Date) == 0))
                            {
                                foreach (String dr in doctors)
                                {
                                    if (t.GetTitle().Equals(dr))
                                    {
                                        filteredAppointments.Add(t);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (Appointment t in appointments.GetAppointments())
                    {
                        if (t.Available())
                        {
                            if (t.GetStartTime().Date >= dates[0].Date && t.GetStartTime().Date <= dates[1].Date)
                            {
                                foreach (String dr in doctors)
                                {
                                    if (t.GetTitle().Equals(dr))
                                    {
                                        filteredAppointments.Add(t);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(filteredAppointments);
        }