Exemplo n.º 1
0
        private void btnAceptar_Click_1(object sender, EventArgs e)
        {
            switch (formMode)
            {
            case FormMode.insert:
            {
                if (ValidarCampos())
                {
                    int newId = Convert.ToInt32(oPlanService.consultarMaxId());
                    newId += 10;
                    newId++;
                    txtplan.Text = newId.ToString();
                    var oPlan = new Plan
                    {
                        Id_Plan_Prueba = newId,
                        Id_Proyecto    = Convert.ToInt32(cboProy.SelectedValue),
                        Nombre         = txtNombre.Text,
                        Id_Responsable = Convert.ToInt32(cboResp.SelectedValue),
                        Descripcion    = txtDescripcion.Text,
                        Borrado        = false
                    };
                    if (oPlanService.crearPlan(oPlan))
                    {
                        //btnConsultar_Click(sender, e); //Esto lo use en el otro cuando elimina para q actualice
                        MessageBox.Show("Plan insertado!", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                }

                else
                {
                    MessageBox.Show("Plan encontrado!. Ingrese un nombre diferente", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                break;
            }

            case FormMode.update:
            {
                if (ValidarCampos())
                {
                    oPlanSelected.Id_Plan_Prueba = Convert.ToInt32(txtplan.Text);
                    oPlanSelected.Id_Proyecto    = Convert.ToInt32(cboProy.SelectedValue);
                    oPlanSelected.Nombre         = txtNombre.Text;
                    oPlanSelected.Id_Responsable = (int)Convert.ToInt64(cboResp.SelectedIndex);
                    oPlanSelected.Descripcion    = txtDescripcion.Text;

                    if (oPlanService.ActualizarPlan(oPlanSelected))
                    {
                        MessageBox.Show("Plan actualizado!", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("Error al actualizar el Plan!", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                break;
            }
            }
        }