コード例 #1
0
ファイル: TodoDB.cs プロジェクト: maeyan/TempToDo
        /// <summary>
        /// 未処理の全Todoデータを取得
        /// </summary>
        /// <returns>Todoデータのリストを返す</returns>
        public List <TodoManager.DataType> All()
        {
            List <TodoManager.DataType> dataList = new List <TodoManager.DataType>();

            string sql = "SELECT [id], [deadline], [contents], [tobedetermined], [createtime], [deletedtime], [deleted] " +
                         "FROM [ToDo] " +
                         "WHERE ([deleted] = 0 Or [deleted] = 1 AND [deletedtime] = @deletedtime);";

            using (SqlCeCommand cmd = this.con.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.Parameters.Add("deletedtime", System.Data.DbType.DateTime);
                cmd.Parameters["deletedtime"].Value = DateTime.Now.ToString("yyyy-MM-dd");
                cmd.Prepare();

                using (SqlCeDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        TodoManager.DataType d = new TodoManager.DataType();
                        d.Contents       = reader["contents"].ToString();
                        d.CreateTime     = Convert.ToDateTime(reader["createtime"]);
                        d.Deadline       = Convert.ToDateTime(reader["deadline"]);
                        d.Id             = Convert.ToInt32(reader["id"]);
                        d.ToBeDetermined = (Convert.ToInt32(reader["tobedetermined"]) == 0) ? false : true;
                        d.Deleted        = Convert.ToInt32(reader["deleted"]);
                        d.Deletedtime    = Convert.ToDateTime(reader["deletedtime"]);

                        dataList.Add(d);
                    }
                }
            }

            return(dataList);
        }
コード例 #2
0
ファイル: TodoDB.cs プロジェクト: maeyan/TempToDo
        /// <summary>
        /// TODOデータをDBに登録する
        /// </summary>
        /// <param name="data">Todoのデータ</param>
        /// <returns>dbに登録した際のid番号を返す</returns>
        public int InsertToDo(TodoManager.DataType data)
        {
            int id = 0;

            try
            {
                using (SqlCeTransaction trans = this.con.BeginTransaction())
                {
                    using (SqlCeCommand cmd = this.con.CreateCommand())
                    {
                        string sql = @"INSERT INTO [ToDo] (deadline, contents, tobedetermined, createtime, updatetime, deletedtime, deleted) "
                                     + @"values (@deadline, @contents, @tobedetermined, @createtime, @updatetime, @deletedtime, @deleted);";
                        cmd.CommandText = sql;

                        cmd.Parameters.Add("deadline", System.Data.DbType.DateTime);
                        cmd.Parameters.Add("contents", System.Data.DbType.String);
                        cmd.Parameters.Add("tobedetermined", System.Data.DbType.Int32);
                        cmd.Parameters.Add("createtime", System.Data.DbType.DateTime);
                        cmd.Parameters.Add("updatetime", System.Data.DbType.DateTime);
                        cmd.Parameters.Add("deletedtime", System.Data.DbType.String);
                        cmd.Parameters.Add("deleted", System.Data.DbType.Int32);

                        cmd.Parameters["deadline"].Value       = data.Deadline.ToString("yyyy-MM-dd");
                        cmd.Parameters["contents"].Value       = data.Contents;
                        cmd.Parameters["tobedetermined"].Value = data.ToBeDetermined;
                        cmd.Parameters["createtime"].Value     = DateTime.Now.ToString("yyyy-MM-dd");
                        cmd.Parameters["updatetime"].Value     = new DateTime(0).ToString("yyyy-MM-dd");
                        cmd.Parameters["deletedtime"].Value    = DateTime.Now.ToString("yyyy-MM-dd");
                        cmd.Parameters["deleted"].Value        = 0;

                        cmd.Prepare();
                        cmd.ExecuteNonQuery();

                        trans.Commit();

                        // 挿入したidを何かしらで取得する
                        cmd.CommandText = "SELECT  MAX(id) FROM ToDo;";
                        id = Convert.ToInt32(cmd.ExecuteScalar());
                    }
                }
            }
            catch
            {
                throw;
            }

            return(id);
        }
コード例 #3
0
ファイル: TodoDB.cs プロジェクト: maeyan/TempToDo
        /// <summary>
        /// ToDoデータの更新
        /// </summary>
        /// <param name="data">ToDoデータ</param>
        public void UpdateTodo(TodoManager.DataType data)
        {
            try
            {
                using (SqlCeTransaction trans = this.con.BeginTransaction())
                {
                    using (SqlCeCommand cmd = this.con.CreateCommand())
                    {
                        string sql = @"UPDATE [ToDo] "
                                     + "SET deadline = @deadline, contents = @contents, tobedetermined = @tobedetermined, updatetime = @updatetime "
                                     + "WHERE id = @id;";
                        cmd.CommandText = sql;

                        cmd.Parameters.Add("deadline", System.Data.DbType.DateTime);
                        cmd.Parameters.Add("contents", System.Data.DbType.String);
                        cmd.Parameters.Add("tobedetermined", System.Data.DbType.Int32);
                        cmd.Parameters.Add("updatetime", System.Data.DbType.DateTime);
                        cmd.Parameters.Add("id", System.Data.DbType.Int32);

                        cmd.Parameters["deadline"].Value       = data.Deadline.ToString("yyyy-MM-dd");
                        cmd.Parameters["contents"].Value       = data.Contents;
                        cmd.Parameters["tobedetermined"].Value = data.ToBeDetermined;
                        cmd.Parameters["updatetime"].Value     = DateTime.Now.ToString("yyyy-MM-dd");
                        cmd.Parameters["id"].Value             = data.Id;

                        cmd.Prepare();
                        cmd.ExecuteNonQuery();

                        trans.Commit();
                    }
                }
            }
            catch
            {
                throw;
            }
        }
