public int ThemNhanVien(NHANVIEN nv) { try { db.NHANVIENs.Add(nv); return(db.SaveChanges()); } catch (Exception ex) { return(0); } }
public IHttpActionResult PostNHANVIEN(NHANVIEN nHANVIEN) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.NHANVIENs.Add(nHANVIEN); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = nHANVIEN.MaNV }, nHANVIEN)); }
public List <NHANVIEN> LoadNhanVien() { List <NHANVIEN> result = new List <NHANVIEN>(); DataTable dt = DataProvider.Instance.ExcuteQuery("pLoadNhanVien"); foreach (DataRow item in dt.Rows) { NHANVIEN tmp = new NHANVIEN(item); result.Add(tmp); } return(result); }
private void btnXoa_Click(object sender, EventArgs e) { if (btnXoa.Text == "Xóa") { NHANVIEN tg = getNhanVienByID(); if (tg.ID == 0) { MessageBox.Show("Chưa có nhân viên nào được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa thông tin nhân viên này?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (rs == DialogResult.Cancel) { return; } try { db.NHANVIENs.Remove(tg); db.SaveChanges(); MessageBox.Show("Xóa nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Xóa nhân viên thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvNhanVien(); return; } if (btnXoa.Text == "Hủy") { btnXoa.Text = "Xóa"; btnThem.Text = "Thêm"; btnSua.Text = "Sửa"; btnThem.Enabled = true; btnSua.Enabled = true; groupThongTin.Enabled = false; dgvNhanVien.Enabled = true; btnTimKiem.Enabled = true; txtTimKiem.Enabled = true; UpdateDetail(); return; } }
public ActionResult Create([Bind(Include = "manv,tennv,tendangnhap,matkhau,maloainv")] NHANVIEN nHANVIEN) { if (ModelState.IsValid) { db.NHANVIEN.Add(nHANVIEN); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.maloainv = new SelectList(db.LOAINHANVIEN, "maloainv", "tenloainv", nHANVIEN.maloainv); return(View(nHANVIEN)); }
private int ChiaViec(int[] viec, int n, int m) { NHANVIEN[] nv = new NHANVIEN[50]; int min, max; for (int k = 0; k < m; k++) { nv[k] = new NHANVIEN(); GanMangBangKhong(nv[k].array, 50); nv[k].bot = 0; nv[k].sum = 0; } for (int i = 0; i < n; i++) { min = MinDong(nv, m); nv[min].array[nv[min].bot++] = viec[i]; nv[min].sum = nv[min].sum + viec[i]; } max = nv[0].sum; //for (int j = 0; j < m; j++) //{ // Console.WriteLine("Nhan Vien " + (j + 1) + ":"); // XuatMang(nv[j].array, nv[j].bot); // Console.WriteLine("Tong thoi gian lam cua nhan vien " + (j + 1) + " : " + nv[j].sum + "\n"); // Console.WriteLine(""); // if (nv[j].sum > max) // { // max = nv[j].sum; // } //} for (int j = 0; j < m; j++) { txbLL.AppendText("Nhân Viên " + (j + 1) + ":" + Environment.NewLine); XuatMang(nv[j].array, nv[j].bot); txbLL.AppendText(Environment.NewLine); txbLL.AppendText("Tổng thời gian làm của nhân viên " + (j + 1) + " : " + nv[j].sum + " h" + "\n"); txbLL.AppendText(Environment.NewLine + Environment.NewLine + Environment.NewLine); if (nv[j].sum > max) { max = nv[j].sum; } } return(max); }
private bool Check() { if (txtMaNhanVien.Text == "") { MessageBox.Show("Mã nhân viên không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } int cnt = db.NHANVIENs.Where(p => p.MANV == txtMaNhanVien.Text).ToList().Count; if (cnt > 0) { bool ok = false; if (btnSua.Text == "Lưu") { // Nếu là sửa NHANVIEN nv = getNhanVienByID(); if (nv.MANV == txtMaNhanVien.Text) { ok = true; } } if (!ok) { MessageBox.Show("Mã nhân viên đã được sử dụng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } if (txtHoVaTen.Text == "") { MessageBox.Show("Họ và tên nhân viên không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (txtTaiKhoan.Text == "") { MessageBox.Show("Tài khoản của nhân viên không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (txtQueQuan.Text == "") { MessageBox.Show("Quê quán của nhân viên không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
private void btnSua_Click(object sender, EventArgs e) { if (!CheckLuaChon()) { return; } if (btnSua.Text == "Sửa") { btnSua.Text = "Lưu"; btnXoa.Text = "Hủy"; btnThem.Enabled = false; UnlockControl(); return; } if (btnSua.Text == "Lưu") { if (Check()) { btnSua.Text = "Sửa"; btnXoa.Text = "Xóa"; LockControl(); NHANVIEN cu = getNhanVienByID(); NHANVIEN moi = getNhanVienByForm(); CapNhat(ref cu, moi); try { db.SaveChanges(); MessageBox.Show("Sưa thông tin nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Sửa thông tin nhân viên thất bại\n" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvNhanVien(); } return; } }
private void btnThem_Click(object sender, EventArgs e) { if (btnThem.Text == "Thêm") { btnThem.Text = "Lưu"; btnSua.Enabled = false; btnXoa.Text = "Hủy"; groupThongTin.Enabled = true; dgvNhanVien.Enabled = false; btnTimKiem.Enabled = false; txtTimKiem.Enabled = false; ClearControl(); return; } if (btnThem.Text == "Lưu") { if (Check()) { btnThem.Text = "Thêm"; btnSua.Enabled = true; btnXoa.Text = "Xóa"; groupThongTin.Enabled = false; dgvNhanVien.Enabled = true; btnTimKiem.Enabled = true; txtTimKiem.Enabled = true; try { NHANVIEN tg = getNhanVienByForm(); db.NHANVIENs.Add(tg); db.SaveChanges(); MessageBox.Show("Thêm thông tin nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Thêm thông tin mặt hàng thất bại\n" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvNhanVien(); } return; } }
public ActionResult XacNhanXoa(int id) { NHANVIEN ctpm = db.NHANVIENs.SingleOrDefault(n => n.MaNV == id); //if (ctpm == null) //{ // Response.StatusCode = 404; // return null; //} HttpResponseMessage response = GlobalVariables.WebApiClient.DeleteAsync("NHANVIEN/" + id.ToString()).Result; db.SaveChanges(); return(RedirectToAction("Index")); }
public bool Insert(NHANVIEN customer) { try { cf.NHANVIEN.Add(customer); cf.SaveChanges(); return(true); } catch { return(false); } }
public JsonResult CheckSoDT(string SoDT) { NHANVIEN nhanvien = db.NHANVIENs.SingleOrDefault(n => n.SoDT == SoDT); if (nhanvien != null) { return(Json("Yes", JsonRequestBehavior.AllowGet)); //truong hop da ton tai } else { return(Json("No", JsonRequestBehavior.AllowGet)); } }
public JsonResult CheckTenDN(string tenDN) { NHANVIEN nhanvien = db.NHANVIENs.SingleOrDefault(n => n.TenDangNhap == tenDN); if (nhanvien != null) { return(Json("Yes", JsonRequestBehavior.AllowGet)); //truong hop da ton tai } else { return(Json("No", JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteConfirmed(int id) { try { NHANVIEN tblNhanVien = db.NHANVIENs.Find(id); db.NHANVIENs.Remove(tblNhanVien); db.SaveChanges(); } catch { } return(RedirectToAction("Index")); }
public ActionResult XuatHoaDon(FormCollection collection) { NHANVIEN nv = (NHANVIEN)Session["NHANVIEN"]; var id = int.Parse(collection["ma"]); var ngaygiao = DateTime.Parse(collection["NGAYGIAOHD"]); var gc = collection["GHICHUHD"]; var mst = collection["MST"]; var ten = collection["TENCONGTY"]; var dc = collection["DIACHICONTY"]; _db.XUATHOADON(id, nv.MANHANVIEN, ngaygiao, gc, mst, ten, dc); return(RedirectToAction("Details", new { id = id })); }
public string getMANVLast() { List <NHANVIEN> a = da.NHANVIENs.ToList(); if (a.Count == 0)// neu chua co nhan vien nao { return(""); } //da co ma nhan vien NHANVIEN b = da.NHANVIENs.ToList().OrderByDescending(t => t.MANV).First(); return(b.MANV); }
public ActionResult Delete(int id) { if (Session["us"] == null) { return(RedirectToAction("Login", "MayAnh")); } else { NHANVIEN pr = new NHANVIEN(); pr = db.NHANVIENs.Find(id); return(View(pr)); } }
public ActionResult Create([Bind(Include = "MaNV,Ho,Ten,NgaySinh,GioiTinh,AnhMinhHoa,Luong,SDT,DiaChi,MaPB")] NHANVIEN nhanVien) { if (ModelState.IsValid) { //nhanVien.MaNV = LayMaNV(); db.NHANVIENs.Add(nhanVien); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaPB = new SelectList(db.PHONGBANs, "MaPB", "TenPB", nhanVien.MaPB); return(View(nhanVien)); }
public bool checkDaCoTaiKhoan(NHANVIEN nv) { ObservableCollection <TAIKHOAN> listTK = new ObservableCollection <TAIKHOAN>(DataProvider.Ins.DB.TAIKHOANs); foreach (var tk in listTK) { if (tk.NHANVIEN.id == nv.id) { return(false); } } return(true); }
public ActionResult Index1() { NHANVIEN nv = (NHANVIEN)Session["TaiKhoan"]; if (nv == null) { return(RedirectToAction("DangNhap", "DangNhap")); } else { return(View(nv)); } }
public static NHANVIEN CheckLogin(KaraokeEntities kara, string user, string pass) { if (!String.IsNullOrEmpty(user) && !String.IsNullOrEmpty(pass)) { var Parameter_TenDangNhap = new System.Data.SqlClient.SqlParameter("@TenDangNhap", System.Data.SqlDbType.VarChar, 50); Parameter_TenDangNhap.Value = user; var Parameter_MatKhau = new System.Data.SqlClient.SqlParameter("@MatKhau", System.Data.SqlDbType.VarChar, 255); Parameter_MatKhau.Value = pass; NHANVIEN nv = kara.ExecuteStoreQuery <NHANVIEN>("SP_Login_NhanVien @TenDangNhap, @MatKhau", Parameter_TenDangNhap, Parameter_MatKhau).FirstOrDefault(); return(nv); } return(null); }
public ActionResult XoaNV(int id) { //Lấy ra đối tượng sách cần xóa theo mã NHANVIEN nv = db.NHANVIENs.SingleOrDefault(n => n.MaNV == id); ViewBag.MaNV = nv.MaNV; if (nv == null) { Response.StatusCode = 404; return(null); } return(View(nv)); }
private void btnXoaNV_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { string manv = dataGridView1.CurrentRow.Cells[0].Value.ToString(); NHANVIEN nv = qlks.NHANVIENs.Where(t => t.MANV == manv).FirstOrDefault(); qlks.NHANVIENs.DeleteOnSubmit(nv); qlks.SubmitChanges(); var nhanviens = from nv1 in qlks.NHANVIENs select nv1; dataGridView1.DataSource = nhanviens; } catch { }; }
public ActionResult XacNhanXoa(int maNV) { NHANVIEN nv = db.NHANVIENs.SingleOrDefault(n => n.MANV == maNV); if (nv == null) { Response.StatusCode = 404; return(null); } db.NHANVIENs.Remove(nv); db.SaveChanges(); return(RedirectToAction("QuanLyNhanVien")); }
//sửa nhân viên private void btneditstaff_Click(object sender, EventArgs e) { string id = dtgstaff.SelectedCells[0].OwningRow.Cells["ID"].Value.ToString(); using (TrachanhbuiphoDataContext db = new TrachanhbuiphoDataContext()) { NHANVIEN edit = db.NHANVIENs.Where(staff => staff.ID.Equals(id)).SingleOrDefault(); fEditStaff f = new fEditStaff(); f.Tag = edit; f.ShowDialog(); } loadstaff(); }
public string InsertEmloyee(NHANVIEN entity) { try { db.NHANVIENs.Add(entity); db.SaveChanges(); return(entity.MANHANVIEN); } catch (Exception ex) { return(""); } }
public ActionResult Create([Bind(Include = "MaNV,TenNV,CMND,NgaySinh,DiaChi,SDT,Email,Password,TrangThaiTaiKhoan,createUser,lastupdateUser,createDate,lastupdateDate,isDeleted")] NHANVIEN nHANVIEN) { if (ModelState.IsValid) { nHANVIEN.Password = EncryptionUtil.instant(nHANVIEN.CMND); nHANVIEN.TrangThaiTaiKhoan = 0; nHANVIEN.isDeleted = 0; service.Add(nHANVIEN); return(RedirectToAction("Index")); } return(View(nHANVIEN)); }
private NHANVIEN GetNhanVienWithID() { try { int ID = (int)dgvNhanVienView.GetFocusedRowCellValue("ID"); NHANVIEN ans = db.NHANVIENs.Where(p => p.ID == ID).FirstOrDefault(); return(ans); } catch { return(new NHANVIEN()); } }
private NHANVIEN getNhanVienByID() { try { int id = (int)dgvNhanVien.SelectedRows[0].Cells["ID"].Value; NHANVIEN nhanvien = db.NHANVIENs.Where(p => p.ID == id).FirstOrDefault(); return((nhanvien != null) ? nhanvien : new NHANVIEN()); } catch { return(new NHANVIEN()); } }
private void SearchEmployee(string id) { using (MainDataClassesDataContext db = new MainDataClassesDataContext()) { NHANVIEN foundEmployee = db.NHANVIENs.Where(item => item.ID.Equals(id)).FirstOrDefault(); if (foundEmployee != null) { Result = foundEmployee; timer1.Stop(); stream.Stop(); this.Close(); } } }