private void txtSearchBox_SelectedIndexChanged(object sender, EventArgs e)// thsi method runs the search option in the drop down based on the linq query { var test = CRUDperations.getAllEmp(); if (txtSearchBox.SelectedIndex == 0) { using (var emp = new Context()) { comboSearcrslt.DataSource = emp.Employees.Include(e => e.Department). Select(e => new { e.FirstName, e.LastName, e.Department.DepartmentName }).ToList(); //emp.Employees.ToList(); } } else if (txtSearchBox.SelectedIndex == 1) { using (var emps = new Context()) { comboSearcrslt.DataSource = emps.Employees.Where(e => e.Salary > 150000).Select(e => new { e.FirstName, e.LastName, e.Salary }).ToList(); } } else if (txtSearchBox.SelectedIndex == 2) { using (var empes = new Context()) { comboSearcrslt.DataSource = empes.Employees.OrderBy(e => e.Department.DepartmentName).Select(s => new { s.FirstName, s.LastName, s.Department.DepartmentName }).ToList(); } } }
private void button1_Click_1(object sender, EventArgs e) // on thsi click of the button a new row is created and populated with a new employee { // Department dept = new Department(); CRUDperations.Add( new Employees { FirstName = txtFirstName.Text, LastName = txtLastName.Text, Email = txtEmail.Text, PhoneNumber = txtPhoneNumber.Text, HireDate = dateTimePicker1.Value, Salary = decimal.Parse(txtSalary.Text) }, comboBox1.SelectedIndex + 1); dataGridView1.DataSource = CRUDperations.getAllEmp(); // the following lines clear the text boxes after the program runs the add method txtFirstName.Clear(); txtLastName.Clear(); txtEmail.Clear(); txtPhoneNumber.Clear(); txtSalary.Clear(); }
private void updateEmployeeBtn_Click(object sender, EventArgs e)// on the click of the button the database values are updated with the new values { var dept = deptUpdateCombo.Text; CRUDperations.Update( new Employees { Id = ID, FirstName = txtUpdateFirstName.Text, LastName = txtUpdateLastName.Text, Email = txtUpdatEmail.Text, PhoneNumber = txtUpdatePhoneNumber.Text, Salary = decimal.Parse(txtUpdateSalary.Text) }, dept); txtUpdateFirstName.Clear(); txtUpdateLastName.Clear(); txtUpdatEmail.Clear(); txtUpdatePhoneNumber.Clear(); txtUpdateSalary.Clear(); dataGridView1.DataSource = CRUDperations.getAllEmp(); }
private void Form1_Load(object sender, EventArgs e) { //comboBox1.DataSource = CUDOperations.AddDept(new Department {DepartmentName = "", }); // CUDOperations.AddDept(new Department {DepartmentName = "", }); dataGridView1.DataSource = CRUDperations.getAllEmp(); // on wform load this populates the form with data from the database }
private void button3_Click(object sender, EventArgs e) { CRUDperations.Delete(ID); dataGridView1.DataSource = CRUDperations.getAllEmp(); }