Exemplo n.º 1
0
        private void pictureBox8_Click(object sender, EventArgs e)
        {
            EventName.Text = "Event's Name";
            EventName.Focus();
            EventName.SelectAll();
            EventPlace.Text     = "Event's Location";
            Start_Date.Value    = DateTime.Today;
            S_T_Hours.Text      = "HR";
            S_T_Minutes.Text    = "MN";
            A_P_M.SelectedIndex = -1;
            A_P_M.Text          = "AM/PM";

            End_Date.Value           = DateTime.Today;
            ReminderTimePicker.Value = DateTime.Today;
            yesDone.Checked          = false;
            noDone.Checked           = false;
        }
Exemplo n.º 2
0
        //BUTTON, add an appointment.
        private async void AddAppointmentClick(object sender, RoutedEventArgs e)
        {
            try
            {
                string eventName = EventName.Text;
                string location  = Location.Text;

                string startDay   = StartDate.Date.Day.ToString();
                string startMonth = StartDate.Date.Month.ToString();
                string startYear  = StartDate.Date.Year.ToString();

                string finalDate = "" + startMonth + "/" + startDay + "/" + startYear;



                string startHour   = StartTime.Time.Hours.ToString();
                string startMinute = StartTime.Time.Minutes.ToString();

                string finalStartTime = "" + startHour + ":" + startMinute;


                string endHour      = EndTime.Time.Hours.ToString();
                string endMinute    = EndTime.Time.Minutes.ToString();
                string finalEndTime = "" + endHour + ":" + endMinute;


                //This varible is the number of hours the appointment will run for.
                int durationHours = StartTime.Time.Hours - EndTime.Time.Hours;
                //This variable is the number of minutes the appointment will run for.
                int durationMinutes = StartTime.Time.Minutes - EndTime.Time.Minutes;

                //IF appointment time is 0 hours and 0 minutes or less, show an error.
                if (durationHours >= 0 && durationMinutes >= 0)
                {
                    MessageDialog messageDialog1 = new MessageDialog("Start Time can't be less than End Time");
                    await messageDialog1.ShowAsync();

                    //IF there is no event name, show an error.
                    if (eventName == "")
                    {
                        MessageDialog messageDialog2 = new MessageDialog("Please enter a unique Event Name. ");
                        await messageDialog2.ShowAsync();

                        EventName.Focus(FocusState.Programmatic);

                        //IF there is no location, show an error.
                        if (eventName == "")
                        {
                            MessageDialog messageDialog3 = new MessageDialog("Please enter a Location for the appointment. ");
                            await messageDialog3.ShowAsync();

                            Location.Focus(FocusState.Programmatic);
                            return;
                        }
                    }
                }

                // ELSE insert data
                else
                {
                    conn.Insert(new Appointments()
                    {
                        EventName = eventName,
                        Location  = location,
                        StartDate = finalDate,
                        StartTime = finalStartTime,
                        EndTime   = finalEndTime
                    });
                    MessageDialog AddedConfirmed = new MessageDialog("Appointment added");
                    await AddedConfirmed.ShowAsync();

                    //Reload the data into the list view.
                    Reload();
                    ClearForm();
                }
            }
            catch (Exception ex)
            {
                if (ex is FormatException)
                {
                    MessageDialog dialog = new MessageDialog("Please check all fields have data, then press Add.");
                    await dialog.ShowAsync();
                }
            }
        }
