コード例 #1
0
        private void addToDoBtn_Click(object sender, RoutedEventArgs e)
        {
            BDMSData.TodoInfo newTodo = new BDMSData.TodoInfo();

            newTodo.id = GenerateId();
            newTodo.date = DateTime.Now;
            newTodo.details = detailsTB.Text;

            BDMSDb.DbInteraction.DoRegisterNewTodo(newTodo);

            this.Close();

            ToDo.ToDoWindow ToDoWindowObj = new ToDo.ToDoWindow();
            ToDoWindowObj.Show();
        }
コード例 #2
0
        private static int DoRegisterNewTodoInDb(TodoInfo todoDetails)
        {
            int returnVal = 0;
            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

            try
            {
                //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();

                //define the connection used by the command object
                msqlCommand.Connection = msqlConnection;

                msqlCommand.CommandText = "INSERT INTO todo(todo_id,todo_date,todo_details) "
                                                   + "VALUES(@todo_id,@todo_date,@todo_details)";

                msqlCommand.Parameters.AddWithValue("@todo_id", todoDetails.id);
                msqlCommand.Parameters.AddWithValue("@todo_date", todoDetails.date);
                msqlCommand.Parameters.AddWithValue("@todo_details", todoDetails.details);

                msqlCommand.ExecuteNonQuery();

                returnVal = 1;
            }
            catch (Exception er)
            {
                returnVal = 0;
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
            return returnVal;
        }
コード例 #3
0
 public static int DoRegisterNewTodo(TodoInfo todoDetails)
 {
     return DoRegisterNewTodoInDb(todoDetails);
 }
コード例 #4
0
        private static List<TodoInfo> QueryAllTodoList()
        {
            List<TodoInfo> TodoList = new List<TodoInfo>();
            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

            try
            {   //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
                msqlCommand.Connection = msqlConnection;

                msqlCommand.CommandText = "Select * From todo;";
                MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();

                while (msqlReader.Read())
                {
                    TodoInfo todo = new TodoInfo();

                    todo.id = msqlReader.GetString("todo_id");
                    todo.date = msqlReader.GetDateTime("todo_date");
                    todo.details = msqlReader.GetString("todo_details");

                    TodoList.Add(todo);
                }

            }
            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }

            return TodoList;
        }
コード例 #5
0
        //public static void EditTodo(TodoInfo todoToEdit)
        //{
        //    MySql.Data.MySqlClient.MySqlConnection msqlConnection = null;
        //    msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password="******";database=" + dbmsCurrent + ";persist security info=False");
        //    try
        //    {   //define the command reference
        //        MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
        //        msqlCommand.Connection = msqlConnection;
        //        msqlConnection.Open();
        //        msqlCommand.CommandText = "UPDATE todo SET todo_id=@todo_id,todo_date=@todo_date,todo_details=@todo_details WHERE todo_id= @todoIdToDelete";
        //        msqlCommand.Parameters.AddWithValue("@todo_id", todoToEdit.id);
        //        msqlCommand.Parameters.AddWithValue("@todo_date", todoToEdit.date);
        //        msqlCommand.Parameters.AddWithValue("@todo_details", todoToEdit.details);
        //        msqlCommand.ExecuteNonQuery();
        //    }
        //    catch (Exception er)
        //    {
        //    }
        //    finally
        //    {
        //        //always close the connection
        //        msqlConnection.Close();
        //    }
        //}]
        public static List<TodoInfo> SearchAllTodoList(TodoInfo ToDoInfoObj)
        {
            List<TodoInfo> TodoList = new List<TodoInfo>();
            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

            try
            {   //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
                msqlCommand.Connection = msqlConnection;

                msqlCommand.CommandText = "Select * From todo where todo_date = @input or todo_details = @input;";
                msqlCommand.Parameters.AddWithValue("@input", ToDoInfoObj.details);
                MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();

                while (msqlReader.Read())
                {
                    TodoInfo todo = new TodoInfo();

                    todo.id = msqlReader.GetString("todo_id");
                    todo.date = msqlReader.GetDateTime("todo_date");
                    todo.details = msqlReader.GetString("todo_details");

                    TodoList.Add(todo);
                }

            }
            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }

            return TodoList;
        }
コード例 #6
0
        private void searchBtn_Click(object sender, RoutedEventArgs e)
        {
            TodoInfo ToDoInfoObj = new TodoInfo();
            ToDoInfoObj.details = searchTxtBlck.Text;

            List<TodoInfo> todoList = BDMSDb.DbInteraction.SearchAllTodoList(ToDoInfoObj);

            _todoCollection.Clear();

            foreach (TodoInfo todo in todoList)
            {
                _todoCollection.Add(todo);
            }
        }