Example #1
0
        // make the user enter only minutes from 0 to 59 in hours cell
        private void S_T_Minutes_Leave(object sender, EventArgs e)
        {
            int a = int.Parse(S_T_Minutes.Text);

            if ((a > 59) || (a < 0))
            {
                MessageBox.Show("Please Enter Valid Time!", "Error!");
                S_T_Minutes.Text = "";
                S_T_Minutes.Focus();
            }
        }
Example #2
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!");
                }
            }
        }
Example #3
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();
            }
        }