private void Insert_btn_Click(object sender, EventArgs e)
        {
            if (busID.Text == "")
            {
                MessageBox.Show("Please Select a Bus ID");
                return;
            }
            Validation_Class v = new Validation_Class();

            DateTime startDate   = startd.Value;
            DateTime Enddate     = endd.Value;
            int      price       = Convert.ToInt32(Price.Value);
            string   Gender      = genderCombo.Text;
            string   Name        = name.Text;
            string   NID         = id.Text;
            string   Address     = address.Text;
            string   PhoneNumber = phonenum.Text;

            if (v.Check_Name(Name) && v.NationalID(NID) && v.Is_Empty(Address) && v.PhoneNumber(PhoneNumber) && v.Two_Dates(startDate, Enddate))
            {
                int BusID  = Convert.ToInt32(busID.Text);
                int result = controller.Insert_Rent_Contract(startDate, Enddate, price, Name, NID, Address, Gender, BusID, PhoneNumber);
                if (result == 0)
                {
                    MessageBox.Show("Error");
                }
                else
                {
                    MessageBox.Show("Inserted");
                }
                Date_ValueChanged(sender, e);
            }
        }
Exemple #2
0
        private void Search_btn_Click(object sender, EventArgs e)
        {
            Validation_Class v = new Validation_Class();

            if (v.PhoneNumber(DPhone_Search_Texbox.Text))
            {
                DataTable result = Controller.Search_Driver(DPhone_Search_Texbox.Text);
                if (result == null)
                {
                    NotFound();
                }
                else
                {
                    Found();
                    DName_Label.Text   = result.Rows[0][1].ToString();
                    D_DOB.Text         = String.Format("{0:dd-MM-yyyy}", result.Rows[0][2]);
                    DPhone_Label.Text  = result.Rows[0][3].ToString();
                    DAddrees.Text      = result.Rows[0][4].ToString();
                    DSalary_Label.Text = result.Rows[0][5].ToString();
                    DNationalID.Text   = result.Rows[0][6].ToString();
                    DType.Text         = result.Rows[0][9].ToString();
                    DTraffic.Text      = result.Rows[0][10].ToString();
                    DLicence.Text      = result.Rows[0][11].ToString();
                    DEndDate.Text      = String.Format("{0:dd-MM-yyyy}", result.Rows[0][12]);
                    BloodTypeConvert(DType.Text);
                    DBUSID.Text = result.Rows[0][13].ToString();
                }
            }
        }