コード例 #4
0
        /// <summary>
        /// Todoデータを作成する
        /// </summary>
        /// <param name="data">作成に必要なTodoデータ</param>
        /// <param name="completeTaskStyle">完了タスクの表示方法</param>
        /// <param name="modify">修正ボタンを押した際の挙動(フォーム部分の変更を行う受け取る)</param>
        /// <returns>PanelにTodoデータを載せてそれを返す</returns>
        public Panel Create(TodoManager.DataType data, TodoManager.CompleteTaskShowStyle completeTaskStyle, Action <string, string, string> modify)
        {
            // 修正ボタンを押した際に、このメソッドを使うとフォームの変更が行える
            this.modify = modify;

            // 何日後?
            Label lblCountDown = new Label();

            if (data.ToBeDetermined)
            {
                lblCountDown.Text = "未定…";
            }
            else
            {
                int countdown = (data.Deadline - DateTime.Today).Days;
                if (countdown == 0)
                {
                    lblCountDown.ForeColor = Color.Blue;
                    lblCountDown.Text      = "本日期限";
                }
                else if (countdown < 0)
                {
                    lblCountDown.ForeColor = Color.Red;
                    lblCountDown.Text      = string.Format("{0}日遅延", Math.Abs(countdown).ToString());
                }
                else
                {
                    lblCountDown.Text = string.Format("{0}日後", countdown.ToString());
                }
            }

            lblCountDown.AutoSize    = true;
            lblCountDown.Location    = new Point(5, 5);
            lblCountDown.Tag         = "CountDown";
            lblCountDown.MouseEnter += new System.EventHandler(this.Label_MouseEnter);
            lblCountDown.MouseLeave += new System.EventHandler(this.Label_MouseLeave);
            lblCountDown.Click      += new System.EventHandler(this.LblTodoDeleteClick);

            // 修正ボタン
            Button btnModify = new Button();

            btnModify.AutoSize  = false;
            btnModify.BackColor = Color.FromArgb(150, 150, 150);
            btnModify.FlatStyle = FlatStyle.Flat;
            btnModify.Font      = new Font("メイリオ", 8);
            btnModify.ForeColor = Color.White;
            btnModify.Location  = new Point(5, 25);
            btnModify.Size      = new Size(50, 25);
            //// btnModify.Tag = "ModifyButton"; // Tagは、別なところで使っているため指定したらだめ
            btnModify.Text        = "修正";
            btnModify.Visible     = false;
            btnModify.MouseEnter += new System.EventHandler(this.Label_MouseEnter);
            btnModify.MouseLeave += new System.EventHandler(this.Label_MouseLeave);
            btnModify.Click      += new EventHandler(this.BtnModify_Click);

            // DeadLine
            Label lblDeadLine = new Label();

            lblDeadLine.AutoSize    = true;
            lblDeadLine.ForeColor   = Color.FromArgb(150, 150, 150);
            lblDeadLine.Location    = new Point(635, 30);
            lblDeadLine.Tag         = "DeadLine";
            lblDeadLine.Text        = data.ToBeDetermined ? string.Empty : data.Deadline.ToString("yyyy-MM-dd(ddd)");
            lblDeadLine.MouseEnter += new System.EventHandler(this.Label_MouseEnter);
            lblDeadLine.MouseLeave += new System.EventHandler(this.Label_MouseLeave);
            lblDeadLine.Click      += new System.EventHandler(this.LblTodoDeleteClick);

            // Contents
            Label lblContents = new Label();

            lblContents.AutoSize    = false;
            lblContents.Location    = new Point(Todo.LblContentsLeft, 5);
            lblContents.Size        = new Size(660, 40); // 555,40
            lblContents.Tag         = "Contents";
            lblContents.Text        = data.Contents;
            lblContents.Click      += new System.EventHandler(this.LblTodoDeleteClick);
            lblContents.MouseEnter += new System.EventHandler(this.Label_MouseEnter);
            lblContents.MouseLeave += new System.EventHandler(this.Label_MouseLeave);

            // CreateTime
            Label lblCreateTime = new Label();

            lblCreateTime.Text    = data.CreateTime.ToString("yyyy-MM-dd");
            lblCreateTime.Tag     = "CreateTime";
            lblCreateTime.Visible = false;

            // Panel
            Panel pnlArea = new Panel();

            pnlArea.BackColor = DefaultBGColor;
            pnlArea.Controls.Add(lblCountDown);
            pnlArea.Controls.Add(lblDeadLine);
            pnlArea.Controls.Add(lblContents);
            pnlArea.Controls.Add(lblCreateTime);
            pnlArea.Controls.Add(btnModify);
            pnlArea.Size        = new Size(Todo.PnlAreaWidth, 50);
            pnlArea.Tag         = data.Id.ToString();
            pnlArea.MouseEnter += new System.EventHandler(this.PnlArea_MouseEnter);
            pnlArea.MouseLeave += new System.EventHandler(this.PnlArea_MouseLeave);
            pnlArea.Click      += new System.EventHandler(this.PnlTodoDeleteClick);

            // 完了タスクの場合は、完了タスク用のしょりを行う
            if (data.Deleted == 1)
            {
                this.ChangeCompleteTaskStyle(pnlArea, completeTaskStyle);
            }

            return(pnlArea);
        }