コード例 #1
0
ファイル: ToDoDB.cs プロジェクト: seymej72/ToDoList
        //Update or Save Task
        public void UpdateTask(DisposableTask disposableTask)
        {
            if (CheckTaskExistsInDB(disposableTask.getTaskId()))
            {
                MySqlConnection conn = null;
                try
                {
                    conn = new MySqlConnection(connectionString);
                    conn.Open();
                    MySqlCommand cmd = new MySqlCommand("UPDATE `Task` SET `title` = @title, `notes` = @notes," +
                                                        "`allowNotifications` = @allowNotifications, `isComplete` = @isComplete, `isRepeatable` = @isRepeatable, `taskFKey` = @taskFKey" +
                                                        " WHERE `taskId` =  @taskId", conn);
                    cmd.Parameters.AddWithValue("taskId", disposableTask.getTaskId());
                    cmd.Parameters.AddWithValue("title", disposableTask.getTitle());
                    cmd.Parameters.AddWithValue("notes", disposableTask.getDescription());
                    cmd.Parameters.AddWithValue("allowNotifications", disposableTask.getAllowNotifications());
                    cmd.Parameters.AddWithValue("isComplete", disposableTask.getIsComplete());
                    cmd.Parameters.AddWithValue("isRepeatable", false);
                    cmd.Parameters.AddWithValue("taskFKey", disposableTask.getTaskFKey());

                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("UpdateTask Failure!" + ex);
                }
                finally
                {
                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
            }
        }
コード例 #2
0
ファイル: ToDoDB.cs プロジェクト: seymej72/ToDoList
        //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);
        }