Exemple #1
0
        //
        // Events
        //

        private void btnChangeValue_Click(object sender, EventArgs e)
        {
            if (cbUpdateValue.Text == "Välj värde..." || cbUpdateValue.Text == "Skriv in värde...")
            {
                cbUpdateValue.BackColor = Color.Pink;
            }
            else
            {
                cbUpdateValue.BackColor = Color.White;
                updateInProgress        = true;
                string            columnName = DbDisplay.SortedColumn == null ? "Id" : DbDisplay.SortedColumn.Name;
                SortOrder         order      = DbDisplay.SortOrder;
                ListSortDirection direction  = GetSortOrder(order);

                string column = DbDisplay.Columns[Convert.ToInt32(numChangeColumn.Value)].HeaderText;
                string Id     = DbDisplay.Rows[Convert.ToInt32(numChangeRow.Value) - 1].Cells[0].Value.ToString();

                Db.Command($"UPDATE {cbTabell.SelectedValue.ToString()} SET [{column}] = '{cbUpdateValue.Text}', Version = 0 WHERE Id = '{Id}'", Db.connectionString);

                updateInProgress = false;
                UpdateGridView($"SELECT * FROM {cbTabell.SelectedValue.ToString()}");
                DbDisplay.Sort(DbDisplay.Columns[columnName], direction);

                if (Convert.ToInt32(numChangeRow.Value) < DbDisplay.Rows.Count)
                {
                    DbDisplay.CurrentCell = DbDisplay.Rows[Convert.ToInt32(numChangeRow.Value)].Cells[Convert.ToInt32(numChangeColumn.Value)];
                }
                else
                {
                    DbDisplay.CurrentCell = DbDisplay.Rows[Convert.ToInt32(numChangeRow.Value) - 1].Cells[Convert.ToInt32(numChangeColumn.Value)];
                }
                Db.Command("UPDATE TblVersion SET Modified = 1", Db.connectionString);
            }
        }
Exemple #2
0
        private void btnAddRow_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(Db.GetValue($"SELECT COUNT(*) FROM {cbTabell.SelectedValue}", Db.connectionString)) > 999)
            {
                MessageBox.Show("Det går inte att lägga till fler ord i den här tabellen");
            }
            else
            {
                updateInProgress = true;

                string            columnName = DbDisplay.SortedColumn.Name == null ? "Id" : DbDisplay.SortedColumn.Name;
                SortOrder         order      = DbDisplay.SortOrder;
                ListSortDirection direction  = GetSortOrder(order);

                switch (cbTabell.SelectedValue)
                {
                case "TblAdjectives":

                    Db.Command($"INSERT INTO TblAdjectives ([N-genus], [T-genus], Plural, Preposition, Passar, [Lämpligt för], Använt, Version) " +
                               $"VALUES ('{tbxAddColumn1.Text}', '{tbxAddColumn2.Text}','{tbxAddColumn3.Text}', " +
                               $"'{tbxAddColumn4.Text}', '{cbRelation.Text}', '{cbCensur.Text}', 0, 0)", Db.connectionString);

                    break;

                case "TblNouns":

                    if (cbGenus.Text == "")
                    {
                    }
                    else
                    {
                        Db.Command($"INSERT INTO TblNouns ([Singular obestämd], [Singular bestämd], Plural, Preposition, Benämner, Genus, [Lämpligt för], " +
                                   $"Använt, Version) VALUES ('{tbxAddColumn1.Text}', '{tbxAddColumn2.Text}','{tbxAddColumn3.Text}', " +
                                   $"'{tbxAddColumn4.Text}', '{cbTermFor.Text}', '{cbGenus.Text}','{cbCensur.Text}', 0, 0)", Db.connectionString);
                    }

                    break;

                case "TblVerbs":

                    Db.Command($"INSERT INTO TblVerbs (Infinitiv, Uppmaning, Perfekt, Presens, Preposition, Passar, [Lämpligt för], Använt, Version)" +
                               $"VALUES ('{tbxAddColumn1.Text}', '{tbxAddColumn2.Text}','{tbxAddColumn3.Text}', " +
                               $"'{tbxAddColumn4.Text}', '{tbxAddColumn5.Text}', '{cbRelation.Text}','{cbCensur.Text}', 0, 0)", Db.connectionString);

                    break;

                case "TblJokeNames":
                    Db.Command($"INSERT INTO TblJokeNames (Namn, [Lämpligt för], Använt, Version) " +
                               $"VALUES ('{tbxAddColumn1.Text}', '{cbCensur.Text}', 0, 0)", Db.connectionString);
                    break;

                case "TblMissions":
                    Db.Command($"INSERT INTO TblMissions (Uppdrag, [Lämpligt för], Använt, Version)" +
                               $"VALUES ('{tbxAddColumn1.Text}', '{cbCensur.Text}', 0, 0)", Db.connectionString);
                    break;

                case "TblNobelPrizes":
                    Db.Command($"INSERT INTO TblNobelPrizes (Pris, [Lämpligt för], Använt, Version) VALUES ('{tbxAddColumn1.Text}','{cbCensur.Text}', 0, 0)", Db.connectionString);
                    break;

                case "TblSavedResults":
                    Db.Command($"INSERT INTO TblSavedResults (Mening, Version) VALUES ('{tbxAddColumn1.Text}', 0)", Db.connectionString);
                    break;

                case "TblStatus":
                    Db.Command($"INSERT INTO TblStatus (Högstatus, Lågstatus, [Lämpligt för], Använt, Version) " +
                               $"VALUES ('{tbxAddColumn1.Text}', '{tbxAddColumn2.Text}', '{cbCensur.Text}', 0, 0)", Db.connectionString);
                    break;
                }
                updateInProgress = false;
                UpdateGridView($"SELECT * FROM {cbTabell.SelectedValue.ToString()}");
                DbDisplay.Sort(DbDisplay.Columns[columnName], direction);
                Db.Command("UPDATE TblVersion SET Modified = 1", Db.connectionString);
            }
        }
Exemple #3
0
        private void btnDeleteRow_Click(object sender, EventArgs e)
        {
            string            columnName = DbDisplay.SortedColumn == null ? "Id" : DbDisplay.SortedColumn.Name;
            SortOrder         order      = DbDisplay.SortOrder;
            ListSortDirection direction  = GetSortOrder(order);


            // Kolla att dbdiplay lämpligt för är barn och räkna bara barn i query för det är bara då jag vill att den ska reagera annars kan den ta bort.

            // Target column
            int    tC      = DbDisplay.ColumnCount - 3;
            string message = "Det måste finnas minst 2 av typen av ord som du försöker ta bort";

            if (cbTabell.SelectedValue == "TblAdjectives" && DbDisplay.Rows[(Int32)numDeleteRow.Value - 1].Cells[tC].Value.ToString() == "Barn" &&
                Convert.ToInt32(Db.GetValue($"SELECT COUNT(*) FROM TblAdjectives WHERE Passar = '{DbDisplay.Rows[(Int32)numDeleteRow.Value - 1].Cells[tC - 1].Value.ToString()}'", Db.connectionString)) < 3)
            {
                MessageBox.Show(message);
            }

            else if (cbTabell.SelectedValue == "TblVerbs" && DbDisplay.Rows[(Int32)numDeleteRow.Value - 1].Cells[tC].Value.ToString() == "Barn" &&
                     Convert.ToInt32(Db.GetValue($"SELECT COUNT(*) FROM TblVerbs WHERE Passar = '{DbDisplay.Rows[(Int32)numDeleteRow.Value - 1].Cells[tC - 1].Value.ToString()}'", Db.connectionString)) < 3)
            {
                MessageBox.Show(message);
            }

            else if (cbTabell.SelectedValue == "TblNouns" && DbDisplay.Rows[(Int32)numDeleteRow.Value - 1].Cells[tC].Value.ToString() == "Barn" &&
                     Convert.ToInt32(Db.GetValue($"SELECT COUNT(*) FROM TblNouns WHERE Benämner = '{DbDisplay.Rows[(Int32)numDeleteRow.Value - 1].Cells[tC - 2].Value.ToString()}'", Db.connectionString)) < 3)
            {
                MessageBox.Show(message);
            }

            else if (DbDisplay.Rows[(Int32)numDeleteRow.Value - 1].Cells[tC].Value.ToString() == "Barn" && Convert.ToInt32(Db.GetValue($"SELECT COUNT(*) FROM {cbTabell.SelectedValue}", Db.connectionString)) < 3)
            {
                MessageBox.Show(message);
            }

            else
            {
                updateInProgress = true;

                // Get the value of the first column on the specified row, then use it in the query string.
                string Id = DbDisplay.Rows[Convert.ToInt32(numDeleteRow.Value) - 1].Cells[0].Value.ToString();
                Db.Command($"DELETE FROM {cbTabell.SelectedValue.ToString()} WHERE Id = '{Id}'", Db.connectionString);

                updateInProgress = false;
                UpdateGridView($"SELECT * FROM {cbTabell.SelectedValue.ToString()}");

                // If the number of total rows is less than the number of the specified row, then don't
                // select the row after (because there are none left)
                if (DbDisplay.Rows.Count < Convert.ToInt32(numChangeRow.Value))
                {
                    DbDisplay.CurrentCell = DbDisplay.Rows[Convert.ToInt32(numChangeRow.Value) - 2].Cells[Convert.ToInt32(numChangeColumn.Value)];
                }
                // If there are rows left, then move to the next row.
                else
                {
                    DbDisplay.CurrentCell = DbDisplay.Rows[Convert.ToInt32(numChangeRow.Value) - 1].Cells[Convert.ToInt32(numChangeColumn.Value)];
                }

                Db.Command("UPDATE TblVersion SET Modified = 1", Db.connectionString);
            }
            DbDisplay.Sort(DbDisplay.Columns[columnName], direction);
        }