private void btnAddSalary_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(cmbEmployees.Text) && !string.IsNullOrEmpty(txtSalaryAmount.Text)) { ve = new VehicleManagementEntities(); cmbBoxValues selEmp = cmbEmployees.SelectedItem as cmbBoxValues; int selectedEmployee = selEmp.cmbVal; EmployeeSalaries employeeSalary = new EmployeeSalaries() { EmployeeId = long.Parse(selectedEmployee.ToString()), Amount = double.Parse(txtSalaryAmount.Text), Description = txtDescription.Text, Status = "1", DatePayed = DateTime.Now }; ve.EmployeeSalaries1.Add(employeeSalary); ve.SaveChanges(); MessageBox.Show("Salary saved successfully!"); fetchEmpSalary(); } else { MessageBox.Show("You must fill all fields!"); } }
private void btnDeleteSalary_Click(object sender, EventArgs e) { DialogResult res = MessageBox.Show("Are you sure you want to Delete this Salary? You cannot reverse this action.", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (res == DialogResult.OK) { ve = new VehicleManagementEntities(); var singleSalary = ve.EmployeeSalaries1.Where(r => r.SalaryId == selectedSalId).First(); ve.EmployeeSalaries1.Remove(singleSalary); ve.SaveChanges(); MessageBox.Show("Payment successfully deleted!"); fetchEmpSalary(); clearSalFields(); selectedSalId = 0; } }
private void btnUpdateSalary_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(cmbEmployees.Text) && !string.IsNullOrEmpty(txtSalaryAmount.Text)) { ve = new VehicleManagementEntities(); cmbBoxValues selEmp = cmbEmployees.SelectedItem as cmbBoxValues; int selectedEmployee = selEmp.cmbVal; var singleContractor = ve.EmployeeSalaries1.Where(r => r.SalaryId == selectedSalId).First(); singleContractor.EmployeeId = long.Parse(selectedEmployee.ToString()); singleContractor.Amount = double.Parse(txtSalaryAmount.Text); singleContractor.Description = txtDescription.Text; singleContractor.Status = "1"; ve.SaveChanges(); MessageBox.Show("Salary successfully updated!"); fetchEmpSalary(); clearSalFields(); selectedSalId = 0; } else { MessageBox.Show("You must fill all fields!"); } }