// GET: Vehicles/Create public ActionResult Create() { sqlconn.Open(); List <VehicleType> types = VehicleTypeXmlMapper.SelectAll(); List <VehicleBrand> brands = VehicleBrandXmlMapper.SelectAll(); List <UserDriver> drivers = UserDriverLogic.FindAll(sqlconn); List <UserBoss> bosses = UserBossLogic.FindAll(sqlconn); sqlconn.Close(); ViewData["vehicleTypes"] = types; ViewData["vehicleBrands"] = brands; ViewData["drivers"] = drivers; ViewData["bosses"] = bosses; return(View()); }
public static int Create(SQLiteConnection conn, Vehicle vh, int typeId, int brandId, int driverId, int bossId) { // kontrola existence VIN v databázi bool vinExists = VehicleDbMapper.VinExists(conn, vh.Vin); if (vinExists) { return(-1); } vh.VehicleType = VehicleTypeXmlMapper.SelectById(typeId); vh.VehicleBrand = VehicleBrandXmlMapper.SelectById(brandId); vh.Driver = UserDriverDbMapper.SelectById(conn, 4); vh.Boss = UserBossDbMapper.SelectById(conn, 1); int result = VehicleDbMapper.Insert(conn, vh); return(result); }
public void Refresh() { List <VehicleType> typesList = VehicleTypeXmlMapper.SelectAll(); cbType.ItemsSource = typesList; cbType.DisplayMemberPath = "TypeName"; cbType.SelectedValuePath = "Id"; List <VehicleBrand> brandsList = VehicleBrandXmlMapper.SelectAll(); cbBrand.ItemsSource = brandsList; cbBrand.DisplayMemberPath = "BrandName"; cbBrand.SelectedValuePath = "Id"; tbLicensePlate.Text = ""; tbPrice.Text = ""; tbTitle.Text = ""; tbVin.Text = ""; tbVintage.Text = ""; }
public static List <Vehicle> SelectAll(SQLiteConnection conn) { List <Vehicle> result = new List <Vehicle>(); using (SQLiteCommand cmd = new SQLiteCommand(selectAll, conn)) { SQLiteDataReader reader = null; try { reader = cmd.ExecuteReader(); while (reader.Read()) { Vehicle vm = new Vehicle() { Id = Convert.ToInt32(reader["rowid"].ToString()), VehicleType = VehicleTypeXmlMapper.SelectById(Convert.ToInt32(reader["VehicleTypeId"])), VehicleBrand = VehicleBrandXmlMapper.SelectById(Convert.ToInt32(reader["VehicleBrandId"])), Title = reader["Title"].ToString(), Vin = reader["Vin"].ToString(), LicensePlate = reader["LicensePlate"].ToString(), Vintage = Convert.ToInt16(reader["Vintage"]), PurchasedOn = Convert.ToDateTime(reader["PurchasedOn"]), Price = Convert.ToDecimal(reader["Price"].ToString()), Boss = UserBossDbMapper.SelectById(conn, Convert.ToInt32(reader["AdminId"])), Driver = UserDriverDbMapper.SelectById(conn, Convert.ToInt32(reader["DriverId"])) }; result.Add(vm); } } catch (Exception e) { Trace.WriteLine($"EXCEPTION: VehicleDbMapper.SelectAll: {e.Message}"); } finally { reader?.Close(); } } return(result); }
public static Vehicle SelectById(SQLiteConnection conn, int id) { using (SQLiteCommand cmd = new SQLiteCommand(selectById, conn)) { cmd.Parameters.AddWithValue("@Id", id); SQLiteDataReader reader = null; try { reader = cmd.ExecuteReader(); while (reader.Read()) { Vehicle vm = new Vehicle() { Id = Convert.ToInt32(reader["rowid"].ToString()), VehicleType = VehicleTypeXmlMapper.SelectById(Convert.ToInt32(reader["VehicleTypeId"])), VehicleBrand = VehicleBrandXmlMapper.SelectById(Convert.ToInt32(reader["VehicleBrandId"])), Title = reader["Title"].ToString(), Vin = reader["Vin"].ToString(), LicensePlate = reader["LicensePlate"].ToString(), Vintage = Convert.ToInt16(reader["Vintage"]), PurchasedOn = Convert.ToDateTime(reader["PurchasedOn"]), Price = Convert.ToDecimal(reader["Price"].ToString()), Boss = UserBossDbMapper.SelectById(conn, Convert.ToInt32(reader["AdminId"])), Driver = UserDriverDbMapper.SelectById(conn, Convert.ToInt32(reader["DriverId"])) }; reader.Close(); return(vm); } } catch (Exception e) { reader?.Close(); Trace.WriteLine($"EXCEPTION: VehicleDbMapper.SelectById: {e.Message}"); } } return(null); }