Пример #1
0
        public List <SysUserRolDTO> GetAllSysUser()
        {
            DataSet ds = null;
            List <SysUserRolDTO> lista   = new List <SysUserRolDTO>();
            SqlCommand           command = new SqlCommand();

            string sql = @"usp_SELECT_SysUser_All";

            try
            {
                command.CommandText = sql;
                command.CommandType = CommandType.StoredProcedure;

                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(_Usuario.Login, _Usuario.Password)))
                {
                    ds = db.ExecuteReader(command, "query");
                }

                // Si devolvió filas
                if (ds.Tables[0].Rows.Count > 0)
                {
                    // Iterar en todas las filas y Mapearlas
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        SysUserRolDTO oSysUserRolDTO = new SysUserRolDTO()
                        {
                            Login    = (dr["Login"].ToString()),
                            Password = (dr["Password"].ToString()),
                            Id       = double.Parse(dr["IdRol"].ToString()),
                            //Descripcion = (dr["Descripcion"].ToString()),
                            IDUser = (int)(dr["IDUser"])
                        };

                        lista.Add(oSysUserRolDTO);
                    }
                }

                return(lista);
            }
            catch (SqlException sqlError)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                msg.AppendFormat("SQL             {0}\n", command.CommandText);
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateGenericErrorExceptionDetail(er));
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
        }
Пример #2
0
        public SysUser GetSysUserById(double pId)
        {
            DataSet       ds       = null;
            SysUser       oSysUser = null;
            SysUserRolDTO DTO      = new SysUserRolDTO();
            string        sql      = @" select * from  [SysUser] where IDUser = @IDUser";

            SqlCommand command = new SqlCommand();

            try
            {
                command.Parameters.AddWithValue("@IDUser", pId);
                command.CommandText = sql;
                command.CommandType = CommandType.Text;

                using (IDataBase db = FactoryDataBase.CreateDataBase(FactoryConexion.CreateConnection(_Usuario.Login, _Usuario.Password)))
                {
                    ds = db.ExecuteReader(command, "query");
                }

                // Si retornó valores
                if (ds.Tables[0].Rows.Count > 0)
                {
                    //Extraer la primera fila, como se buscó por Id entonces solo una debe devolver
                    DataRow dr = ds.Tables[0].Rows[0];
                    oSysUser = new SysUser()
                    {
                        Login    = (dr["Login"].ToString()),
                        Password = (dr["Password"].ToString()),
                        IdRol    = (int)(dr["IdRol"]),
                        IDUser   = (int)(dr["IDUser"])
                    };
                }

                return(oSysUser);
            }
            catch (SqlException sqlError)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError));
                msg.AppendFormat("SQL             {0}\n", command.CommandText);
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat(Utilitarios.CreateGenericErrorExceptionDetail(er));
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                throw;
            }
        }
Пример #3
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            SysUserRolDTO oSysUserRolDTO = null;

            try
            {
                if (this.dgvDatos.SelectedRows.Count > 0)
                {
                    // Cambiar de estado

                    //Extraer el DTO seleccionado
                    oSysUserRolDTO = this.dgvDatos.SelectedRows[0].DataBoundItem as SysUserRolDTO;

                    this.txtUsuario.Text    = oSysUserRolDTO.Login.ToString();
                    this.txtIdUser.Text     = oSysUserRolDTO.IDUser.ToString();
                    this.txtContrasena.Text = oSysUserRolDTO.Password.ToString();
                    this.txtIdRol.Text      = oSysUserRolDTO.Id.ToString();
                }
                else
                {
                    MessageBox.Show("Seleccione el registro !", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat("Message        {0}\n", er.Message);
                msg.AppendFormat("Source         {0}\n", er.Source);
                msg.AppendFormat("InnerException {0}\n", er.InnerException);
                msg.AppendFormat("StackTrace     {0}\n", er.StackTrace);
                msg.AppendFormat("TargetSite     {0}\n", er.TargetSite);
                // Log error
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                // Mensaje de Error
                MessageBox.Show("Se ha producido el siguiente error " + er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #4
0
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            SysUserRolDTO oSysUserRolDTO = new SysUserRolDTO();

            IBLLSysUserRolDTO _BLLSysUser = new BLLSysUserRolDTO();

            try
            {
                if (this.dgvDatos.SelectedRows.Count > 0)
                {
                    oSysUserRolDTO = this.dgvDatos.SelectedRows[0].DataBoundItem as SysUserRolDTO;
                    if (MessageBox.Show($"¿Seguro que desea borrar el registro {oSysUserRolDTO.Login} {oSysUserRolDTO.IDUser}?", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        _BLLSysUser.DeleteSysUser(oSysUserRolDTO.Login);
                        this.CargarDatos();
                    }
                }
                else
                {
                    MessageBox.Show("Seleccione el registro !", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat("Message        {0}\n", er.Message);
                msg.AppendFormat("Source         {0}\n", er.Source);
                msg.AppendFormat("InnerException {0}\n", er.InnerException);
                msg.AppendFormat("StackTrace     {0}\n", er.StackTrace);
                msg.AppendFormat("TargetSite     {0}\n", er.TargetSite);
                // Log error
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                // Mensaje de Error
                MessageBox.Show("Se ha producido el siguiente error " + er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }