/* * Deletes parts with the given SN * * @param KeyNum */ public void DeletePart(int KeyNum) { OleDbCommand deletePart = cn.CreateCommand(); OleDbCommand deleteEngine = cn.CreateCommand(); OleDbCommand deleteTire = cn.CreateCommand(); OleDbCommand selectPart = cn.CreateCommand(); deletePart.CommandText = ("DELETE FROM Part WHERE SerialNumber =" + KeyNum); deleteEngine.CommandText = ("DELETE FROM Engine WHERE SerialNumber =" + KeyNum); deleteTire.CommandText = ("DELETE FROM Tire WHERE SerialNumber =" + KeyNum); selectPart.CommandText = ("SELECT SerialNumber FROM Part WHERE SerialNumber = @SerialNumber"); selectPart.Parameters.AddWithValue("@SerialNumber", KeyNum); try { if (selectPart.ExecuteScalar() == null) { ErrorWindow Error = new ErrorWindow("Required field does not match any values within the database."); Error.ShowDialog(); return; } deleteEngine.ExecuteNonQuery(); deleteTire.ExecuteNonQuery(); deletePart.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } }
public ErrorWindow createEmployee(string[] d) { MakePerson P = new MakePerson(d, cn); MakeEmployee E = new MakeEmployee(d[5], d[6], d[7], d[8], cn); try { P.CreatePerson(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); return Error; } try { E.CreateEmployee(); } catch (OleDbException ex) { try { P.DeletePerson(); } catch (OleDbException ex2) { } ErrorWindow Error = new ErrorWindow(ex.Message); return Error; } return null; }
public ErrorWindow createCustomer(string[] d) { MakePerson P = new MakePerson(d, cn); MakeCustomer C = new MakeCustomer(d[5], d[6], cn); try { P.CreatePerson(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); return Error; } try { C.CreateCustomer(); } catch (OleDbException ex) { try { P.DeletePerson(); } catch (OleDbException ex2) { } ErrorWindow Error = new ErrorWindow(ex.Message); return Error; } return null; }
private void AddCarSubmit_Click(object sender, RoutedEventArgs e) { string[] Data = new string[6]; Data[0] = VINText.GetLineText(0); Data[1] = ModelText.GetLineText(0); Data[2] = YearText.GetLineText(0); Data[3] = ManufacturerText.GetLineText(0); Data[4] = SeatsText.GetLineText(0); Data[5] = PriceText.GetLineText(0); string Type = TypeText.GetLineText(0); string VIN = Data[0]; MakeVehicle V = new MakeVehicle(Data, cn); MakeCar C = new MakeCar(VIN, Type, cn); try { V.CreateVehicle(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); return; } try { C.CreateCar(); } catch (OleDbException ex) { try { V.DeleteVehicle(); } catch (OleDbException ex2) { } ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); return; } if (used) { R = new VehicleHistoryReport(Parent, cn); R.ShowDialog(); } this.Close(); }
private void CalculateRevenue_Click(object sender, RoutedEventArgs e) { StatsCalc SC = new StatsCalc(cn); try { RevenueText.Text = SC.Revenue(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } }
private void ViewTrucks_Click(object sender, RoutedEventArgs e) { StatsCalc SC = new StatsCalc(cn); try { InventoryGrid.ItemsSource = SC.TrucksInventory().DefaultView; } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } }
private void CalculateEmployeeProgress_Click(object sender, RoutedEventArgs e) { StatsCalc SC = new StatsCalc(cn); try { EmployeeProgressGrid.ItemsSource = SC.CalculateProgress().DefaultView; } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } }
private void CalculateMonthlySales_Click(object sender, RoutedEventArgs e) { string Month = MonthText.GetLineText(0); string Year = YearText.GetLineText(0); StatsCalc SC = new StatsCalc(cn); try { MonthlySalesText.Text = SC.MonthlySales(Month, Year); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } }
private void AddEmployeeSubmit_Click(object sender, RoutedEventArgs e) { string[] Data = new string[5]; Data[0] = IDText.GetLineText(0); Data[1] = NameText.GetLineText(0); Data[2] = PhoneText.GetLineText(0); Data[3] = AddressText.GetLineText(0); Data[4] = SexText.GetLineText(0); string EID = Data[0]; string Salary = SalaryText.GetLineText(0); string StartDate = StartDateText.GetLineText(0); string ManagerID = ManagerText.GetLineText(0); MakePerson P = new MakePerson(Data, cn); MakeEmployee E = new MakeEmployee(EID, Salary, StartDate, ManagerID, cn); try { P.CreatePerson(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); return; } try { E.CreateEmployee(); } catch (OleDbException ex) { try { P.DeletePerson(); } catch (OleDbException ex2) { } ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); return; } this.Close(); }
private void button1_Click(object sender, RoutedEventArgs e) { string VIN = Parameter1.GetLineText(0); ResponseBlock1.Visibility = Visibility.Visible; StatsCalc SC = new StatsCalc(cn); try { ResponseBlock1.ItemsSource = SC.VehicleParts(VIN).DefaultView; } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } }
private void AddEngine_Click(object sender, RoutedEventArgs e) { noError = true; string[] Data = new string[4]; Data[0] = SerialNumberText.GetLineText(0); Data[1] = VINText.GetLineText(0); Data[2] = NameText.GetLineText(0); Data[3] = ManufacturerText.GetLineText(0); string SerialNumber = Data[0]; string HorsePower = HorsePowerText.GetLineText(0); string Cylinders = CylindersText.GetLineText(0); MakePart P = new MakePart(Data, cn); MakeEngine E = new MakeEngine(SerialNumber, HorsePower, Cylinders, cn); try { P.CreatePart(); } catch (OleDbException ex) { noError = false; ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } try { E.CreateEngine(); } catch (OleDbException ex) { try { P.DeletePart(); } catch (OleDbException ex2) { } ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); return; } if (noError) this.Close(); }
private void AddCustomerSubmit_Click(object sender, RoutedEventArgs e) { string[] Data = new string[5]; Data[0] = IDText.GetLineText(0); Data[1] = NameText.GetLineText(0); Data[2] = PhoneText.GetLineText(0); Data[3] = AddressText.GetLineText(0); Data[4] = SexText.GetLineText(0); string EID = Data[0]; string Type = TypeText.GetLineText(0); MakePerson P = new MakePerson(Data, cn); MakeCustomer E = new MakeCustomer(EID, Type, cn); try { P.CreatePerson(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); return; } try { E.CreateCustomer(); } catch (OleDbException ex) { try { P.DeletePerson(); } catch (OleDbException ex2) { } ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); return; } this.Close(); }
private void AddTire_Click(object sender, RoutedEventArgs e) { noError = true; string[] Data = new string[4]; Data[0] = SerialNumberText.GetLineText(0); Data[1] = VINText.GetLineText(0); Data[2] = NameText.GetLineText(0); Data[3] = ManufacturerText.GetLineText(0); string SerialNumber = Data[0]; string Type = TypeText.GetLineText(0); string Size = SizeText.GetLineText(0); MakePart P = new MakePart(Data, cn); MakeTires T = new MakeTires(SerialNumber, Type, Size, cn); try { P.CreatePart(); } catch (OleDbException ex) { noError = false; ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } try { T.CreateTires(); } catch (OleDbException ex) { try { P.DeletePart(); } catch (OleDbException ex2) { } ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); return; } if (noError) this.Close(); }
private void RemoveButton_Click(object sender, RoutedEventArgs e) { int KeyNum = 0; string Num = IDText.GetLineText(0); try { KeyNum = int.Parse(Num); } catch (Exception ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } if (Person) { D.DeletePart(KeyNum); } else if (Vehicle) { D.DeleteVehicle(KeyNum); } else if (Part) { D.DeletePart(KeyNum); } PersonCheck.IsChecked = false; VehicleCheck.IsChecked = false; PartCheck.IsChecked = false; Person = false; Vehicle = false; Part = false; PersonCheck.Visibility = Visibility.Visible; VehicleCheck.Visibility = Visibility.Visible; PartCheck.Visibility = Visibility.Visible; TextBoxLabel.Text = ""; IDText.Clear(); }
private void AddVehicleHistoryReport_Click(object sender, RoutedEventArgs e) { noError = true; string[] Data = new string[4]; Data[0] = VINText.GetLineText(0); Data[1] = NumOwnersText.GetLineText(0); Data[2] = RatingText.GetLineText(0); Data[3] = MileageText.GetLineText(0); MakeVHR VHR = new MakeVHR(Data, cn); try { VHR.CreateVHR(); } catch (OleDbException ex) { noError = false; ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } if (noError) this.Close(); }
private void AddPart_Click(object sender, RoutedEventArgs e) { noError = true; string[] Data = new string[4]; Data[0] = SerialNumberText.GetLineText(0); Data[1] = VINText.GetLineText(0); Data[2] = NameText.GetLineText(0); Data[3] = ManufacturerText.GetLineText(0); MakePart P = new MakePart(Data, cn); try { P.CreatePart(); } catch (OleDbException ex) { noError = false; ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } if (noError) this.Close(); }
public void ModifyEngine(string[] data) { OleDbCommand updatePart = cn.CreateCommand(); OleDbCommand updateEngine = cn.CreateCommand(); OleDbCommand selectEngine = cn.CreateCommand(); selectEngine.CommandText = "SELECT SerialNumber FROM Engine WHERE SerialNumber = @SerialNumber"; selectEngine.Parameters.AddWithValue("@SerialNumber", data[0]); if (data[0].CompareTo("") == 0 || selectEngine.ExecuteScalar() == null) { ErrorWindow Error = new ErrorWindow("Please enter a valid Serial Number"); Error.Title = "Serial# Field Error"; Error.ShowDialog(); } else { if (data[1].CompareTo("") != 0) { try { updatePart.CommandText = "UPDATE Part SET VIN = ? WHERE SerialNumber = ?"; updatePart.Parameters.AddWithValue("@VIN", data[1]); updatePart.Parameters.AddWithValue("@SerialNumber", data[0]); updatePart.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "VIN Field Error"; Error.ShowDialog(); } } if (data[2].CompareTo("") != 0) { try { updatePart.CommandText = "UPDATE Part SET PartName = ? WHERE SerialNumber = ?"; updatePart.Parameters.AddWithValue("@PartName", data[2]); updatePart.Parameters.AddWithValue("@SerialNumber", data[0]); updatePart.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "PartName Field Error"; Error.ShowDialog(); } } if (data[3].CompareTo("") != 0) { try { updatePart.CommandText = "UPDATE Part SET Manufacturer = ? WHERE SerialNumber = ?"; updatePart.Parameters.AddWithValue("@Manufacturer", data[3]); updatePart.Parameters.AddWithValue("@SerialNumber", data[0]); updatePart.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Manufacturer Field Error"; Error.ShowDialog(); } } if (data[4].CompareTo("") != 0) { try { updateEngine.CommandText = "UPDATE Engine SET Cylinders = ? WHERE SerialNumber = ?"; updateEngine.Parameters.AddWithValue("@Cylinders", data[4]); updateEngine.Parameters.AddWithValue("@SerialNumber", data[0]); updateEngine.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Cylinders Field Error"; Error.ShowDialog(); } } if (data[5].CompareTo("") != 0) { try { updateEngine.CommandText = "UPDATE Engine SET HorsePower = ? WHERE SerialNumber = ?"; updateEngine.Parameters.AddWithValue("@HorsePower", data[5]); updateEngine.Parameters.AddWithValue("@SerialNumber", data[0]); updateEngine.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "HorsePower Field Error"; Error.ShowDialog(); } } } }
public void ModifyVHR(string[] data) { OleDbCommand updateVHR = cn.CreateCommand(); OleDbCommand selectVHR = cn.CreateCommand(); selectVHR.CommandText = "SELECT VIN FROM VehicleHistoryReport WHERE VIN = @VIN"; selectVHR.Parameters.AddWithValue("@VIN", data[0]); if (data[0].CompareTo("") == 0 || selectVHR.ExecuteScalar() == null) { ErrorWindow Error = new ErrorWindow("Please enter a valid VIN"); Error.Title = "VIN Field Error"; Error.ShowDialog(); } else { if (data[1].CompareTo("") != 0) { try { updateVHR.CommandText = "UPDATE VehicleHistoryReport SET NumberOwners = ? WHERE VIN = ?"; updateVHR.Parameters.AddWithValue("@NumberOwners", data[1]); updateVHR.Parameters.AddWithValue("@VIN", data[0]); updateVHR.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Number of Owners Field Error"; Error.ShowDialog(); } } if (data[2].CompareTo("") != 0) { try { updateVHR.CommandText = "UPDATE VehicleHistoryReport SET Rating = ? WHERE VIN = ?"; updateVHR.Parameters.AddWithValue("@Rating", data[2]); updateVHR.Parameters.AddWithValue("@VIN", data[0]); updateVHR.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Rating Field Error"; Error.ShowDialog(); } } if (data[3].CompareTo("") != 0) { try { updateVHR.CommandText = "UPDATE VehicleHistoryReport SET Mileage = ? WHERE VIN = ?"; updateVHR.Parameters.AddWithValue("@Mileage", data[3]); updateVHR.Parameters.AddWithValue("@VIN", data[0]); updateVHR.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Mileage Field Error"; Error.ShowDialog(); } } } }
private void SubmitPerson_Click(object sender, RoutedEventArgs e) { if (Employee) { string[] data = new string[8]; data[0] = PersonIDBox.GetLineText(0); data[1] = PersonNameBox.GetLineText(0); data[2] = PersonPhoneBox.GetLineText(0); data[3] = PersonAddressBox.GetLineText(0); data[4] = PersonSexBox.GetLineText(0); data[5] = PersonOther1Box.GetLineText(0); data[6] = PersonOther2Box.GetLineText(0); data[7] = PersonOther3Box.GetLineText(0); try { try { MC.ModifyEmployee(data); } catch (ArgumentException AE) { ErrorWindow Error = new ErrorWindow(AE.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } PersonIDBox.Clear(); PersonNameBox.Clear(); PersonPhoneBox.Clear(); PersonAddressBox.Clear(); PersonSexBox.Clear(); PersonOther1Box.Clear(); PersonOther2Box.Clear(); PersonOther3Box.Clear(); Employee = false; EmployeeCheck.IsChecked = false; CustomerCheck.Visibility = Visibility.Visible; PersonOther1Box.Visibility = Visibility.Collapsed; PersonOther1Label.Visibility = Visibility.Collapsed; PersonOther2Box.Visibility = Visibility.Collapsed; PersonOther2Label.Visibility = Visibility.Collapsed; PersonOther3Box.Visibility = Visibility.Collapsed; PersonOther3Label.Visibility = Visibility.Collapsed; } else if (Customer) { string[] data = new string[6]; data[0] = PersonIDBox.GetLineText(0); data[1] = PersonNameBox.GetLineText(0); data[2] = PersonPhoneBox.GetLineText(0); data[3] = PersonAddressBox.GetLineText(0); data[4] = PersonSexBox.GetLineText(0); data[5] = PersonOther1Box.GetLineText(0); try { try { MC.ModifyCustomer(data); } catch (ArgumentException AE) { ErrorWindow Error = new ErrorWindow(AE.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } PersonIDBox.Clear(); PersonNameBox.Clear(); PersonPhoneBox.Clear(); PersonAddressBox.Clear(); PersonSexBox.Clear(); PersonOther1Box.Clear(); Customer = false; CustomerCheck.IsChecked = false; EmployeeCheck.Visibility = Visibility.Visible; PersonOther1Box.Visibility = Visibility.Collapsed; PersonOther1Label.Visibility = Visibility.Collapsed; } }
private void button1_Click(object sender, RoutedEventArgs e) { string Para1 = Parameter1.GetLineText(0); string Para2 = Parameter2.GetLineText(0); string Para3 = Parameter3.GetLineText(0); if (type.CompareTo("Person") == 0) { if (PersonID) { ResponseBlock.Visibility = Visibility.Visible; SearchFunction SF = new SearchFunction(cn); try { ResponseBlock.ItemsSource = SF.SearchPersonID(Para3).DefaultView; } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } } if (PersonName) { ResponseBlock.Visibility = Visibility.Visible; SearchFunction SF = new SearchFunction(cn); try { ResponseBlock.ItemsSource = SF.SearchPersonName(Para3).DefaultView; } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } } } else if (type.CompareTo("Vehicle") == 0) { ResponseBlock.Visibility = Visibility.Visible; ResponseBlock2.Visibility = Visibility.Visible; SearchFunction SF = new SearchFunction(cn); try { ResponseBlock.ItemsSource = SF.SearchVehicle(Para3).DefaultView; ResponseBlock2.ItemsSource = SF.SearchVHR(Para3).DefaultView; } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } } else if (type.CompareTo("Part") == 0) { ResponseBlock.Visibility = Visibility.Visible; SearchFunction SF = new SearchFunction(cn); try { ResponseBlock.ItemsSource = SF.SearchPart(Para3).DefaultView; } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } } else { ResponseBlock.Visibility = Visibility.Visible; SearchFunction SF = new SearchFunction(cn); try { ResponseBlock.ItemsSource = SF.SearchSale(Para1, Para2, Para3).DefaultView; } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } } }
public void ModifyTires(string[] data) { OleDbCommand updatePart = cn.CreateCommand(); OleDbCommand updateTire = cn.CreateCommand(); OleDbCommand selectTire = cn.CreateCommand(); selectTire.CommandText = "SELECT SerialNumber FROM Tire WHERE SerialNumber = @SerialNumber"; selectTire.Parameters.AddWithValue("@SerialNumber", data[0]); if (data[0].CompareTo("") == 0 || selectTire.ExecuteScalar() == null) { ErrorWindow Error = new ErrorWindow("Please enter a valid Serial Number"); Error.Title = "Serial# Field Error"; Error.ShowDialog(); } else { if (data[1].CompareTo("") != 0) { try { updatePart.CommandText = "UPDATE Part SET VIN = ? WHERE SerialNumber = ?"; updatePart.Parameters.AddWithValue("@VIN", data[1]); updatePart.Parameters.AddWithValue("@SerialNumber", data[0]); updatePart.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "VIN Field Error"; Error.ShowDialog(); } } if (data[2].CompareTo("") != 0) { try { updatePart.CommandText = "UPDATE Part SET PartName = ? WHERE SerialNumber = ?"; updatePart.Parameters.AddWithValue("@PartName", data[2]); updatePart.Parameters.AddWithValue("@SerialNumber", data[0]); updatePart.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "PartName Field Error"; Error.ShowDialog(); } } if (data[3].CompareTo("") != 0) { try { updatePart.CommandText = "UPDATE Part SET Manufacturer = ? WHERE SerialNumber = ?"; updatePart.Parameters.AddWithValue("@Manufacturer", data[3]); updatePart.Parameters.AddWithValue("@SerialNumber", data[0]); updatePart.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Manufacturer Field Error"; Error.ShowDialog(); } } if (data[4].CompareTo("") != 0) { try { updateTire.CommandText = "UPDATE Tire SET Type = ? WHERE SerialNumber = ?"; updateTire.Parameters.AddWithValue("@NumberSeats", data[4]); updateTire.Parameters.AddWithValue("@SerialNumber", data[0]); updateTire.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Type Field Error"; Error.ShowDialog(); } } if (data[5].CompareTo("") != 0) { try { updateTire.CommandText = "UPDATE Tire SET TireSize = ? WHERE SerialNumber = ?"; updateTire.Parameters.AddWithValue("@TireSize", data[5]); updateTire.Parameters.AddWithValue("@SerialNumber", data[0]); updateTire.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Size Field Error"; Error.ShowDialog(); } } } }
private void SubmitVHR_Click(object sender, RoutedEventArgs e) { string[] data = new string[6]; data[0] = VHRVINBox.GetLineText(0); data[1] = VHRPreviousOwnersBox.GetLineText(0); data[2] = VHRRatingBox.GetLineText(0); data[3] = VHRMileageBox.GetLineText(0); try { try { MC.ModifyVHR(data); } catch (ArgumentException AE) { ErrorWindow Error = new ErrorWindow(AE.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } VHRVINBox.Clear(); VHRPreviousOwnersBox.Clear(); VHRRatingBox.Clear(); VHRMileageBox.Clear(); }
private void SubmitSaleButton_Click(object sender, RoutedEventArgs e) { string[] Data = new string[5]; Data[0] = VehicleText.GetLineText(0); Data[1] = CustomerText.GetLineText(0); Data[2] = EmployeeText.GetLineText(0); Data[3] = DateText.GetLineText(0); Data[4] = PriceText.GetLineText(0); MakeSale S = new MakeSale(Data, cn); try { S.CreateSale(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); return; } VehicleText.Clear(); CustomerText.Clear(); EmployeeText.Clear(); DateText.Clear(); PriceText.Clear(); }
private void SubmitVehicle_Click(object sender, RoutedEventArgs e) { if (Car) { string[] data = new string[6]; data[0] = VINBox.GetLineText(0); data[1] = VehicleModelBox.GetLineText(0); data[2] = VehicleYearBox.GetLineText(0); data[3] = VehicleMakerBox.GetLineText(0); data[4] = VehicleSeatsBox.GetLineText(0); data[5] = VehiclePriceBox.GetLineText(0); data[6] = VehicleOther1Box.GetLineText(0); try { try { MC.ModifyCar(data); } catch (ArgumentException AE) { ErrorWindow Error = new ErrorWindow(AE.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } VINBox.Clear(); VehicleModelBox.Clear(); VehicleYearBox.Clear(); VehicleMakerBox.Clear(); VehicleSeatsBox.Clear(); VehiclePriceBox.Clear(); VehicleOther1Box.Clear(); Car = false; CarCheck.IsChecked = false; TruckCheck.Visibility = Visibility.Visible; VehicleOther1Box.Visibility = Visibility.Collapsed; VehicleOther1Label.Visibility = Visibility.Collapsed; } else if (Truck) { string[] data = new string[6]; data[0] = VINBox.GetLineText(0); data[1] = VehicleModelBox.GetLineText(0); data[2] = VehicleYearBox.GetLineText(0); data[3] = VehicleMakerBox.GetLineText(0); data[4] = VehicleSeatsBox.GetLineText(0); data[5] = VehiclePriceBox.GetLineText(0); data[6] = VehicleOther1Box.GetLineText(0); try { try { MC.ModifyTruck(data); } catch (ArgumentException AE) { ErrorWindow Error = new ErrorWindow(AE.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } VINBox.Clear(); VehicleModelBox.Clear(); VehicleYearBox.Clear(); VehicleMakerBox.Clear(); VehicleSeatsBox.Clear(); VehiclePriceBox.Clear(); VehicleOther1Box.Clear(); Truck = false; TruckCheck.IsChecked = false; CarCheck.Visibility = Visibility.Visible; VehicleOther1Box.Visibility = Visibility.Collapsed; VehicleOther1Label.Visibility = Visibility.Collapsed; } }
private void SubmitPart_Click(object sender, RoutedEventArgs e) { if (Tires) { string[] data = new string[6]; data[0] = PartSerialNumberBox.GetLineText(0); data[1] = PartVINBox.GetLineText(0); data[2] = PartNameBox.GetLineText(0); data[3] = PartManufacturerBox.GetLineText(0); data[4] = PartOther2Box.GetLineText(0); data[5] = PartOther1Box.GetLineText(0); try { try { MC.ModifyTires(data); } catch (ArgumentException AE) { ErrorWindow Error = new ErrorWindow(AE.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } PartSerialNumberBox.Clear(); PartVINBox.Clear(); PartNameBox.Clear(); PartManufacturerBox.Clear(); PartOther1Box.Clear(); PartOther2Box.Clear(); Tires = false; TiresCheck.IsChecked = false; EngineCheck.Visibility = Visibility.Visible; OtherPartCheck.Visibility = Visibility.Visible; PartOther1Box.Visibility = Visibility.Collapsed; PartOther1Label.Visibility = Visibility.Collapsed; PartOther2Box.Visibility = Visibility.Collapsed; PartOther2Label.Visibility = Visibility.Collapsed; } else if (Engine) { string[] data = new string[6]; data[0] = PartSerialNumberBox.GetLineText(0); data[1] = PartVINBox.GetLineText(0); data[2] = PartNameBox.GetLineText(0); data[3] = PartManufacturerBox.GetLineText(0); data[4] = PartOther2Box.GetLineText(0); data[5] = PartOther1Box.GetLineText(0); try { try { MC.ModifyEngine(data); } catch (ArgumentException AE) { ErrorWindow Error = new ErrorWindow(AE.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } PartSerialNumberBox.Clear(); PartVINBox.Clear(); PartNameBox.Clear(); PartManufacturerBox.Clear(); PartOther1Box.Clear(); PartOther2Box.Clear(); Engine = false; EngineCheck.IsChecked = false; TiresCheck.Visibility = Visibility.Visible; OtherPartCheck.Visibility = Visibility.Visible; PartOther1Box.Visibility = Visibility.Collapsed; PartOther1Label.Visibility = Visibility.Collapsed; PartOther2Box.Visibility = Visibility.Collapsed; PartOther2Label.Visibility = Visibility.Collapsed; } else if (Part) { string[] data = new string[6]; data[0] = PartSerialNumberBox.GetLineText(0); data[1] = PartVINBox.GetLineText(0); data[2] = PartNameBox.GetLineText(0); data[3] = PartManufacturerBox.GetLineText(0); try { try { MC.ModifyPart(data); } catch (ArgumentException AE) { ErrorWindow Error = new ErrorWindow(AE.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Data Field Error"; Error.ShowDialog(); } PartSerialNumberBox.Clear(); PartVINBox.Clear(); PartNameBox.Clear(); PartManufacturerBox.Clear(); Part = false; OtherPartCheck.IsChecked = false; TiresCheck.Visibility = Visibility.Visible; EngineCheck.Visibility = Visibility.Visible; } }
/* * Deletes vehicles with the given VIN * * @param KeyNum */ public void DeleteVehicle(int KeyNum) { OleDbCommand deleteVehicle = cn.CreateCommand(); OleDbCommand deleteVHR = cn.CreateCommand(); OleDbCommand deleteCar = cn.CreateCommand(); OleDbCommand deleteTruck = cn.CreateCommand(); OleDbCommand selectSale = cn.CreateCommand(); OleDbCommand selectPart = cn.CreateCommand(); OleDbCommand selectVehicle = cn.CreateCommand(); deleteVHR.CommandText = ("DELETE FROM VehicleHistoryReport WHERE VIN =" + KeyNum); deleteVehicle.CommandText = ("DELETE FROM Vehicle WHERE VIN =" + KeyNum); deleteCar.CommandText = ("DELETE FROM Car WHERE VIN =" + KeyNum); deleteTruck.CommandText = ("DELETE FROM Truck WHERE VIN =" + KeyNum); selectVehicle.CommandText = ("SELECT VIN FROM Vehicle WHERE VIN = @VIN"); selectSale.CommandText = "SELECT VIN FROM Sale WHERE VIN = @VIN"; selectPart.CommandText = "SELECT VIN FROM Part WHERE VIN = @VIN"; selectVehicle.Parameters.AddWithValue("@VIN", KeyNum); selectSale.Parameters.AddWithValue("@VIN", KeyNum); selectPart.Parameters.AddWithValue("@VIN", KeyNum); try { if (selectVehicle.ExecuteScalar() == null) { ErrorWindow Error = new ErrorWindow("Required field does not match any values within the database."); Error.ShowDialog(); return; } if (selectSale.ExecuteScalar() != null || selectPart.ExecuteScalar() != null) { ErrorWindow Error = new ErrorWindow("Cannot delete Vehicle because it is referenced in Sale and/or Part"); Error.ShowDialog(); return; } deleteCar.ExecuteNonQuery(); deleteTruck.ExecuteNonQuery(); deleteVHR.ExecuteNonQuery(); deleteVehicle.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } }
public void ModifyTruck(string[] data) { OleDbCommand updateVehicle = cn.CreateCommand(); OleDbCommand updateTruck = cn.CreateCommand(); OleDbCommand selectTruck = cn.CreateCommand(); selectTruck.CommandText = "SELECT VIN FROM Truck WHERE VIN = @VIN"; selectTruck.Parameters.AddWithValue("@VIN", data[0]); if (data[0].CompareTo("") == 0 || selectTruck.ExecuteScalar() == null) { ErrorWindow Error = new ErrorWindow("Please enter a valid VIN"); Error.Title = "VIN Field Error"; Error.ShowDialog(); } else { if (data[1].CompareTo("") != 0) { try { updateVehicle.CommandText = "UPDATE Vehicle SET Model = ? WHERE VIN = ?"; updateVehicle.Parameters.AddWithValue("@Model", data[1]); updateVehicle.Parameters.AddWithValue("@VIN", data[0]); updateVehicle.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Model Field Error"; Error.ShowDialog(); } } if (data[2].CompareTo("") != 0) { try { updateVehicle.CommandText = "UPDATE Vehicle SET YearProd = ? WHERE VIN = ?"; updateVehicle.Parameters.AddWithValue("@YearProd", data[2]); updateVehicle.Parameters.AddWithValue("@VIN", data[0]); updateVehicle.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Year Field Error"; Error.ShowDialog(); } } if (data[3].CompareTo("") != 0) { try { updateVehicle.CommandText = "UPDATE Vehicle SET Maker = ? WHERE VIN = ?"; updateVehicle.Parameters.AddWithValue("@Maker", data[3]); updateVehicle.Parameters.AddWithValue("@VIN", data[0]); updateVehicle.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Maker Field Error"; Error.ShowDialog(); } } if (data[4].CompareTo("") != 0) { try { updateVehicle.CommandText = "UPDATE Vehicle SET NumberSeats = ? WHERE VIN = ?"; updateVehicle.Parameters.AddWithValue("@NumberSeats", data[4]); updateVehicle.Parameters.AddWithValue("@VIN", data[0]); updateVehicle.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Number of Seats Field Error"; Error.ShowDialog(); } } if (data[5].CompareTo("") != 0) { try { updateVehicle.CommandText = "UPDATE Vehicle SET Price = ? WHERE VIN = ?"; updateVehicle.Parameters.AddWithValue("@Price", data[5]); updateVehicle.Parameters.AddWithValue("@VIN", data[0]); updateVehicle.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Price Field Error"; Error.ShowDialog(); } } if (data[6].CompareTo("") != 0) { try { updateTruck.CommandText = "UPDATE Truck SET TowingCapacity = ? WHERE VIN = ?"; updateTruck.Parameters.AddWithValue("@TowingCapacity", data[6]); updateTruck.Parameters.AddWithValue("@VIN", data[0]); updateTruck.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "TowingCapacity Field Error"; Error.ShowDialog(); } } } }
public void ModifyEmployee(string[] data) { OleDbCommand updatePerson = cn.CreateCommand(); OleDbCommand updateEmployee = cn.CreateCommand(); OleDbCommand selectEmployee = cn.CreateCommand(); selectEmployee.CommandText = "SELECT EID FROM Employee WHERE EID = @EID"; selectEmployee.Parameters.AddWithValue("@EID", data[0]); if (data[0].CompareTo("") == 0 || selectEmployee.ExecuteScalar() == null) { ErrorWindow Error = new ErrorWindow("Please enter a valid EID"); Error.Title = "EID Field Error"; Error.ShowDialog(); } else { if (data[1].CompareTo("") != 0) { try { updatePerson.CommandText = "UPDATE Person SET PersonName = ? WHERE ID = ?"; updatePerson.Parameters.AddWithValue("@PersonName", data[1]); updatePerson.Parameters.AddWithValue("@ID", data[0]); updatePerson.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Name Field Error"; Error.ShowDialog(); } } if (data[2].CompareTo("") != 0) { try { updatePerson.CommandText = "UPDATE Person SET PhoneNumber = ? WHERE ID = ?"; updatePerson.Parameters.AddWithValue("@PhoneNumber", data[2]); updatePerson.Parameters.AddWithValue("@ID", data[0]); updatePerson.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Phone Field Error"; Error.ShowDialog(); } } if (data[3].CompareTo("") != 0) { try { updatePerson.CommandText = "UPDATE Person SET Address = ? WHERE ID = ?"; updatePerson.Parameters.AddWithValue("@Address", data[3]); updatePerson.Parameters.AddWithValue("@ID", data[0]); updatePerson.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Address Field Error"; Error.ShowDialog(); } } if (data[4].CompareTo("") != 0) { try { updatePerson.CommandText = "UPDATE Person SET Sex = ? WHERE ID = ?"; updatePerson.Parameters.AddWithValue("@Sex", data[4]); updatePerson.Parameters.AddWithValue("@ID", data[0]); updatePerson.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Sex Field Error"; Error.ShowDialog(); } } if (data[5].CompareTo("") != 0) { try { updateEmployee.CommandText = "UPDATE Employee SET Salary = ? WHERE EID = ?"; updateEmployee.Parameters.AddWithValue("@Salary", data[5]); updateEmployee.Parameters.AddWithValue("@EID", data[0]); updateEmployee.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Salary Field Error"; Error.ShowDialog(); } } if (data[6].CompareTo("") != 0) { try { updateEmployee.CommandText = "UPDATE Employee SET StartDate = ? WHERE EID = ?"; updateEmployee.Parameters.AddWithValue("@StartDate", data[6]); updateEmployee.Parameters.AddWithValue("@EID", data[0]); updateEmployee.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Start Date Field Error"; Error.ShowDialog(); } } if (data[7].CompareTo("") != 0) { try { updateEmployee.CommandText = "UPDATE Employee SET ManagerID = ? WHERE EID = ?"; updateEmployee.Parameters.AddWithValue("@ManagerID", data[7]); updateEmployee.Parameters.AddWithValue("@EID", data[0]); updateEmployee.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Manager Field Error"; Error.ShowDialog(); } } } }
public void ModifyCustomer(string[] data) { OleDbCommand updatePerson = cn.CreateCommand(); OleDbCommand updateCustomer = cn.CreateCommand(); OleDbCommand selectCustomer = cn.CreateCommand(); selectCustomer.CommandText = "SELECT CID FROM Customer WHERE CID = @CID"; selectCustomer.Parameters.AddWithValue("@CID", data[0]); if (data[0].CompareTo("") == 0 || selectCustomer.ExecuteScalar() == null) { ErrorWindow Error = new ErrorWindow("Please enter a valid CID"); Error.Title = "CID Field Error"; Error.ShowDialog(); } else { if (data[1].CompareTo("") != 0) { try { updatePerson.CommandText = "UPDATE Person SET PersonName = ? WHERE ID = ?"; updatePerson.Parameters.AddWithValue("@PersonName", data[1]); updatePerson.Parameters.AddWithValue("@ID", data[0]); updatePerson.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Name Field Error"; Error.ShowDialog(); } } if (data[2].CompareTo("") != 0) { try { updatePerson.CommandText = "UPDATE Person SET PhoneNumber = ? WHERE ID = ?"; updatePerson.Parameters.AddWithValue("@PhoneNumber", data[2]); updatePerson.Parameters.AddWithValue("@ID", data[0]); updatePerson.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Phone Field Error"; Error.ShowDialog(); } } if (data[3].CompareTo("") != 0) { try { updatePerson.CommandText = "UPDATE Person SET Address = ? WHERE ID = ?"; updatePerson.Parameters.AddWithValue("@Address", data[3]); updatePerson.Parameters.AddWithValue("@ID", data[0]); updatePerson.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Address Field Error"; Error.ShowDialog(); } } if (data[4].CompareTo("") != 0) { try { updatePerson.CommandText = "UPDATE Person SET Sex = ? WHERE ID = ?"; updatePerson.Parameters.AddWithValue("@Sex", data[4]); updatePerson.Parameters.AddWithValue("@ID", data[0]); updatePerson.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Sex Field Error"; Error.ShowDialog(); } } if (data[5].CompareTo("") != 0) { try { updateCustomer.CommandText = "UPDATE Customer SET Type = ? WHERE CID = ?"; updateCustomer.Parameters.AddWithValue("@Type", data[5]); updateCustomer.Parameters.AddWithValue("@CID", data[0]); updateCustomer.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.Title = "Salary Field Error"; Error.ShowDialog(); } } } }
/* * Deletes the person with the given ID * * @param KeyNum */ public void DeletePerson(int KeyNum) { OleDbCommand deletePerson = cn.CreateCommand(); OleDbCommand deleteEmployee = cn.CreateCommand(); OleDbCommand deleteCustomer = cn.CreateCommand(); OleDbCommand selectPerson = cn.CreateCommand(); deletePerson.CommandText = ("DELETE FROM Person WHERE ID =" + KeyNum); deleteEmployee.CommandText = ("DELETE FROM Employee WHERE EID =" + KeyNum); deleteCustomer.CommandText = ("DELETE FROM Customer WHERE CID =" + KeyNum); selectPerson.CommandText = ("SELECT ID FROM Person WHERE ID = @ID"); selectPerson.Parameters.AddWithValue("@ID", KeyNum); try { if (selectPerson.ExecuteScalar() == null) { ErrorWindow Error = new ErrorWindow("Required field does not match any values within the database."); Error.ShowDialog(); return; } deleteEmployee.ExecuteNonQuery(); deleteCustomer.ExecuteNonQuery(); deletePerson.ExecuteNonQuery(); } catch (OleDbException ex) { ErrorWindow Error = new ErrorWindow(ex.Message); Error.ShowDialog(); } }