private void listBoxReg_DoubleClick(object sender, EventArgs e) { VRegistration vreg = (VRegistration)listBoxReg.SelectedItem; int idx = listBoxReg.SelectedIndex; FormRegistration formRegistration = new FormRegistration(); formRegistration.IdReg = vreg.Id; formRegistration.txtNumber.Text = vreg.Number; formRegistration.txtOwner.Text = vreg.Owner; formRegistration.CarId = vreg.CarId; formRegistration.OwnerId = vreg.OwnerId; var list = formRegistration.cbCars.Items; for (var i = 0; i < list.Count; i++) { if (list[i].ToString().Contains($"{vreg.Carmodel}\t[{vreg.Caryear}]")) { formRegistration.cbCars.SelectedIndex = i; break; } } if (formRegistration.ShowDialog() == DialogResult.OK) { int newIdOwner = dbContext.NewOwner(formRegistration.txtOwner.Text); Registration registration = new Registration(); registration.CarId = formRegistration.CarId; registration.Number = formRegistration.txtNumber.Text; registration.OwnerId = newIdOwner; dbContext.UpdateRegistration(registration); listBoxReg.SelectedIndex = idx; } UpdateListReg(txtNumber.Text); }
private void bNewNumber_Click(object sender, EventArgs e) { Registration newRegistration = new Registration(); FormRegistration formRegistration = new FormRegistration(); formRegistration.OwnerId = 0; formRegistration.CarId = 0; formRegistration.txtNumber.Text = ""; if (formRegistration.ShowDialog() == DialogResult.OK) { //либо новый владелец либо находит по условию имеющегося int newIdOwner = dbContext.NewOwner(formRegistration.txtOwner.Text); Registration registration = new Registration(); registration.CarId = formRegistration.CarId; registration.Number = formRegistration.txtNumber.Text; registration.OwnerId = newIdOwner; int newRegistr = dbContext.NewRegistration(registration); } UpdateListReg(txtNumber.Text); }