static void Main(string[] args) { NewCar tesla = new NewCar(); tesla.Model = "Modle S"; tesla.Price = 27877.99m; tesla.VIN = "2349898wjc8w92r"; UsedCar usedToyota = new UsedCar(); CertifiedUsedCar jaguar = new CertifiedUsedCar(); Car[] inventory = new Car[] { new UsedCar {VIN="78YSDDFSD45", Price=17000m}, new CertifiedUsedCar {VIN="888SDDFSD45", Price=17000m}, new NewCar {VIN="YIUIU66II77", Price=44000m}, new UsedCar {VIN="3NBMM99887", Price=12000m}, new UsedCar {VIN="55555OOOOOP", Price=11000m} }; decimal total = 0; foreach (Car car in inventory) { if (car is UsedCar) { total += car.Price; } } Console.WriteLine("Total inventory value: " + total.ToString("c")); Console.ReadLine(); }
private static void Generate02Inserts(ISession session) { var newCar = new NewCar() { AvailableFrom = DateTime.Now, ConstructionDate = DateTime.Now, Manufacturer = "BMW", StickerPrice = 130000, VIN = "123456789", WasRefreshed = true }; var usedCar = new UsedCar() { Manufacturer = "BMW", VIN = "23456789", ConstructionDate = DateTime.Now, StickerPrice = 130000, IsFirstOwner = true, LastOwnerName = "Jan", LastOwnerSurname = "Kowalski" }; session.Save(newCar); session.Save(usedCar); }
public ActionResult CarNew(NewCar newCar) { ViewBag.Statussss = new SelectList(Statuses.StatusList, "Id", "Name"); if (ModelState.IsValid) { var car = new Car(); car.CarNo = newCar.RegNo; car.Chasis = newCar.ChasisNo; car.Engine = newCar.EngineNo; car.Model = newCar.Model; Database.Session.Save(car); var machineCar = new Models.Machine(); machineCar.CarId = car.Id; machineCar.Staff.Id = Convert.ToInt32(newCar.DriverName); machineCar.BoughtDate = newCar.BoughtDate; machineCar.Status = StatusName(Convert.ToInt32(newCar.Status)); machineCar.Remarks = newCar.Remarks; machineCar.Name = newCar.Name; Database.Session.Save(machineCar); ViewBag.ActionMethod = "New"; return(PartialView("Success")); } return(PartialView()); }
static void Main(string[] args) { NewCar tesla = new NewCar(); tesla.Model = "Model S"; tesla.Price = 283473472983742.239844m; tesla.VIN = "2387429837293"; UsedCar usedToyota = new UsedCar(); usedToyota.Price = 8734.273m; usedToyota.CalculateTax(); CertifiedUsedCar jaguar = new CertifiedUsedCar(); Car[] inventory = new Car[] { new UsedCar { VIN = "234982738", Price = 17000m }, new CertifiedUsedCar { VIN = "7873483", Price = 17000m }, new NewCar { VIN = "37f83723", Price = 44000m }, new UsedCar { VIN = "e72338574", Price = 12000m }, new UsedCar { VIN = "9723874538", Price = 11000m } }; decimal total = 0; foreach(Car car in inventory) { if (car is UsedCar) { total = total + car.Price; } } Console.WriteLine("Total inventory value: " + total.ToString("c")); Console.ReadLine(); }
private static void InsertNewCar(InventoryDAL invDal) { Write("Enter Car ID: "); var newCarID = int.Parse(ReadLine() ?? "0"); Write("Enter Car Color: "); var newCarColor = ReadLine(); Write("Enter Car Make: "); var newCarMake = ReadLine(); Write("Enter Pet Name: "); var newCarPetName = ReadLine(); //the insert method takes on a car class var c = new NewCar { CarId = newCarID, Color = newCarColor, Make = newCarMake, PetName = newCarPetName }; //Now pass to dat access library invDal.InsertAuto(c); WriteLine("Car has been inserted"); }
public (Car, ApiError?) AddCar(ApiClient current_client, NewCar new_car) { if (new_car.Year < 1886) { return(null, ApiError.BadRequest( $@"The first gas powered vehicle was invented in 1886. Your car's built year { new_car.Year} is earlier than that." )); } if (new_car.Year > DateTime.Now.Year) { return(null, ApiError.BadRequest( $"Your car's built year {new_car.Year} is in the future." )); } var car = new Car { Client = current_client, Id = Guid.NewGuid(), Make = new_car.Make, Model = new_car.Model, Year = new_car.Year, Stock = new_car.Stock, }; if (!_carsRepository.TryAdd(car.Id, car)) { // We don't know what's going on; this shouldn't happen return(null, ApiError.Internal($"Unexpected error: failed to add new car")); } return(car, null); }
private static void InsertNewCar(InventoryDAL invDAL) { // Сначала получить пользовательские данные int newCarID; string newCarColor, newCarMake, newCarPetName; Console.Write("Enter Car ID: "); newCarID = int.Parse(Console.ReadLine()); Console.Write("Enter Car color: "); newCarColor = Console.ReadLine(); Console.Write("Enter Car make: "); newCarMake = Console.ReadLine(); Console.Write("Enter Pet name: "); newCarPetName = Console.ReadLine(); // Теперь передать информацию библиотеке доступа к данным NewCar car = new NewCar { CarID = newCarID, Color = newCarColor, Make = newCarMake, PetName = newCarPetName }; invDAL.InsertAuto(car); }
public void FabricationNewCarTest() { var newCar = new NewCar(); var response = newCar.Fabricate(new FastFabrication()); Assert.AreEqual(response, "Car Fabricated in 5"); }
public ActionResult CarList() { NewCar newCar = new NewCar(Request.Query["new-make"], Request.Query["new-model"], Request.Query["new-color"], Request.Query["new-year"], Request.Query["new-price"]); newCar.Save(); return(View(NewCar.GetAll())); }
public string GetModelInformation(string model) { StringBuilder sb = new StringBuilder(); if (NewCar.Count != 0) { foreach (var car in NewCar.Where(nc => nc.Model == model)) { sb.Append("Type: Car\n"); sb.Append($"Model: {car.Model}\n"); sb.Append($"Color: {car.Color}\n"); sb.Append($"Horsepower: {car.Horsepower}"); } } if (NewTruck.Count != 0) { foreach (var truck in NewTruck.Where(nt => nt.Model == model)) { sb.Append("Type: Truck\n"); sb.Append($"Model: {truck.Model}\n"); sb.Append($"Color: {truck.Color}\n"); sb.Append($"Horsepower: {truck.Horsepower}"); } } return(sb.ToString()); }
private static void InsertNewCar(InventoryDAL invDAL) { // First get the user data. int newCarID; string newCarColor, newCarMake, newCarPetName; Console.Write("Enter Car ID: "); newCarID = int.Parse(Console.ReadLine()); Console.Write("Enter Car Color: "); newCarColor = Console.ReadLine(); Console.Write("Enter Car Make: "); newCarMake = Console.ReadLine(); Console.Write("Enter Pet Name: "); newCarPetName = Console.ReadLine(); // Now pass to data access library. // invDAL.InsertAuto(newCarID, newCarColor, newCarMake, newCarPetName); NewCar c = new NewCar { CarID = newCarID, Color = newCarColor, Make = newCarMake, PetName = newCarPetName }; invDAL.InsertAuto(c); }
private static void InsertNewCar(InventoryDAL invDAL) { Write("Enter Car ID: "); var newCarId = int.Parse(ReadLine() ?? "0"); Write("Enter Car Color: "); var newCarColor = ReadLine(); Write("Enter Car Make: "); var newCarMake = ReadLine(); Write("Enter Pet Name: "); var newCarPetName = ReadLine(); // Now pass to data access library. // invDAL.InsertAuto(newCarId, newCarColor, newCarMake, newCarPetName); var c = new NewCar { CarId = newCarId, Color = newCarColor, Make = newCarMake, PetName = newCarPetName }; invDAL.InsertAuto(c); }
public static void Example() { OldBrokenDownCar oldCar = new OldBrokenDownCar(); NewCar newCar = new NewCar(); TestCar(oldCar); TestCar(newCar); }
private void metroTile2_Click(object sender, EventArgs e) { NewCar form = new NewCar(); this.Hide(); form.FormClosed += new FormClosedEventHandler(delegate { Close(); }); form.Show(); }
public IActionResult AddMyCar([FromForm] NewCar newCar) { var user = User.Claims.Where(u => u.Type == ClaimTypes.UserData).FirstOrDefault().Value; var userid = new Guid(user); var result = _myCarService.AddMyCar(newCar, userid); return(Ok(result)); }
public void InsertAuto(NewCar car) { string sql = "Insert Into Inventory" + $"(Make, Color, PetName) Values ('{car.Make}', '{car.Color}', '{car.PetName}')"; using (SqlCommand command = new SqlCommand(sql, _sqlConnection)) { command.ExecuteNonQuery(); } }
public void InsertAuto(NewCar car) { var sql = "INSERT INTO Inventory" + "(Make, Color, PetName) VALUES" + $"('{car.Make}','{car.Color}','{car.PetName}')"; using (var command = new SqlCommand(sql, _sqlConnection)) { command.ExecuteNonQuery(); } }
public void InsertAuto(NewCar car) { // Format and execute SQL statement string sql = $"INSERT INTO Inventory(Make, Color, PetName) VALUES('{car.Make}', '{car.Color}', '{car.PetName}')"; // Execute using our connection using (SqlCommand command = new SqlCommand(sql, _sqlConnection)) { command.ExecuteNonQuery(); } }
public void InsertAuto(NewCar car) { var sqlQuery = "Insert into Inventory " + "(Make, Color, PetName) Values " + $"('{car.Make}', '{car.Color}', '{car.PetName}')"; using (var command = new SqlCommand(sqlQuery, _sqlConnection)) { command.ExecuteNonQuery(); } }
public IActionResult Add(NewCar new_car) { var current_client = HttpContext.Items["current_client"] as ApiClient; (var car, var maybe_error) = _carService.AddCar(current_client, new_car); if (maybe_error is ApiError error) { return(error.ToObjectResult()); } return(Ok(car)); }
public void InsertAuto(NewCar car) { //Note the placeholders in the SQL query string sql = $"Insert into Inventory (Make, Color, PetName) VALUES ('{car.Make}','{car.Color}','{car.PetName}')"; //This command will have internal parameter using (SqlCommand command = new SqlCommand(sql, _sqlconnection)) { command.ExecuteNonQuery(); } }
//public void InsertAuto(string color, string make, string petName) //{ // // Format and execute SQL statement. // string sql = "Insert Into Inventory" + // $"(Make, Color, PetName) Values ('{make}', '{color}', '{petName}')"; // // Execute using our connection. // using (SqlCommand command = new SqlCommand(sql, _sqlConnection)) // { // command.ExecuteNonQuery(); // } //} public void InsertAuto(NewCar car) { // Format and execute SQL statement. string sql = "Insert Into Inventory (Make, Color, PetName) Values" + $"('{car.Make}', '{car.Color}', '{car.PetName}')"; // Execute using our connection. using (SqlCommand command = new SqlCommand(sql, _sqlConnection)) { command.ExecuteNonQuery(); } }
public NewCar ReadData(SQLiteDataReader reader) { NewCar x = new NewCar(); x.id = G.ReadI(reader, 0); x.name = G.ReadS(reader, 1); x.carType = G.ReadS(reader, 2); x.color = G.ReadS(reader, 3); x.plate = G.ReadS(reader, 4); x.seats = G.ReadI(reader, 5); return(x); }
static void Main() //入口方法 { Car c = new Car(); //创建Car对象 c.Name = "HongQi"; //为Name字段赋值 c.run(); //执行Run方法 NewCar nc = new NewCar(); //创建NewCar对象 nc.Name = "HongQi"; //为Name字段赋值 nc.run(); //执行Run方法 System.Console.ReadLine(); //等待回车继续 }
static void Main(string[] args) { NewCar tesla = new NewCar(); tesla.Model = "Model S"; tesla.Price = 90000m; tesla.VIN = "SC54SD5F4SDF5S5SD"; UsedCar usedToyota = new UsedCar(); usedToyota.Price = 20000m; usedToyota.CalculateTax(); CertifiedUsedCar cuLexus = new CertifiedUsedCar(); NewCar[] newCars = new NewCar[] { tesla, /*usedToyota,*/ }; //No no bc the toyota isn't a NewCar Car[] newerCars = new Car[] { tesla, usedToyota, cuLexus }; //sisisi bc they're all cars Car[] inventory = new Car[] { new UsedCar { VIN = "65465AS4D6F5AS4FD", Price = 17000m }, new CertifiedUsedCar { VIN = "52152452152452451", Price = 17000m }, new NewCar { VIN = "22452145259554525", Price = 44000m }, new UsedCar { VIN = "s98sdf8ds9f89s9d6", Price = 12000m }, new UsedCar { VIN = "asdfasd2342342345", Price = 11000m } }; decimal total = 0; foreach (Car car in inventory) { if (car is UsedCar) { total += car.Price; } } Console.WriteLine("Total inventory value: " + total.ToString("c")); Console.ReadLine(); }
static void Main(string[] args) { UsedCar nicksCar = new UsedCar(); nicksCar.Model = "Accord"; CertifiedUsedCar certCar = new CertifiedUsedCar(); certCar.Model = "Camry"; NewCar tesla = new NewCar(); tesla.Model = "Tesla Model S"; Car[] cars = new Car[] { nicksCar, tesla, certCar }; foreach (Car car in cars) { Console.WriteLine(car.Model); Console.WriteLine(car.Price); Console.WriteLine(car.VIN); if (car is CertifiedUsedCar) { CertifiedUsedCar cert = car as CertifiedUsedCar; Console.WriteLine("Your car type is: {0}", cert.GetType().Name); Console.WriteLine(cert.Miles); Console.WriteLine(cert.WarrantyMonths); } else if (car is UsedCar) { UsedCar used = car as UsedCar; Console.WriteLine("Your car type is: {0}", used.GetType().Name); } else if (car is NewCar) { NewCar newCar = car as NewCar; Console.WriteLine("Your car type is: {0}", newCar.GetType().Name); } Console.WriteLine("----------"); } Console.ReadLine(); }
//插入数据1 private void button1_Click(object sender, EventArgs e) { string cnStr = ConfigurationManager.ConnectionStrings["InventoryConnectionString"].ConnectionString; InventoryDAL inventoryDAL = new InventoryDAL(); inventoryDAL.OpenConnection(cnStr); NewCar newCar = new NewCar(); newCar.CarID = 888; newCar.Make = "1"; newCar.Color = "蓝色"; newCar.PetName = "法拉第"; inventoryDAL.InsertAutoForClass(newCar); inventoryDAL.CloseConnection(); BindData(); }
static void Main(string[] args) { NewCar tesla = new NewCar(); tesla.Model = "Model S"; tesla.Price = 283473472983742.239844m; tesla.VIN = "2387429837293"; UsedCar usedToyota = new UsedCar(); usedToyota.Price = 8734.273m; usedToyota.CalculateTax(); CertifiedUsedCar jaguar = new CertifiedUsedCar(); Car[] inventory = new Car[] { new UsedCar { VIN = "234982738", Price = 17000m }, new CertifiedUsedCar { VIN = "7873483", Price = 17000m }, new NewCar { VIN = "37f83723", Price = 44000m }, new UsedCar { VIN = "e72338574", Price = 12000m }, new UsedCar { VIN = "9723874538", Price = 11000m } }; decimal total = 0; foreach (Car car in inventory) { if (car is UsedCar) { total = total + car.Price; } } Console.WriteLine("Total inventory value: " + total.ToString("c")); Console.ReadLine(); }
public Task <long> Add(NewCar newCar) { lock (carPersistanceLock) { if (!cars.Any()) { cars.Add(new Car(1, newCar.Brand, newCar.YearOfProduction)); return(Task.FromResult((long)1)); } else { long id = cars.Max(x => x.Id) + 1; cars.Add(new Car(id, newCar.Brand, newCar.YearOfProduction)); return(Task.FromResult(id)); } } }
static void Main() { // 1) binary writer/reader - stream // 2) File.WriteAllText File.WriteAllBytes File.WriteAllLines // File.WriteAllLines //Серіалізація - спосіб потокового збереження об'єкта в файл // Десеріалізація - спосіб відновлення об'єкта із файла Car c = new NewCar() { Brand = "VW", Model = "LT 35", Year = 2008, Price = 10000, Engine = new Engine { Name = "Brazil", Volume = 2.8 } }; List <Car> cars = new List <Car>(); cars.AddRange(new[] { c, new Car { Brand = "Audi", Model = "A6", Price = 6000, Year = 2004, Engine = new Engine { Volume = 2.5, Name = "TDI" } } }); Print(cars); using (FileStream fs = new FileStream("binary.dat", FileMode.Create)) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, cars); } Console.WriteLine("\n\n"); using (FileStream fs = new FileStream("binary.dat", FileMode.OpenOrCreate)) { BinaryFormatter formatter = new BinaryFormatter(); var car = (List <Car>)formatter.Deserialize(fs); } }
static void Main(string[] args) { UsedCar nicksCar = new UsedCar(); nicksCar.Model = "Accord"; CertifiedUsedCar certCar = new CertifiedUsedCar(); certCar.Model = "Camry"; NewCar tesla = new NewCar(); tesla.Model = "Tesla Model S"; Car[] cars = new Car[] { nicksCar, tesla, certCar }; foreach(Car car in cars) { Console.WriteLine(car.Model); Console.WriteLine(car.Price); Console.WriteLine(car.VIN); if (car is CertifiedUsedCar) { CertifiedUsedCar cert = car as CertifiedUsedCar; Console.WriteLine("Your car type is: {0}", cert.GetType().Name); Console.WriteLine(cert.Miles); Console.WriteLine(cert.WarrantyMonths); } else if (car is UsedCar) { UsedCar used = car as UsedCar; Console.WriteLine("Your car type is: {0}", used.GetType().Name); } else if (car is NewCar) { NewCar newCar = car as NewCar; Console.WriteLine("Your car type is: {0}", newCar.GetType().Name); } Console.WriteLine("----------"); } Console.ReadLine(); }
static void Main(string[] args) { NewCar tesla = new NewCar(); tesla.Model = "Modle S"; tesla.Price = 27877.99m; tesla.VIN = "2349898wjc8w92r"; UsedCar usedToyota = new UsedCar(); CertifiedUsedCar jaguar = new CertifiedUsedCar(); Car[] inventory = new Car[] { new UsedCar { VIN = "78YSDDFSD45", Price = 17000m }, new CertifiedUsedCar { VIN = "888SDDFSD45", Price = 17000m }, new NewCar { VIN = "YIUIU66II77", Price = 44000m }, new UsedCar { VIN = "3NBMM99887", Price = 12000m }, new UsedCar { VIN = "55555OOOOOP", Price = 11000m } }; decimal total = 0; foreach (Car car in inventory) { if (car is UsedCar) { total += car.Price; } } Console.WriteLine("Total inventory value: " + total.ToString("c")); Console.ReadLine(); }
private static void InsertNewCar(InventoryDAL dal) { Write("Enter Car ID: "); var newCarId = int.Parse(ReadLine() ?? "0"); Write("Enter Car Color: "); var newColor = ReadLine(); Write("Enter Car Make: "); var newMake = ReadLine(); Write("Enter Pet Name: "); var newPetName = ReadLine(); var c = new NewCar { CarId = newCarId, Color = newColor, Make = newMake, PetName = newPetName }; dal.InsertAuto(c); }
static void Main(string[] args) { NewCar tesla = new NewCar(); tesla.Model = "Model S"; tesla.Price = 90000m; tesla.VIN = "SC54SD5F4SDF5S5SD"; UsedCar usedToyota = new UsedCar(); usedToyota.Price = 20000m; usedToyota.CalculateTax(); CertifiedUsedCar cuLexus = new CertifiedUsedCar(); NewCar[] newCars = new NewCar[] { tesla, /*usedToyota,*/ }; //No no bc the toyota isn't a NewCar Car[] newerCars = new Car[] { tesla, usedToyota, cuLexus }; //sisisi bc they're all cars Car[] inventory = new Car[] { new UsedCar { VIN = "65465AS4D6F5AS4FD", Price = 17000m }, new CertifiedUsedCar { VIN = "52152452152452451", Price = 17000m }, new NewCar { VIN = "22452145259554525", Price = 44000m }, new UsedCar { VIN = "s98sdf8ds9f89s9d6", Price = 12000m }, new UsedCar { VIN = "asdfasd2342342345", Price = 11000m } }; decimal total = 0; foreach(Car car in inventory) { if (car is UsedCar) { total += car.Price; } } Console.WriteLine("Total inventory value: " + total.ToString("c")); Console.ReadLine(); }