Beispiel #1
0
        private void but_agregar_persona_Click(object sender, EventArgs e)
        {
            if (this.verificar_datos_persona1() == false && this.verificar_datos_persona2() == false)
            {
                if (tex_direccion.Text.Length == 0)
                {
                    tex_direccion.Text = " ";
                }

                if (tex_telefono.Text.Length == 0)
                {
                    tex_telefono.Text = " ";
                }

                StringBuilder errorMessages = new StringBuilder();
                Persona       per           = new Persona();
                per.v_documento          = tex_documento.Text;
                per.v_DcodTipoDocumento  = com_tipo_documento.SelectedItem.ToString();
                per.v_DcodTipoPersona    = com_tipo_persona.SelectedItem.ToString();
                per.v_nombre             = tex_nombre.Text;
                per.v_apellido           = tex_apellido.Text;
                per.v_fechaNacimiento    = Convert.ToDateTime(tex_fecha_nacimiento.Text);
                per.v_DcodPaisNacimiento = com_pais_nacimiento.SelectedItem.ToString();
                per.v_direccion          = tex_direccion.Text;
                per.v_telefono           = tex_telefono.Text;
                per.v_correoElectronico  = tex_correo_electronico.Text;
                per.v_usuario            = this.usuario;

                try
                {
                    if (per.AgregarPersona(per) != 0)
                    {
                        MessageBox.Show("Persona creada correctamente" + "\n" + "Documento: " + per.v_documento,
                                        "Agregar Persona",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                        this.inicializarDatos();
                    }
                }
                catch (SqlException ex)
                {
                    for (int i = 0; i < ex.Errors.Count; i++)
                    {
                        errorMessages.Append("Index #" + i + "\n" +
                                             "Message: " + ex.Errors[i].Message + "\n" +
                                             "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                                             "Source: " + ex.Errors[i].Source + "\n" +
                                             "Procedure: " + ex.Errors[i].Procedure + "\n");
                    }
                    Console.WriteLine(errorMessages.ToString());

                    MessageBox.Show(ex.Errors[0].Message.ToString(),
                                    "Agregar Persona",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
        }