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

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

            FormPersonal dlg = new FormPersonal("Edit entry", "Edit personal", "Save", id);

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

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

                    db.close();
                    buttonRefreshPersonal_Click(sender, e);
                }
            }
        }
Пример #2
0
        private void buttonAddPersonal_Click(object sender, EventArgs e)
        {
            FormPersonal dlg = new FormPersonal("New entry", "Add to personal", "Add", 0);

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

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

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