/// <summary> /// Delete Nhan vien /// </summary> /// <param name="ID"></param> public bool Delete(int manv) { using (QLDLEntities db = new QLDLEntities()) { if ((db.PHIEUXUATHANGs.Where(p => p.NGUOIXUAT == manv).Count() > 0) || (db.PHIEUTHUTIENs.Where(p => p.NGUOITHU == manv).Count() > 0)) { return(false); } else { List <TAIKHOAN> li = db.TAIKHOANs.Where(p => p.MANV == manv).ToList(); foreach (TAIKHOAN item in li) { db.TAIKHOANs.Remove(item); } db.SaveChanges(); NHANVIEN nv = db.NHANVIENs.Single(p => p.MANV == manv); db.NHANVIENs.Remove(nv); db.SaveChanges(); return(true); } } }
/// <summary> /// Insert Nhanvien into database /// </summary> /// <param name="dl"></param> /// <returns></returns> public bool Insert(string ten, DateTime ngay, string dc, int macv, string acc, string pass) { using (QLDLEntities db = new QLDLEntities()) { NHANVIEN nv = new NHANVIEN() { TENNV = ten, NGAYSINH = ngay, DIACHI = dc, MACHUCVU = macv }; db.NHANVIENs.Add(nv); db.SaveChanges(); TAIKHOAN tk = new TAIKHOAN() { TENDANGNHAP = acc, PASSWORD = pass, MANV = db.NHANVIENs.Single(p => p.TENNV == ten && p.NGAYSINH == ngay && p.MACHUCVU == macv).MANV }; db.TAIKHOANs.Add(tk); db.SaveChanges(); return(true); } }
/// <summary> /// Change max-number of SONOTOIDA in LOAIDL /// </summary> /// <param name="maloaidl"></param> /// <param name="sonotoida"></param> /// <returns></returns> public bool ChangeMaxNumOfTienNo(int maloaidl, int sonotoida) { using (QLDLEntities db = new QLDLEntities()) { LOAIDL loaidl = db.LOAIDLs.Where(p => p.MALOAI == maloaidl).Single(); loaidl.SONOTOIDA = sonotoida; db.SaveChanges(); return(true); } }
/// <summary> /// insert a record into table DVT- increament number of DVT /// </summary> /// <param name="tendvt"></param> /// <returns></returns> public bool InsertDVT(string tendvt) { using (QLDLEntities db = new QLDLEntities()) { DVT dvt = new DVT(); dvt.DVT1 = tendvt; db.DVTs.Add(dvt); db.SaveChanges(); return(true); } }
/// <summary> /// Change max-number of DAILY in QUAN /// </summary> /// <param name="maquan"></param> /// <param name="sodailytoida"></param> /// <returns></returns> public bool ChangeNumOfDaily(int maquan, int sodailytoida) { using (QLDLEntities db = new QLDLEntities()) { QUAN quan = db.QUANs.Where(p => p.MAQUAN == maquan).Single(); quan.SODLTOIDA = sodailytoida; db.SaveChanges(); //change succeed return(true); } }
/// <summary> /// insert a record into table MATHANG- increament number of MATHANG /// </summary> /// <param name="tenhang"></param> /// <param name="tendvt"></param> /// <param name="dongia"></param> /// <returns></returns> public bool InsertMATHANG(string tenhang, int madvt, int dongia) { using (QLDLEntities db = new QLDLEntities()) { MATHANG mh = new MATHANG(); mh.TENHANG = tenhang; mh.MADVT = madvt; mh.DONGIA = dongia; db.MATHANGs.Add(mh); db.SaveChanges(); return(true); } }
/// <summary> /// insert a record into table LOAIDL- increament number of LOAIDL /// </summary> /// <param name="tenloai"></param> /// <param name="sonotoida"></param> /// <returns></returns> public bool InsertLoaiDL(string tenloai, int sonotoida) { using (QLDLEntities db = new QLDLEntities()) { LOAIDL dl = new LOAIDL(); dl.TENLOAI = tenloai; dl.SONOTOIDA = sonotoida; db.LOAIDLs.Add(dl); db.SaveChanges(); //insert suceed return(true); } }
/// <summary> /// Update NHANVIEN /// </summary> /// <param name="dl"></param> /// <returns></returns> public bool Update(NHANVIEN nhanvien) { using (QLDLEntities db = new QLDLEntities()) { NHANVIEN nv = db.NHANVIENs.Where(p => p.MANV == nhanvien.MANV).Single(); nv.TENNV = nhanvien.TENNV; //nv.NGAYSINH = nhanvien.NGAYSINH; //nv.DIACHI = nhanvien.DIACHI; //nv.MACHUCVU = nhanvien.MACHUCVU; db.SaveChanges(); return(true); } }
/// <summary> /// Get all DVT's name and show upto ComboBox /// </summary> /// <returns></returns> public ObservableCollection <DVT> GetAllDVT() { ObservableCollection <DVT> li = new ObservableCollection <DVT>(); using (QLDLEntities db = new QLDLEntities()) { var l = db.DVTs.Select(p => p); foreach (var item in l) { li.Add(item as DVT); } return(li); } }
/// <summary> /// Get all LAOIDAILY's name and show upto ComboBox /// </summary> /// <returns></returns> public ObservableCollection <LOAIDL> GetAllLoaiDL() { ObservableCollection <LOAIDL> li = new ObservableCollection <LOAIDL>(); using (QLDLEntities db = new QLDLEntities()) { var l = db.LOAIDLs.Select(p => p); foreach (var item in l) { li.Add(item as LOAIDL); } return(li); } }
/// <summary> /// Get all QUAN's name and show upto ComboBox /// </summary> /// <returns></returns> public ObservableCollection <QUAN> GetAllQuan() { ObservableCollection <QUAN> li = new ObservableCollection <QUAN>(); using (QLDLEntities db = new QLDLEntities()) { var l = db.QUANs.Select(p => p); foreach (var item in l) { li.Add(item as QUAN); } return(li); } }
/// <summary> /// Get all DaiLy's name and show upto ComboBox /// </summary> /// <returns></returns> public ObservableCollection <DAILY> GetAllDaiLy() { ObservableCollection <DAILY> li = new ObservableCollection <DAILY>(); using (QLDLEntities db = new QLDLEntities()) { var l = db.DAILies.Select(p => p); foreach (var item in l) { li.Add(item as DAILY); } return(li); } }
/// <summary> /// get all CHUC VU /// </summary> /// <returns></returns> public ObservableCollection <CHUCVU> GetAllCV() { ObservableCollection <CHUCVU> li = new ObservableCollection <CHUCVU>(); using (QLDLEntities db = new QLDLEntities()) { var l = db.CHUCVUs.Select(p => p); foreach (var item in l) { li.Add(item as CHUCVU); } return(li); } }
/// <summary> /// delete a record into table DVT - descreament number of DVT /// </summary> /// <param name="madvt"></param> /// <returns></returns> public bool DeleteDVT(int madvt) { using (QLDLEntities db = new QLDLEntities()) { if (db.MATHANGs.Where(p => p.MADVT == madvt).Count() <= 0) { DVT dvt = db.DVTs.Where(p => p.MADVT == madvt).Single(); db.DVTs.Remove(dvt); db.SaveChanges(); return(true); } return(false); } }
/// <summary> /// Get worker by name /// </summary> /// <param name="name"></param> /// <returns></returns> public ObservableCollection <vwCHUCVU_NHANVIEN_TAIKHOAN> GetAllNV(string name) { ObservableCollection <vwCHUCVU_NHANVIEN_TAIKHOAN> li = new ObservableCollection <vwCHUCVU_NHANVIEN_TAIKHOAN>(); using (QLDLEntities db = new QLDLEntities()) { var l = db.vwCHUCVU_NHANVIEN_TAIKHOAN.Where(p => p.TENNV.Contains(name)); foreach (var item in l) { li.Add(item as vwCHUCVU_NHANVIEN_TAIKHOAN); } return(li); } }
/// <summary> /// delete a record into table MATHANG - descreament number of MATHANG /// </summary> /// <param name="mamh"></param> /// <returns></returns> public bool DeleteMATHANG(int mamh) { using (QLDLEntities db = new QLDLEntities()) { if (db.CTPXes.Where(p => p.MAHANG == mamh).Count() <= 0) { MATHANG mh = db.MATHANGs.Where(p => p.MAHANG == mamh).Single(); db.MATHANGs.Remove(mh); db.SaveChanges(); return(true); } return(false); } }
/// <summary> /// Search NHan vien from database and display it to GUI /// Load if nhanvien's search condition equal empty string /// </summary> public ObservableCollection <NHANVIEN> Search(int macv, string ten, string dc) { ObservableCollection <NHANVIEN> li = new ObservableCollection <NHANVIEN>(); using (QLDLEntities db = new QLDLEntities()) { var l = db.NHANVIENs.Where(p => p.MACHUCVU == macv && p.TENNV.Contains(ten) && p.DIACHI.Contains(dc)); foreach (var item in l) { li.Add(item as NHANVIEN); } return(li); } }
/// <summary> /// delete a record into table LOAIDL - descreament number of LOAIDL /// </summary> /// <param name="loaidl"></param> /// <returns></returns> public bool DeleteLAOIDL(int loaidl) { using (QLDLEntities db = new QLDLEntities()) { if (db.DAILies.Where(p => p.LOAIDL == loaidl).Count() <= 0) { LOAIDL ldl = db.LOAIDLs.Where(p => p.MALOAI == loaidl).Single(); db.LOAIDLs.Remove(ldl); db.SaveChanges(); //delete succeed return(true); } //delete false return(false); } }