Exemple #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();
        }
        internal List<ClsToDoModel> ExecuteToDo()
        {
            var reader = selectCommand.ExecuteReader();

            var list = new List<ClsToDoModel>();
            while (reader.Read() == true)
            {
                var model = new ClsToDoModel();

                model.TodoCode = Convert.ToInt32(reader[0]);
                model.Title = Convert.ToString(reader[1]);
                model.RegDate = Convert.ToDateTime(reader[2]);
                model.StartDate = ClsConvertUtil.ConvertDateTime(reader[3]);
                model.EndDate = ClsConvertUtil.ConvertDateTime(reader[4]);
                model.Detail = ClsConvertUtil.ConvertString(reader[5]);
                model.EndFlg = Convert.ToByte(reader[6]);
                list.Add(model);
            }

            return list;
        }
        internal List<ClsToDoModel> ExecuteToDo(byte flg)
        {
            if (flg == 0)
            {
                return ExecuteToDo();
            }
            else
            {

                SqlCeDataAdapter da = new SqlCeDataAdapter(selectCommand);
                DataTable dt = new DataTable("todo");

                da.Fill(dt);

                //var reader = selectCommand.ExecuteReader();

                var list = new List<ClsToDoModel>();

                foreach (DataRow r in dt.Rows)
                {
                    var model = new ClsToDoModel();

                    model.TodoCode = Convert.ToInt32(r[0]);
                    model.Title = Convert.ToString(r[1]);
                    model.RegDate = Convert.ToDateTime(r[2]);
                    model.StartDate = ClsConvertUtil.ConvertDateTime(r[3]);
                    model.EndDate = ClsConvertUtil.ConvertDateTime(r[4]);
                    model.Detail = ClsConvertUtil.ConvertString(r[5]);
                    model.EndFlg = Convert.ToByte(r[6]);
                    list.Add(model);
                }
                //while (reader.Read() == true)
                //{
                //    var model = new ClsToDoModel();

                //    model.TodoCode = Convert.ToInt32(reader[0]);
                //    model.Title = Convert.ToString(reader[1]);
                //    model.RegDate = Convert.ToDateTime(reader[2]);
                //    model.StartDate = ClsConvertUtil.ConvertDateTime(reader[3]);
                //    model.EndDate = ClsConvertUtil.ConvertDateTime(reader[4]);
                //    model.Detail = ClsConvertUtil.ConvertString(reader[5]);
                //    model.EndFlg = Convert.ToByte(reader[6]);
                //    list.Add(model);
                //}

                var whereList = from ClsToDoModel model in list where model.EndFlg == 0 select model;

                return whereList.ToList();
            }
        }
        internal int InsertToDo(ClsToDoModel model)
        {
            insertCommand.Parameters["TODO_CODE"].Value = model.TodoCode;
            insertCommand.Parameters["TITLE"].Value = model.Title;
            insertCommand.Parameters["REG"].Value = model.RegDate;
            insertCommand.Parameters["START"].Value = model.StartDate;
            insertCommand.Parameters["END"].Value = model.EndDate;
            insertCommand.Parameters["DETAIL"].Value = model.Detail;

            return insertCommand.ExecuteNonQuery();
        }