Exemplo n.º 3
0
        // check if the reminder after start date show error message


        private void button1_Click(object sender, EventArgs e)
        {
            // clear the errors every sumbitting and check for errors again

            errorProvider1.Clear();

            // check if it is no name and give error

            if ((EventName.Text == "") || (EventName.Text == "Event's Name"))
            {
                errorProvider1.SetError(EventName, "Please Enter Event's Name");
                EventName.Focus();
            }

            // check if it is no place and give error
            else if ((EventPlace.Text == "") || (EventPlace.Text == "Event's Location"))
            {
                errorProvider1.SetError(this.EventPlace, "Please Enter Event's Place");
                EventPlace.Focus();
            }

            // check if it is no start date and give error
            else if (this.Start_Date.Value.ToString() == "")
            {
                errorProvider1.SetError(this.Start_Date, "Please Enter Start Day Date");
                Start_Date.Focus();
            }

            else if (Start_Date.Value < DateTime.Today.AddDays(1))
            {
                errorProvider1.SetError(this.Start_Date, "The Evnet Must Be At Least Tomorrow");
                Start_Date.Value = DateTime.Today.AddDays(1);
            }

            // check if it is no start time hours  and give error
            else if ((S_T_Hours.Text == "") || (S_T_Hours.Text == "HR"))
            {
                errorProvider1.SetError(this.S_T_Hours, "Please Start Day Time");
                S_T_Hours.Focus();
            }


            else if ((int.Parse(S_T_Hours.Text) > 12) || (int.Parse(S_T_Hours.Text) < 0))
            {
                errorProvider1.SetError(this.S_T_Hours, "Please Enter Valid Hour (0->12) ");
                S_T_Hours.Text = "";
                S_T_Hours.Focus();
            }

            else if (S_T_Hours.Text.Length == 1)
            {
                int a = int.Parse(S_T_Hours.Text);
                S_T_Hours.Text = "0" + S_T_Hours.Text;
            }

            // check if it is no sart time minutes and give error
            else if ((S_T_Minutes.Text == "") || (S_T_Minutes.Text == "MN"))
            {
                errorProvider1.SetError(S_T_Minutes, "Please Enter Start Day Time");
                S_T_Minutes.Focus();
            }

            else if ((int.Parse(S_T_Minutes.Text) > 59) || (int.Parse(S_T_Minutes.Text) < 0))
            {
                errorProvider1.SetError(this.S_T_Minutes, "Please Enter Valid Minute (0 -> 59)");
                S_T_Minutes.Text = "";
                S_T_Minutes.Focus();
            }

            // check if it is no choice of (am) or (pm) and give error
            else if (A_P_M.SelectedIndex == -1)
            {
                errorProvider1.SetError(this.A_P_M, "Please Choose am or pm");
                A_P_M.Focus();
            }

            else if ((int.Parse(S_T_Hours.Text) == 12) && (A_P_M.SelectedIndex == 0))
            {
                S_T_Hours.Text = "00";
            }

            // check if it is no end date and give error
            else if (End_Date.Value.ToString() == "")
            {
                errorProvider1.SetError(this.End_Date, "Please Enter End Day Date");
                End_Date.Focus();
            }
            else if (End_Date.Value < Start_Date.Value)
            {
                errorProvider1.SetError(this.End_Date, "The End Date must not be before Start Date");
                errorProvider1.SetError(this.Start_Date, "The Start Date must not be After End Date");
                Start_Date.Focus();
                End_Date.Focus();
            }

            // check if is no reminder time and give error
            else if (ReminderTimePicker.Value.ToString() == "")
            {
                errorProvider1.SetError(this.ReminderTimePicker, "Please Enter The Reminder Time ");
                ReminderTimePicker.Focus();
            }

            else if (ReminderTimePicker.Value < DateTime.Today)
            {
                errorProvider1.SetError(this.ReminderTimePicker, "Please Enter A Valid Reminder Time");
                ReminderTimePicker.Focus();
            }

            else if (ReminderTimePicker.Value >= Start_Date.Value)
            {
                errorProvider1.SetError(this.ReminderTimePicker, "The Reminder must not Be After Or Equal Start Date");
                ReminderTimePicker.Focus();
            }

            // check if it is no choice of yes done and give error
            else if (yesDone.Checked == false)
            {
                errorProvider1.SetError(this.yesDone, "Please Check Yes Done To Sumbit The Event");
                noDone.Checked = false;
            }



            // if thers is no error submitting the data to file
            else
            {
                // check if there is intersection with another event
                bool Intersects = false;

                for (int i = 0; i < EventsData.Count; i++)
                {
                    DateTime DataStartD = Convert.ToDateTime(EventsData[i].EStartDate);
                    DateTime DataEndD   = Convert.ToDateTime(EventsData[i].E_EndDate);

                    if ((Start_Date.Value == DataStartD) || (End_Date.Value == DataEndD))
                    {
                        Intersects = true;
                        break;
                    }
                    else if ((End_Date.Value == DataStartD) || (Start_Date.Value == DataEndD))
                    {
                        Intersects = true;
                        break;
                    }
                    else if ((Start_Date.Value > DataStartD) && (End_Date.Value < DataEndD))
                    {
                        Intersects = true;
                        break;
                    }
                    else if ((Start_Date.Value < DataStartD) && (End_Date.Value > DataEndD))
                    {
                        Intersects = true;
                        break;
                    }
                    else if ((Start_Date.Value < DataStartD) && (End_Date.Value > DataStartD))
                    {
                        Intersects = true;
                        break;
                    }
                    else if ((Start_Date.Value < DataEndD) && (End_Date.Value > DataEndD))
                    {
                        Intersects = true;
                        break;
                    }
                }



                // if no intersection sumbit
                if (Intersects == false)
                {
                    Event AddingEvent = new Event(); // object of adding event class
                                                     // copy the data of event to the class members

                    AddingEvent.EName          = EventName.Text;
                    AddingEvent.EPlace         = EventPlace.Text;
                    AddingEvent.EStartDate     = Start_Date.Value.ToShortDateString();
                    AddingEvent.EStartTime     = S_T_Hours.Text + ":" + S_T_Minutes.Text + " " + A_P_M.SelectedItem.ToString();
                    AddingEvent.E_EndDate      = End_Date.Value.ToShortDateString();
                    AddingEvent.E_ReminderTime = ReminderTimePicker.Value.ToShortDateString();

                    // Adding the class event in the vector
                    EventsData.Add(AddingEvent);
                    MessageBox.Show("Successful Submitting", "Great Job");
                }

                // if there is intersection sow messagebox
                else if (Intersects == true)
                {
                    MessageBox.Show("The Event Intersects with another Event\nYou must change The Dates", "Error!");
                }
            }
        }
