Beispiel #1
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();
            }
        }
Beispiel #2
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();
            }
        }