Exemple #3
0
        private void Insert_btn_Click(object sender, EventArgs e)
        {
            Validation_Class v = new Validation_Class();

            if (v.Check_Name(nametxt.Text) && v.NationalID(id.Text) && v.PhoneNumber(phonenum.Text) && v.Is_Empty(address.Text) && v.Two_Dates(DateTime.Today, startd.Value))
            {
                int       interval = Convert.ToInt32(controller.Find_Duration(packageCombo.Text).Rows[0][0]);
                DateTime  s        = startd.Value;
                DateTime  end      = s.AddDays(interval);
                DataTable Buses    = controller.Search_Bus_For_AD_Contract(s, end);

                if (Buses != null)
                {
                    int x = controller.Insert_Ad_Contract(s, end, nametxt.Text, id.Text, address.Text, genderCombo.Text, packageCombo.Text, phonenum.Text, Convert.ToInt32(Buses.Rows[0][0]));
                    if (x == 0)
                    {
                        MessageBox.Show("Error");
                    }
                    else
                    {
                        MessageBox.Show("Inserted");
                    }
                }
                else
                {
                    MessageBox.Show("No Available Buses With this Dates");
                }
            }
        }
        private void Driver_AddBtn_Click_1(object sender, EventArgs e)
        {
            Validation_Class v = new Validation_Class();

            if (Bus_ID_CB.Text == "")
            {
                MessageBox.Show("Please Enter a Bus ID");
                return;
            }
            if (v.Check_Name(DriverName_Insert_Texbox.Text) && v.PhoneNumber(DriverPhone_Texbox.Text) && v.IsPositiveNumber(DriverSalary_Insert_Texbox.Text))
            {
                if (v.NationalID(DriverNID_Insert_Texbox.Text) && v.Two_Dates(BD_DatePicker.Value, DateTime.Today.AddYears(-18)))
                {
                    if (v.Is_Empty(DriverAdress_Insert_Texbox.Text) && v.IsPositiveNumber(DriverLicence_Number_Insert_Texbox.Text) && v.Check_Name(Driver_Traffic.Text) && v.Two_Dates(DateTime.Today, Driver_Licence_EndDate.Value))
                    {
                        string   name              = DriverName_Insert_Texbox.Text;
                        string   phone             = DriverPhone_Texbox.Text;
                        int      salary            = Convert.ToInt32(DriverSalary_Insert_Texbox.Text);
                        string   blood             = Blood_CBox.Text;
                        string   NID               = DriverNID_Insert_Texbox.Text;
                        DateTime BD                = BD_DatePicker.Value;
                        string   address           = DriverAdress_Insert_Texbox.Text;
                        string   gender            = Gender_CBox.Text;
                        string   DrivingLicence    = DriverLicence_Number_Insert_Texbox.Text;
                        string   trafficDepartment = Driver_Traffic.Text;
                        DateTime RDate             = Driver_Licence_EndDate.Value;
                        int      result            = controller.Insert_Driver(name, BD, phone, address, salary, NID, gender, blood, trafficDepartment, DrivingLicence, RDate, Convert.ToInt32(Bus_ID_CB.Text));
                        if (result == 0)
                        {
                            Message_Form message = new Message_Form();
                            message.Title("There was an Error inserting the Driver");
                            message.Title_Color(Color.Red);
                            message.Show();
                        }
                        else
                        {
                            Message_Form message = new Message_Form();
                            Object       id      = controller.Last_Driver_ID();
                            message.Title("Driver was added with ID = " + id.ToString());
                            message.Show();
                            DataTable d = controller.Get_Non_Driven_Buses();
                            Bus_ID_CB.DataSource    = d;
                            Bus_ID_CB.DisplayMember = "Bus_ID";
                            Bus_ID_CB.ValueMember   = "Bus_ID";
                            Bus_ID_CB.Refresh();
                        }
                    }
                }
            }
        }
Exemple #5
0
        private void Search_btn_Click(object sender, EventArgs e)
        {
            Validation_Class v = new Validation_Class();

            if (v.PhoneNumber(DPhone_Search_Texbox.Text))
            {
                DataTable result = controller.Search_Driver(DPhone_Search_Texbox.Text);
                if (result == null)
                {
                    NotFound();
                }
                else
                {
                    Found();

                    DataTable d = controller.Get_Non_Driven_Buses();
                    Bus_ID_CB.DataSource    = d;
                    Bus_ID_CB.DisplayMember = "Bus_ID";
                    Bus_ID_CB.ValueMember   = "Bus_ID";
                    Bus_ID_CB.Refresh();

                    if (d == null)
                    {
                        Bus_ID_CB.Text = "";
                    }
                    else
                    {
                        Bus_ID_CB.Text = d.Rows[0][0].ToString();
                    }

                    DName_Update_Texbox.Text       = result.Rows[0][1].ToString();
                    BD_DatePicker.Value            = Convert.ToDateTime(result.Rows[0][2].ToString());
                    DriverPhone_Update_Texbox.Text = result.Rows[0][3].ToString();
                    DAdress_Update_Texbox.Text     = result.Rows[0][4].ToString();
                    DSalary_Update_Texbox.Text     = result.Rows[0][5].ToString();
                    DID_Update_Texbox.Text         = result.Rows[0][6].ToString();
                    Blood_CBox.Text = result.Rows[0][9].ToString();
                    Driver_Traffic_Update_TB.Text           = result.Rows[0][10].ToString();
                    DriverLicence_Number_Update_Texbox.Text = result.Rows[0][11].ToString();
                    Driver_Licence_EndDate.Value            = Convert.ToDateTime(result.Rows[0][12].ToString());
                    OldPhone = DriverPhone_Update_Texbox.Text;
                }
            }
        }
