Esempio n. 1
0
 private void btnCancelar_Click(object sender, EventArgs e)
 {
     if (editing)
     {
         if (ejecutaAdmin)
         {
             if (tipoUsuario == 3)
             {
                 UberFrba.Abm_Cliente.AbmCliente abmCliente = new Abm_Cliente.AbmCliente();
                 this.Hide();
                 abmCliente.Show();
             }
             else
             {
                 UberFrba.Abm_Chofer.AbmChofer abmChofer = new Abm_Chofer.AbmChofer();
                 this.Hide();
                 abmChofer.Show();
             }
         }
         else
         {
             this.Hide();
         }
     }
     else
     {
         if (altaConRol)
         {
             if (tipoUsuario == 3)
             {
                 UberFrba.Abm_Cliente.AbmCliente abmCliente = new Abm_Cliente.AbmCliente();
                 this.Hide();
                 abmCliente.Show();
             }
             else
             {
                 UberFrba.Abm_Chofer.AbmChofer abmChofer = new Abm_Chofer.AbmChofer();
                 this.Hide();
                 abmChofer.Show();
             }
         }
         else
         {
             Inicial formInicial = new Inicial();
             this.Hide();
             formInicial.Show();
         }
     }
 }
Esempio n. 2
0
        private void btnRegistrar_Click(object sender, EventArgs e)
        {
            int esChofer  = 0;
            int esCliente = 0;

            bool huboErrorDato = false;
            bool errorYaExiste = false;

            List <string> lstErroresCampos     = new List <string>();
            List <string> lstErroresExistencia = new List <string>();

            huboErrorDato = validarCampos(ref lstErroresCampos);

            if (huboErrorDato)
            {
                Validator.mostrarErrores(lstErroresCampos, "");
            }
            else
            {
                Usuario usuarioNuevo = crearNuevoUsuario(ref esChofer, ref esCliente);

                errorYaExiste = verificarExistencia(ref lstErroresExistencia, usuarioNuevo);

                if (errorYaExiste)
                {
                    Validator.mostrarErrores(lstErroresExistencia, "");
                }
                else
                {
                    List <SqlParameter> parameterList = cargarParametrosComunesQuery(usuarioNuevo);

                    try
                    {
                        if (editing)
                        {
                            #region if editing

                            bool continuar = true;

                            if (!chkHabilitado.Checked && !ejecutaAdmin)
                            {
                                DialogResult dr = MessageBox.Show("Si se inhabilita saldrá automáticamente del sistema y tendrá que contactar al administrador para volver a ingresar. ¿Desea continuar?",
                                                                  "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (dr == DialogResult.No)
                                {
                                    continuar             = false;
                                    chkHabilitado.Checked = true;
                                }
                            }

                            if (continuar)
                            {
                                if (chkHabilitado.Checked)
                                {
                                    parameterList.Add(new SqlParameter("@habilitado", 1));
                                }
                                else
                                {
                                    parameterList.Add(new SqlParameter("@habilitado", 0));
                                }

                                parameterList.Add(new SqlParameter("@idUsuario", userAEditar.Id_Usuario));
                                if (tipoUsuario == 3)
                                {
                                    parameterList.Add(new SqlParameter("@codPost", usuarioNuevo.CodPost));
                                    SQLHelper.ExecuteNonQuery("PR_editarCliente", CommandType.StoredProcedure, parameterList);
                                }
                                else if (tipoUsuario == 2)
                                {
                                    SQLHelper.ExecuteNonQuery("PR_editarChofer", CommandType.StoredProcedure, parameterList);
                                }

                                MessageBox.Show("El usuario se ha modificado");

                                userAEditar = usuarioNuevo;

                                if (ejecutaAdmin)
                                {
                                    if (tipoUsuario == 3)
                                    {
                                        UberFrba.Abm_Cliente.AbmCliente abmCliente = new Abm_Cliente.AbmCliente();
                                        this.Hide();
                                        abmCliente.Show();
                                    }
                                    else if (tipoUsuario == 2)
                                    {
                                        UberFrba.Abm_Chofer.AbmChofer abmChofer = new Abm_Chofer.AbmChofer();
                                        this.Hide();
                                        abmChofer.Show();
                                    }
                                }
                                else
                                {
                                    if (usuarioNuevo.Habilitado)
                                    {
                                        this.Hide();
                                    }
                                    else
                                    {
                                        Inicial frmInicial = new Inicial();
                                        frmPrincipal.Close();
                                        frmInicial.Show();
                                        this.Close();
                                    }
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            parameterList.Add(new SqlParameter("@esChofer", esChofer));
                            parameterList.Add(new SqlParameter("@esCliente", esCliente));
                            parameterList.Add(new SqlParameter("@codPost", usuarioNuevo.CodPost));

                            SQLHelper.ExecuteNonQuery("PR_altaUsuario", CommandType.StoredProcedure, parameterList);
                            MessageBox.Show("El usuario se ha registrado correctamente");

                            if (altaConRol)
                            {
                                if (rolAlta == 3)
                                {
                                    UberFrba.Abm_Cliente.AbmCliente abmCliente = new Abm_Cliente.AbmCliente();
                                    this.Hide();
                                    abmCliente.Show();
                                }
                                else if (rolAlta == 2)
                                {
                                    UberFrba.Abm_Chofer.AbmChofer abmChofer = new Abm_Chofer.AbmChofer();
                                    this.Hide();
                                    abmChofer.Show();
                                }
                            }
                            else
                            {
                                Inicial inicialForm = new Inicial();
                                this.Hide();
                                inicialForm.Show();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        //MessageBox.Show("Hubo un error registrando el usuario. Revise los datos ingresados e intente de nuevo");
                    }
                }
            }
        }