// button Event.
        private void button_ok_Click(object sender, EventArgs e)
        {
            int    length;
            string sql;

            length = Encoding.Default.GetBytes(textBox_calendarText.Text).Length;


            if (length <= 20 && length > 0)
            {
                try {
                    sql = QueryList.overlapCheckSQL(dateStr);

                    // add schedule mode.
                    if (!modifyMode)
                    {
                        // overlap alarm check.
                        if (!overlapCheck(sql, false))
                        {
                            return;
                        }

                        // insert data. (normal)
                        if (!checkBox_multiMode.Checked)
                        {
                            sql = QueryList.insertSQL(dateStr, numericUpDown_setHour.Value, numericUpDown_setMinute.Value, textBox_calendarText.Text, checkBox_checkAlarm.Checked);
                            queryActive(sql);
                        }

                        // insert data. (multi)
                        else
                        {
                            DateTime temp_nextday = new DateTime(startDateTemp.Ticks);
                            TimeSpan temp         = DateTime.Parse(dateTimePicker_end.Value.ToString("yyyy-MM-dd")) - DateTime.Parse(startDateTemp.ToString("yyyy-MM-dd"));
                            int      dayTemp      = temp.Days;
                            bool     oncemessage  = true;

                            if (dayTemp > 0)
                            {
                                for (int count = 0; count <= dayTemp; count++, temp_nextday = temp_nextday.AddDays(1))
                                {
                                    // DB Check
                                    string[] curDateStr = temp_nextday.ToString("yyyy-MM-dd").Split('-');
                                    sql = QueryList.overlapMultiCheckSQL(curDateStr, numericUpDown_setHour.Value, numericUpDown_setMinute.Value);

                                    dbConnect.Open();
                                    SQLiteCommand    command = new SQLiteCommand(sql, dbConnect);
                                    SQLiteDataReader reader  = command.ExecuteReader();

                                    // data is already exist.
                                    if (reader.Read())
                                    {
                                        reader.Close();
                                        dbConnect.Close();
                                        if (oncemessage)
                                        {
                                            MessageBox.Show("Existing data was maintained due to overlapping schedules.");
                                        }
                                        oncemessage = false;
                                    }

                                    // data is not already exist.
                                    else
                                    {
                                        reader.Close();
                                        dbConnect.Close();

                                        sql = QueryList.insertSQL(curDateStr, numericUpDown_setHour.Value, numericUpDown_setMinute.Value, textBox_calendarText.Text, checkBox_checkAlarm.Checked);

                                        dbConnect.Open();
                                        command = new SQLiteCommand(sql, dbConnect);
                                        command.ExecuteNonQuery();
                                        dbConnect.Close();
                                    }
                                }
                                calendar.changeCalendar();
                                calendar.calendarListRefresh();
                                calendar.refreshAlarm();
                                Close();
                                return;
                            }

                            else
                            {
                                MessageBox.Show("Invalid input.\nPlease select the correct date."); return;
                            }
                        }
                    }


                    // modify schedule mode. (normal)
                    else
                    {
                        // overlap alarm check.
                        if (!overlapCheck(sql, true))
                        {
                            return;
                        }

                        // update data. (normal)
                        if (!checkBox_multiMode.Checked)
                        {
                            sql = QueryList.updateSQL(dateStr, numericUpDown_setHour.Value, numericUpDown_setMinute.Value, textBox_calendarText.Text, checkBox_checkAlarm.Checked, original_hour, original_minute);
                            queryActive(sql);
                        }

                        // update data. (multi)
                        else
                        {
                            DateTime temp_nextday = new DateTime(startDateTemp.Ticks);
                            TimeSpan temp         = DateTime.Parse(dateTimePicker_end.Value.ToString("yyyy-MM-dd")) - DateTime.Parse(startDateTemp.ToString("yyyy-MM-dd"));
                            int      dayTemp      = temp.Days;

                            if (dayTemp > 0)
                            {
                                for (int count = 0; count <= dayTemp; count++, temp_nextday = temp_nextday.AddDays(1))
                                {
                                    // DB Check
                                    string[] curDateStr = temp_nextday.ToString("yyyy-MM-dd").Split('-');
                                    sql = QueryList.overlapMultiCheckSQL(curDateStr, numericUpDown_setHour.Value, numericUpDown_setMinute.Value);

                                    dbConnect.Open();
                                    SQLiteCommand    command = new SQLiteCommand(sql, dbConnect);
                                    SQLiteDataReader reader  = command.ExecuteReader();

                                    // data is already exist.
                                    if (reader.Read())
                                    {
                                        reader.Close();
                                        dbConnect.Close();

                                        sql = QueryList.updateMultiSQL(curDateStr, numericUpDown_setHour.Value, numericUpDown_setMinute.Value, textBox_calendarText.Text, checkBox_checkAlarm.Checked);

                                        dbConnect.Open();
                                        command = new SQLiteCommand(sql, dbConnect);
                                        command.ExecuteNonQuery();
                                        dbConnect.Close();
                                    }


                                    // data is not already exist.
                                    else
                                    {
                                        reader.Close(); dbConnect.Close();
                                    }
                                }
                            }
                            calendar.changeCalendar();
                            calendar.calendarListRefresh();
                            calendar.refreshAlarm();
                            Close();
                            return;
                        }
                    }
                }
                catch (Exception exc) {
                    MessageBox.Show("Error : " + exc.Message);
                    if (dbConnect.State.ToString() == "Open")
                    {
                        dbConnect.Close();
                    }
                }
            }

            else if (length <= 0)
            {
                MessageBox.Show("You didn't enter anything!");
            }
            else
            {
                MessageBox.Show("Character size must be no larger than 20.");
            }
        }
