コード例 #1
0
        //INSERTAR USUARIO EMPLEADO
        public int insertarUsuarioE(string username, string contrasena, string rol, int ci)
        {
            NpgsqlConnection conn = DAOUsuario.getInstanceDAO();

            conn.Open();

            String sql = "INSERT INTO \"Usuario\" (\"COD\",\"Nombre\", \"Contrasena\", \"FK-RolU\", \"FK-EmpleadoU\") " +
                         "VALUES ((SELECT NEXTVAL('seq')),'" + username + "', '" + contrasena + "', " + rol + ", " + ci + ")";
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            try
            {
                int resp = cmd.ExecuteNonQuery(); //CONTROLAR EXCEPTION DE UNIQUE
                conn.Close();
                return(resp);
            }
            catch (Exception e)
            {
                System.Diagnostics.TextWriterTraceListener writer = new System.Diagnostics.TextWriterTraceListener(System.Console.Out);
                System.Diagnostics.Debug.Listeners.Add(writer);
                System.Diagnostics.Debug.WriteLine(e.ToString());
                conn.Close();
                return(0);
            }
        }
コード例 #2
0
        //AUDITORIA DEL SISTEMA
        public int insertarAccion(int codU, int codAcc, string fecha, string accion)
        {
            NpgsqlConnection conn = DAOUsuario.getInstanceDAO();

            conn.Open();

            String sql = "INSERT INTO \"Accion-Usuario\" (\"codUsuario\", \"codAccion\", \"Fecha\", \"Descripcion\") " +
                         "VALUES (" + codU + ", " + codAcc + ", TO_TIMESTAMP('" + fecha + "', 'DD-MM-YYYY HH24:MI:SS'), '" + accion + "');";
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            try
            {
                int resp = cmd.ExecuteNonQuery(); //CONTROLAR EXCEPTION DE UNIQUE
                conn.Close();
                return(resp);
            }
            catch (Exception e)
            {
                System.Diagnostics.TextWriterTraceListener writer = new System.Diagnostics.TextWriterTraceListener(System.Console.Out);
                System.Diagnostics.Debug.Listeners.Add(writer);
                System.Diagnostics.Debug.WriteLine(e.ToString());
                conn.Close();
                return(0);
            }
        }
コード例 #3
0
 public static DAOUsuario getInstance()
 {
     if (DAOUsuario.u != null)
     {
         return(u);
     }
     else
     {
         u = new DAOUsuario();
         return(u);
     }
 }
コード例 #4
0
        //Buscando USUARIO EMPLEADO
        public int buscandoUsuarioE(string username, string contrasena)
        {
            NpgsqlConnection conn = DAOUsuario.getInstanceDAO();

            conn.Open();

            string sql = "SELECT \"Nombre\", \"Contrasena\", \"FK-EmpleadoU\", \"FK-RolU\" " +
                         "FROM \"Usuario\" WHERE \"Nombre\" = '" + username + "' AND" +
                         "\"FK-ClienteU\" is NULL";
            NpgsqlCommand    cmd = new NpgsqlCommand(sql, conn);
            NpgsqlDataReader dr  = cmd.ExecuteReader();
            int compData         = 0;

            try
            {
                while (dr.Read())
                {
                    System.Diagnostics.Debug.WriteLine("connection established");

                    if (String.Equals(dr[1].ToString(), contrasena))
                    {
                        compData = 1;
                    }
                }
            }
            catch (Exception e)
            {
                compData = 0;
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            dr.Close();

            conn.Close();


            return(compData);
        }