/** * Return a reader to the DAO Class to read Database Records * * @query : the query for the reader * * return SQLiteDataReader with it's query **/ public SQLiteDataReader getReader(String query) { try { setupDatabaseConnection(); command.CommandText = query; reader = command.ExecuteReader(); return(reader); } catch (Exception e) { Logging.logInfo(true, e.Message); } throw new DatabaseException(DatabaseConstants.INVALID("404")); }
/** * Getting all note * * @lastNoteId : the last note that was read from the last call * * return a list of notes id if it was found and throw an exception otherwise **/ public List <String> findAll(String lastNoteId = "1") { //Logging Logging.paramenterLogging(nameof(findAll), false, new Pair(nameof(lastNoteId), lastNoteId)); try { return(findAll(parser, tableName, "-1", lastNoteId)); } catch (Exception e) { Logging.logInfo(true, e.Message); } //Logging Logging.paramenterLogging(nameof(findByTitle), true, new Pair(nameof(lastNoteId), lastNoteId)); //Note was not found throw new DatabaseException(DatabaseConstants.INVALID(lastNoteId)); }
/** * Getting the user from the SQLiteReader * * @reader : the SQLiteDataReader for access the database * * return user object **/ public override User find(SQLiteDataReader reader) { if (reader.Read()) { User user = new User(); user.setFullName(reader[DatabaseConstants.COLUMN_FULLNAME].ToString()); user.setIsAuthenticated(int.Parse(reader[DatabaseConstants.COLUMN_AUTH].ToString())); user.setNotebookId(reader[DatabaseConstants.COLUMN_NOTEBOOKID].ToString()); user.setUsername(reader[DatabaseConstants.COLUMN_USERNAME].ToString()); user.setId(reader[idColumn].ToString()); return(user); } throw new DatabaseException(DatabaseConstants.INVALID("No Row to Read")); }
/** * This method is a generic SQL Update Query statment * * @tableName : The Table Name in the Database * @filter : the filter for the Where Statment * @condition : the condition for the Where statment * @column : the column name in the database * @t : the object that will be updated * * It Throws and Exception when one of the parameters are invalid * * return an SQL Update Statment **/ public String getUpdate(String tableName, String filter, String condition, T t, params String[] columns) { //Validation if (columns.Count() == 0) { throw new ArgumentException(DatabaseConstants.INVALID(DatabaseConstants.EMPTY_UPDATE) + Logging.paramenterLogging(nameof(getUpdate), true , new Pair(nameof(columns), columns.ToString()))); } if (!DataValidator.isValidParameters(tableName, filter, condition) || t == null) { throw new ArgumentException(Logging.paramenterLogging(nameof(getUpdate), true , new Pair(nameof(tableName), tableName) , new Pair(nameof(filter), filter), new Pair(nameof(t), t.ToString()) , new Pair(nameof(condition), condition))); } //Logging Logging.paramenterLogging(nameof(getUpdate), false , new Pair(nameof(tableName), tableName) , new Pair(nameof(filter), filter), new Pair(nameof(t), t.ToString()) , new Pair(nameof(condition), condition)); //Building SQL Statment StringBuilder query = new StringBuilder(); query.Append("UPDATE "); query.Append(tableName); query.Append(" SET "); String val = "", prefix = ""; foreach (String columnName in columns) { query.Append(prefix); prefix = ","; query.Append(columnName); query.Append(" = '"); try { val = getFieldFromColumn(columnName, t); } catch (DatabaseException e) { Logging.logInfo(true, e.Message); return(null); } query.Append(val); query.Append("'"); } query.Append(getWhere(filter, condition)); query.Append(";"); return(query.ToString()); }
private void btnBrowesFile_Click(object sender, EventArgs e) { openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); openFileDialog.Filter = TypesConstants.FILE_TYPES; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (openFileDialog.FileName.Length > 4) { txtNote.Text = File.ReadAllText(openFileDialog.FileName); } else { MessageBox.Show(DatabaseConstants.INVALID("File")); } } }
/** * Register for the user * * @auth : the usernamae and password for the user (the authentication object) * * return true if and only if the register was done successfully **/ public bool register(Authentication auth) { //Logging Logging.paramenterLogging(nameof(register), false, new Pair(nameof(auth), auth.ToString())); //Register try { auth.setPassword(encrypt(auth.getPassword())); return(driver.executeQuery(parser.getInsert(auth)) != -11); } catch (Exception e) { Logging.logInfo(true, e.Message); } //Logging Logging.paramenterLogging(nameof(register), true, new Pair(nameof(auth), auth.ToString())); //Something went wrong throw new DatabaseException(DatabaseConstants.INVALID(auth.ToString())); }
/** * Open a docuemt * * @openFileDialog: the dialog to open and open the file locally **/ public void open(OpenFileDialog openFileDialog) { openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); openFileDialog.Filter = TypesConstants.FILE_TYPES; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (openFileDialog.FileName.Length > 4) { getCurrentDocument.LoadFile(openFileDialog.FileName, RichTextBoxStreamType.PlainText); } else { MessageBox.Show(DatabaseConstants.INVALID("File")); } } }
/** * Getting all the task by it's priority * * @priority : the priority to search for in the database * * return a list of tasknotes ids with a priority if it was found and throw an exception otherwise **/ public List <String> findAllByPriority(Priority priority) { //Logging Logging.paramenterLogging(nameof(findAllByPriority), false, new Pair(nameof(priority), priority.ToString())); //Finding try { SQLiteDataReader reader = driver.getReader(parser.getSelect(tableName, DatabaseConstants.COLUMN_PRIORITY, idColumn, priority.ToString())); List <String> notesids = new List <String>(); while (reader.Read()) { notesids.Add(reader[idColumn].ToString()); } return(notesids); } catch (Exception e) { Logging.logInfo(true, e.Message); } //Logging Logging.paramenterLogging(nameof(findAllByPriority), true, new Pair(nameof(priority), priority.ToString())); //NoN were found or something went wrong throw new DatabaseException(DatabaseConstants.INVALID(priority.ToString())); }
/** * Getting all records in range * * @parser : the object database parser * @tableName : the tableName for the records * @orderByColumnName : the name of the column to order the data * @lastTId : the last id of the previous call * * Return a list of ids **/ public List <String> findAll(DatabaseParser <T> parser, String tableName, String orderbyColumnName = "", String lastTId = "1") { //Logging Logging.paramenterLogging(nameof(findAll), false , new Pair(nameof(orderbyColumnName), orderbyColumnName), new Pair(nameof(tableName), tableName) , new Pair(nameof(lastTId), lastTId)); //Finding T List <String> ids = new List <String>(); try { int lastId = int.Parse(lastTId), range = int.Parse(DatabaseConstants.RANGE); String query = ""; if (orderbyColumnName.Equals("-1")) { query = "SELECT ID FROM " + tableName + " WHERE ID BETWEEN " + lastTId + " AND " + (int.Parse(lastTId) + 20).ToString(); } else { query = parser.getSelect(tableName, "" , DatabaseConstants.COLUMN_ID, "", true , lastId, lastId + 20, orderbyColumnName != "", orderbyColumnName); } SQLiteDataReader reader = DatabaseDriverImplementation.getInstance() .getReader(query); while (reader.Read()) { ids.Add(reader[DatabaseConstants.COLUMN_ID].ToString()); } reader.Close(); return(ids); } catch (Exception e) { Logging.logInfo(true, e.Message); } throw new DatabaseException(DatabaseConstants.INVALID("EMPTY")); }