Exemple #6
0
        private void Weekly_Update_btn_Click(object sender, EventArgs e)
        {
            Validation_Class v = new Validation_Class();

            if (v.Check_Name(Start_Point_tb.Text) && v.Check_Name(End_Point_tb.Text) && v.IsPositiveNumber(PriceAns_tb.Text))
            {
                Start = Start_Point_tb.Text;
                End   = End_Point_tb.Text;
                Price = Convert.ToInt32(PriceAns_tb.Text);
                Day   = DayAns_CB.SelectedItem.ToString();
                Time  = TimeAns_Picker.Value.TimeOfDay;


                if (v.PhoneNumber(Driver_Phone_tb.Text))
                {
                    if (Av == 1)
                    {
                        if (Phone == Driver_Phone_tb.Text)
                        {
                            int result = controller.Update_Weeklytrip(Start, End, WeekTripID, -1
                                                                      , Price, Day, Time, Av);
                            if (result == 0)
                            {
                                Message_Form message = new Message_Form();
                                message.Title("There was an Error Updating this Weekly Trip");
                                message.Title_Color(Color.Red);
                                message.Show();
                            }
                            else
                            {
                                this.Close();
                                Message_Form message = new Message_Form();
                                Object       id      = controller.Last_WeeklyTrip_ID();
                                message.Title("Weekly Trip was Updated Successfully");
                                message.Show();
                            }
                        }
                        else
                        {
                            DataTable Driver = controller.Search_Driver(Driver_Phone_tb.Text);
                            if (Driver == null)
                            {
                                Message_Form message = new Message_Form();
                                message.Title("The Driver is not Found");
                                message.Title_Color(Color.Red);
                                message.Show();
                                return;
                            }
                            else
                            {
                                int driverid = Convert.ToInt32(Driver.Rows[0][0].ToString());

                                DataTable DriverTrips = controller.Search_Weekly_Trips_Driver(driverid, Day);
                                if (DriverTrips != null)
                                {
                                    if (DriverTrips.Rows.Count > 1)
                                    {
                                        Message_Form message = new Message_Form();
                                        message.Title("The Driver already make two Trips on this day");
                                        message.Title_Color(Color.Red);
                                        message.Show();
                                        return;
                                    }
                                    else if (DriverTrips.Rows.Count == 1)
                                    {
                                        TimeSpan t        = Convert.ToDateTime(DriverTrips.Rows[0][5].ToString()).TimeOfDay;
                                        TimeSpan constant = new TimeSpan(5, 0, 0);
                                        TimeSpan a        = t.Add(constant);
                                        TimeSpan s        = t.Subtract(constant);

                                        if (Time < a && Time > s)
                                        {
                                            Message_Form message = new Message_Form();
                                            message.Title("The Driver already make Trips in");
                                            message.Title_Color(Color.Red);
                                            message.Extra_Message("the same day and the time is not Sufficent");
                                            message.Extra_Message_Color(Color.Red);
                                            message.Show();
                                            return;
                                        }

                                        if (Start != DriverTrips.Rows[0][2].ToString() || End != DriverTrips.Rows[0][1].ToString())
                                        {
                                            Message_Form message = new Message_Form();
                                            message.Title("The Driver already make Trips in");
                                            message.Title_Color(Color.Red);
                                            message.Extra_Message("Another Place at the same day");
                                            message.Extra_Message_Color(Color.Red);
                                            message.Show();
                                            return;
                                        }
                                    }
                                }

                                int result = controller.Update_Weeklytrip(Start, End, WeekTripID, driverid, Price, Day, Time, Av);
                                if (result == 0)
                                {
                                    Message_Form message = new Message_Form();
                                    message.Title("There was an Error Updating this Weekly Trip");
                                    message.Title_Color(Color.Red);
                                    message.Show();
                                }
                                else
                                {
                                    this.Close();
                                    Message_Form message = new Message_Form();
                                    Object       id      = controller.Last_WeeklyTrip_ID();
                                    message.Title("Weekly Trip was Updated Successfully");
                                    message.Show();
                                }
                            }
                        }
                    }
                    else
                    {
                        int result = controller.Update_Weeklytrip(Start, End, WeekTripID, 0, Price, Day, Time, Av);
                        if (result == 0)
                        {
                            Message_Form message = new Message_Form();
                            message.Title("There was an Error Updating this Weekly Trip");
                            message.Title_Color(Color.Red);
                            message.Show();
                        }
                        else
                        {
                            this.Close();
                            Message_Form message = new Message_Form();
                            Object       id      = controller.Last_WeeklyTrip_ID();
                            message.Title("Weekly Trip was Updated Successfully");
                            message.Show();
                        }
                    }
                }
            }
        }
