private void BUS_Insert_btn_Click(object sender, EventArgs e) { Validation_Class v = new Validation_Class(); if (v.Is_Empty(EngineNo_TB.Text) && v.Check_Name(Manufacturer_TB.Text) && v.Check_Name(Model_TB.Text)) { if (v.IsPositiveNumber(ModelYear_TB.Text)) { int modelYear = Convert.ToInt32(ModelYear_TB.Text); if (modelYear < 2010 || modelYear > 2021) { Message_Form message = new Message_Form(); message.Title("Please Enter Model Year"); message.Title_Color(Color.Red); message.Extra_Message("Between 2010 and 2021"); message.Extra_Message_Color(Color.Red); message.Show(); return; } if (v.Two_Dates(DateTime.Today, RDate_Picker.Value) && v.Check_Name(Department_TB.Text) && v.Is_Empty(License_TB.Text)) { string engineNO = EngineNo_TB.Text; string mac = Manufacturer_TB.Text; string model = Model_TB.Text; DateTime Rdate = RDate_Picker.Value; string department = Department_TB.Text; string type = Type_CB.SelectedItem.ToString(); string licnece = License_TB.Text; int seats = Convert.ToInt32(Seats_Numeric.Value); int result = controller.Insert_Bus(modelYear, engineNO, mac, model, Rdate, department, licnece, type, seats); if (result == 0) { Message_Form message = new Message_Form(); message.Title("There was an Error Inserting this Bus"); message.Title_Color(Color.Red); message.Show(); } else { Message_Form message = new Message_Form(); Object id = controller.Last_Bus_ID(); message.Title("Bus was added with ID = " + id.ToString()); message.Show(); } } } } }
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); } }
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(); } } } } }
private void Insert_btn_Click(object sender, EventArgs e) { Validation_Class v = new Validation_Class(); if (v.Check_Name(name.Text) && v.IsPositiveNumber(intervaltxt.Text)) { int x = controller.Insert_Packages(name.Text, Convert.ToInt32(intervaltxt.Text), Convert.ToInt32(price.Value)); if (x == 0) { MessageBox.Show("There is a Package with the same Name"); } else { MessageBox.Show("Inserted"); } } }
private void Employee_AddBtn_Click(object sender, EventArgs e) { Validation_Class v = new Validation_Class(); if (v.Check_Name(EmployeeName_Insert_Texbox.Text) && v.IsPositiveNumber(EmployeeSalary_Insert_Texbox.Text) && v.IsValidEmail(EmployeeEmail_Insert_Texbox.Text)) { if (EPassword_TB.Text.Length < 8) { MessageBox.Show("PassWord cannot be less than 8 Characters"); return; } // It Should me before 18 years from today else if (v.NationalID(EmployeeID_Insert_Texbox.Text) && v.Is_Empty(EmployeeAdress_Insert_Texbox.Text) && v.Two_Dates(BD_DatePicker.Value, DateTime.Today.AddYears(-18))) { if (EPassword_TB.Text.Length < 8) { MessageBox.Show("PassWord cannot be less than 8 Characters"); return; } string name = EmployeeName_Insert_Texbox.Text; int salary = Convert.ToInt32(EmployeeSalary_Insert_Texbox.Text); string email = EmployeeEmail_Insert_Texbox.Text; string pass = v.Encrypt_PassWord(EPassword_TB.Text); string type = Type_CBox.Text; string NID = EmployeeID_Insert_Texbox.Text; DateTime BOD = BD_DatePicker.Value; string adress = EmployeeAdress_Insert_Texbox.Text; string gender = Gender_CBox.Text; if (controller.Insert_Employee(name, salary, email, pass, type, NID, BOD, adress, gender) == 1) { Message_Form message = new Message_Form(); Object id = controller.Last_Emplopyee_ID(); message.Title("Employee was added with ID = " + id.ToString()); message.Show(); } else { Message_Form message = new Message_Form(); message.Title("There was an Error inserting this Emoployee"); message.Title_Color(Color.Red); message.Show(); } } } }
private void Employee_UpdateBtn_Click(object sender, EventArgs e) { Validation_Class v = new Validation_Class(); if (v.Check_Name(EName_Update_Texbox.Text) && v.IsPositiveNumber(ESalary_Update_Texbox.Text) && v.IsValidEmail(EEmail_Update_Texbox.Text)) { if (EPass_Update_Texbox.Text.Length < 8) { MessageBox.Show("PassWord cannot be less than 8 Characters"); return; } // It Should me before 18 years from today else if (v.NationalID(EID_Update_Texbox.Text) && v.Is_Empty(EAdress_Update_Texbox.Text) && v.Two_Dates(BD_DatePicker.Value, DateTime.Today.AddYears(-18))) { string name = EName_Update_Texbox.Text; string email = EEmail_Update_Texbox.Text; string pass = v.Encrypt_PassWord(EPass_Update_Texbox.Text); int salary = Convert.ToInt32(ESalary_Update_Texbox.Text); string NID = EID_Update_Texbox.Text; DateTime BD = BD_DatePicker.Value; string address = EAdress_Update_Texbox.Text; string type = Type_CBox.SelectedItem.ToString(); int result = controller.Update_Employee(name, salary, email, pass, type, NID, BD, address); if (result == 0) { Message_Form message = new Message_Form(); message.Title("There was an Error Updating this Employee"); message.Title_Color(Color.Red); message.Show(); } else { Message_Form message = new Message_Form(); message.Title("The Employee is Updated Successfully"); message.Show(); } } } }
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(); } } } } }
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; } } } } }
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(); } } } } } }