Exemplo n.º 4
0
        // submit button if ther is a missing data show an error provider next to the cell
        // else accept and submit the data to the file
        private void Submit_Btn_Click(object sender, EventArgs e)
        {
            // clear the errors every sumbitting and check for errors again
            errorProvider1.Clear();

            // check if it is no name and give error
            if ((EventName.Text == "") || (EventName.Text == "Enter Events' name"))
            {
                errorProvider1.SetError(this.EventName, "Please Enter Event's Name");
                EventName.Focus();
            }

            // check if it is no place and give error
            else if ((EventPlace.Text == "") || (EventPlace.Text == "Enter Place The Event Will Be"))
            {
                errorProvider1.SetError(this.EventPlace, "Please Enter Event's Place");
                EventPlace.Focus();
            }

            // check if it is no start date and give error
            else if (Start_Date.Value.ToString() == "")
            {
                errorProvider1.SetError(this.Start_Date, "Please Enter Start Day Date");
                Start_Date.Focus();
            }

            // check if it is no start time hours  and give error
            else if ((S_T_Hours.Text == "") || (S_T_Hours.Text == "HR"))
            {
                errorProvider1.SetError(this.S_T_Hours, "Please Start Day Time");
                S_T_Hours.Focus();
            }

            // check if it is no sart time minutes and give error
            else if ((S_T_Minutes.Text == "") || (S_T_Minutes.Text == "MN"))
            {
                errorProvider1.SetError(this.S_T_Minutes, "Please Start Day Time");
                S_T_Minutes.Focus();
            }

            // check if it is no choice of (am) or (pm) and give error
            else if (A_P_M.SelectedIndex == -1)
            {
                errorProvider1.SetError(this.A_P_M, "Please Choose am or pm");
                A_P_M.Focus();
            }

            // check if it is no end date and give error
            else if (End_Date.Value.ToString() == "")
            {
                errorProvider1.SetError(this.End_Date, "Please Enter End Day Date");
                End_Date.Focus();
            }

            // check if it is no choice of yes done and give error
            else if (yesDone.Checked == false)
            {
                errorProvider1.SetError(this.yesDone, "Please Check Yes Done To Sumbit The Event");
                noDone.Checked = false;
            }

            // if thers is no error submitting the data to file
            else
            {
                AddingE AE = new AddingE(); // object of adding event class
                // copy the data of event to the class members
                AE.EName      = EventName.Text;
                AE.EPlace     = EventPlace.Text;
                AE.EStartDate = Start_Date.Value.ToShortDateString();
                AE.EStartTime = S_T_Hours.Text + ":" + S_T_Minutes.Text + " " + A_P_M.SelectedItem.ToString();
                AE.E_EndDate  = End_Date.Value.ToShortDateString();

                // writing the data of event in file by member function
                AE.Writing_in_file();
                // check if the event is today by member function
                AE.TodayTimeReminder();
            }
        }