Exemple #7
0
        private void Weekly_Insert_btn_Click(object sender, EventArgs e)
        {
            string   start, end, day;
            TimeSpan time;
            int      price;
            int      Available;

            Validation_Class v = new Validation_Class();

            if (v.Check_Name(Start_Point_tb.Text) && v.Check_Name(End_Point_tb.Text) && v.IsPositiveNumber(PriceAns_tb.Text))
            {
                if (Start_Point_tb.Text == End_Point_tb.Text)
                {
                    Message_Form message = new Message_Form();
                    message.Title("Start Point Can't be the same as the End Point");
                    message.Title_Color(Color.Red);
                    message.Show();
                    return;
                }

                start = Start_Point_tb.Text;
                end   = End_Point_tb.Text;
                day   = DayAns_CB.Text;
                time  = TimeAns_Picker.Value.TimeOfDay;
                price = Convert.ToInt32(PriceAns_tb.Text);

                if (Available_CheckBox.Checked == true)
                {
                    Available = 0;
                    int result = controller.Insert_WeeklyTrip_WithoutDriver(start, end, day, time, price, Available);
                    if (result == 0)
                    {
                        Message_Form message = new Message_Form();
                        message.Title("There was an Error Inserting this Weekly Trip");
                        message.Title_Color(Color.Red);
                        message.Extra_Message("There is another WeeklyTrip with Same Paramters");
                        message.Show();
                        return;
                    }
                    else
                    {
                        Message_Form message = new Message_Form();
                        Object       id      = controller.Last_WeeklyTrip_ID();
                        message.Title("Weekly Trip was added with ID = " + id.ToString());
                        message.Extra_Message("NOTE: This weekly trip has no Driver");
                        message.Extra_Message_Color(Color.Red);
                        message.Show();
                        return;
                    }
                }
                else if (v.PhoneNumber(Driver_Phone_tb.Text))
                {
                    Available = 1;

                    DataTable Driver = controller.Search_Driver(Driver_Phone_tb.Text);
                    if (Driver == null)
                    {
                        Message_Form message = new Message_Form();
                        message.Title("The Driver is not Found");
                        message.Title_Color(Color.Red);
                        message.Show();
                        return;
                    }
                    else
                    {
                        int driverid = Convert.ToInt32(Driver.Rows[0][0].ToString());

                        DataTable DriverTrips = controller.Search_Weekly_Trips_Driver(driverid, day);
                        if (DriverTrips != null)
                        {
                            if (DriverTrips.Rows.Count > 1)
                            {
                                Message_Form message = new Message_Form();
                                message.Title("The Driver already make two Trips on this day");
                                message.Title_Color(Color.Red);
                                message.Show();
                                return;
                            }
                            else if (DriverTrips.Rows.Count == 1)
                            {
                                TimeSpan t        = Convert.ToDateTime(DriverTrips.Rows[0][5].ToString()).TimeOfDay;
                                TimeSpan constant = new TimeSpan(5, 0, 0);
                                TimeSpan a        = t.Add(constant);
                                TimeSpan s        = t.Subtract(constant);

                                if (time < a && time > s)
                                {
                                    Message_Form message = new Message_Form();
                                    message.Title("The Driver already make Trips in");
                                    message.Title_Color(Color.Red);
                                    message.Extra_Message("the same day and the time is not Sufficent");
                                    message.Extra_Message_Color(Color.Red);
                                    message.Show();
                                    return;
                                }

                                if (start != DriverTrips.Rows[0][2].ToString() || end != DriverTrips.Rows[0][1].ToString())
                                {
                                    Message_Form message = new Message_Form();
                                    message.Title("The Driver already make Trips in");
                                    message.Title_Color(Color.Red);
                                    message.Extra_Message("Another Place at the same day");
                                    message.Extra_Message_Color(Color.Red);
                                    message.Show();
                                    return;
                                }
                            }
                        }

                        int result = controller.Insert_WeeklyTrip_WithDriver(start, end, driverid, day, time, price, Available);
                        if (result == 0)
                        {
                            Message_Form message = new Message_Form();
                            message.Title("There was an Error Inserting this Weekly Trip");
                            message.Title_Color(Color.Red);
                            message.Extra_Message("There is another WeeklyTrip with Same Paramters");
                            message.Show();
                            return;
                        }
                        else
                        {
                            Message_Form message = new Message_Form();
                            Object       id      = controller.Last_WeeklyTrip_ID();
                            message.Title("Weekly Trip was added with ID = " + id.ToString());
                            message.Show();
                            return;
                        }
                    }
                }
            }
        }
