Exemple #1
0
        public List <Eusuarios> usuarios_GetAll(ref ETransactionResult _transResult)
        {
            var list = new List <Eusuarios>();

            _transResult = new ETransactionResult();
            SqlTransaction transaction = null;

            try
            {
                using (SqlConnection sqlCon = new SqlConnection(conn))
                {
                    sqlCon.Open();
                    using (SqlCommand sqlCmd = new SqlCommand())
                    {
                        transaction        = sqlCon.BeginTransaction("SelectAllTranstaction");
                        sqlCmd.Transaction = transaction;
                        sqlCmd.Connection  = sqlCon;
                        sqlCmd.CommandType = CommandType.StoredProcedure;
                        sqlCmd.CommandText = "D_PR_usuarios_SelectAll";
                        using (var reader = sqlCmd.ExecuteReader())
                            while (reader.Read())
                            {
                                var item = new Eusuarios();
                                item.usuario   = (string)reader["usuario"];
                                item.passwd    = (string)reader["passwd"];
                                item.nombre    = (string)reader["nombre"];
                                item.apellidoP = (string)reader["apellidoP"];
                                item.apellidoM = (string)reader["apellidoM"];
                                item.roll      = (string)reader["roll"];
                                item.estatus   = reader["estatus"] == DBNull.Value ? null :  (bool?)reader["estatus"];
                                list.Add(item);
                            }
                        transaction.Commit();
                        _transResult.message = "OK";
                        _transResult.result  = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                _transResult.message = ex.Message;
                _transResult.result  = 1;
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollBackEx)
                {
                    _transResult.rollbackMessage = rollBackEx.Message;
                    _transResult.result          = 1;
                }
            }
            return(list);
        }
Exemple #2
0
        public Eusuarios usuarios_Get(Eusuarios item, ref ETransactionResult _transResult)
        {
            Eusuarios itemFinded = null;

            _transResult = new ETransactionResult();
            SqlTransaction transaction = null;

            try
            {
                using (SqlConnection sqlCon = new SqlConnection(conn))
                {
                    sqlCon.Open();
                    using (SqlCommand sqlCmd = new SqlCommand())
                    {
                        transaction        = sqlCon.BeginTransaction("SelectTransaction");
                        sqlCmd.Transaction = transaction;
                        sqlCmd.Connection  = sqlCon;
                        sqlCmd.CommandType = CommandType.StoredProcedure;
                        sqlCmd.Parameters.AddWithValue("@usuario", item.usuario);
                        sqlCmd.CommandText = "D_PR_usuarios_Select";
                        using (var reader = sqlCmd.ExecuteReader())
                            while (reader.Read())
                            {
                                itemFinded           = new Eusuarios();
                                itemFinded.usuario   = (string)reader["usuario"];
                                itemFinded.passwd    = (string)reader["passwd"];
                                itemFinded.nombre    = (string)reader["nombre"];
                                itemFinded.apellidoP = (string)reader["apellidoP"];
                                itemFinded.apellidoM = (string)reader["apellidoM"];
                                itemFinded.roll      = (string)reader["roll"];
                                itemFinded.estatus   = reader["estatus"] == DBNull.Value ? null :  (bool?)reader["estatus"];
                            }
                        transaction.Commit();
                        _transResult.message = "OK";
                        _transResult.result  = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                _transResult.message = ex.Message;
                _transResult.result  = 1;
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollBackEx)
                {
                    _transResult.rollbackMessage = rollBackEx.Message;
                    _transResult.result          = 1;
                }
            }
            return(itemFinded);
        }
Exemple #3
0
        private void btn_aceptar_Click(object sender, EventArgs e)
        {
            Eusuarios          user   = null;
            ETransactionResult result = new ETransactionResult();

            user = (Eusuarios)_usuarios.Get(new Eusuarios {
                usuario = txt_usr.Text.Trim()
            }, ref result);

            if (user != null && user.passwd == txt_passwd.Text.Trim() && user.estatus == true)
            {
                txt_usr.Clear();
                txt_passwd.Clear();


                this.SendToBack();
                this.Hide();

                //Principal principal = new Principal();
                //principal.cajero = user;
                //principal.Show();


                Principal Principal = new Principal();
                Principal.cajero = user;
                DialogResult dr = Principal.ShowDialog(this);

                if (dr == DialogResult.Cancel)
                {
                    Principal.Close();
                    this.BringToFront();
                    this.Show();
                }
                else if (dr == DialogResult.OK)
                {
                    Principal.Close();
                    this.BringToFront();
                    this.Show();
                }
                txt_usr.Focus();
            }
            else
            {
                //Log.Error("Error de inicio de sesión: Ususario o Password incorrecto " + result.message);
                txt_usr.Clear();
                txt_passwd.Clear();
                txt_usr.Focus();
                MessageBox.Show("Usuario ó contraseña incorrectos.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #4
0
        private void Usuarios_Load(object sender, EventArgs e)
        {
            if (!nuevo)
            {
                txtUser.Enabled = false;

                usuario.usuario = user;
                usuario         = (Eusuarios)_usuarios.Get(usuario, ref result);

                if (result.result == 0)
                {
                    txtUser.Text        = usuario.usuario;
                    txtPassword.Text    = usuario.passwd;
                    txtName.Text        = usuario.nombre;
                    txtApellidoP.Text   = usuario.apellidoP;
                    txtApellidoM.Text   = usuario.apellidoM;
                    chkEstado.Checked   = (bool)usuario.estatus;
                    cboRol.SelectedText = (usuario.roll == "ADMIN") ? "Administrador" : "Cajero";
                }
            }
        }
Exemple #5
0
        public void  usuarios_Delete(Eusuarios item, ref ETransactionResult _transResult)
        {
            _transResult = new ETransactionResult();
            SqlTransaction transaction = null;

            try
            {
                using (SqlConnection sqlCon = new SqlConnection(conn))
                {
                    sqlCon.Open();
                    using (SqlCommand sqlCmd = new SqlCommand())
                    {
                        transaction        = sqlCon.BeginTransaction("DeleteTransaction");
                        sqlCmd.Transaction = transaction;
                        sqlCmd.Connection  = sqlCon;
                        sqlCmd.CommandType = CommandType.StoredProcedure;
                        sqlCmd.CommandText = "D_PR_usuarios_Delete";
                        sqlCmd.Parameters.AddWithValue("@usuario", item.usuario);
                        sqlCmd.ExecuteNonQuery();
                        transaction.Commit();
                        _transResult.message = "OK";
                        _transResult.result  = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                _transResult.message = ex.Message;
                _transResult.result  = 1;
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollBackEx)
                {
                    _transResult.rollbackMessage = rollBackEx.Message;
                    _transResult.result          = 1;
                }
            }
        }
Exemple #6
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (validar())
            {
                usuario = new Eusuarios();

                usuario.usuario   = txtUser.Text;
                usuario.passwd    = txtPassword.Text;
                usuario.nombre    = txtName.Text;
                usuario.apellidoP = txtApellidoP.Text;
                usuario.apellidoM = txtApellidoM.Text;
                usuario.estatus   = chkEstado.Checked;
                usuario.roll      = (cboRol.Text == "Administrador" ? "ADMIN" : "CAJA");

                try
                {
                    if (!nuevo)
                    {
                        _usuarios.Update(usuario, ref result);
                    }
                    else
                    {
                        _usuarios.Insert(usuario, ref result);
                    }

                    if (result.result != 0)
                    {
                        throw new Exception(result.message);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error al guardar el registro: " + ex.Message + " " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }