コード例 #1
0
ファイル: DataBase.cs プロジェクト: slicenbeat/SmartLearn
        public void LoadCardList(CardList D)        // Перенос имнофрмации из бд в объект CardList D
        {
            D.SetCurrent(1);
            DB = new SQLiteConnection("Data Source=DB.db; Version=3");
            DB.Open();
            SQLiteCommand CMD = DB.CreateCommand();

            CMD.CommandText = "SELECT Count(*) From " + '\u0022' + D.GetName() + '\u0022';      // Количество строк в таблице бд
            string s = CMD.ExecuteScalar().ToString();

            int size = Convert.ToInt32(s);

            SQLiteCommand    CMD1 = DB.CreateCommand();
            SQLiteDataReader SQL;

            for (int i = 1; i < size + 1; i++)
            {
                CMD1.CommandText = "SELECT * FROM " + '\u0022' + D.GetName() + '\u0022' + " WHERE id like '%' || @Numb || '%' ";      // Выбрать строку таблицы бд в номером i
                CMD1.Parameters.Add("@Numb", DbType.Int16).Value = i;                                                                 //
                SQL = CMD1.ExecuteReader();                                                                                           //
                SQL.Read();                                                                                                           //
                DateTime T = DateTime.Parse(SQL["time"].ToString());                                                                  //
                Card     C = new Card(SQL["question"].ToString(), SQL["answer"].ToString(), T, Int32.Parse(SQL["level"].ToString())); // и перенести информацию из этой строки в объект Card C
                D.Add(C);
                SQL.Close();
            }
        }
