示例#1
0
        //Fetch existing DT from Database based on taskId and update this instance with its info
        public DisposableTask FetchDisposableTask(int taskId)
        {
            MySqlConnection conn             = null;
            DisposableTask  myDisposableTask = new DisposableTask();

            try
            {
                conn = new MySqlConnection(connectionString);
                conn.Open();
                MySqlCommand cmd = new MySqlCommand("SELECT* from `Task` WHERE `TaskId` =  @taskId", conn);
                cmd.Parameters.Add(new MySqlParameter("taskId", taskId));
                MySqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                myDisposableTask.setTaskId((int)reader.GetValue(0));                 //TaskId
                myDisposableTask.setTitle((String)reader.GetValue(1));               //Title
                myDisposableTask.setDescription((String)reader.GetValue(2));         //Notes
                myDisposableTask.setAllowNotifications((Boolean)reader.GetValue(3)); //allowNotifications
                myDisposableTask.setIsComplete((Boolean)reader.GetValue(4));         //isComplete
                myDisposableTask.setRepeatability((Boolean)reader.GetValue(5));      //isRepeatable
                myDisposableTask.setTaskFKey((int)reader.GetValue(6));               //taskFKey
            }
            catch (Exception ex)
            {
                Console.WriteLine("FetchDisposableTask Failure!" + ex);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            myDisposableTask.setSubTasks(FetchAllSubTasks(taskId));
            return(myDisposableTask);
        }
示例#2
0
        //Inserts the new row into the TASK table and returns the new Task ID it gets auto assigned
        public int InsertDisposableTask(DisposableTask disposableTask)
        {
            MySqlConnection conn    = null;
            MySqlCommand    command = null;

            try
            {
                conn = new MySqlConnection(connectionString);
                conn.Open();

                command = new MySqlCommand("INSERT INTO `Task` (`title`,`notes`,`allowNotifications`, `isComplete`,`isRepeatable`, `taskFKey`) " +
                                           "VALUES(@title, @notes, @allowNotifications, @isComplete, @isRepeatable, @taskFKey);", conn);

                command.Parameters.AddWithValue("@title", disposableTask.getTitle());
                command.Parameters.AddWithValue("@notes", disposableTask.getDescription());
                command.Parameters.AddWithValue("@allowNotifications", disposableTask.getAllowNotifications());
                command.Parameters.AddWithValue("@isComplete", disposableTask.getIsComplete());
                command.Parameters.AddWithValue("@isRepeatable", 0); //0 for not repeatable
                command.Parameters.AddWithValue("@taskFKey", disposableTask.getTaskFKey());

                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine("InsertDisposableTask: Failure!" + ex);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            int highestId = GetNextTaskId();

            disposableTask.setTaskId(highestId);
            UpdateTask(disposableTask);
            return(highestId);
        }