private void btnAdd_Click(object sender, EventArgs e) { Admins admins = new Admins(); admins.FullName = txtName.Text; admins.Birth = dtpbirth.Value.Date; admins.Phone = txtPhone.Text; admins.Email = txtEmail.Text; admins.Password = txtPassword.Text; admins.AdedDate = DateTime.Now.Date; db.Admins.Add(admins); db.SaveChanges(); FillDgvAdmins(); Reset(); }
private void btnAdd_Click(object sender, EventArgs e) { Clients client = new Clients(); client.Name = txtName.Text; client.Surname = txtSurname.Text; client.RealId = txtClientId.Text; client.DrivingLicence = txtDrivingId.Text; client.Phone = txtPhone.Text; client.Email = txtEmail.Text; client.Birth = dtpbirth.Value.Date; db.Clients.Add(client); db.SaveChanges(); FillDgvClients(); Reset(); }
private void btnReceive_Click(object sender, EventArgs e) { Rents rents = db.Rents.Find(Rent.Id); rents.ReceiveDate = dtpReceive.Value.Date; rents.PenaltyPrice = numPenalty.Value; rents.ReceiveAdminID = ReceiveAdminId; db.SaveChanges(); MessageBox.Show("Car " + rents.Cars.Number + " received"); this.Close(); }
private void btnRent_Click(object sender, EventArgs e) { Rents rent = new Rents(); rent.CarId = db.Cars.FirstOrDefault(c => cbCars.Text.Contains(c.Number)).Id; rent.ClientId = db.Clients.FirstOrDefault(c => cbClients.Text.Contains(c.Name) && cbClients.Text.Contains(c.Surname)).Id; rent.SellDate = dtpSell.Value; rent.PromiseDate = dtpPromise.Value; rent.Price = numPrice.Value; rent.AdminId = AdminId; db.Rents.Add(rent); db.SaveChanges(); MessageBox.Show("Car " + rent.Cars.Number + " rented"); this.Close(); }
private void btnAdd_Click(object sender, EventArgs e) { Cars car = new Cars(); int brandId = 0; int modelId = 0; if (cbBrands.SelectedIndex < 0 && cbModels.SelectedIndex < 0) { Brands brands = new Brands(); brands.Name = txtBrand.Text; db.Brands.Add(brands); db.SaveChanges(); brandId = db.Brands.FirstOrDefault(b => b.Name == txtBrand.Text).Id; Models models = new Models(); models.BrandId = brandId; models.Name = txtModel.Text; db.Models.Add(models); db.SaveChanges(); modelId = db.Models.FirstOrDefault(m => m.Name == txtModel.Text && m.BrandId == brandId).Id; } else if (cbBrands.SelectedIndex >= 0 && cbModels.SelectedIndex < 0) { brandId = db.Brands.FirstOrDefault(b => b.Name == cbBrands.Text).Id; Models models = new Models(); models.BrandId = brandId; models.Name = txtModel.Text; db.Models.Add(models); db.SaveChanges(); modelId = db.Models.FirstOrDefault(m => m.Name == txtModel.Text && m.BrandId == brandId).Id; } else { brandId = db.Brands.FirstOrDefault(b => b.Name == cbBrands.Text).Id; modelId = db.Models.FirstOrDefault(m => m.Name == cbModels.Text).Id; } car.BrandId = brandId; car.ModelId = modelId; car.Number = txtNumber.Text; car.Price = numPrice.Value; car.Year = (int)numYear.Value; car.PassportNumber = txtPassportId.Text; car.AddedDate = DateTime.Now.Date; db.Cars.Add(car); db.SaveChanges(); FillDgvCars(); }