コード例 #2
0
 //Изучение колоды
 private void bLearnCardList_Click(object sender, EventArgs e)
 {
     try
     {
         if (CardListComboBox.SelectedItem == null)
         {
             throw new Exception();
         }
         this.Deck = new CardList(CardListComboBox.SelectedItem.ToString());
         Deck.SetCurrent(0);
         db = new DataBase();
         int size = Convert.ToInt32(db.GetCountCardList(Deck));
         if (size < 3)
         {
             MessageBox.Show("Для того, чтобы учить колоду, в ней должно быть не менее трёх карт.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             ReviewForm reviewform = new ReviewForm(Deck);
             reviewform.StyleManager = this.StyleManager;
             reviewform.ShowDialog();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Выберите колоду, с которой вы будете работать.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
コード例 #3
0
ファイル: DataBase.cs プロジェクト: slicenbeat/SmartLearn
        public void DeleteCard(CardList Deck)       // Удаление колоды
        {
            DB = new SQLiteConnection("Data Source=DB.db; Version=3");
            DB.Open();
            SQLiteCommand CMD = DB.CreateCommand();

            CMD.CommandText = " DROP TABLE '" + Deck.GetName() + "'; ";         // Удаление колоды
            CMD.ExecuteNonQuery();


            SQLiteCommand CMD1 = DB.CreateCommand();

            // Создание колоды с таким же именем
            CMD1.CommandText = "CREATE TABLE '" + Deck.GetName() + "' (id INTEGER PRIMARY KEY AUTOINCREMENT, question VARCHAR(1000) NOT NULL, answer VARCHAR(1000) NOT NULL, level INTEGER NOT NULL, time VARCHAR(1000)); ";
            CMD1.ExecuteNonQuery();

            SQLiteCommand CMD2 = DB.CreateCommand();

            for (int i = 0; i < Deck.Cards.Count; i++)                          // Перезапись колоды без удаленной карты
            {
                CMD2.CommandText = "insert into '" + Deck.GetName() + "'(question, answer, level, time) values( @question , @answer, @level, @time)";
                CMD2.Parameters.Add("@question", DbType.String).Value = Deck.Cards[i].GetQuestion();
                CMD2.Parameters.Add("@answer", DbType.String).Value   = Deck.Cards[i].GetAnswer();
                CMD2.Parameters.Add("@level", DbType.Int32).Value     = Deck.Cards[i].GetLevel();
                CMD2.Parameters.Add("@time", DbType.String).Value     = Deck.Cards[i].GetTime().ToString();
                CMD2.ExecuteNonQuery();
            }
        }
コード例 #4
0
ファイル: DataBase.cs プロジェクト: slicenbeat/SmartLearn
        public string GetCountCardList(CardList deck)       // Вернуть количество строк в колоде
        {
            DB = new SQLiteConnection("Data Source=DB.db; Version=3");
            DB.Open();
            SQLiteCommand CMD = DB.CreateCommand();

            CMD.CommandText = "SELECT Count(*) From " + '\u0022' + deck.GetName() + '\u0022';
            return(CMD.ExecuteScalar().ToString());
        }
コード例 #5
0
ファイル: DataBase.cs プロジェクト: slicenbeat/SmartLearn
        public void InsertCard(CardList D, DateTime t, string q, string ans)        // Добавление карты
        {
            DB = new SQLiteConnection("Data Source=DB.db; Version=3");
            DB.Open();
            string        name = D.GetName();
            SQLiteCommand CMD  = DB.CreateCommand();

            // Добавление карты в конец колоды
            CMD.CommandText = "INSERT INTO'" + name + "'(question, answer, level, time) VALUES( @question , @answer , @level , @time ); ";
            CMD.Parameters.Add("@question", System.Data.DbType.String).Value = q;
            CMD.Parameters.Add("@answer", System.Data.DbType.String).Value   = ans;
            CMD.Parameters.Add("@level", System.Data.DbType.Int32).Value     = 0;
            CMD.Parameters.Add("@time", System.Data.DbType.String).Value     = t.ToString();
            CMD.ExecuteNonQuery();
        }
コード例 #6
0
ファイル: DataBase.cs プロジェクト: slicenbeat/SmartLearn
 public void UpdateCard(CardList d, string q, string ans, int index)     // Изменение строки в бд
 {
     DB = new SQLiteConnection("Data Source=DB.db; Version=3");
     DB.Open();
     using (SQLiteConnection con = new SQLiteConnection("Data Source=DB.db; Version=3"))
     {
         string        name = d.GetName();
         SQLiteCommand CMD  = DB.CreateCommand();
         // Изменение всех полей строки с номером index в колоде
         CMD.CommandText = @"Update '" + name + "' Set question = '" + q + "', answer = '" + ans + "', level = '" + d.Cards[index].GetLevel() + "', time = '" + d.Cards[index].GetTime().ToString() + "' Where id = '" + (index + 1).ToString() + "' ";
         CMD.Connection  = con;
         con.Open();
         CMD.ExecuteNonQuery();
     }
 }
コード例 #7
0
 //Печать колоды
 private void metroLink1_Click_1(object sender, EventArgs e)
 {
     if (CardListComboBox.Text == "")
     {
         MessageBox.Show("Выберите колоду, с которой вы будете работать.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         Deck = new CardList(CardListComboBox.Text);
         db.LoadCardList(Deck);
         if (this.Deck.GetSizeofList() < 5)
         {
             MessageBox.Show("Для экспорта колоды в ней должно быть не менее 5 карт.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             String result = "";
             for (int i = 0; i < Deck.GetSizeofList(); i++)
             {
                 result += "Вопрос: " + Deck.GetList(i).GetQuestion() + "\n" + "Ответ: " + Deck.GetList(i).GetAnswer() + "\n\n";
             }
             System.IO.File.WriteAllText(Deck.GetName() + ".txt", result);
             using (PrintDialog PrintDialog = new PrintDialog())
             {
                 if (PrintDialog.ShowDialog() == DialogResult.OK)
                 {
                     ProcessStartInfo info = new ProcessStartInfo(Deck.GetName() + ".txt");
                     info.Arguments       = "\"" + PrintDialog.PrinterSettings.PrinterName + "\"";
                     info.CreateNoWindow  = true;
                     info.WindowStyle     = ProcessWindowStyle.Hidden;
                     info.UseShellExecute = true;
                     info.Verb            = "printto";
                     List <Process> l = new List <Process>();
                     l.Add(Process.Start(info));
                     while (true)
                     {
                         if (l[0].HasExited)
                         {
                             break;
                         }
                     }
                     File.Delete(Deck.GetName() + ".txt");
                 }
             }
         }
     }
 }
コード例 #8
0
        //Редактирование колоды
        private void bEditCardList_Click(object sender, EventArgs e)
        {
            try
            {
                if (CardListComboBox.SelectedItem == null)
                {
                    throw new Exception();
                }

                this.Deck = new CardList(CardListComboBox.SelectedItem.ToString());
                db        = new DataBase();
                db.LoadCardList(Deck);
                EditCardList editcardlist = new EditCardList(Deck);
                editcardlist.StyleManager = this.StyleManager;
                editcardlist.ShowDialog();
                CardListComboBox.Items.Clear();
                MyCardLists_Load(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Выберите колоду, с которой вы будете работать.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #9
0
ファイル: EditCardList.cs プロジェクト: slicenbeat/SmartLearn
 public EditCardList(CardList d)
 {
     InitializeComponent();
     this.Deck = d;
 }
コード例 #10
0
 public EditCard(CardList d, int i)
 {
     InitializeComponent();
     this.Deck  = d;
     this.index = i;
 }
コード例 #11
0
 public ReviewForm(string name)
 {
     InitializeComponent();
     this.Deck = new CardList(name);
     //db.LoadCardList(Deck);
 }
コード例 #12
0
 public ReviewForm(CardList d)
 {
     InitializeComponent();
     this.Deck = d;
 }
コード例 #13
0
 public AddCard(CardList d)
 {
     InitializeComponent();
     this.Deck = d;
 }