private void LoadPhieuNhap(List <PHIEUNHAP> ls = null) { if (ls == null) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { pHIEUNHAPBindingSource.DataSource = db.PHIEUNHAPs.ToList(); } } else { pHIEUNHAPBindingSource.DataSource = ls; } }
private void LoadPhieuXuat(List <PHIEUXUAT> ls = null) { if (ls == null) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { pHIEUXUATBindingSource.DataSource = db.PHIEUXUATs.ToList(); } } else { pHIEUXUATBindingSource.DataSource = ls; } }
private void LoadDonVi(List <DONVI> ls = null) { if (ls != null) { dONVIBindingSource1.DataSource = ls; } else { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { dONVIBindingSource1.DataSource = db.DONVIs.ToList(); } } }
private void LoadNhaCungCap(List <NHACUNGCAP> ls = null) { if (ls != null) { nHACUNGCAPBindingSource1.DataSource = ls; } else { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { nHACUNGCAPBindingSource1.DataSource = db.NHACUNGCAPs.ToList(); } } }
private void LoadHangNhap(List <HANGNHAP> ls = null) { if (ls == null) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { hANGNHAPBindingSource.DataSource = db.HANGNHAPs.ToList(); } } else { hANGNHAPBindingSource.DataSource = ls; } }
private void LoadHangXuat(List <HANGXUAT> ls = null) { if (ls == null) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { hANGXUATBindingSource.DataSource = db.HANGXUATs.ToList(); } } else { hANGXUATBindingSource.DataSource = ls; } }
public bool IsUserName(string userName) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var user = db.Table_User.Where(x => x.UserName == userName).ToList(); if (user.Count == 0) { return(false); } else { return(true); } } }
public static int GetId(string userName) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var user = db.Table_User.Where(x => x.UserName == userName).FirstOrDefault(); if (user == null) { return(-1); } else { return(user.UserId); } } }
private void LoadNhanVien(List <NHANVIEN> ls = null) { if (ls != null) { nHANVIENBindingSource1.DataSource = ls; return; } else { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { nHANVIENBindingSource1.DataSource = db.NHANVIENs.ToList(); } } }
private void LoadNhomHang(List <NHOMHANG> ls = null) { if (ls != null) { nHOMHANGBindingSource.DataSource = ls; return; } else { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { nHOMHANGBindingSource.DataSource = db.NHOMHANGs.ToList(); } } }
private void btnTKDonVi_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { if (string.IsNullOrEmpty(txtTKDonVi.Text) || txtTKDonVi.Text == " ") { LoadDonVi(); } else { var lsDV = db.DONVIs.Where(x => x.tendonvi == txtTKDonVi.Text || x.chucnang == txtTKDonVi.Text).ToList(); LoadDonVi(lsDV); } } }
private void btnTKNCC_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { if (string.IsNullOrEmpty(txtTKNCC.Text) || txtTKNCC.Text == " ") { LoadNhaCungCap(); } else { var lsNCC = db.NHACUNGCAPs.Where(x => x.tenNCC == txtTKNCC.Text || x.sodienthoai == txtTKNCC.Text || x.diachi == txtTKNCC.Text).ToList(); LoadNhaCungCap(lsNCC); } } }
private void tilXoaNV_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var nv = nHANVIENBindingSource1.Current as NHANVIEN; var NV = db.NHANVIENs.SingleOrDefault(x => x.ma == nv.ma); if (NV != null) { db.NHANVIENs.Attach(NV); db.NHANVIENs.Remove(NV); db.SaveChanges(); LoadNhanVien(); } } }
private void btnTKNV_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { if (string.IsNullOrEmpty(txtTKNV.Text) || txtTKNV.Text == " ") { LoadNhanVien(); } else { var lsNCC = db.NHANVIENs.Where(x => x.hoten == txtTKNV.Text || x.gioitinh == txtTKNV.Text).ToList(); LoadNhanVien(lsNCC); } } }
private void btnTKNhomHang_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { if (string.IsNullOrEmpty(txtTKNhomHang.Text) || txtTKNhomHang.Text == " ") { LoadNhomHang(); } else { var nh = db.NHOMHANGs.Where(x => x.tennhom == txtTKNhomHang.Text || x.tacdung == txtTKNhomHang.Text).ToList(); LoadNhomHang(nh); } } }
public string GetPassword(string userName) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var pass = db.Table_User.Where(x => x.UserName == userName).Select(x => x.UserPassword).FirstOrDefault(); if (pass != null) { return(pass); } else { return(null); } } }
private void txtTimKiem_TextChanged(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { if (string.IsNullOrEmpty(txtTimKiem.Text) || txtTimKiem.Text == " ") { LoadHangHoa(); } else { var ls = db.HANGHOAs.Where(x => x.tenhang.Contains(txtTimKiem.Text) || x.donvitinh.Contains(txtTimKiem.Text)).ToList(); LoadHangHoa(ls); } } }
private void btnTkPX_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { if (txtTkPX.Text == " " || string.IsNullOrEmpty(txtTkPX.Text)) { LoadPhieuXuat(); } else { var lsPX = db.PHIEUXUATs.Where(x => x.Spxuat == txtTkPX.Text).ToList(); LoadPhieuXuat(lsPX); } } }
private void btnTkHN_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { if (txtTkHN.Text == " " || string.IsNullOrEmpty(txtTkHN.Text)) { LoadHangNhap(); } else { var tkHN = db.HANGNHAPs.Where(x => x.Spnhap == txtTkHN.Text).ToList(); LoadHangNhap(tkHN); } } }
private void btnTkPN_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { if (txtTkPN.Text == " " || string.IsNullOrEmpty(txtTkPN.Text)) { LoadPhieuNhap(); } else { var lsPN = db.PHIEUNHAPs.Where(x => x.Spnhap == txtTkPN.Text).ToList(); LoadPhieuNhap(lsPN); } } }
private void btnTkHX_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { if (txtTkHX.Text == " " || string.IsNullOrEmpty(txtTkHX.Text)) { LoadHangXuat(); } else { var tkXH = db.HANGXUATs.Where(x => x.Spxuat == txtTkHX.Text).ToList(); LoadHangXuat(tkXH); } } }
private void btnPXx_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var px = pHIEUXUATBindingSource.Current as PHIEUXUAT; var PX = db.PHIEUXUATs.SingleOrDefault(x => x.Spxuat == px.Spxuat); if (PX != null) { db.PHIEUXUATs.Remove(PX); db.SaveChanges(); } else { return; } LoadPhieuXuat(); } }
private void btnPxT_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var px = pHIEUXUATBindingSource.Current as PHIEUXUAT; if (db.PHIEUXUATs.SingleOrDefault(x => x.Spxuat == px.Spxuat) == null) { db.PHIEUXUATs.Add(px); db.SaveChanges(); } else { MetroMessageBox.Show(this, "Sản phẩm đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } LoadPhieuXuat(); } }
private void btnXoaPN_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var pn = pHIEUNHAPBindingSource.Current as PHIEUNHAP; var PN = db.PHIEUNHAPs.SingleOrDefault(x => x.Spnhap == pn.Spnhap); if (PN != null) { db.PHIEUNHAPs.Remove(PN); db.SaveChanges(); } else { return; } LoadPhieuNhap(); } }
private void btnNhapPN_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var pn = pHIEUNHAPBindingSource.Current as PHIEUNHAP; if (db.PHIEUNHAPs.SingleOrDefault(x => x.Spnhap == pn.Spnhap) == null) { db.PHIEUNHAPs.Add(pn); db.SaveChanges(); } else { MetroMessageBox.Show(this, "Sản phẩm đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } LoadPhieuNhap(); } }
public static List <User> GetListUser() { List <User> listUser = new List <User>(); using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { foreach (var item in db.Table_User) { User _user = new User { UserName = item.UserName, Name = item.UserProfile.Name, Role = item.UserRoles.FirstOrDefault().RoleId }; listUser.Add(_user); } } return(listUser); }
private void btnSuaDonVi_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var dv = dONVIBindingSource1.Current as DONVI; var Dvd = db.DONVIs.SingleOrDefault(x => x.ma == dv.ma); if (Dvd != null) { Dvd.tendonvi = dv.tendonvi; Dvd.chucnang = dv.chucnang; db.DONVIs.Attach(Dvd); db.Entry(Dvd).State = EntityState.Modified; db.SaveChanges(); LoadDonVi(); } } }
private void btnHxX_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var xHX = hANGXUATBindingSource.Current as HANGXUAT; var xhx = db.HANGXUATs.SingleOrDefault(x => x.Spxuat == xHX.Spxuat); if (xhx != null) { if (MetroMessageBox.Show(this, "Bạn chắc có muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { db.HANGXUATs.Attach(xhx); db.HANGXUATs.Remove(xhx); db.SaveChanges(); LoadHangXuat(); } } } }
private void btnXoaHN_Click(object sender, EventArgs e) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { var xHN = hANGNHAPBindingSource.Current as HANGNHAP; var xhn = db.HANGNHAPs.SingleOrDefault(x => x.Spnhap == xHN.Spnhap); if (xhn != null) { if (MetroMessageBox.Show(this, "Bạn chắc có muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { db.HANGNHAPs.Attach(xhn); db.HANGNHAPs.Remove(xhn); db.SaveChanges(); LoadHangNhap(); } } } }
public bool ThemPhieuNhapHH(int ma_phieu, Phieu_Nhap_Json pn) { using (QuanLyKhoEntities db = new QuanLyKhoEntities()) { using (var tran = db.Database.BeginTransaction()) { try { var pnhh = new Phieu_Nhap_Hang_Hoa(); pnhh.Phieu_Nhap_Id = ma_phieu; pnhh.Don_gia = pn.Don_gia; pnhh.So_Luong = pn.So_Luong; pnhh.Hang_Hoa_id = pn.Hang_Hoa_id; db.Phieu_Nhap_Hang_Hoa.Add(pnhh); var kho = db.Kho_Chua.Find(pnhh.Hang_Hoa_id); if (kho != null) { kho.So_Luong += pnhh.So_Luong; db.Entry(kho).State = System.Data.Entity.EntityState.Modified; } else { kho = new Kho_Chua(); kho.Hang_Hoa_Id = pnhh.Hang_Hoa_id; kho.So_Luong = pnhh.So_Luong; db.Entry(kho).State = System.Data.Entity.EntityState.Added; } db.SaveChanges(); tran.Commit(); return(true); }catch (Exception) { tran.Rollback(); return(false); } } } }