private void LoadCargoInfo(object sender, EventArgs e) { if (dgvCargoes.SelectedRows.Count > 0) { int selectedIndex = dgvCargoes.SelectedRows[0].Index; int id = 0; bool converted = int.TryParse(dgvCargoes[0, selectedIndex].Value.ToString(), out id); if (!converted) return; Cargo cargo = db.Cargoes.Find(id); tbCTName.Text = cargo.CargoType.Name; rtbCTDescription.Text = cargo.CargoType.Description; pbCTPhoto.Image = ImageExtension.ByteArrayToImage(cargo.CargoType.Photo); tbLenght.Text = cargo.Lenght.ToString(); tbWidth.Text = cargo.Width.ToString(); tbHeight.Text = cargo.Height.ToString(); } else { tbCTName.Text = ""; rtbCTDescription.Text = ""; pbCTPhoto.Image = null; tbLenght.Text = ""; tbWidth.Text = ""; tbHeight.Text = ""; } }
private void btnChange_Click(object sender, EventArgs e) { if (dgvCargoType.SelectedRows.Count > 0) { int selectedIndex = dgvCargoType.SelectedRows[0].Index; int id = 0; bool converted = int.TryParse(dgvCargoType[0, selectedIndex].Value.ToString(), out id); if (!converted) { return; } CargoType cargoType = db.CargoTypes.Find(id); DFormCargoType dFormCargoType = new DFormCargoType(); dFormCargoType.tbName.Text = cargoType.Name; dFormCargoType.rtbDescription.Text = cargoType.Description; dFormCargoType.pbPhoto.Image = ImageExtension.ByteArrayToImage(cargoType.Photo); DialogResult dialogResult = dFormCargoType.ShowDialog(); if (dialogResult == DialogResult.Cancel) { return; } cargoType.Name = dFormCargoType.tbName.Text; cargoType.Description = dFormCargoType.rtbDescription.Text; cargoType.Photo = ImageExtension.ImageToByteArray(dFormCargoType.pbPhoto.Image); db.SaveChanges(); dgvCargoType.Refresh(); LoadCargoInfo(this, EventArgs.Empty); MessageBox.Show("Объект обновлен.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void LoadCargoInfo(object sender, EventArgs e) { if (dgvCargoType.SelectedRows.Count > 0) { int selectedIndex = dgvCargoType.SelectedRows[0].Index; int id = 0; bool converted = int.TryParse(dgvCargoType[0, selectedIndex].Value.ToString(), out id); if (!converted) { return; } CargoType cargoType = db.CargoTypes.Find(id); rtbDescription.Text = cargoType.Description; pbPhoto.Image = ImageExtension.ByteArrayToImage(cargoType.Photo); } else { rtbDescription.Text = ""; pbPhoto.Image = null; } }