// 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); } } }