Exemplo n.º 2
0
        /*** Method List. ***/

        // select "Add mode"
        public void addMode()
        {
            string sql;

            string[]      date;
            SQLiteCommand command;

            date = new string[3];
            date = (this.dateTimePicker_start.Value.ToString("yyyy-M-d")).Split('-');

            // duplicate check.
            sql = QueryList.overlapMultiCheckSQL(date, numericUpDown_hour.Value, numericUpDown_minute.Value);
            connect.Open();
            command = new SQLiteCommand(sql, connect);
            SQLiteDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                MessageBox.Show("Duplicate alarm time.");
                reader.Close(); connect.Close(); return;
            }

            reader.Close();
            connect.Close();


            /* normal mode */
            if (this.checkBox_isMulti.Checked == false)
            {
                // input data.
                sql = QueryList.insertSQL(date, numericUpDown_hour.Value, numericUpDown_minute.Value, textBox_text.Text, checkBox_alarm.Checked);
                connect.Open();
                command = new SQLiteCommand(sql, connect);
                command.ExecuteNonQuery();
                connect.Close();
            }


            /* multi mode */
            else
            {
                DateTime temp_nextday = new DateTime(dateTimePicker_start.Value.Ticks);
                TimeSpan temp         = DateTime.Parse(dateTimePicker_end.Value.ToString("yyyy-M-d")) - DateTime.Parse(dateTimePicker_start.Value.ToString("yyyy-M-d"));
                int      dayTemp      = temp.Days;
                bool     oncemessage  = true;

                // input data (multi).
                for (int count = 0; count <= dayTemp; count++, temp_nextday = temp_nextday.AddDays(1))
                {
                    date = new string[3];
                    date = temp_nextday.ToString("yyyy-M-d").Split('-');
                    sql  = QueryList.overlapMultiCheckSQL(date, numericUpDown_hour.Value, numericUpDown_minute.Value);

                    connect.Open();
                    command = new SQLiteCommand(sql, connect);
                    reader  = command.ExecuteReader();


                    // data is already exist.
                    if (reader.Read())
                    {
                        reader.Close(); connect.Close();
                        if (oncemessage)
                        {
                            MessageBox.Show("Existing data was maintained due to overlapping schedules."); oncemessage = false;
                        }
                    }

                    // data is not already exist.
                    else
                    {
                        reader.Close(); connect.Close();

                        sql = QueryList.insertSQL(date, numericUpDown_hour.Value, numericUpDown_minute.Value, textBox_text.Text, checkBox_alarm.Checked);
                        connect.Open(); command = new SQLiteCommand(sql, connect);
                        command.ExecuteNonQuery();
                        connect.Close();
                    }
                }
            }

            // refresh data
            refreshData();
            cmain.changeCalendar();
            cmain.calendarListRefresh();
            cmain.refreshAlarm();
        }