Esempio n. 1
0
        private void SynsNhapThanhPham()
        {
            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);
            SanXuatLenhProvier.tmpSanXuatDelete(inventoryOrg);
            SanXuatLenhProvier.tmpSanXuatCTietDelete(inventoryOrg);

            frmProgress.Instance.Value += 1;

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

            bool success = false;

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

            frmProgress.Instance.Value += 1;

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

            litmpSX = SanXuatLenhProvier.GetAlltmpSanXuatLenh(MaTrungTam, "GHEPMA");
            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_COMBO), litmpSX[i].MaLenh, currentTrungTam.MaTrungTam);
                if (SoLuongHT == 0)
                {
                    liChiTiet[i].TrangThai = Convert.ToInt32(TrangThaiSanXuat.ChoXuat);
                }
                if (SoLuongHT > 0 && SoLuongHT < litmpSX[i].SoLuongTP &&
                    (litmpSX[i].Status != 2 || litmpSX[i].Status != 3))
                {
                    liChiTiet[i].TrangThai = Convert.ToInt32(TrangThaiSanXuat.DangSX);
                }
                if (SoLuongHT == litmpSX[i].SoLuongTP && litmpSX[i].Status != 2)
                {
                    liChiTiet[i].TrangThai = Convert.ToInt32(TrangThaiSanXuat.DaSanXuatXong);
                }
                if (litmpSX[i].Status == 2)
                {
                    liChiTiet[i].TrangThai = Convert.ToInt32(TrangThaiSanXuat.HuyLenh);
                }
                if (SoLuongHT != litmpSX[i].SoLuongTP && litmpSX[i].Status == 3)
                {
                    liChiTiet[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);
                }
                //SanXuatCTietLenhProvider.Insert(sxct);
            }
            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       = frmProgress.Instance.MaxValue;
            frmProgress.Instance.Description = "Đã hoàn thành.";
            frmProgress.Instance.IsCompleted = true;

            LockControl.Unlock("SynsNhapThanhPham");
        }
Esempio n. 2
0
        private void SynsNhapDoiMa()
        {
            try
            {
                frmProgress.Instance.Text = "Đồng bộ dữ liệu";

                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(31) < 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(-31);
                }

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

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

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

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

                    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.Description      = litmpSX[i].Description;
                        sx.Last_update_date = litmpSX[i].Last_update_date;

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

                        if (SoLuongHT == 0)
                        {
                            sx.TrangThai = Convert.ToInt32(TrangThaiSanXuat.ChoXuat);
                        }

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

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

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

                        if (SoLuongHT != litmpSX[i].SoLuongTP && litmpSX[i].Status == 3)
                        {
                            sx.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 = "Đã hoàn thành.";

                    frmProgress.Instance.IsCompleted = true;

                    LockControl.Unlock("SynsNhapDoiMa");
                }
                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("SynsNhapDoiMa");

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

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

                LockControl.Unlock("SynsNhapDoiMa");

                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;
            }
        }