Example #1
0
        //Obtained when U double-click the form. Auto generated code which is generated as Event handler.
        private void Form1_Load(object sender, EventArgs e)
        {
            var com  = new EmpDatabase();
            var list = com.GetAllEmployees();   //List implements IList.

            lstNames.DisplayMember = "EmpName"; //Display the property called name
            lstNames.ValueMember   = "EmpID";   //It represents ID...
            lstNames.DataSource    = list;      //U can bind only those objects that implement IList Interface
        }
Example #2
0
        //Event handler for adding button in the Tab2...
        private void myAddingEvent(object sender, EventArgs e)
        {
            var emp = new Employee
            {
                EmpID     = int.Parse(txtNewID.Text),
                EmpName   = txtNewName.Text,
                EmpSalary = int.Parse(txtNewSalary.Text)
            };
            var com = new EmpDatabase();

            com.AddNewEmployee(emp);
            MessageBox.Show("Employee added successfully to the database");
            Form1_Load(sender, e);
        }
Example #3
0
        private void Button1_Click(object sender, EventArgs e)
        {
            var emp = new Employee
            {
                EmpID     = int.Parse(txtID.Text),
                EmpName   = txtName.Text,
                EmpSalary = int.Parse(txtSalary.Text)
            };

            try
            {
                var com = new EmpDatabase();
                com.UpdateEmployee(emp);
                MessageBox.Show("Employee updated successfully to the database");
                Form1_Load(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }