public int TrangThaiNhanVien(string username) { using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { try { var data = from nhanvien in db.NhanViens from taikhoan in db.TaiKhoans where (nhanvien.MaNhanVien == taikhoan.MaNhanVien && taikhoan.Username == username) select new { State = nhanvien.TrangThai }; foreach (var item in data) { return(item.State); } return(-1); } catch (Exception) { return(-1); } } }
public bool ThemTaiKhoan(TaiKhoan taiKhoan) { using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { try { db.TaiKhoans.Add(taiKhoan); db.SaveChanges(); } catch (Exception) { return(false); } return(true); } }
public bool DoiMatKhau(int id, string newPassword) { using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { try { TaiKhoan account = db.TaiKhoans.Find(id); account.Password = newPassword; db.SaveChanges(); } catch (Exception) { return(false); } return(true); } }
public bool XoaTaiKhoan(int id) { using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { try { TaiKhoan taikhoan = db.TaiKhoans.Find(id); db.TaiKhoans.Remove(taikhoan); db.SaveChanges(); } catch (Exception) { return(false); } return(true); } }
public bool TenTaiKhoanHopLe(string username) { using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { try { int data = db.TaiKhoans.Where(p => p.Username == username).Count(); if (data == 0) { return(true); } return(false); } catch (Exception) { return(false); } } }
public List <ThongTinBan> HoaDonBan() { List <ThongTinBan> data = new List <ThongTinBan>(); using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { var query = from hdb in db.HoaDonBans join cthdb in db.ChiTietHoaDonBans on hdb.MaHoaDonBan equals cthdb.MaHoaDonBan join kh in db.KhachHangs on hdb.MaKhachHang equals kh.MaKhachHang join sp in db.SanPhams on cthdb.MaSanPham equals sp.MaSanPham group new { TongSoLuong = cthdb.SoLuongBan, TongTien = sp.GiaBan } by new { MaHoaDon = hdb.MaHoaDonBan, TenKhach = kh.TenKhachHang, Ngay = hdb.NgayBan } into g select new { MaHoaDon = g.Key.MaHoaDon, TenKhach = g.Key.TenKhach, Ngay = g.Key.Ngay, TongSoLuong = g.Sum(x => x.TongSoLuong), TongTien = g.Sum(x => x.TongTien) }; foreach (var item in query.ToList()) { data.Add(new ThongTinBan() { MaHoaDonBan = item.MaHoaDon, TenKhachHang = item.TenKhach, NgayBan = item.Ngay, TongSoLuong = item.TongSoLuong, TongGiaBan = item.TongTien }); } } return(data); }
public List <TaiKhoan_View> GetTaiKhoan() { List <TaiKhoan_View> accounts = new List <TaiKhoan_View>(); using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { foreach (var item in db.TaiKhoans.ToList()) { accounts.Add(new TaiKhoan_View() { MaTaiKhoan = item.MaTaiKhoan, TenNhanVien = item.NhanVien.TenNhanVien, Username = item.Username, TrangThai = (item.NhanVien.TrangThai == 1) ? "Quản lý" : "Nhân viên" }); } } return(accounts); }
public bool DangNhap(string username, string password) { using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { try { int data = db.TaiKhoans. Where(p => p.Username == username && p.Password == password). Count(); if (data == 1) { return(true); } return(false); } catch (Exception) { return(false); } } }
public List <TaiKhoan_View> GetTaiKhoanBangTen(string name) { List <TaiKhoan_View> accounts = new List <TaiKhoan_View>(); using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { var data = db.TaiKhoans.Where(p => p.NhanVien.TenNhanVien.Contains(name)).ToList(); foreach (var item in data) { accounts.Add(new TaiKhoan_View() { MaTaiKhoan = item.MaTaiKhoan, TenNhanVien = item.NhanVien.TenNhanVien, Username = item.Username, TrangThai = (item.NhanVien.TrangThai == 1) ? "Quản lý" : "Nhân viên" }); } } return(accounts); }
public List <NhanVien> GetNhanVienChuaCoTK() { List <NhanVien> nhanVien = new List <NhanVien>(); using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { var data = from nhanvien in db.NhanViens where !(from taikhoan in db.TaiKhoans select taikhoan.MaNhanVien) .Contains(nhanvien.MaNhanVien) select nhanvien; foreach (var item in data) { nhanVien.Add(new NhanVien() { MaNhanVien = item.MaNhanVien, TenNhanVien = item.TenNhanVien }); } } return(nhanVien); }
public int LayIDTaiKhoan(string username, string password) { using (QuanLyPhuKienDienTuEntities db = new QuanLyPhuKienDienTuEntities()) { try { var data = from taikhoan in db.TaiKhoans where (taikhoan.Username == username && taikhoan.Password == password) select taikhoan; foreach (var item in data) { return(item.MaTaiKhoan); } return(-1); } catch (Exception) { return(-1); } } }