Exemplo n.º 1
0
        private void btnRegistrar_Click(object sender, EventArgs e)
        {
            string mensaje = "";

            try
            {
                errorProvider1.Clear();
                if (Utilidades.ValidarForm(this, errorProvider1) == false)
                {
                    return;
                }
                if (Program.Evento == 0)
                {
                    P.Nombre  = txtNombre.Text;
                    P.Idtipot = Convert.ToInt32(cbTipoProveedor.SelectedValue);
                    mensaje   = P.Registrar();
                    if (mensaje == "1")
                    {
                        P.Identificacion = txtIdentificacion.Text;
                        if (cbTipoProveedor.Text == "Empresa")
                        {
                            P.Idtipoi = 8;
                        }
                        else if (cbTipoProveedor.Text == "Persona")
                        {
                            P.Idtipoi = 6;
                        }
                        mensaje = P.RegistrarI();
                        for (int x = 0; x < dtgContacto.Rows.Count; x++)
                        {
                            P.Contacto = dtgContacto.Rows[x].Cells[1].Value.ToString();
                            P.Idtipoc  = Convert.ToInt32(dtgContacto.Rows[x].Cells[2].Value);
                            mensaje    = P.RegistrarC();
                        }
                        for (int x = 0; x < dtgDireccion.Rows.Count; x++)
                        {
                            P.Direccion = dtgDireccion.Rows[x].Cells[1].Value.ToString();
                            P.Idbarrio  = Convert.ToInt32(dtgDireccion.Rows[x].Cells[2].Value);
                            P.Idciudad  = Convert.ToInt32(dtgDireccion.Rows[x].Cells[3].Value);
                            P.Idregion  = Convert.ToInt32(dtgDireccion.Rows[x].Cells[4].Value);
                            mensaje     = P.RegistrarD();
                        }
                        if (mensaje == "1")
                        {
                            MessageBoxEx.Show("Registrado con éxito", "FactSYS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Limpiar();
                        }
                    }
                }
                else if (Program.Evento == 1)
                {
                    P.Idtercero = Program.Codigo;
                    P.Nombre    = txtNombre.Text;
                    P.Idtipot   = Convert.ToInt32(cbTipoProveedor.SelectedValue);
                    mensaje     = P.Actualizar();
                    if (mensaje == "1")
                    {
                        P.Identificacion = txtIdentificacion.Text;
                        if (cbTipoProveedor.Text == "Empresa")
                        {
                            P.Idtipoi = 8;
                        }
                        else if (cbTipoProveedor.Text == "Persona")
                        {
                            P.Idtipoi = 6;
                        }
                        mensaje = P.ActualizarI();
                        for (int x = 0; x < dtgContacto.Rows.Count; x++)
                        {
                            P.Idcontacto = Convert.ToInt32(dtgContacto.Rows[x].Cells[0].Value);
                            P.Contacto   = dtgContacto.Rows[x].Cells[1].Value.ToString();
                            P.Idtipoc    = Convert.ToInt32(dtgContacto.Rows[x].Cells[2].Value);
                            mensaje      = P.ActualizarC();
                        }
                        for (int x = 0; x < dtgDireccion.Rows.Count; x++)
                        {
                            P.Iddireccion = Convert.ToInt32(dtgDireccion.Rows[x].Cells[0].Value);
                            P.Direccion   = dtgDireccion.Rows[x].Cells[1].Value.ToString();
                            P.Idbarrio    = Convert.ToInt32(dtgDireccion.Rows[x].Cells[2].Value);
                            P.Idciudad    = Convert.ToInt32(dtgDireccion.Rows[x].Cells[3].Value);
                            P.Idregion    = Convert.ToInt32(dtgDireccion.Rows[x].Cells[4].Value);
                            mensaje       = P.ActualizarD();
                        }
                        if (mensaje == "1")
                        {
                            MessageBoxEx.Show("Actualizado con éxito", "FactSYS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Limpiar();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show(ex.Message);
            }
        }