public void loadData() { lkTenKhoHang.Text = temp; txtTenKhuVuc.Text = TenKeHang; loadLK(); var data = (from d in db.KiemKeHangHoas join t in db.HangHoas on d.ID_HangHoa equals t.HangHoaID where (d.ID_Users == ID_User && d.TenKeHang == TenKeHang && d.updated_at.Day == ThoiGian.Day && d.updated_at.Month == ThoiGian.Month && d.updated_at.Year == ThoiGian.Year && d.updated_at.Hour == ThoiGian.Hour && d.updated_at.Minute == ThoiGian.Minute && d.ID_Kho == IDStore) select new { stt = d.STT, IDHangHoa = d.ID_HangHoa, MaHH = t.MaHH, TenHH = t.TenHH, MaGoiNho = t.MaGoiNho, LoaiKiemKe = d.LoaiKiemKe, ThoiGianQuet = d.NgayKiemKe, ThoiGianCapNhat = d.updated_at }).ToList(); foreach (var c in data) { clsHangHoa entity = new clsHangHoa() { IDHangHoa = c.IDHangHoa, SoTT = (int)c.stt, ProductCode = c.MaHH, ProductName = c.TenHH, MaGoiNho = c.MaGoiNho, ThoiGianQuet = c.ThoiGianQuet, ThoiGianCapNhat = c.ThoiGianCapNhat, LoaiKiemKe = (int)c.LoaiKiemKe }; list.Add(entity); bindingSource1.DataSource = list; _SoTT = _SoTT + 1; } }
private void CheckMaHangHoa() { try { // _id = Convert.ToInt64(gridView1.GetRowCellValue(0, colID)); if (txtMa.Text == "") { return; } else { if (lkTenKhoHang.Text == "" || txtTenKhuVuc.Text == "") { MessageBox.Show("Chưa nhập tên khu vực và tên kho hàng"); txtMa.Text = ""; return; } else { string _productCode = txtMa.Text; string IDStore = (string)(lkTenKhoHang as LookUpEdit).EditValue; // ID Kho string tenKV = txtTenKhuVuc.Text; var data = (from e in db.HangHoas where (e.MaHH == _productCode || e.MaGoiNho == _productCode) select new { IDHangHoa = e.HangHoaID, MaHH = e.MaHH, TenHH = e.TenHH, MaGoiNho = e.MaGoiNho }).ToList(); //sửa //foreach(var c in data) //{ // var kiemke = new KiemKeHangHoa // { // STT = _SoTT, // ID_Users = ID_User, // ID_HangHoa = c.IDHangHoa, // ID_Kho = IDStore, // TenKeHang = tenKV, // SoLuong = 1, // NgayKiemKe = DateTime.Now, // updated_at = ThoiGian, // LoaiKiemKe = bLoaiKiemKe // }; // db.KiemKeHangHoas.Add(kiemke); // db.SaveChanges(); //} //string IDStore = (string)(lkTenKhoHang as LookUpEdit).EditValue; if (data.Count != 0) { foreach (var c in data) { clsHangHoa entity = new clsHangHoa() { // ID = _id+1 , IDHangHoa = c.IDHangHoa, SoTT = _SoTT, ProductCode = c.MaHH, ProductName = c.TenHH, MaGoiNho = c.MaGoiNho, //SoLuong = _SoLuong, ThoiGianQuet = DateTime.Now, ThoiGianCapNhat = DateTime.Now, LoaiKiemKe = bLoaiKiemKe }; list.Add(entity); bindingSource1.ResetBindings(true); gcDSHangHoa.RefreshDataSource(); gcDSHangHoa.DataSource = list; txtMessage.Text = string.Format("Tìm thấy: {0}", txtMa.Text); txtMessage.ForeColor = Color.Green; txtMa.Text = ""; bLoaiKiemKe = 0; // _id = _id + 1; _SoTT = _SoTT + 1; } } else if (data.Count == 0) { System.Media.SystemSounds.Beep.Play(); if (MessageBox.Show("Không tìm thấy mã trong kho ! \n Xem gợi ý hàng hóa ?", "Thông Báo ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { var frmSelect = new ListMaHH(); frmSelect._MaHHPartial = txtMa.Text; frmSelect._MaGoiNho = txtMa.Text; if (frmSelect.GetListMa()) { if (frmSelect.ShowDialog() == DialogResult.OK) { _SoLuong = frmSelect._SoLuong; for (int i = 0; i < _SoLuong; i++) { txtMa.Text = frmSelect.MaHHSelect; bLoaiKiemKe = 1; CheckMaHangHoa(); } return; } } txtMessage.Text = string.Format("{0}: {1}", txtMa.Text); txtMessage.ForeColor = Color.Red; txtMa.Text = ""; bLoaiKiemKe = 0; } } } } } catch { } }
//check hàng private void CheckMaHangHoa() { try { if (txtMa.Text == "") { return; } else { if (lkTenKhoHang.Text == "" || txtTenKhuVuc.Text == "") { System.Media.SystemSounds.Beep.Play(); MessageBox.Show("Chưa nhập tên khu vực và tên kho hàng"); txtMa.Text = ""; return; } else { string _productCode = txtMa.Text; var data = (from e in db.HangHoas where (e.MaHH == _productCode || e.MaGoiNho == _productCode) select new { IDHangHoa = e.HangHoaID, MaHH = e.MaHH, TenHH = e.TenHH, MaGoiNho = e.MaGoiNho }).ToList(); string IDStore = (string)(lkTenKhoHang as LookUpEdit).EditValue; if (data.Count != 0) { foreach (var c in data) { clsHangHoa entity = new clsHangHoa() { IDHangHoa = c.IDHangHoa, SoTT = _SoTT, ProductCode = c.MaHH, ProductName = c.TenHH, MaGoiNho = c.MaGoiNho, //SoLuong = _SoLuong, ThoiGianQuet = DateTime.Now, LoaiKiemKe = bLoaiKiemKe }; list.Add(entity); bindingSource1.ResetBindings(true); gcDSHangHoa.RefreshDataSource(); txtMessage.Text = string.Format("Tìm thấy: {0}", txtMa.Text); txtMessage.ForeColor = Color.Green; txtMa.Text = ""; bLoaiKiemKe = 0; _SoTT = _SoTT + 1; } } else if (data.Count == 0) { System.Media.SystemSounds.Beep.Play(); // MessageBox.Show("Không tìm thấy mã trong kho ! \n Xem gợi ý hàng hóa ?", "Thông Báo ", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (MessageBox.Show("Không tìm thấy mã trong kho ! \n Xem gợi ý hàng hóa ?", "Thông Báo ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { var frmSelect = new ListMaHH(); frmSelect._MaHHPartial = txtMa.Text; frmSelect._MaGoiNho = txtMa.Text; if (frmSelect.GetListMa()) { if (frmSelect.ShowDialog() == DialogResult.OK) { _SoLuong = frmSelect._SoLuong; for (int i = 0; i < _SoLuong; i++) { txtMa.Text = frmSelect.MaHHSelect; bLoaiKiemKe = 1; CheckMaHangHoa(); } return; } } txtMessage.Text = string.Format("{0}: {1}", txtMa.Text); txtMessage.ForeColor = Color.Red; txtMa.Text = ""; bLoaiKiemKe = 0; } } } } } catch { } }