Пример #1
0
        //Thêm chức năng nút xóa cho deadline

        void DL_Deleted(object sender, EventArgs e)
        {
            DeadLineControl DL  = sender as DeadLineControl;
            string          sql = $"delete from Deadline where IdDeadline = {DL.Tag}";

            NoteData.UpdateInsertDelete(sql);
            ControlPanel.Controls.Remove(DL);
            ControlPanel.Controls.Clear();
            AddNoteToDay();
        }
Пример #2
0
        //Thêm chức năng nút xóa cho lập lịch
        void Td_Deleted(object sender, EventArgs e)
        {
            ToDoControl Td  = sender as ToDoControl;
            string      sql = $"delete from NoteByDate where IdNote = {Td.Tag}";

            NoteData.UpdateInsertDelete(sql);
            ControlPanel.Controls.Remove(Td);
            ControlPanel.Controls.Clear();
            AddNoteToDay();
        }
Пример #3
0
        //Thay đổi trạng thái done

        private void DL_Done(object sender, EventArgs e)
        {
            string          sql;
            DeadLineControl DLC = sender as DeadLineControl;

            if (DLC.DoneCB.Checked == true)
            {
                sql = $"update Deadline set Priority = '{5}' where IdDeadline = { DLC.Tag}";
                NoteData.UpdateInsertDelete(sql);
                AddNoteToDay();
            }
            else
            {
                sql = $"update Deadline set Priority = '{0}' where IdDeadline = { DLC.Tag}";
                NoteData.UpdateInsertDelete(sql);
                AddNoteToDay();
            }
        }
