private void btnSave_Click(object sender, EventArgs e) { try { int MaNV = int.Parse(txtEmpID.Text); string HoTen = txtFullName.Text; int MaCV = int.Parse(cbCongViec.SelectedValue.ToString()); string UserName = cbUserName.SelectedValue.ToString(); string GioiTinh = cbGender.SelectedItem.ToString(); string DiaChi = txtHomeAddress.Text; int Tuoi = int.Parse(txtAge.Text); DateTime NgayBD = dtpkNgayBD.Value; string status = Employee.Insert(MaNV, HoTen, GioiTinh, Tuoi, DiaChi, NgayBD, UserName, MaCV); if (status != "Successful") { throw new Exception(status); } MessageBox.Show("Thêm thành công", "STATUS", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); } catch (FormatException exception) { MessageBox.Show("Mã không hợp lệ!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ActionResult Create(EmployeeModel emp) { if (ModelState.IsValid) { var bal = new EmployeeBAL(); bal.Insert(emp); return(RedirectToAction("Index", "Employee")); } else { return(View(emp)); } }