// Delet the data for the vehical table //Check if provided id is avilable in the vehical table // if avialble first it will delet accociat data from the inventory // delete the data form vehical public void deletVehicle(int id) { DataRow row = _vehicle.Rows.Find(id); if (row == null) { Console.WriteLine("-------------WARNING--------------\n" + "This id is not in the vehical list\n" + "-------------------------------------"); } else { string cs = GetConnectionString("CarrepairMdf"); SqlConnection conn = new SqlConnection(cs); conn.Open(); string query_1 = "SELECT id FROM inventory WHERE vehicleID =" + id + " "; SqlCommand cummand = new SqlCommand(query_1, conn); var read = cummand.ExecuteReader(); if (read.Read()) { int inventoryId = (int)read[0]; // Console.WriteLine(inventoryId); dataHelperInventory one = new dataHelperInventory(); one.deletInventory(inventoryId); conn.Close(); } row.Delete(); _sadapter.DeleteCommand = _scmdbuilder.GetDeleteCommand(); _sadapter.Update(_vehicle); FillDataSet(); } }
// operation on the inventory table and collect the the input // validate the input public void opOnInventory(int cases) { int vehicalId = 0; int numbeOnHand = 0; double price = 0; double cost = 0; int id = 0; dataHelperInventory one = new dataHelperInventory(); if (cases == 3 || cases == 4) { do { try { Console.WriteLine("Enter the id of the Inventory"); id = Int32.Parse(Console.ReadLine()); } catch { Console.WriteLine("Pleae Enter Valid input"); } }while (id == 0); if (cases == 4) { one.deletInventory(id); } } if (cases == 2 || cases == 3) { while (vehicalId == 0 || price == 0 || cost == 0) { try { Console.WriteLine("Please Enter Vehical id from the vehical table List\n "); vehicalId = Int32.Parse(Console.ReadLine()); Console.WriteLine("Please Enter the Number of the unit on hand \n"); numbeOnHand = Int32.Parse(Console.ReadLine()); Console.WriteLine("Please Enter price of the vehical\n"); price = Double.Parse(Console.ReadLine()); Console.WriteLine("Please Enter Cost of the vehical \n"); cost = Double.Parse(Console.ReadLine()); } catch { Console.WriteLine("Enter the valid input"); } } if (cases == 2) { one.insertInventory(vehicalId, numbeOnHand, price, cost); } if (cases == 3) { one.updateInventory(id, numbeOnHand, price, cost); } } }
static void Main(string[] args) { DisplayMenu display = new DisplayMenu(); // class for the Dispay all the Menue and user input testing DataHelper one = new DataHelper(); // Class for vehical table handel all the vehical table manipulation dataHelperInventory inventory = new dataHelperInventory(); //Class for inventory table handel all the inventory table data manipulation dataHelperRepair repair = new dataHelperRepair(); //Class for repair table handel all the repair table data manioulation do { int choice = display.mainMenu(); bool menu = true; switch (choice) { case 1: // Case for the vehical do { String input = "vehicle"; choice = display.vehicleMenu(input); switch (choice) { case 1: one.PrintCars(); break; case 2: one.PrintCars(); display.opOnVehicle(choice); break; case 3: one.PrintCars(); display.opOnVehicle(choice); break; case 4: one.PrintCars(); display.opOnVehicle(choice); one.PrintCars(); break; case 5: menu = false; break; } }while (menu); break; case 2: // case for the Inventory do { string input = "Inventory"; choice = display.vehicleMenu(input); //choice = display.inventoryMenu(); switch (choice) { case 1: inventory.pritInventory(); break; case 2: inventory.pritInventory(); display.opOnInventory(choice); break; case 3: inventory.pritInventory(); Console.WriteLine("-----------------------------WARNING------------------------\n" + "Update will not update vehicalID to avoid duplicate record\n" + "--------------------------------------------------------------"); display.opOnInventory(choice); break; case 4: inventory.pritInventory(); display.opOnInventory(choice); inventory.pritInventory(); break; case 5: menu = false; break; } }while (menu); break; case 3: // case for the repair do { string input = "Repair"; choice = display.vehicleMenu(input); switch (choice) { case 1: repair.pritRepair(); break; case 2: repair.pritRepair(); display.opOnRepair(choice); break; case 3: repair.pritRepair(); Console.WriteLine("-----------------------------WARNING------------------------\n" + "Update will not update inventoryID to avoid duplicate record\n" + "--------------------------------------------------------------"); display.opOnRepair(choice); break; case 4: repair.pritRepair(); display.opOnRepair(choice); repair.pritRepair(); break; case 5: menu = false; break; } }while (menu); break; case 4: Environment.Exit(0); break; } } while (true); }