Exemplo n.º 1
0
        private void btnReg_Click(object sender, EventArgs e)
        {
            string errMsg = Validate();
            if (string.IsNullOrEmpty(errMsg) == false)
            {
                MessageBox.Show(this,errMsg,this.Text,MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }

            var exDao = new ClsExecuteDao(dao.Connection);

            var list = exDao.ExecuteToDo();
            ClsToDoModel insertModel = null;
            if (list.Count == 0)
            {
                insertModel = new ClsToDoModel()
                {
                    TodoCode = 1,
                    Title = textBox1.Text,
                    RegDate = DateTime.Today,
                    StartDate = dateTimePicker2.Value,
                    EndDate = dateTimePicker3.Value,
                    Detail = textBox2.Text
                };

            }
            else
            {
                insertModel = list.Last();
                insertModel.TodoCode = insertModel.TodoCode + 1;
                insertModel.Title = textBox1.Text;
                insertModel.RegDate = DateTime.Today;
                insertModel.StartDate = dateTimePicker2.Value;
                insertModel.EndDate = dateTimePicker3.Value;
                insertModel.Detail = textBox2.Text;
            }

            int result = exDao.InsertToDo(insertModel);

            if (result != 1)
            {
                MessageBox.Show(this, "登録が正常に行われませんでした", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                MessageBox.Show(this, "登録に成功しました", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            Clear();
        }