Esempio n. 1
0
        private void buttonS_Click(object sender, EventArgs e)
        {
            enAbleButton();
            if (isAdd == true)
            {
                DBstuinfo add = new DBstuinfo(textBoxF.Text, textBoxL.Text, textBoxM.Text, comboBoxC.Text, Convert.ToInt32(comboBoxY.Text), textBoxA.Text);
                add.Add();

                load_dataGridView1();

                MessageBox.Show("Added successfuly");
            }
            else if (isAdd == false)
            {
                try
                {
                    int idx = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString());

                    DBstuinfo cards = DBstuinfo.GetDataID(idx);

                    cards.FirstName  = textBoxF.Text;
                    cards.LastName   = textBoxL.Text;
                    cards.MiddleName = textBoxM.Text;
                    cards.Course     = comboBoxC.Text;
                    cards.Year       = Convert.ToInt32(comboBoxY.Text);
                    cards.Address    = textBoxA.Text;

                    cards.Update();
                    load_dataGridView1();
                    MessageBox.Show("Edited successfuly");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error updating record " + ex.Message);
                }
            }
        }
Esempio n. 2
0
        private void buttonD_Click(object sender, EventArgs e)
        {
            try
            {
                int idx = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString());

                DBstuinfo cards = DBstuinfo.GetDataID(idx);

                if (cards != null)
                {
                    DialogResult dialogResult = MessageBox.Show(" Do you want to delete this record?", "Delete", MessageBoxButtons.YesNo);

                    if (dialogResult == DialogResult.Yes)
                    {
                        cards.Delete();
                        load_dataGridView1();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error deleting record " + ex.Message);
            }
        }