コード例 #1
0
        // 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.");
            }
        }