private void bnEdit_Click(object sender, EventArgs e) { frmEditFuelType frmEditFuelType = new frmEditFuelType(); int currentRow = dgvFuelTypes.SelectedRows[0].Index; int id = (int)dgvFuelTypes.Rows[currentRow].Cells[0].Value; FuelType fuelType = rentACarEntities.FuelTypes.Where(ct => ct.Id == id).FirstOrDefault(); frmEditFuelType.FuelType = fuelType; frmEditFuelType.Show(); Hide(); }
private void btnSave_Click(object sender, EventArgs e) { if (IsValid()) { FuelType fuelType = rentACarEntities.FuelTypes.Where(ft => ft.Id == FuelType.Id).FirstOrDefault(); fuelType.Description = txtDescription.Text; rentACarEntities.Entry(fuelType).State = System.Data.Entity.EntityState.Modified; rentACarEntities.SaveChanges(); MessageBox.Show("El tipo de combustible fue editado correctamente.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); frmFuelTypes frmFuelTypes = new frmFuelTypes(); frmFuelTypes.Show(); Hide(); } }
private void bnDelete_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("¿Seguro de eliminar este tipo de combustible?", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { int currentRow = dgvFuelTypes.SelectedRows[0].Index; int id = (int)dgvFuelTypes.Rows[currentRow].Cells[0].Value; FuelType fuelType = rentACarEntities.FuelTypes.Where(ct => ct.Id == id).FirstOrDefault(); rentACarEntities.Entry(fuelType).State = System.Data.Entity.EntityState.Modified; fuelType.Status = false; rentACarEntities.SaveChanges(); MessageBox.Show("El tipo de combustible fue eliminado correctamente.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); BindGridView(); } }
private bool IsValid() { FuelType fuelType = rentACarEntities.FuelTypes.Where(m => m.Description.Trim() == txtDescription.Text).FirstOrDefault(); if (fuelType != null && fuelType.Status == true) { MessageBox.Show($"Ya existe un tipo de combustible con la descripción: {txtDescription.Text}.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } else if (txtDescription.Text.Trim() == "") { MessageBox.Show($"La descripción del tipo de combustible es requerida.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } else if (txtDescription.Text.Count() < 3 || txtDescription.Text.Count() > 20) { MessageBox.Show($"La descripción del tipo de combustible debe estar entre 3 y 20 caracteres.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } return(true); }