Exemple #1
0
        /// <summary>
        /// Возвращает экземпляр автомобиля по ID. Не протестировано. Автор: Марина.
        /// </summary>
        /// <param name="CarID"></param>
        /// <returns></returns>
        public AutomobileClass ReadCarDB(string CarID)
        {
            AutomobileClass ReadCarDB = new AutomobileClass();

            ReadCarDB.IDCar = CarID;

            using (SQLiteConnection DBConnection = new SQLiteConnection("data source=" + DBFileName))
            {
                DBConnection.Open();
                using (SQLiteCommand Command = new SQLiteCommand(DBConnection))
                {
                    // Считываем информацию о водителе
                    Command.CommandText = @"SELECT model, priceForHour, photoFileName, carCapacity, yearOfIssue, gosNumber, carCapacityTrunc, typeID FROM cars WHERE ID = '" + ReadCarDB.IDCar + "';";
                    MyDBLogger("Select Car by ID: " + Command.CommandText);
                    using (SQLiteDataReader Reader = Command.ExecuteReader())
                    {
                        Reader.Read();
                        ReadCarDB.ModelCar      = Reader.GetString(0);
                        ReadCarDB.PriceHourCar  = Reader.GetValue(1).ToString();
                        ReadCarDB.PhotoCar      = Reader.GetString(2);
                        ReadCarDB.CapacityCar   = Reader.GetValue(3).ToString();
                        ReadCarDB.YearIssueCar  = Reader.GetValue(4).ToString();
                        ReadCarDB.GosNumberCar  = Reader.GetValue(5).ToString();
                        ReadCarDB.CarryingCar   = Reader.GetValue(6).ToString();
                        ReadCarDB.CarCategoryID = Convert.ToInt32(Reader.GetValue(7).ToString());
                    }
                }
            }
            return(ReadCarDB);
        }
Exemple #2
0
 /// <summary>
 /// Помечает автомобиль как удалённый.
 /// </summary>
 /// <param name="CarToDelete"></param>
 public void DeleteCar(AutomobileClass CarToDelete)
 {
     using (SQLiteConnection DBConnection = new SQLiteConnection("data source=" + DBFileName))
     {
         DBConnection.Open();
         using (SQLiteCommand Command = new SQLiteCommand(DBConnection))
         {
             Command.CommandText = @"UPDATE cars SET deleted = 1 WHERE ID = " + CarToDelete.IDCar + ";";
             MyDBLogger("Delete car by ID: " + Command.CommandText);
             Command.ExecuteNonQuery();
         }
     }
 }
Exemple #3
0
 /// <summary>
 /// Метод для редактирования автомобиля.
 /// </summary>
 /// <param name="CarToEdit"></param>
 public void EditCarDB(AutomobileClass CarToEdit)
 {
     using (SQLiteConnection DBConnection = new SQLiteConnection("data source=" + DBFileName))
     {
         DBConnection.Open();
         using (SQLiteCommand Command = new SQLiteCommand(DBConnection))
         {
             Command.CommandText = @"UPDATE cars SET model ='" + CarToEdit.ModelCar.ToUpper() + "', " +
                                   "priceForHour = '" + CarToEdit.PriceHourCar + "', " +
                                   "photoFileName = '" + CarToEdit.PhotoCar + "', " +
                                   "carCapacity = '" + CarToEdit.CapacityCar + "', " +
                                   "yearOfIssue = '" + CarToEdit.YearIssueCar + "', " +
                                   "gosNumber = '" + CarToEdit.GosNumberCar + "', " +
                                   "carCapacityTrunc = '" + CarToEdit.CarryingCar + "', " +
                                   "typeID = '" + CarToEdit.CarCategoryID + "' " +
                                   "WHERE ID = " + CarToEdit.IDCar + ";";
             MyDBLogger("Edit car with SQL-command: " + Command.CommandText);
             Command.ExecuteNonQuery();
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// Добавляет новый автомобиль. Автор: Марина.
 /// </summary>
 /// <param name="NewCar"></param>
 public void AddNewCarDB(AutomobileClass NewCar)
 {
     using (SQLiteConnection DBConnection = new SQLiteConnection("data source=" + DBFileName))
     {
         DBConnection.Open();
         using (SQLiteCommand Command = new SQLiteCommand(DBConnection))
         {
             Command.CommandText = @"INSERT INTO cars (model, priceForHour, photoFileName, carCapacity, yearOfIssue, gosNumber, carCapacityTrunc, typeID) VALUES ('" +
                                   NewCar.ModelCar.ToUpper() + "','" +
                                   NewCar.PriceHourCar + "','" +
                                   NewCar.PhotoCar + "','" +
                                   NewCar.CapacityCar + "','" +
                                   NewCar.YearIssueCar + "','" +
                                   NewCar.GosNumberCar + "','" +
                                   NewCar.CarryingCar + "'," +
                                   NewCar.CarCategoryID + ");";
             MyDBLogger("Create car with SQL-command: " + Command.CommandText);
             Command.ExecuteNonQuery();
         }
     }
 }