コード例 #1
0
        private void buttonEditTooaeg_Click(object sender, EventArgs e)
        {
            int id = 0;

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

            FormTooaeg dlg = new FormTooaeg("Edit entry", "Edit Tooaeg", "Save", id);

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

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

                    buttonRefreshTooaeg_Click(sender, e);
                }
            }
        }
コード例 #2
0
        private void buttonAddTooaeg_Click(object sender, EventArgs e)
        {
            FormTooaeg dlg = new FormTooaeg("New entry", "Add to tooaeg", "Add", 0);

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

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

                    buttonRefreshTooaeg_Click(sender, e);
                }
            }
        }