Пример #4
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            if (MainNote.Text == "Ghi chú")
            {
                MessageBox.Show("Ghi chú không được rỗng", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (DescriptionTB.Text == "Mô tả")
            {
                DescriptionTB.Text = null;
            }
            if (ImportantCheck.Checked == true)
            {
                ImportanceCheck = 1;
            }
            else
            {
                ImportanceCheck = 0;
            }
            Dtpk.Value = new DateTime(Dtpk.Value.Year, Dtpk.Value.Month, Dtpk.Value.Day, Int32.Parse(HoursCB.Text), Int32.Parse(MinutesCB.Text), 0);
            string sql;

            if (NoteData.IsConfirm("Bạn có muốn lưu lại?"))
            {
                try
                {
                    if (IDDeadLine == 0)
                    {
                        switch (UrgentCB.SelectedIndex)
                        {
                        case 0:
                            sql = $"insert into Deadline(DeadlineText,DescriptionText,DateEnd,TimeHEnd,TimeMEnd,Importance,UrgentCount)" +
                                  $"values('{MainNote.Text}','{DescriptionTB.Text}','{Dtpk.Value}','{HoursCB.Text}','{MinutesCB.Text}','{ImportanceCheck}','{1}')";
                            NoteData.UpdateInsertDelete(sql);
                            break;

                        case 1:
                            sql = $"insert into Deadline(DeadlineText,DescriptionText,DateEnd,TimeHEnd,TimeMEnd,Importance,UrgentCount)" +
                                  $"values('{MainNote.Text}','{DescriptionTB.Text}','{Dtpk.Value}','{HoursCB.Text}','{MinutesCB.Text}','{ImportanceCheck}','{3}')";
                            NoteData.UpdateInsertDelete(sql);
                            break;

                        case 2:
                            sql = $"insert into Deadline(DeadlineText,DescriptionText,DateEnd,TimeHEnd,TimeMEnd,Importance,UrgentCount)" +
                                  $"values('{MainNote.Text}','{DescriptionTB.Text}','{Dtpk.Value}','{HoursCB.Text}','{MinutesCB.Text}','{ImportanceCheck}','{7}')";
                            NoteData.UpdateInsertDelete(sql);
                            break;

                        case 3:
                            sql = $"insert into Deadline(DeadlineText,DescriptionText,DateEnd,TimeHEnd,TimeMEnd,Importance,UrgentCount)" +
                                  $"values('{MainNote.Text}','{DescriptionTB.Text}','{Dtpk.Value}','{HoursCB.Text}','{MinutesCB.Text}','{ImportanceCheck}','{14}')";
                            NoteData.UpdateInsertDelete(sql);
                            break;
                        }
                    }
                    else
                    {
                        switch (UrgentCB.SelectedIndex)
                        {
                        case 0:
                            sql = $"update Deadline set DeadlineText = '{MainNote.Text}', DescriptionText = '{DescriptionTB.Text}', DateEnd = '{Dtpk.Value}', TimeHEnd = '{HoursCB.Text}', TimeMEnd = '{MinutesCB.Text}', Importance = '{ImportanceCheck}',UrgentCount = '{1}' where IdDeadline = {IDDeadLine}";
                            NoteData.UpdateInsertDelete(sql);
                            break;

                        case 1:
                            sql = $"update Deadline set DeadlineText = '{MainNote.Text}', DescriptionText = '{DescriptionTB.Text}', DateEnd = '{Dtpk.Value}', TimeHEnd = '{HoursCB.Text}', TimeMEnd = '{MinutesCB.Text}', Importance = '{ImportanceCheck}',UrgentCount = '{3}' where IdDeadline = {IDDeadLine}";
                            NoteData.UpdateInsertDelete(sql);
                            break;

                        case 2:
                            sql = $"update Deadline set DeadlineText = '{MainNote.Text}', DescriptionText = '{DescriptionTB.Text}', DateEnd = '{Dtpk.Value}', TimeHEnd = '{HoursCB.Text}', TimeMEnd = '{MinutesCB.Text}', Importance = '{ImportanceCheck}',UrgentCount = '{7}' where IdDeadline = {IDDeadLine}";
                            NoteData.UpdateInsertDelete(sql);
                            break;

                        case 3:
                            sql = $"update Deadline set DeadlineText = '{MainNote.Text}', DescriptionText = '{DescriptionTB.Text}', DateEnd = '{Dtpk.Value}', TimeHEnd = '{HoursCB.Text}', TimeMEnd = '{MinutesCB.Text}', Importance = '{ImportanceCheck}',UrgentCount = '{14}' where IdDeadline = {IDDeadLine}";
                            NoteData.UpdateInsertDelete(sql);
                            break;
                        }
                    }
                    MessageBox.Show("Lưu dữ liệu thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Lưu dữ liệu thất bại!", "Báo Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Пример #5
0
        //Thêm Note hoặc Deadline
        public void AddNoteToDay()
        {
            int y = 0;
            int i = 0;

            //Thêm lập lịch

            if (Button == 1)
            {
                ControlPanel.Controls.Clear();
                AddJobBtn.Text        = "Thêm Công việc";
                DeadlineLabel.Visible = false;
                Dtpk.Visible          = true;
                NextBtn.Visible       = true;
                PreviousBtn.Visible   = true;

                DateTime datefirst = new DateTime(Dtpk.Value.Year, Dtpk.Value.Month, Dtpk.Value.Day, 0, 0, 0);
                DateTime dateafter = datefirst.AddDays(1).AddSeconds(-1);

                string    sql = $"select * from NoteByDate where AppDate between #{datefirst.ToShortDateString()}# and #{dateafter.ToShortDateString()}# order by FromH asc, FromM asc";
                DataTable dt  = NoteData.QueryAsDatatable(sql);

                foreach (DataRow row in dt.Rows)
                {
                    ToDoControl Td = new ToDoControl();
                    Td.BackColor = System.Drawing.Color.Transparent;
                    Td.Location  = new System.Drawing.Point(1, -1 + y);
                    Td.Size      = new System.Drawing.Size(787, 86);
                    Td.TabIndex  = i++;
                    c.Id         = Convert.ToInt32(row["IdNote"]);
                    if (Convert.ToInt32(row["Important"]) == 1)
                    {
                        c.CheckImportant = true;
                    }
                    else
                    {
                        c.CheckImportant = false;
                    }
                    Td.Tag        = Convert.ToInt32(row["IdNote"]);
                    c.Date        = Convert.ToDateTime(row["AppDate"]);
                    c.Description = row["Description"].ToString();
                    c.FHours      = Convert.ToInt32(row["FromH"]);
                    c.FMinutes    = Convert.ToInt32(row["FromM"]);
                    c.THours      = Convert.ToInt32(row["ToH"]);
                    c.TMinutes    = Convert.ToInt32(row["ToM"]);
                    c.Notes       = row["NoteText"].ToString();
                    Td.AddDetails(c);
                    Td.Deleted += Td_Deleted;
                    Td.Edited  += Td_Edited;
                    Td.Details += Td_Details;
                    ControlPanel.Controls.Add(Td);
                    y += Td.Height;
                }
            }

            //Thêm Deadline

            if (Button == 2)
            {
                AddJobBtn.Text = "Thêm Deadline";
                ControlPanel.Controls.Clear();
                DeadlineLabel.Visible = true;
                Dtpk.Visible          = false;
                NextBtn.Visible       = false;
                PreviousBtn.Visible   = false;

                string    sql = $"select * from Deadline";
                DataTable dt  = NoteData.QueryAsDatatable(sql);
                foreach (DataRow row in dt.Rows)
                {
                    if (Convert.ToInt32(row["Priority"]) != 5)
                    {
                        if (DateTime.Now > Convert.ToDateTime(row["DateEnd"]))
                        {
                            sql = $"update Deadline set Priority ='{6}' where IdDeadline =" + Convert.ToInt32(row["IdDeadLine"]);
                            NoteData.UpdateInsertDelete(sql);
                        }
                        else if (DateTime.Now.AddDays(Convert.ToInt32(row["UrgentCount"])) >= Convert.ToDateTime(row["DateEnd"]) && Convert.ToInt32(row["Importance"]) == 1)
                        {
                            sql = $"update Deadline set Priority = '{1}' where IdDeadline = " + Convert.ToInt32(row["IdDeadLine"]);
                            NoteData.UpdateInsertDelete(sql);
                        }
                        else if (DateTime.Now.AddDays(Convert.ToInt32(row["UrgentCount"])) < Convert.ToDateTime(row["DateEnd"]) && Convert.ToInt32(row["Importance"]) == 1)
                        {
                            sql = $"update Deadline set Priority = '{2}' where IdDeadline = " + Convert.ToInt32(row["IdDeadLine"]);
                            NoteData.UpdateInsertDelete(sql);
                        }
                        else if (DateTime.Now.AddDays(Convert.ToInt32(row["UrgentCount"])) >= Convert.ToDateTime(row["DateEnd"]) && Convert.ToInt32(row["Importance"]) == 0)
                        {
                            sql = $"update Deadline set Priority = '{3}' where IdDeadline = " + Convert.ToInt32(row["IdDeadLine"]);
                            NoteData.UpdateInsertDelete(sql);
                        }
                        else if (DateTime.Now.AddDays(Convert.ToInt32(row["UrgentCount"])) < Convert.ToDateTime(row["DateEnd"]) && Convert.ToInt32(row["Importance"]) == 0)
                        {
                            sql = $"update Deadline set Priority = '{4}' where IdDeadline = " + Convert.ToInt32(row["IdDeadLine"]);
                            NoteData.UpdateInsertDelete(sql);
                        }
                    }
                }
                sql = $"select * from Deadline order by Priority asc, DateEnd asc";
                dt  = NoteData.QueryAsDatatable(sql);
                foreach (DataRow row in dt.Rows)
                {
                    DeadLineControl DL = new DeadLineControl();
                    DL.BackColor = System.Drawing.Color.Transparent;
                    DL.Location  = new System.Drawing.Point(1, -1 + y);
                    DL.Size      = new System.Drawing.Size(787, 94);
                    DL.TabIndex  = i++;
                    DL.Tag       = Convert.ToInt32(row["IdDeadline"]);
                    if (Convert.ToInt32(row["Priority"]) == 5)
                    {
                        DL.DoneCB.Checked = true;
                    }
                    if (Convert.ToInt32(row["Importance"]) == 1)
                    {
                        d.CheckImportant = true;
                    }
                    else
                    {
                        d.CheckImportant = false;
                    }
                    d.Id          = Convert.ToInt32(row["IdDeadline"]);
                    d.Urgent      = Convert.ToInt32(row["UrgentCount"]);
                    d.Priorities  = Convert.ToInt32(row["Priority"]);
                    d.Date        = Convert.ToDateTime(row["DateEnd"]);
                    d.Description = row["DescriptionText"].ToString();
                    d.Notes       = row["DeadlineText"].ToString();
                    d.HoursEnd    = Convert.ToInt32(row["TimeHEnd"]);
                    d.MinutesEnd  = Convert.ToInt32(row["TimeMEnd"]);
                    ControlPanel.Controls.Add(DL);
                    DL.Deleted += DL_Deleted;
                    DL.Edited  += DL_Edited;
                    DL.AddDetails(d);
                    DL.Details += DL_Details;
                    DL.Done    += DL_Done;
                    y          += DL.Height;
                }
            }
        }
Пример #6
0
        private void SaveBtn_Click_1(object sender, EventArgs e)
        {
            if (MainNote.Text == "Nhập ghi chú")
            {
                MessageBox.Show("Ghi chú không được rỗng!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (DescriptionTB.Text == "Mô tả")
            {
                DescriptionTB.Text = null;
            }
            if ((Convert.ToInt32(FHoursCB.Text) > Convert.ToInt32(THoursCB.Text)) || ((Convert.ToInt32(FHoursCB.Text) == Convert.ToInt32(THoursCB.Text)) && (Convert.ToInt32(FMinutesCB.Text) > Convert.ToInt32(TMinutesCB.Text))) || FromDtpk.Value > ToDtpk.Value)
            {
                MessageBox.Show("Đặt thời gian không hợp lệ!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (ImportantCheck.Checked == true)
            {
                Check = 1;
            }
            else
            {
                Check = 0;
            }
            string sql;

            if (NoteData.IsConfirm("Bạn có muốn lưu lại?"))
            {
                FromDtpk.Value = new DateTime(FromDtpk.Value.Year, FromDtpk.Value.Month, FromDtpk.Value.Day, 0, 0, 0);
                ToDtpk.Value   = new DateTime(ToDtpk.Value.Year, ToDtpk.Value.Month, ToDtpk.Value.Day, 0, 0, 0);
                if (IdNote == 0)
                {
                    if (RepeatCB.SelectedIndex == 0)
                    {
                        FromDtpk.Value.AddSeconds(1);
                        sql = $"insert into NoteByDate(NoteText,Description,AppDate,FromH,FromM,ToH,ToM,Important) " +
                              $"values('{MainNote.Text}','{DescriptionTB.Text}','{FromDtpk.Value}','{FHoursCB.Text}','{FMinutesCB.Text}','{THoursCB.Text}','{TMinutesCB.Text}','{Check}')";
                        NoteData.UpdateInsertDelete(sql);
                    }
                    else if (RepeatCB.SelectedIndex == 1)
                    {
                        while (FromDtpk.Value <= ToDtpk.Value)
                        {
                            sql = $"insert into NoteByDate(NoteText,Description,AppDate,FromH,FromM,ToH,ToM,Important) " +
                                  $"values('{MainNote.Text}','{DescriptionTB.Text}','{FromDtpk.Value}','{FHoursCB.Text}','{FMinutesCB.Text}','{THoursCB.Text}','{TMinutesCB.Text}','{Check}')";
                            NoteData.UpdateInsertDelete(sql);
                            FromDtpk.Value = FromDtpk.Value.AddDays(1);
                        }
                    }
                    else if (RepeatCB.SelectedIndex == 2)
                    {
                        while (FromDtpk.Value <= ToDtpk.Value)
                        {
                            sql = $"insert into NoteByDate(NoteText,Description,AppDate,FromH,FromM,ToH,ToM,Important)" +
                                  $"values('{MainNote.Text}','{DescriptionTB.Text}','{FromDtpk.Value}','{FHoursCB.Text}','{FMinutesCB.Text}','{THoursCB.Text}','{TMinutesCB.Text}','{Check}')";
                            NoteData.UpdateInsertDelete(sql);
                            FromDtpk.Value = FromDtpk.Value.AddDays(7);
                        }
                    }
                    else if (RepeatCB.SelectedIndex == 3)
                    {
                        while (FromDtpk.Value <= ToDtpk.Value)
                        {
                            sql = $"insert into NoteByDate(NoteText,Description,AppDate,FromH,FromM,ToH,ToM,Important) " +
                                  $"values('{MainNote.Text}','{DescriptionTB.Text}','{FromDtpk.Value}','{FHoursCB.Text}','{FMinutesCB.Text}','{THoursCB.Text}','{TMinutesCB.Text}','{Check}')";
                            NoteData.UpdateInsertDelete(sql);
                            FromDtpk.Value = FromDtpk.Value.AddMonths(1);
                        }
                    }
                    else if (RepeatCB.SelectedIndex == 4)
                    {
                        while (FromDtpk.Value <= ToDtpk.Value)
                        {
                            sql = $"insert into NoteByDate(NoteText,Description,AppDate,FromH,FromM,ToH,ToM,Important) " +
                                  $"values('{MainNote.Text}','{DescriptionTB.Text}','{FromDtpk.Value}','{FHoursCB.Text}','{FMinutesCB.Text}','{THoursCB.Text}','{TMinutesCB.Text}','{Check}')";
                            NoteData.UpdateInsertDelete(sql);
                            FromDtpk.Value = FromDtpk.Value.AddYears(1);
                        }
                    }
                }
                else
                {
                    sql = $"update NoteByDate set NoteText = '{MainNote.Text}', Description = '{DescriptionTB.Text}', AppDate = '{FromDtpk.Value}', FromH = '{FHoursCB.Text}', FromM = '{FMinutesCB.Text}', ToH = '{THoursCB.Text}', ToM = '{TMinutesCB.Text}', Important = '{Check}' where IdNote = {IdNote}";
                    NoteData.UpdateInsertDelete(sql);
                }
                MessageBox.Show("Lưu dữ liệu thành công.", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }