Пример #1
0
        private void buttonEditKeeled_Click(object sender, EventArgs e)
        {
            int id = 0;

            try
            {
                id = Convert.ToInt32(dataGridView2[0, dataGridView2.CurrentRow.Index].Value.ToString());
            }
            catch (NullReferenceException) { }

            FormKeeled dlg = new FormKeeled("Edit entry", "Edit keeled", "Save", id);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Database db = new Database();
                db.open();

                if (db.Connected)
                {
                    try
                    {
                        db.cmd_exec("UPDATE [dbo].[Keeled] SET Keel = '" + dlg.Keel + "' WHERE Id = '" + dlg.Id + "'");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Entry edit fail!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    }

                    db.close();
                    buttonRefreshKeeled_Click(sender, e);
                }
            }
        }
Пример #2
0
        private void buttonAddKeeled_Click(object sender, EventArgs e)
        {
            FormKeeled dlg = new FormKeeled("New entry", "Add to keeled", "Add", 0);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Database db = new Database();
                db.open();

                if (db.Connected)
                {
                    try
                    {
                        db.cmd_exec("INSERT INTO [dbo].[Keeled] (Keel) VALUES('" + dlg.Keel + "')");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Entry add fail!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    }

                    db.close();
                    buttonRefreshKeeled_Click(sender, e);
                }
            }
        }