示例#1
0
        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();
        }
示例#2
0
 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();
     }
 }
示例#3
0
        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();
            }
        }
示例#4
0
        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);
        }