示例#1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            //SE VERIFICA QUE NINGÚN CAMPO REQUERIDO SE ENCUENTRE VACIO.
            if (string.IsNullOrEmpty(txtAACanton.Text) || string.IsNullOrEmpty(txtAACorreo.Text) || string.IsNullOrEmpty(txtAADistrito.Text) || string.IsNullOrEmpty(txtAAFechaIngreso.Text) || string.IsNullOrEmpty(txtAAIdentificacion.Text) || string.IsNullOrEmpty(txtAANacionalidad.Text) || string.IsNullOrEmpty(txtAANombre.Text) || string.IsNullOrEmpty(txtAAOtrasSenias.Text) || string.IsNullOrEmpty(txtAAPrimerApellido.Text) || string.IsNullOrEmpty(txtAASegundoApellido.Text) || string.IsNullOrEmpty(txtAATel.Text) || string.IsNullOrEmpty(CmbAAProvincia.Text) || string.IsNullOrEmpty(CmbEstado.Text))
            {
                MessageBox.Show("Algún campo requerido se encuentra vacio.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                //SE HACE LA INSTANCIACION A LAS CLSES NECESARIAS.
                ClsEntidadEstudiantes vlo_EntidadEstudiante;
                ClsLogicaEstudiante   vlo_LogicaEstudiantes = new ClsLogicaEstudiante();
                string vlc_Resultado = string.Empty;
                try
                {
                    //SE INVOCA A LA FUNCIÓN DE GENERAR DATOS, LA CUAL DA COMO RESULTADO UNA ENTIDAD CON LOS DATOS DE LA VENTANA.
                    vlo_EntidadEstudiante = GenerarDatos();

                    //SE VERIFICA SI EL REGISTRO ES NUEVO O SI HAY QUE ANTUALIZAR UN REGISTRO.
                    if (RegistroNuevo == true)
                    {
                        //EN CASO DE QUE EL REGISTRO ES NUEVO SE INSERTA
                        vlc_Resultado = vlo_LogicaEstudiantes.InsertarEstudiante(vlo_EntidadEstudiante);
                    }
                    else
                    {
                        // EN CASO CONTRARIO SE ACTUALIZA EL REGISTRO.
                        vlc_Resultado = vlo_LogicaEstudiantes.ModificarEstudiante(vlo_EntidadEstudiante).ToString();
                    }

                    if (vlc_Resultado != string.Empty)
                    {
                        //SE MUESTRA UN MENSAJE SEGÚN EL RESULTADO.
                        MessageBox.Show("Operación realizada satisfactoriamente.");
                        Limpiar();
                    }
                    else
                    {
                        MessageBox.Show("La operación no realizó ningún cambio.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }