public void ChangeCarryingCapacityTest() { Lorry car = new Lorry(5, 3, "mitsubishi", 9); car.ChangeCarryingCapacity(10); Assert.AreEqual(10, car.CarryingCapacity); }
private void Form1_Load(object sender, EventArgs e) { Car car = new Car(100); Lorry lorry = new Lorry(500, 50); richTextBox1.Text += car.CarText() + "\n" + lorry.CarText(); }
static void Main(string[] args) { Car auto1 = new Car(ManufacturersForTransmissionsAndVehicles.BMW, new Engine(250, 2.5, EngineTypes.Petrol, 123), new Chassis(4, 4000, 321), new Transmission("2x2", 6, ManufacturersForTransmissionsAndVehicles.BMW), 4); Car auto2 = new Car(ManufacturersForTransmissionsAndVehicles.Mitsubishi, new Engine(90, 1.1, EngineTypes.Hybrid, 123877), new Chassis(4, 4000, 321), new Transmission("2x2", 5, ManufacturersForTransmissionsAndVehicles.Mitsubishi), 4); Bus bus1 = new Bus(ManufacturersForTransmissionsAndVehicles.Mercedes, new Engine(385, 6.2, EngineTypes.Diesel, 777), new Chassis(6, 2000, 751), new Transmission("2x4", 7, ManufacturersForTransmissionsAndVehicles.Mercedes), 48, 2); Lorry lorry1 = new Lorry(ManufacturersForTransmissionsAndVehicles.Citroen, new Engine(350, 5.45, EngineTypes.Diesel, 500500), new Chassis(4, 1200, 123789), new Transmission("2x2", 6, ManufacturersForTransmissionsAndVehicles.Kia), 5000); Scooter scooter1 = new Scooter(ManufacturersForTransmissionsAndVehicles.Ducati, new Engine(290, 2.2, EngineTypes.Petrol, 222222), new Chassis(2, 250, 123784), new Transmission("1x1", 8, ManufacturersForTransmissionsAndVehicles.Ferrari), 5000); Console.Write(auto1.GetInformation()); Console.Write(auto2.GetInformation()); Console.Write(bus1.GetInformation()); Console.Write(lorry1.GetInformation()); Console.Write(scooter1.GetInformation()); }
public void changeModelTest() { Lorry car = new Lorry(5, 3, "mitsubishi", 9); car.ChangeModel("nissan"); Assert.AreEqual("nissan", car.Model); }
static void Main(string[] args) { Func <Vehicle, bool> chooseMoreThan15 = x => x.VehicleEngine.Volume >= 1.5; Func <Vehicle, bool> choose2x2Transmission = x => x.VehicleTransmission.TransmissionType == "2x2"; Func <Vehicle, string> transmissionComparer = x => x.VehicleTransmission.TransmissionType; Func <Vehicle, bool> chooseVehicleType = x => x.GetType().Equals(typeof(Lorry)) || x.GetType().Equals(typeof(Bus)); Func <Vehicle, SerialClass> proectionCondition = x => new SerialClass(x.VehicleEngine.EngineType, x.VehicleEngine.SerialNumber, x.VehicleEngine.Power); string fileForVehiclesName = "Vehicles.xml"; string fileForVehiclesWithEngineVolume15Name = "Vehicles15.xml"; string fileLorryAndBusEngines = "LorryAndBusEngines.xml"; string fileVehiclesWith2x2Transmission = "2x2VehicleTypes.xml"; string fileForSortedByTransmissionVehicles = "SortedTransmissions.xml"; Car auto1 = new Car(ManufacturersForTransmissionsAndVehicles.BMW, new Engine(250, 2.5, EngineTypes.Petrol, 123), new Chassis(4, 4000, 321), new Transmission("2x2", 6, ManufacturersForTransmissionsAndVehicles.BMW), 4); Car auto2 = new Car(ManufacturersForTransmissionsAndVehicles.Mitsubishi, new Engine(90, 1.1, EngineTypes.Hybrid, 123877), new Chassis(4, 4000, 321), new Transmission("2x2", 5, ManufacturersForTransmissionsAndVehicles.Mitsubishi), 4); Bus bus1 = new Bus(ManufacturersForTransmissionsAndVehicles.Mercedes, new Engine(385, 6.2, EngineTypes.Diesel, 777), new Chassis(6, 2000, 751), new Transmission("2x4", 7, ManufacturersForTransmissionsAndVehicles.Mercedes), 48, 2); Lorry lorry1 = new Lorry(ManufacturersForTransmissionsAndVehicles.Citroen, new Engine(350, 5.45, EngineTypes.Diesel, 500500), new Chassis(4, 1200, 123789), new Transmission("2x2", 6, ManufacturersForTransmissionsAndVehicles.Kia), 5000); Scooter scooter1 = new Scooter(ManufacturersForTransmissionsAndVehicles.Ducati, new Engine(290, 2.2, EngineTypes.Petrol, 222222), new Chassis(2, 250, 123784), new Transmission("1x1", 8, ManufacturersForTransmissionsAndVehicles.Ferrari), 5000); List <Vehicle> vehicles = new List <Vehicle>() { auto1, bus1, lorry1, scooter1, auto2 }; CarPark carPark = new CarPark(vehicles); Console.Write(carPark.GetInformation()); carPark.SaveToFile(fileForVehiclesName); carPark.SaveToFileWithCondition(fileForVehiclesWithEngineVolume15Name, chooseMoreThan15); carPark.SaveToFileProection(fileLorryAndBusEngines, chooseVehicleType, proectionCondition); carPark.SaveToFileWithCondition(fileVehiclesWith2x2Transmission, choose2x2Transmission); carPark.SaveToFileSort(fileForSortedByTransmissionVehicles, transmissionComparer); List <Vehicle> vehiclesWithEngineVolume15FromFile = carPark.ReadFromFile <Vehicle>(fileForVehiclesWithEngineVolume15Name); List <SerialClass> enginesFromFile = carPark.ReadFromFile <SerialClass>(fileLorryAndBusEngines); List <Vehicle> vehiclesChosenByTransmissionFromFile = carPark.ReadFromFile <Vehicle>(fileVehiclesWith2x2Transmission); List <Vehicle> sortedVehiclesByTransmission = carPark.ReadFromFile <Vehicle>(fileForSortedByTransmissionVehicles); }
// события с грузовиками private void AddListLorry_Click(object sender, EventArgs e) { Lorry lorry = new Lorry(); lorries.Add(lorry); lorry.SetParams(markLorry.Text, (int)countCylindersLorry.Value, (int)powerLorry.Value); lorry.SetParams((int)capacity.Value); listBoxLorry.Items.Add(lorry.GetParams()); }
public ActionResult AddLorry(Lorry lorry) { InvertoryViewModel = new InvertoryViewModel(); InvertoryViewModel.Lorry = new Lorry() { EndUserMessage = "با موفقیت اضافه شد" }; return(View(PartnerViewModel)); }
public static void Main() { Car obj = new Car(); obj.weight(); obj = new Lorry(); obj.show(); Console.WriteLine(); }
private void Form1_Load(object sender, EventArgs e) { ICargoCarrier lorry = new Lorry("iveco", 100000, 50000, 2500, 55, 15); richTextBox1.Text += ((Lorry)lorry).CarText(); richTextBox1.Text += String.Format("\nЗапас хода: {0}км; \nМаксимальная длина груза: {1}м; Максимальная масса груза: {2}кг", ((Lorry)lorry).TankRange(), ((Lorry)lorry).MaxCargoLength(), ((Lorry)lorry).MaxCargoWeight()); }
public void Delete() { Console.WriteLine("Delete passenger"); Console.Write("Id: "); Guid lorryId = Guid.Parse(Console.ReadLine()); Passenger passengerToDelete = selectedLorry.passengers.SingleOrDefault(x => x.Id == lorryId); selectedLorry.passengers.Remove(passengerToDelete); selectedLorry = lorryServiceObj.Update(selectedLorry); }
private void textBoxPallet_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Return) { e.Handled = true; Lorry lorry = new Lorry(); int count = 0; if (textBoxPallet.Text.Length > 16 && textBoxPallet.Text.Substring(0, 16) == "0198765432101234") { if (clDtGriData.Rows.Count == 0) { lorry = SavePalletScanInfo();//Correct EAN128 barcode scanned. do something viewScannedInfo(lorry); } else { //if the scanned barcode matches any value in the datagrid, then the count will be greaeter than 0 foreach (DataRow dr in clDtGriData.Rows) { //check to see if scanned ean128 matches one on the datagrid. if it matches, count will be greater than 0. if no match, count will be 0 string batch = textBoxPallet.Text.Substring(36, 5); if (batch.TrimStart('0') == dr[5].ToString()) { count++; break; } } //count is 0 so there is no repeat in scanned crates or boxes if (count == 0) { lorry = SavePalletScanInfo();//Correct EAN128 barcode scanned. do something viewScannedInfo(lorry); } //count is greater than 0, a box/crate ean128 barcode has already been scanned before else { MessageBox.Show("The item has already been scanned"); } } } else { MessageBox.Show("That item cannot be scanned on this page"); } textBoxPallet.Text = ""; textBoxPallet.Focus(); } }
public void Delete(Lorry lorryToDelete) { using (var session = NHibernateHelper.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Delete(lorryToDelete); tx.Commit(); } } }
public Lorry Update(Lorry lorryToUpdate) { using (var session = NHibernateHelper.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Update(lorryToUpdate); tx.Commit(); } } return(lorryToUpdate); }
public Lorry Refuel(Lorry lorryToRefuel) { lorryToRefuel.currentFuel = lorryToRefuel.maximumFuel; using (var session = NHibernateHelper.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Update(lorryToRefuel); tx.Commit(); } } return(lorryToRefuel); }
public Lorry GetById(Guid Id) { Lorry lorryToReturn = null; using (var session = NHibernateHelper.OpenSession()) { using (var tx = session.BeginTransaction()) { lorryToReturn = session.Get <Lorry>(Id); tx.Commit(); } } return(lorryToReturn); }
private void ChangeLorry_Click(object sender, EventArgs e) { Lorry lorry = new Lorry(); lorries[listBoxLorry.SelectedIndex] = lorry; try { lorry.SetParams(markLorry.Text, (int)countCylindersLorry.Value, (int)powerLorry.Value); lorry.SetParams((int)capacity.Value); listBoxLorry.Items[listBoxLorry.SelectedIndex] = lorry.GetParams(); } catch { MessageBox.Show("Элемент списка не выбран"); } }
public Lorry Add(string vehicleName, string numberPlate, FuelEconomy milage, Weight weight, bool hasLoad, Weight loadWeight, Volume maximumFuel, int maximumPassengers) { Lorry lorryToAdd = new Lorry(vehicleName, numberPlate, milage, weight, hasLoad, loadWeight, maximumFuel, maximumPassengers); using (var session = NHibernateHelper.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Save(lorryToAdd); tx.Commit(); } } return(lorryToAdd); }
public Lorry CalculateFuel(Lorry lorryToCalculate, Distance distance) { lorryToCalculate.currentFuel.gallons -= (distance.miles / lorryToCalculate.milage.milesPerGallon); if (lorryToCalculate.currentFuel.litres < 0) { lorryToCalculate.currentFuel.litres = 0; } using (var session = NHibernateHelper.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Update(lorryToCalculate); tx.Commit(); } } return(lorryToCalculate); }
public void Add() { if (selectedLorry.passengers.Count != selectedLorry.maximumPassengers) { Passenger passengerToAdd = new Passenger(); Console.WriteLine("Add passenger"); Console.Write("First name: "); passengerToAdd.firstName = Console.ReadLine(); Console.Write("Last name: "); passengerToAdd.lastName = Console.ReadLine(); selectedLorry.passengers.Add(passengerToAdd); selectedLorry = lorryServiceObj.Update(selectedLorry); } else { Console.WriteLine("This vehicle is full"); } }
protected void PrintInfo(Lorry selectedLorry, bool showId) { Console.WriteLine(); if (showId) { Console.WriteLine("Id: " + selectedLorry.Id); } Console.WriteLine(@"Name: ""{0}"" Numberplate: {1}" + "\nMilage: {2}mpg Weight: {3}kg\n" + "Current fuel: {4}/{5}l\n" + "Current passengers: {6}/{7}" , selectedLorry.vehicleName, selectedLorry.numberPlate , decimal.Round(selectedLorry.milage.milesPerGallon, 2), decimal.Round(selectedLorry.weight.kilograms, 2) , decimal.Round(selectedLorry.currentFuel.litres, 2), decimal.Round(selectedLorry.maximumFuel.litres, 2) , selectedLorry.passengers.Count, selectedLorry.maximumPassengers); Console.Write("Has load: {0}", selectedLorry.hasLoad); if (selectedLorry.hasLoad) { Console.Write(" Load weight: {0}", decimal.Round(selectedLorry.loadWeight.kilograms, 2)); } Console.WriteLine("\n"); }
private void viewScannedInfo(Lorry l) { if (l.ean128id2 != 0) { DataRow dr = clDtGriData.NewRow(); //dr["EAN128ID"] = l.ean128; dr["EAN128ID2"] = l.ean128id2; dr["Product Quantity"] = l.prodquantity; dr["Box Quantity"] = l.boxquantity; dr["NetWeight"] = l.netweight; dr["Client"] = l.clientname; dr["DateScanned"] = l.datescanned; clDtGriData.Rows.Add(dr); clDtGriData.AcceptChanges(); dataGridPallet.DataSource = clDtGriData; } else { MessageBox.Show("The scanned pallet does not exist. Please scan again"); } }
static void Main(string[] args) { Console.WindowWidth = 50; BaseVehicle.HEADER_POSITION = 9; Car car = new Car(4000, 180, 1996, 4, "Opel", Car.typesBody.Hatchback); Bicycle bicycle = new Bicycle(710, 80, 2019, 1, "Random", Bicycle.typesFrame.Rigid); Lorry lorry = new Lorry(10000, 160, 2010, 1, "Volvo", Lorry.typesBody.Special); Exercise_Two.models.File file = new Exercise_Two.models.File("text", "txt"); file.create(); Composite composite = new Composite(); composite.addComponent(car); composite.addComponent(bicycle); composite.addComponent(lorry); composite.sort(); file.write(composite.getStateObj()); file.print(); Console.ReadKey(); }
public void changeModelTest() { Lorry car = new Lorry(); }
private void Form1_Load(object sender, EventArgs e) { Lorry lorry = new Lorry(500, 50); richTextBox1.Text += lorry.CarText(); }
public new Lorry Load() { bool exit = false; while (!exit) { Console.WriteLine("Unedited:"); PrintInfo(originalLorry, false); Console.WriteLine("Edited:"); PrintInfo(editedLorry, false); Console.WriteLine("Select field to edit"); Console.WriteLine("\t1. Vehicle name"); Console.WriteLine("\t2. Number plate"); Console.WriteLine("\t3. Load"); Console.WriteLine("\t4. Milage"); Console.WriteLine("\t5. Weight"); Console.WriteLine("\t6. Maximum fuel"); Console.WriteLine("\t7. Maximum passengers"); Console.WriteLine("\t8. Save changes"); Console.WriteLine("\t9. Discard changes and go back"); switch (Console.ReadKey(true).KeyChar) { case '1': editName(); break; case '2': editNumberPlate(); break; case '3': editLoad(); break; case '4': editMilage(); break; case '5': editWeight(); break; case '6': editMaximumFuel(); break; case '7': editMaximumPassengers(); break; case '8': exit = true; break; case '9': Console.WriteLine("Discard changes? Y/N"); if (Console.ReadKey(true).KeyChar == 'y') { editedLorry = originalLorry; exit = true; } break; default: Console.WriteLine("Invalid input"); break; } } return(editedLorry); }
public LorryEditConsoleView(Lorry lorryToEdit) { editedLorry = lorryToEdit.Clone(); originalLorry = lorryToEdit.Clone(); }
private Lorry SavePalletScanInfo() { Lorry lorry = new Lorry(); myConn.Open(); try { string q = "select netweight, cussur, scndat, ean128id2, ean128id3 from xxean.innodis_test where EAN128ID2 = :ean128id2"; using (OracleCommand cmd = new OracleCommand()) { cmd.Connection = myConn; cmd.CommandText = q; cmd.Parameters.Add(new OracleParameter("ean128id2", OracleDbType.Number)); cmd.Parameters[0].Value = Convert.ToInt32(textBoxPallet.Text.Substring(36, 5)); OracleDataReader reader = cmd.ExecuteReader(); int rows = 0; decimal nweight = 0; while (reader.Read()) { rows++; nweight += System.Convert.ToDecimal(reader[0]); lorry.clientname = reader[1].ToString(); //lorry.ean128 = Convert.ToInt32(reader[2]); lorry.datescanned = reader[2].ToString(); lorry.ean128id2 = Convert.ToInt32(reader[3]); if (reader[4] == DBNull.Value) { lorry.ean128id3 = 0; } else { lorry.ean128id3 = Convert.ToInt32(reader[4]); } } //find number of boxes in the pallet string w = "SELECT COUNT(distinct ean128id) FROM innodis_test where ean128id2 = :id2"; using (OracleCommand cmd2 = new OracleCommand()) { cmd2.Connection = myConn; cmd2.CommandText = w; cmd2.Parameters.Add(new OracleParameter("id2", OracleDbType.Number)); cmd2.Parameters[0].Value = lorry.ean128id2; var bq = cmd2.ExecuteScalar(); if (bq != null) { lorry.boxquantity = Convert.ToInt32(bq); } else { lorry.boxquantity = 0; } } lorry.netweight = nweight.ToString(); lorry.prodquantity = rows; return(lorry); } myConn.Close(); } catch (OracleException ex) { if (myConn.State == ConnectionState.Open) { myConn.Close(); } MessageBox.Show("EAN 128 not scanned succesfully!"); return(lorry); } }
public void Add() { Console.WriteLine("Add lorry"); Console.Write("Name: "); string vehicleName = Console.ReadLine(); string numberPlateEntry, numberPlate = null; while (numberPlate == null) { Console.Write("Number plate: "); numberPlateEntry = Console.ReadLine().Replace(" ", ""); if (numberPlateEntry.Length != 7) { Console.WriteLine("Invalid numberplate length"); } else { numberPlate = numberPlateEntry; } } Console.Write("Milage (Miles/Gallon): "); FuelEconomy milage = new FuelEconomy(); milage.milesPerGallon = Convert.ToDecimal(Console.ReadLine()); Console.Write("Weight (kg): "); Weight weight = new Weight(); weight.kilograms = Convert.ToDecimal(Console.ReadLine()); bool hasLoad = false, validLoadInput = false; Weight loadWeight = new Weight(); while (!validLoadInput) { Console.Write("Has load (Y/N):"); switch (Console.ReadKey().KeyChar) { case 'y': hasLoad = true; validLoadInput = true; Console.Write("Load weight (kg): "); loadWeight.kilograms = Convert.ToDecimal(Console.ReadLine()); break; case 'n': hasLoad = false; validLoadInput = true; break; default: Console.WriteLine("\nInvalid input"); break; } } Console.Write("Maximum fuel (litres): "); Volume maximumFuel = new Volume(); maximumFuel.litres = Convert.ToDecimal(Console.ReadLine()); Console.Write("Maximum passengers: "); int maximumPassengers = Convert.ToInt32(Console.ReadLine()); Lorry addedLorry = lorryServicesObj.Add(vehicleName, numberPlate, milage, weight, hasLoad, loadWeight, maximumFuel, maximumPassengers); SelectById(addedLorry.Id); }
public void Select(Lorry selectedLorry) { bool exit = false; while (!exit) { Console.WriteLine("\nSelected Lorry:"); PrintInfo(selectedLorry, false); Console.WriteLine("Choose an option:"); Console.WriteLine("\t1. Edit"); Console.WriteLine("\t2. Delete"); Console.WriteLine("\t3. Calculate fuel"); Console.WriteLine("\t4. Refuel"); Console.WriteLine("\t5. Passengers"); Console.WriteLine("\t6. Back"); switch (Console.ReadKey(true).KeyChar) { case '1': LorryEditConsoleView lorryEditConsoleView = new LorryEditConsoleView(selectedLorry); selectedLorry = lorryServicesObj.Update(lorryEditConsoleView.Load()); break; case '2': Console.Write("Type vehicle name to confirm:"); if (Console.ReadLine() == selectedLorry.vehicleName) { lorryServicesObj.Delete(selectedLorry); exit = true; } else { Console.WriteLine("Cancelled"); } break; case '3': Console.Write("Enter distance in miles: "); Distance distance = new Distance(); distance.miles = Convert.ToDecimal(Console.ReadLine()); selectedLorry = lorryServicesObj.CalculateFuel(selectedLorry, distance); break; case '4': selectedLorry = lorryServicesObj.Refuel(selectedLorry); break; case '5': LorryPassengerConsoleView lorryPassengers = new LorryPassengerConsoleView(selectedLorry); lorryPassengers.Load(); break; case '6': exit = true; break; default: Console.WriteLine("Invalid input"); break; } } }
public PassengerLorryFormView(Lorry lorryToEdit) { this.lorryToEdit = lorryToEdit; InitializeComponent(); }