private void SynsXuatLinhKien()
        {
            try
            {
                frmProgress.Instance.Text = Text;

                frmProgress.Instance.MaxValue = 3;

                ConnectionUtil.Instance.BeginTransaction();

                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...";

                SanXuatLenhProvier.tmpSanXuatDelete(inventoryOrg);

                SanXuatLenhProvier.tmpSanXuatCTietDelete(inventoryOrg);

                frmProgress.Instance.Value += 1;

                frmProgress.Instance.Description = "Đang đồng bộ dữ liệu...";

                bool success = false;

                DateTime sysDate = CommonProvider.Instance.GetSysDate();

                if (dteLastSync.DateTime.AddDays(7) < sysDate)
                {
                    //note: từ 1/6/2013 về trước có dữ liệu lặp trên ORC, nên nếu phải lấy dữ liệu lại từ đầu
                    //note: thì chỉ có thể lấy về từ ngày này, cần hết sức lưu ý.
                    dteLastSync.EditValue = sysDate.AddDays(-7);
                }

                success = BusinessSynchronize.Instance.LenhSanXuatSyncV2(dteLastSync.DateTime.ToString("yyyy/MM/dd hh:mm:ss"), inventoryOrg, "LSX");

                if (success)
                {
                    frmProgress.Instance.Value += 1;

                    frmProgress.Instance.Description = "Đang cập nhật lại lịch sử...";

                    litmpSX = SanXuatLenhProvier.GetAlltmpSanXuatLenh(MaTrungTam, "LSX");

                    litmpCT = SanXuatLenhProvier.GetAlltmpCTSanXuatLenh(MaTrungTam);

                    for (int i = 0; i < litmpSX.Count; i++)
                    {
                        sx.MaLenh           = litmpSX[i].MaLenh;
                        sx.MaThanhPham      = litmpSX[i].MaThanhPham;
                        sx.NgayLap          = litmpSX[i].NgayLap;
                        sx.NguoiLap         = litmpSX[i].NguoiLap;
                        sx.OrgCode          = litmpSX[i].OrgCode;
                        sx.SoLuongTP        = litmpSX[i].SoLuongTP;
                        sx.Status           = litmpSX[i].Status;
                        sx.Loai_Ma_Lenh     = litmpSX[i].Loai_Ma_Lenh;
                        sx.Last_update_date = litmpSX[i].Last_update_date;

                        int SoLuongHT = SanXuatLenhProvier.GetSoLuongDNSanXuatLenh(
                            Convert.ToInt32(TransactionType.NHAP_THANH_PHAM_SX), litmpSX[i].MaLenh, currentTrungTam.MaTrungTam);

                        if (SoLuongHT > 0 && SoLuongHT < litmpSX[i].SoLuongTP &&
                            (litmpSX[i].Status != 2 || litmpSX[i].Status != 3))
                        {
                            litmpSX[i].TrangThai = Convert.ToInt32(TrangThaiSanXuat.DangSX);
                        }

                        if (SoLuongHT == litmpSX[i].SoLuongTP && litmpSX[i].Status != 2)
                        {
                            litmpSX[i].TrangThai = Convert.ToInt32(TrangThaiSanXuat.DaSanXuatXong);
                        }

                        if (litmpSX[i].Status == 2)
                        {
                            litmpSX[i].TrangThai = Convert.ToInt32(TrangThaiSanXuat.HuyLenh);
                        }

                        if (SoLuongHT != litmpSX[i].SoLuongTP && litmpSX[i].Status == 3)
                        {
                            litmpSX[i].TrangThai = Convert.ToInt32(TrangThaiSanXuat.NgungSanXuat);
                        }

                        if (SanXuatLenhProvier.CheckMaLenh(litmpSX[i].MaLenh, litmpSX[i].MaThanhPham, currentTrungTam.MaTrungTam) == 0)
                        {
                            SanXuatLenhProvier.Insert(sx);
                        }
                        else
                        {
                            SanXuatLenhProvier.Update(sx);
                        }
                    }

                    for (int i = 0; i < litmpSX.Count; i++)
                    {
                        SanXuatCTietLenhProvider.Delete(litmpSX[i].MaLenh, currentTrungTam.MaTrungTam);
                    }

                    for (int i = 0; i < litmpCT.Count; i++)
                    {
                        sxct.MaLenh           = litmpCT[i].MaLenh;
                        sxct.MaLinhKien       = litmpCT[i].MaLinhKien;
                        sxct.NgayCanXuat      = litmpCT[i].NgayCanXuat;
                        sxct.OrgCode          = litmpCT[i].OrgCode;
                        sxct.SoLuongCanXuat   = litmpCT[i].SoLuongCanXuat;
                        sxct.SoLuongDaXuat    = litmpCT[i].SoLuongDaXuat;
                        sxct.SoLuongTrenTPham = litmpCT[i].SoLuongTrenTPham;
                        sxct.KhoXuat          = litmpCT[i].KhoXuat;
                        if (SanXuatLenhProvier.CheckCtietMaLenh(litmpCT[i].MaLenh, currentTrungTam.MaTrungTam, litmpCT[i].MaLinhKien) == 0)
                        {
                            SanXuatCTietLenhProvider.Insert(sxct);
                        }
                        else
                        {
                            SanXuatCTietLenhProvider.Update(sxct);
                        }
                    }

                    ConnectionUtil.Instance.CommitTransaction();

                    frmProgress.Instance.Value = frmProgress.Instance.MaxValue;

                    frmProgress.Instance.Description = "Đã xong.";

                    frmProgress.Instance.IsCompleted = true;

                    LockControl.Unlock("SynsXuatLinhKien");
                }
                else
                {
                    ConnectionUtil.Instance.RollbackTransaction();

                    frmProgress.Instance.Value = frmProgress.Instance.MaxValue;

                    frmProgress.Instance.Description = "Không hoàn thành.";

                    frmProgress.Instance.IsCompleted = true;

                    LockControl.Unlock("SynsXuatLinhKien");

                    MessageBox.Show("Gọi webservice không thành công!");

                    return;
                }
            }
            catch (Exception ex)
            {
                ConnectionUtil.Instance.RollbackTransaction();

                LockControl.Unlock("SynsXuatLinhKien");

                EventLogProvider.Instance.WriteOfflineLog(ex.ToString(), this.Name);

                MessageBox.Show(ex.Message);

                frmProgress.Instance.Value = frmProgress.Instance.MaxValue;

                frmProgress.Instance.Description = "Không hoàn thành.";

                frmProgress.Instance.IsCompleted = true;
            }
        }
Esempio n. 2
0
 private string GetMaTrungTam()
 {
     currentTrungTam = DMTrungTamDataProvider.GetTrungTamByIdInfo(Declare.IdTrungTam);
     return(currentTrungTam.MaTrungTam);
 }
Esempio n. 3
0
        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");
        }