private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells["carId"].Value); // taking car if (e.ColumnIndex == 8) { ViewCar car = dataFormDTO.db.ViewCars.SingleOrDefault(o => o.carId == id); basket.AddItem(car.carId, car.company, car.modelName, car.power , car.colourName, car.autoTrans, car.manualTrans, car.price, 1); } // updating if (e.ColumnIndex == 9) { carFormOperDTO.op = CrudOpr.Update; carFormOperDTO.usage = FormUsage.Update; ViewCar findCar = dataFormDTO.db.ViewCars.SingleOrDefault(o => o.carId == id); carFormOperDTO.obj = findCar; DataFormDTO dto = new DataFormDTO(this, dataFormDTO.mainForm, dataFormDTO.db, dataFormDTO.userIdentity, dataFormDTO.userData); CarOperationForm form = new CarOperationForm(dto, carFormOperDTO); form.Show(); } // deleting if (e.ColumnIndex == 10) { // Запрашиваем подтверждение string message = "Точно хотите удалить?"; string caption = "Y/n"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { car c = new car(); c.carId = id; // deleting if (crud.delete(c)) { MessageBox.Show("Авто удалено!"); resetData(); } else { MessageBox.Show("Удаление отменено"); } } } }
private void doCrud() { switch (usage) { case FormUsage.OrderCar: // создание модели авто и самого авто // + заказ ViewCar car = crud.createModel(modelDTO); if (car != null) { ShopBasket basket = new ShopBasket(); basket.AddItem(car.carId, car.company, car.modelName, car.power, car.colourName, car.autoTrans, car.manualTrans, modelDTO.price, Convert.ToInt32(RestCarTextBox.Text)); // DataFormDTO dto = new DataFormDTO(this, dataFormDTO.mainForm, dataFormDTO.db, dataFormDTO.userIdentity, dataFormDTO.userData); BasketForm form = new BasketForm(dto, basket, true); form.Show(); } break; case FormUsage.Create: // создание модели авто и самого авто createCarModel(); break; case FormUsage.Update: // обновление модели авто //getCarPrice(); if (crud.update(modelDTO)) { MessageBox.Show("Car was updated!"); this.Close(); } else { MessageBox.Show("Updating was denied"); } break; } }
public ViewCar createModel(ModelDTO obj) { model o = new model { // стоит сделать проверку на схожие модели, чтоб не создавать лишнее model1 = obj.modelName, transmission = obj.transmission, type = obj.type, engine = obj.engine, colour = obj.colour }; model savedModel = db.models.Add(o); db.SaveChanges(); car c = new car(); c.model = savedModel.modelId; c.model1 = savedModel; c.price = obj.price; c.rest = 0; c.deliveryTime = 5; c.ordered = "y"; ViewCar car = null; car temp = carCrud.createCar(c); if (temp != null) { car = db.ViewCars.SingleOrDefault(t => t.carId == temp.carId); } return(car); }