Exemple #8
0
        private void Driver_UpdateBtn_Click(object sender, EventArgs e)
        {
            Validation_Class v = new Validation_Class();
            int busid          = -1;

            if (Change_CheckBox.Checked)
            {
                if (Bus_ID_CB.Text == "")
                {
                    Message_Form message = new Message_Form();
                    message.Title("Error: The Driver does not have a Bus ID");
                    message.Title_Color(Color.Red);
                    message.Show();
                    return;
                }
                else if (v.IsPositiveNumber(Bus_ID_CB.Text))
                {
                    busid = Convert.ToInt32(Bus_ID_CB.Text);
                }
                else
                {
                    Message_Form message = new Message_Form();
                    message.Title("Please Enter a Positive Bus ID");
                    message.Title_Color(Color.Red);
                    message.Show();
                    return;
                }
            }

            if (v.Check_Name(DName_Update_Texbox.Text) && v.PhoneNumber(DriverPhone_Update_Texbox.Text) && v.IsPositiveNumber(DSalary_Update_Texbox.Text))
            {
                if (v.NationalID(DID_Update_Texbox.Text) && v.Two_Dates(BD_DatePicker.Value, DateTime.Today.AddYears(-18)))
                {
                    if (v.Is_Empty(DAdress_Update_Texbox.Text) && v.IsPositiveNumber(DriverLicence_Number_Update_Texbox.Text) && v.Check_Name(Driver_Traffic_Update_TB.Text) && v.Two_Dates(DateTime.Today, Driver_Licence_EndDate.Value))
                    {
                        string   name              = DName_Update_Texbox.Text;
                        string   phone             = DriverPhone_Update_Texbox.Text;
                        int      salary            = Convert.ToInt32(DSalary_Update_Texbox.Text);
                        string   blood             = Blood_CBox.Text;
                        string   NID               = DID_Update_Texbox.Text;
                        DateTime BD                = BD_DatePicker.Value;
                        string   address           = DAdress_Update_Texbox.Text;
                        string   DrivingLicence    = DriverLicence_Number_Update_Texbox.Text;
                        string   trafficDepartment = Driver_Traffic_Update_TB.Text;
                        DateTime RDate             = Driver_Licence_EndDate.Value;

                        int resulut = controller.Update_Driver(name, BD, OldPhone, phone, address, salary, NID, blood, trafficDepartment, DrivingLicence, RDate, busid);
                        if (resulut == 0)
                        {
                            Message_Form message = new Message_Form();
                            message.Title("There was an Error Updating this Driver");
                            message.Title_Color(Color.Red);
                            message.Show();
                        }
                        else
                        {
                            Message_Form message = new Message_Form();
                            message.Title("Driver was Updated Successfully");
                            message.Show();

                            DataTable d = controller.Get_Non_Driven_Buses();
                            Bus_ID_CB.DataSource    = d;
                            Bus_ID_CB.DisplayMember = "Bus_ID";
                            Bus_ID_CB.ValueMember   = "Bus_ID";
                            Bus_ID_CB.Refresh();

                            if (d == null)
                            {
                                Bus_ID_CB.Text = "";
                            }
                            else
                            {
                                Bus_ID_CB.Text = d.Rows[0][0].ToString();
                            }
                        }
                    }
                }
            }
        }