private void DeleteCardBtn_Click(object sender, EventArgs e) { if (CountFlashcards() == 1) { MessageForm errorForm = new MessageForm("You cannot have an empty set."); errorForm.Show(); } else { Querey querey = new Querey(); using (querey.connection = querey.NewConn) { using (querey.command = querey.NewComm) { querey.command.CommandText = "DELETE FROM Flashcards WHERE Flashcards.Id = @flashId;"; querey.AddParameter("@flashId", currentCard.id); querey.command.ExecuteNonQuery(); } } SaveChanges(); queue.Dequeue(); ChangeSetArray(); PointerVal.Text = queue.Backwards().ToString(); currentCard = queue.Load(); new MessageForm("deleted").Show(); } }
private void BackwardsBtn_Click(object sender, EventArgs e) { currentCard.text1 = Text1.Text; // temporarily saves changes till user goes off set or goes onto the main menu currentCard.text2 = Text2.Text; PointerVal.Text = queue.Backwards().ToString(); currentCard = queue.Load(); // updating card displayed }
private void NewCardBtn_Click(object sender, EventArgs e) { Querey querey = new Querey(); if (CountFlashcards() == 64) { MessageForm errorForm = new MessageForm("You already have the maximum numbers of cards in this set."); errorForm.Show(); } else { int flashId = 0; using (querey.connection = querey.NewConn) { using (querey.command = querey.NewComm) { querey.command.CommandText = "INSERT INTO Flashcards (SetId, Text1, Text2) VALUES (@setId, @text1, @text2);"; querey.AddParameter("@setId", currentCard.setId); querey.AddParameter("@text1", Text1.Text); querey.AddParameter("@text2", Text2.Text); querey.command.ExecuteNonQuery(); } using (querey.command = querey.NewComm) { querey.command.CommandText = "SELECT Flashcards.Id FROM Flashcards WHERE SetId = @setId AND Text1 = @text1 AND Text2 = @text2;"; querey.AddParameter("@setId", currentCard.setId); querey.AddParameter("@text1", Text1.Text); querey.AddParameter("@text2", Text2.Text); using (querey.reader = querey.command.ExecuteReader()) { while (querey.reader.Read()) { flashId = querey.reader.GetInt32(0); } } } } SaveChanges(); new MessageForm("insertion successful").Show(); queue.Enqueue(new Flashcard(flashId, currentCard.setId, Text1.Text, Text2.Text)); PointerVal.Text = queue.Forwards().ToString(); currentCard = queue.Load(); ChangeSetArray(); } }
public Set(int id, int ownerId, string setName, string title1, string title2) { _id = id; _ownerId = ownerId; _setName = setName; _title1 = title1; _title2 = title2; _querey = new Querey(); _strengths = new double[] { 2.10, 3.48, 13.63, 59.16, 104.30, 153.92, 209.57, 313.04, 417.10, 521.39, 625.55 }; using (_querey.connection = _querey.NewConn) { using (_querey.command = _querey.NewComm) { _querey.command.CommandText = "SELECT count(SetId) FROM Flashcards WHERE SetId = @setid;"; _querey.AddParameter("@setid", _id); int length = Convert.ToInt32(_querey.command.ExecuteScalar()); _flashcards = new Flashcard[length]; } using (_querey.command = _querey.NewComm) { _querey.command.CommandText = "SELECT Flashcards.Id, Flashcards.Text1, Flashcards.Text2 FROM Flashcards, Sets WHERE Flashcards.SetId = Sets.Id AND Flashcards.SetId = @id;"; _querey.AddParameter("@id", id); using (_querey.reader = _querey.command.ExecuteReader()) { int i = 0; while (_querey.reader.Read()) { _flashcards[i] = new Flashcard(_querey.reader.GetInt32(0), id, _querey.reader.GetString(1), _querey.reader.GetString(2)); i++; } } } } }
private void SelectSetBtn_Click(object sender, EventArgs e) { if (ChooseSet.Text == "") { MessageForm errorForm = new MessageForm("Please choose a set to edit"); } else { for (int i = 0; i < _sets.Length; i++) // linear search { if (_sets[i].SetName == ChooseSet.Text) { currentSet = _sets[i]; queue = new PartialQueue(_sets[i], Text1, Text2); Title1.Text = _sets[i].Title1; Title2.Text = _sets[i].Title2; currentCard = queue.Load(); break; } } ChangeEdit(true); PointerVal.Text = "1"; } }
private void JumpBtn_Click(object sender, EventArgs e) { if (PointerInput.Text == "") { MessageForm errorForm = new MessageForm("Please enter which card you want to go to"); errorForm.Show(); } else if (int.Parse(PointerInput.Text) < 0 || int.Parse(PointerInput.Text) > queue.GetQueue.Length) { MessageForm errorForm = new MessageForm("Please enter a value within the range of your flashcards"); errorForm.Show(); } else if (queue.GetQueue[int.Parse(PointerInput.Text) - 1] == null) { MessageForm errorForm = new MessageForm("Your set does not have that many flashcards"); errorForm.Show(); } else { int difference = int.Parse(PointerVal.Text) - int.Parse(PointerInput.Text); bool back = false; if (difference < 0) { difference = -difference; back = true; } for (int i = 0; i < difference; i++) { PointerVal.Text = (back ? queue.Forwards() : queue.Backwards()).ToString(); } currentCard = queue.Load(); } PointerInput.Clear(); }
public void Enqueue(Flashcard flashcard) // error handling occurs earlier on in add procedure { _queue[_back] = flashcard; _back++; }