private void SynsChungTuNhap() { try { ConnectionUtil.Instance.BeginTransaction(); string inventoryOrg = currentTrungTam.MaTrungTam; string inventorySub = currentKho.MaKho; frmProgress.Instance.Description = "Đang xóa dữ liệu tạm..."; NhapHangProvider.ClearTemporary(inventoryOrg, inventorySub, Declare.UserId); frmProgress.Instance.Value += 1; frmProgress.Instance.Description = "Đang đồng bộ dữ liệu..."; bool success = false; if (dteLastSync.DateTime.AddDays(15) < CommonProvider.Instance.GetSysDate()) { dteLastSync.DateTime = CommonProvider.Instance.GetSysDate().AddDays(-15); } success = BusinessSynchronize.Instance.ChungTuNhapNCCSync(inventoryOrg, inventorySub, dteLastSync.DateTime.ToString("yyyy/MM/dd HH:mm:ss")); if (success) { frmProgress.Instance.Value += 1; NhapHangProvider.TransferToUserData(inventoryOrg, inventorySub, Declare.UserId); frmProgress.Instance.Value += 1; frmProgress.Instance.Description = "Đang cập nhật lại lịch sử..."; NhapHangProvider.ClearTraHangHistory(inventoryOrg, inventorySub); frmProgress.Instance.Value += 1; NhapHangProvider.LogHistory(inventoryOrg, inventorySub, Convert.ToInt32(LoaiGiaoDichPO.TRA_HANG_NHA_CUNG_CAP)); ConnectionUtil.Instance.CommitTransaction(); LockControl.Unlock("SysnChungTuTraNCC"); frmProgress.Instance.Value = frmProgress.Instance.MaxValue; frmProgress.Instance.Description = "Đã hoàn thành."; Thread.CurrentThread.Join(2500); frmProgress.Instance.IsCompleted = true; } else { ConnectionUtil.Instance.RollbackTransaction(); LockControl.Unlock("SysnChungTuTraNCC"); frmProgress.Instance.Value = frmProgress.Instance.MaxValue; frmProgress.Instance.Description = "Không đồng bộ được dữ liệu."; Thread.CurrentThread.Join(2500); frmProgress.Instance.IsCompleted = true; } } catch (Exception ex) { ConnectionUtil.Instance.RollbackTransaction(); LockControl.Unlock("SysnChungTuTraNCC"); EventLogProvider.Instance. WriteOfflineLog(ex + "\nUser: "******"\nKho: " + Declare.IdKho, this.Name); frmProgress.Instance.Value = frmProgress.Instance.MaxValue; frmProgress.Instance.Description = "Không hoàn thành!!!"; Thread.CurrentThread.Join(2500); frmProgress.Instance.IsCompleted = true; } }
private void SynsChungTuNhap() { currentTrungTam = DMTrungTamDataProvider.GetTrungTamByIdInfo(Declare.IdTrungTam); currentKho = DMKhoDataProvider.GetKhoByIdInfo(Declare.IdKho); string inventoryOrg = currentTrungTam.MaTrungTam; string inventorySub = currentKho.MaKho; frmProgress.Instance.Description = "Đang xóa dữ liệu tạm..."; NhapHangProvider.ClearTemporary(inventoryOrg, inventorySub, Declare.UserId); frmProgress.Instance.Value += 1; frmProgress.Instance.Description = "Đang đồng bộ dữ liệu..."; bool success = false; //success = BusinessSynchronize.Instance.ChungTuNhapNCCSync(inventoryOrg, inventorySub, NhapHangProvider.NhapHangLastUpdateDate(inventoryOrg, inventorySub)); if (!success) { frmProgress.Instance.Value = frmProgress.Instance.MaxValue; frmProgress.Instance.Description = "Không hoàn thành."; frmProgress.Instance.IsCompleted = true; MessageBox.Show("Gọi webservice không thành công!"); return; } frmProgress.Instance.Value += 1; NhapHangProvider.TransferToUserData(inventoryOrg, inventorySub, Declare.UserId); frmProgress.Instance.Value += 1; frmProgress.Instance.Description = "Đang cập nhật lại lịch sử..."; NhapHangProvider.ClearNhapHangHistory(inventoryOrg, inventorySub); frmProgress.Instance.Value += 1; NhapHangProvider.LogHistory(inventoryOrg, inventorySub, Convert.ToInt32(LoaiGiaoDichPO.NHAP_HANG_NHA_CUNG_CAP)); frmProgress.Instance.Value = frmProgress.Instance.MaxValue; frmProgress.Instance.Description = "Đã hoàn thành."; frmProgress.Instance.IsCompleted = true; //sql = String.Format("SELECT COUNT(*) FROM tbl_Tmp_NhapHang WHERE MaSanPham NOT IN (SELECT MaSanPham FROM tbl_SanPham WHERE sudung=1) AND InventoryOrg='{0}' AND InventorySub='{1}'", inventoryOrg, inventorySub); ////sql += String.Format("AND SoPO=N'{0}' AND SoPhieuNhap=N'{1}'", txtSoPO.Text, txtPhieuNhap.Text); //object countNotMa = SqlHelper.ExecuteScalar(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql); //cmdShowNotMa.Visible = false; //if (Convert.ToInt32(countNotMa) > 0) //{ // cmdShowNotMa.Visible = true; // cmdShowNotMa.Text = String.Format("{0} mặt hàng có mã không hợp lệ", countNotMa); //} //string sql = String.Format("SELECT t1.SoPhieuNhap, t1.SoPO, ct.IdChungTu, SUM(SoLuong) AS TongSoLuong, N'Hàng bán' AS TrangThai FROM tbl_Tmp_NhapHang t1 " // + "LEFT OUTER JOIN tbl_ChungTu ct ON ct.SoChungTu=t1.SoPhieuNhap AND ct.SoSeri=t1.SoPO AND ct.LoaiChungTu={0} AND ct.IdKho={5} " // + "AND (SELECT TOP (1) soluong FROM tbl_chungtu_chitiet WHERE tbl_chungtu_chitiet.idchungtu = ct.idchungtu)>=0 " // + "WHERE InventoryOrg='{1}' AND InventorySub='{2}' AND ThoiGian < '{3}' AND ThoiGian > '{4}' AND SoLuong >= 0 GROUP BY SoPhieuNhap, SoPO, IdChungTu " // + "UNION ALL " // + "SELECT t1.SoPhieuNhap, t1.SoPO, ct.IdChungTu, SUM(SoLuong) AS TongSoLuong, N'Hàng trả lại' AS TrangThai FROM tbl_Tmp_NhapHang t1 " // + "LEFT OUTER JOIN tbl_ChungTu ct ON ct.SoChungTu=t1.SoPhieuNhap AND ct.SoSeri=t1.SoPO AND ct.LoaiChungTu={0} AND ct.IdKho={5} " // + "AND (SELECT TOP (1) soluong FROM tbl_chungtu_chitiet WHERE tbl_chungtu_chitiet.idchungtu = ct.idchungtu)<0 " // + "WHERE InventoryOrg='{1}' AND InventorySub='{2}' AND ThoiGian < '{3}' AND ThoiGian > '{4}' AND SoLuong < 0 GROUP BY SoPhieuNhap, SoPO, IdChungTu " // + "ORDER BY SoPhieuNhap, SoPO, TongSoLuong DESC", // (int)TransactionType.NHAP, // inventoryOrg, // inventorySub, // dtNgayDongBo.Value.ToString(new CultureInfo("en-US")), // currentKho.LanDongBoTruoc.ToString(new CultureInfo("en-US")), // Declare.IdKho); LockControl.Unlock("SysnChungTuNhap"); }