private void btnThem_Click(object sender, EventArgs e) { //if (!MyRegular.CheckRequired(txtTen.Text, "Bắt buộc nhập vào tên danh mục")) // return; //else DanhSachCongViec service = new DanhSachCongViec(); service.ViTriViecLam = txtViTriViecLam.Text; try { db.DanhSachCongViecs.Add(service); db.SaveChanges(); //if (open.CheckFileExists) //{ // string directory = AppDomain.CurrentDomain.BaseDirectory; // File.Copy(open.FileName, directory + service.MaDichVu + open.SafeFileName); // service.HinhAnh = open.SafeFileName; //} db.SaveChanges(); MessageBox.Show("Thêm mới thành công"); LoadDtgv(); } catch (Exception) { MessageBox.Show("Thêm mới không thành công. Vui lòng kiểm tra lại"); } }
private void btnSua_Click(object sender, EventArgs e) { try { DanhSachCongViec service = db.DanhSachCongViecs.Find(int.Parse(txtMaDanhSachCongViec.Text)); service.ViTriViecLam = txtViTriViecLam.Text; //if (open.CheckFileExists) //{ // string directory = AppDomain.CurrentDomain.BaseDirectory; // File.Copy(open.FileName, directory + service.MaDichVu + open.SafeFileName); // service.HinhAnh = open.SafeFileName; //} db.SaveChanges(); MessageBox.Show("Cập nhật thành công"); LoadDtgv(); } catch (Exception) { MessageBox.Show("Cập nhật không thành công. Vui lòng kiểm tra lại"); } }
private void btnXoa_Click(object sender, EventArgs e) { var confirmResult = MessageBox.Show("Bạn có chắc chắn muốn xóa", "Xác nhận!!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { try { DanhSachCongViec service = db.DanhSachCongViecs.Find(int.Parse(txtMaDanhSachCongViec.Text)); db.DanhSachCongViecs.Remove(service); db.SaveChanges(); MessageBox.Show("Xóa thành công"); LoadDtgv(); } catch (Exception) { MessageBox.Show("Tồn tại Máy tính trong danh mục này"); } } }