Beispiel #1
0
        /// <summary>
        /// close todo
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCloseTodo_Click(object sender, EventArgs e)
        {
            if (selectTodo == null && selectComplete == null)
            {
                MessageBox.Show("none selected");
                return;
            }

            var todo = selectTodo;

            if (todo == null)
            {
                todo = selectComplete;
            }

            if (MessageBox.Show("确定永久删除[" + todo.Content + "]吗?", "永久删除", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                if (TodoDao.Delete(todo.AddTime))
                {
                    selectTodo     = null;
                    selectComplete = null;
                    initListData();
                }
                else
                {
                    MessageBox.Show("fail");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// restore todo
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRestore_Click(object sender, EventArgs e)
        {
            if (selectComplete == null)
            {
                MessageBox.Show("none selected");
                return;
            }

            if (TodoDao.Restore(selectComplete.AddTime))
            {
                selectComplete = null;
                initListData();
            }
            else
            {
                MessageBox.Show("fail");
            }
        }
Beispiel #3
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void initListData()
        {
            var allList = TodoDao.GetAllTodos();

            // init todo data
            todoList = allList.Where(p => !p.Done).OrderByDescending(p => p.AddTime).ToList();
            var itemList = new List <ListViewItem>();

            foreach (var todo in todoList)
            {
                var item = new ListViewItem(new string[] { "", todo.Content, todo.AddTime.ToString(SHORT_TIME_TEMP) });
                //item.SubItems[2].BackColor = Color.Red;
                item.ForeColor = Color.FromArgb(255, 128, 0);
                itemList.Add(item);
            }
            this.todoView.Items.Clear();
            this.todoView.Items.AddRange(itemList.ToArray());

            // init complete data
            itemList.Clear();
            completeList = allList.Where(p => p.Done).OrderByDescending(p => p.CompleteTime).ToList();
            foreach (var complete in completeList)
            {
                var item = new ListViewItem(new string[] { "", complete.Content, complete.CompleteTime.Value.ToString(SHORT_TIME_TEMP) });
                //item.SubItems[2].BackColor = Color.Red;
                item.ForeColor = Color.FromArgb(88, 88, 88);
                itemList.Add(item);
            }
            this.completeView.Items.Clear();
            this.completeView.Items.AddRange(itemList.ToArray());

            //==other method================================================
            //也可以用this.todoView.Items.Add();不过需要在使用的前后添加Begin... 和End...防止界面自动刷新
            // 添加分组
            //this.todoView.Groups.Add(new ListViewGroup("tou"));
            //this.todoView.Groups.Add(new ListViewGroup("wei"));

            //this.todoView.Items[0].Group = this.todoView.Groups[0];
            //this.todoView.Items[1].Group = this.todoView.Groups[1];
            //=====================================================
        }
Beispiel #4
0
        /// <summary>
        /// close complete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCloseComplete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定彻底删除吗?", "彻底删除", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                if (selectComplete == null)
                {
                    MessageBox.Show("none selected");
                    return;
                }

                if (TodoDao.Delete(selectComplete.AddTime))
                {
                    selectComplete = null;
                    initListData();
                }
                else
                {
                    MessageBox.Show("fail");
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtContent.Text == "")
            {
                MessageBox.Show("your plan is empty");
                return;
            }
            var model = new ToDoModel()
            {
                Content = txtContent.Text,
                AddTime = DateTime.Now,
            };

            if (TodoDao.Add(model))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("fail");
            }
        }