Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
4.2 kB
1
Indexable
Never
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cc105act1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load_1(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.Table1' table. You can move, or remove it, as needed.
            this.table1TableAdapter.Fill(this.dataSet1.Table1);
            table1BindingSource.DataSource = this.dataSet1.Table1;
        }

        private void buttnew_Click(object sender, EventArgs e)
        {
            firstname.Clear();
            middleini.Clear();
            lastname.Clear();
            gender.Clear();
            specialty.Clear();
            phil.Clear();
            jobob.Clear();
            try
            {
                panel1.Enabled = true;
                firstname.Focus();
                this.dataSet1.Table1.AddTable1Row(this.dataSet1.Table1.NewTable1Row());
                table1BindingSource.MoveLast();
               
            }
            catch(Exception ex)
            {
                MessageBox.Show("Error", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                table1BindingSource.ResetBindings(false);
            }


        }

        private void buttcancel_Click(object sender, EventArgs e)
        {
            panel1.Enabled = false;
            table1BindingSource.ResetBindings(false);
            firstname.Clear();
            middleini.Clear();
            lastname.Clear();
            gender.Clear();
            specialty.Clear();
            phil.Clear();
            jobob.Clear();
        }

        private void buttedit_Click(object sender, EventArgs e)
        {
            panel1.Enabled = true;
            firstname.Focus();
        }

        private void buttsave_Click(object sender, EventArgs e)
        {
            try
            {
                table1BindingSource.EndEdit();
                table1TableAdapter.Update(this.dataSet1.Table1);
                panel1.Enabled = false;

            }
            catch
            {
                MessageBox.Show("Error","Message",MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            firstname.Clear();
            middleini.Clear();
            lastname.Clear();
            gender.Clear();
            specialty.Clear();
            phil.Clear();
            jobob.Clear();
        }

        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete) 
            { 
                if(MessageBox.Show("Do you want to delete this record?","Message",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    table1BindingSource.RemoveCurrent();
                }

            }
        }

        private void buttapply_Click(object sender, EventArgs e)
        {
            {
                try
                {
                    table1BindingSource.EndEdit();
                    table1TableAdapter.Update(this.dataSet1.Table1);
                    panel1.Enabled = false;

                }
                catch
                {
                    MessageBox.Show("Error", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                firstname.Clear();
                middleini.Clear();
                lastname.Clear();
                gender.Clear();
                specialty.Clear();
                phil.Clear();
                jobob.Clear();

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to delete this record?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                table1BindingSource.RemoveCurrent();
            }
        }
    }
}