Exemple #1
0
 /// <summary>
 /// Get task from database
 /// </summary>
 /// <param name="task">Return result</param>
 /// <param name="guid">Task unique guid</param>
 /// <returns>Returns 'true' if operation was successful</returns>
 public bool GetTask(out DbCommon.Task task, Guid guid)
 {
     bool result = false;
     task = null;
     System.Data.DataTable dt = new System.Data.DataTable();
     try
     {
         if (this.OpenDb() &&
             guid != null)
         {
             SQLiteCommand myCommand = new SQLiteCommand(_dbConnection);
             myCommand.CommandText = String.Format("SELECT {0},{1},{2},{3} FROM {4} WHERE {5}='{6}'",
                                                   DbCommon.GUIN_COLUMN,         // {0}
                                                   DbCommon.TEXT_COLUMN,         // {1}
                                                   DbCommon.IMPORTANT_COLUMN,    // {2}
                                                   DbCommon.URGENT_COLUMN,       // {3}
                                                   DbCommon.TABLE_NAME,          // {4}
                                                   DbCommon.GUIN_COLUMN,         // {5}
                                                   guid.ToString());             // {6}
             SQLiteDataReader reader = myCommand.ExecuteReader();
             dt.Load(reader);
             reader.Close();
             result = _dbConnection.ResultCode() == SQLiteErrorCode.Ok;
             this.CloseDb();
             if (dt.Rows.Count > 0 &&
                 dt.Rows[0].ItemArray.Count() > 3)
             {
                 task = new DbCommon.Task(dt.Rows[0].ItemArray[0].ToString(),
                                          dt.Rows[0].ItemArray[1].ToString(),
                                          dt.Rows[0].ItemArray[2].ToString(),
                                          dt.Rows[0].ItemArray[3].ToString());
             }
         }
     }
     catch (Exception exc)
     {
         Console.WriteLine(exc.Message);
         result = false;
     }
     return result;
 }
Exemple #2
0
        /// <summary>
        /// Get tasks from database
        /// </summary>
        /// <param name="important">If tasks are important</param>
        /// <param name="urgent">If tasks are urgent</param>
        /// <param name="tasks">Return result</param>
        /// <returns>Returns 'true' if operation was successful</returns>
        public bool GetAllTasks(out List<DbCommon.Task> tasks, bool? important = null, bool? urgent = null)
        {
            bool result = false;
            tasks = new List<DbCommon.Task>();
            System.Data.DataTable dt = new System.Data.DataTable();
            try
            {
                if (this.OpenDb())
                {
                    string where = String.Empty;
                    if (important != null)
                    {
                        where =  String.Format(" WHERE {0}='{1}'",
                                               DbCommon.IMPORTANT_COLUMN,   // {0}
                                               important.Value ? "1" : "0");// {1}
                    }
                    if (urgent != null)
                    {
                        if (!String.IsNullOrWhiteSpace(where))
                        {
                            where = String.Format("{0} AND ",
                                                  where);
                        }
                        else
                        {
                            where = " WHERE ";
                        }
                        where = String.Format("{0}{1}='{2}'",
                                              where,                    // {0}
                                              DbCommon.URGENT_COLUMN,   // {1}
                                              urgent.Value ? "1" : "0");// {2}
                    }

                    SQLiteCommand myCommand = new SQLiteCommand(_dbConnection);
                    myCommand.CommandText = String.Format("SELECT {0},{1},{2},{3} FROM {4}{5}",
                                                          DbCommon.GUIN_COLUMN,         // {0}
                                                          DbCommon.TEXT_COLUMN,         // {1}
                                                          DbCommon.IMPORTANT_COLUMN,    // {2}
                                                          DbCommon.URGENT_COLUMN,       // {3}
                                                          DbCommon.TABLE_NAME,          // {4}
                                                          where);                       // {5}
                    SQLiteDataReader reader = myCommand.ExecuteReader();

                    dt.Load(reader);
                    reader.Close();
                    result = _dbConnection.ResultCode() == SQLiteErrorCode.Ok;
                    this.CloseDb();

                    IEnumerator<System.Data.DataRow> enumerator = (IEnumerator<System.Data.DataRow>)dt.Rows.GetEnumerator();
                    while(enumerator.MoveNext())
                    {
                        if (enumerator.Current.ItemArray.Count() > 3)
                        {
                            DbCommon.Task task = new DbCommon.Task(enumerator.Current.ItemArray[0].ToString(),
                                                                   enumerator.Current.ItemArray[1].ToString(),
                                                                   enumerator.Current.ItemArray[2].ToString(),
                                                                   enumerator.Current.ItemArray[3].ToString());
                            tasks.Add(task);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                result = false;
            }
            return result;
        }