Пример #1
0
 public void saveButton_Click(object sender, EventArgs e)
 {
     if (bEName.Text == "")
     {
         MessageBox.Show("Введите название");
     }
     else if (bENote.Text == "")
     {
         MessageBox.Show("Введите запись");
     }
     else if (mainForm.connectionOpened == false)
     {
         MessageBox.Show("Выберите базу");
     }
     else
     {
         date = dateTimePicker.Value.Day.ToString() + "-" + dateTimePicker.Value.Month.ToString() + "-" + dateTimePicker.Value.Year.ToString();
         time = dateTimePicker.Value.Hour.ToString() + ":" + dateTimePicker.Value.Minute.ToString();
         if (reminderActivator.Checked == true)
         {
             checkStatus = 1;
         }
         else
         {
             checkStatus = 0;
         }
         string        sql     = "INSERT INTO notes (id, name, note, notification, date, time) VALUES (NULL, " + bEName.Text + ", " + bENote.Text + ", '" + checkStatus + "', '" + date + "', '" + time + "')";
         SQLiteCommand command = new SQLiteCommand(sql, mainForm.m_dbConnection);
         command.ExecuteNonQuery();
         mainForm.refresh();
         MessageBox.Show("Запись создана");
         Close();
     }
 }
Пример #2
0
        public void create_Click(object sender, EventArgs e)
        {
            if (regex.IsMatch(baseName.Text, 0) == true)
            {
                MessageBox.Show("Название должно быть без спец-символов");
            }
            else if (System.IO.File.Exists("bases\\" + baseName.Text + ".db"))
            {
                MessageBox.Show("База с таким названием уже существует");
            }
            else if (baseName.Text == "")
            {
                MessageBox.Show("Введите название");
            }
            else
            {
                filename       = "bases\\" + baseName.Text + ".db";
                m_dbConnection = new SQLiteConnection("Data Source=" + filename + "; Version=3;");
                m_dbConnection.Open();
                string        sql3     = "CREATE TABLE notes (id integer primary key, name varchar(30), note varchar(1000), notification int, date varchar(10), time varchar(5))";
                SQLiteCommand command3 = new SQLiteCommand(sql3, m_dbConnection);
                command3.ExecuteNonQuery();

                string        sql4     = "INSERT INTO notes (id, name, note, notification, date, time) VALUES (NULL, 'Имя', 'Пример заметки', 0, '01-01-1970', '00:00')";
                SQLiteCommand command4 = new SQLiteCommand(sql4, m_dbConnection);
                command4.ExecuteNonQuery();
                DialogResult dialogResult = MessageBox.Show("Выбрать эту базу?", "", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    if (mainForm.connectionOpened == true)
                    {
                        mainForm.m_dbConnection.Close();
                        System.Data.SQLite.SQLiteConnection.ClearAllPools();
                        GC.Collect();
                    }
                    mainForm.m_dbConnection = new SQLiteConnection("Data Source=" + filename + "; Version=3;");
                    mainForm.m_dbConnection.Open();
                    mainForm.refresh();
                    ConfigurationManager.AppSettings["lastBase"] = filename;
                    mainForm.connectionOpened = true;
                }

                Close();
            }
        }