//Show All appointment based on userID
        public void DisplayWorkDay()
        {
            List <Schedule> listSchedule = db.GetAllAppointment();

            lvShowWorkDay.Items.Clear();

            List <DateTime> dates = new List <DateTime>();

            foreach (Schedule c in listSchedule)
            {
                lvShowWorkDay.Items.Add(c);
                dates.Add(c.ScheduleDate);
            }
            AppointmentDayConverter.LoadAppointments(dates);
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Schedule schedule = new Schedule();

            schedule.Note         = tbNote.Text;
            schedule.ScheduleDate = Convert.ToDateTime(dpDate.Text);
            schedule.StartTime    = tpStart.Text;
            schedule.EndTime      = tpEnd.Text;
            schedule.Subject      = tbSubject.Text;
            schedule.SalesRepId   = Convert.ToInt32(Application.Current.Resources["UserName"]);
            schedule.CustomerID   = Convert.ToInt32(lblCustomerID.Content);
            ComboBoxItem comboType = (ComboBoxItem)dpType.SelectedItem;

            schedule.Type = comboType.Content.ToString();


            schedule.Status      = cmbState.SelectedIndex;
            schedule.Schedule_id = Convert.ToInt32(lblScheduleID.Content.ToString());
            try
            {
                db = new Database();
                db.UpdateAppointment(schedule);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            this.Close();

            //refresh the list
            var             calendar     = new Calendar();
            List <Schedule> scheduleList = db.GetAllAppointment();
            List <DateTime> dates        = new List <DateTime>();

            calendar.lvShowWorkDay.Items.Clear();
            foreach (Schedule s in scheduleList)
            {
                calendar.lvShowWorkDay.Items.Add(s);
                dates.Add(s.ScheduleDate);
            }
            var mainWin = Application.Current.Windows.Cast <Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;

            AppointmentDayConverter.LoadAppointments(dates);
            mainWin.frTest.Refresh();
        }