예제 #1
0
        private void ClSheduleSet_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
        {
            DoctorAvailability scheduleForSpecificDate = new DoctorAvailability();

            //check if doctor selected from list
            if (lvDoctors.SelectedItem != null)
            {
                try
                {
                    docToSetSchedule = lvDoctors.SelectedItem as Doctor;
                    //check if schedule is set for selected date for the selected doctor
                    if (Globals.Db.CheckIfScheduleIsSet(docToSetSchedule.Id, clSheduleSet.SelectedDate.Value.ToString("yyyy-MM-dd")) > 0)

                    {
                        scheduleForSpecificDate = Globals.Db.GetDoctorScheduleByDoctorIdAndDate(docToSetSchedule.Id, clSheduleSet.SelectedDate.Value.ToString("yyyy-MM-dd"));
                        lbWorkingHours.Content  = scheduleForSpecificDate;
                    }

                    else
                    {
                        lbWorkingHours.Content = "not set";
                    }
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("Error executing SQL query:\n" + ex.Message,
                                    "EasyAppointemtn Database", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Please select a doctor from the list.",
                                "EasyAppointment", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
예제 #2
0
        public void AddDoctorAvailability(DoctorAvailability workDay)
        {
            SqlCommand cmdInsert = new SqlCommand("INSERT INTO DoctorAvailability (DoctorId, AvailableDate, StartHour, EndHour) VALUES (@DoctorId, @AvailableDate, @StartHour, @EndHour)", conn);

            cmdInsert.Parameters.AddWithValue("DoctorId", workDay.DoctorId);
            cmdInsert.Parameters.AddWithValue("AvailableDate", workDay.AvailableDate);
            cmdInsert.Parameters.AddWithValue("StartHour", workDay.StartHour);
            cmdInsert.Parameters.AddWithValue("EndHour", workDay.EndHour);

            cmdInsert.ExecuteNonQuery();
        }
예제 #3
0
        private void BtDelete_Click(object sender, RoutedEventArgs e)
        {
            DoctorAvailability scheduleForSpecificDate = new DoctorAvailability();

            //check if doctor selected from list
            if (lvDoctors.SelectedItem != null)
            {
                try
                {
                    docToSetSchedule = lvDoctors.SelectedItem as Doctor;
                    var selectedDates = clSheduleSet.SelectedDates;

                    if (selectedDates.Count != 1)
                    {
                        MessageBox.Show("Please select one date from the calendar in oreder to delete doctor's schedule.",
                                        "EasyAppointment", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                    //check if schedule is set for selected date for the selected doctor
                    if (Globals.Db.CheckIfScheduleIsSet(docToSetSchedule.Id, clSheduleSet.SelectedDate.Value.ToString("yyyy-MM-dd")) > 0)

                    {
                        Globals.Db.DeleteScheduleForSpecificDoctorAndDate(docToSetSchedule.Id, clSheduleSet.SelectedDate.Value.ToString("yyyy-MM-dd"));
                        MessageBox.Show("Schedule deleted.",
                                        "EasyAppointment Database", MessageBoxButton.OK, MessageBoxImage.Information);
                        lbWorkingHours.Content = "not set";
                    }
                    else
                    {
                        MessageBox.Show("Schedule is not set for this date to be deleted.",
                                        "EasyAppointment Database", MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("Error executing SQL query:\n" + ex.Message,
                                    "EasyAppointemtn Database", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please select a doctor from the list",
                                "EasyAppointment", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
        }
예제 #4
0
        public DoctorAvailability GetDoctorScheduleByDoctorIdAndDate(int id, string date)
        {
            DoctorAvailability daySchedule = new DoctorAvailability();
            SqlCommand         cmdSelect   = new SqlCommand("SELECT StartHour, EndHour FROM DoctorAvailability WHERE DoctorId = @DocId AND convert(varchar(10), AvailableDate, 120) = @AppDate", conn);

            cmdSelect.Parameters.AddWithValue("DocId", id);
            cmdSelect.Parameters.AddWithValue("AppDate", date);
            using (SqlDataReader reader = cmdSelect.ExecuteReader())
            {
                while (reader.Read())
                {
                    int sHour = (int)reader["StartHour"];
                    int eHour = (int)reader["EndHour"];

                    daySchedule.StartHour = sHour;
                    daySchedule.EndHour   = eHour;
                }
            }
            return(daySchedule);
        }
예제 #5
0
        private void BtSave_Click(object sender, RoutedEventArgs e)
        {
            docToSetSchedule = lvDoctors.SelectedItem as Doctor;
            if (docToSetSchedule == null)
            {
                MessageBox.Show("Please select a doctor from the list",
                                "EasyAppointment", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            string startTimeStr = cboStartTime.Text;

            if (startTimeStr == null)
            {
                MessageBox.Show("Please select start time from the list",
                                "EasyAppointment", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            List <string> listStrLineStartTime = startTimeStr.Split(':').ToList <string>();
            int           startTime            = int.Parse(listStrLineStartTime[0]);

            string endTimeStr = cboEndTime.Text;

            if (endTimeStr == null)
            {
                MessageBox.Show("Please select end time from the list",
                                "EasyAppointment", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            List <string> listStrLineEndTime = endTimeStr.Split(':').ToList <string>();
            int           endTime            = int.Parse(listStrLineEndTime[0]);

            //List<DateTime> selectedDates = new List<DateTime>();

            var selectedDates = clSheduleSet.SelectedDates;

            if (selectedDates.Count == 0)
            {
                MessageBox.Show("Please select dates from the calendar.",
                                "EasyAppointment", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            foreach (var sDate in selectedDates)
            {
                try
                {
                    DoctorAvailability workDay = new DoctorAvailability()
                    {
                        DoctorId = docToSetSchedule.Id, AvailableDate = sDate.ToString("yyyy-MM-dd"), StartHour = startTime, EndHour = endTime
                    };
                    Globals.Db.AddDoctorAvailability(workDay);
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("Error executing SQL query:\n" + ex.Message,
                                    "EasyAppointemtn Database", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            MessageBox.Show("Schedule saved.",
                            "EasyAppointment", MessageBoxButton.OK, MessageBoxImage.Information);
        }