Ejemplo n.º 1
0
        public static DataTable performItemSearch(string searchCategory, string searchString)
        {
            searchCategory = "'" + searchCategory + "'";
            searchString = "'%" + searchString + "%'";
            DatabaseHandler db = new DatabaseHandler();

            DataTable dataTable = new DataTable();

            try
            {
                db.open();

                string sql = "SELECT * FROM " + sItemTable + " WHERE (`Category`=" + searchCategory + " && (`Title` LIKE " + searchString
                    + " OR `Year` LIKE " + searchString + " OR `Genre` LIKE " + searchString + " OR `Author` LIKE " + searchString
                    + " OR `Publisher` LIKE " + searchString + "));";

                MySqlCommand cmd = new MySqlCommand(sql, db.getDB());
                MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);

                adapter.Fill(dataTable);
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine("ItemHelper PerformItemSearch" + exception.StackTrace);
            }

            db.close();

            return dataTable;
        }
Ejemplo n.º 2
0
        public bool verifyID()
        {
            DatabaseHandler db = new DatabaseHandler();

            try
            {
                // Get ID from database and check to see if it matches one setup with Librarian Object
                db.open();

                // Query to select all columns from database where LibrarianID == mId
                string sql = "SELECT * FROM " + sLibrarianTable + " WHERE `LibrarianID`=" + mId + ";";

                // Create a command
                MySqlCommand cmd = new MySqlCommand(sql, db.getDB());

                // Execute command and store results in reader
                MySqlDataReader reader = cmd.ExecuteReader();

                // We found a matching record in the database
                if (reader.Read())
                {
                    // Get the Librarian ID and name from records and set isLoggedIn to true
                    mId = int.Parse(reader["LibrarianID"].ToString());
                    mName = reader["Name"].ToString();
                    mIsLoggedIn = true;
                }

                // Close reader
                reader.Close();
            }
            catch (FormatException formException)
            {
                System.Diagnostics.Debug.WriteLine("LibrarianVerifyId" + formException.StackTrace);
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine("LibrarianVerifyId" +  exception.StackTrace);
            }

            // Close db
            db.close();

            return mIsLoggedIn;
        }