示例#1
0
        public bool DownloadTheLastestVersion()
        {
            bool result = true;

            UpdateStatusProgressBar(0, "Chuẩn bị dữ liệu...");

            //Step 0: Prepare data
            string sPath = Path.GetDirectoryName(Application.ExecutablePath);

            UpdateStatusProgressBar(10, "Đang lấy thông tin phiên bản mới...");
            //Step 1: Get the lastest version
            VersionOBJ verObj = VersionCTL.GetLastestVersion();

            if (verObj.VersionID == string.Empty)
            {
                MessageBox.Show("Lỗi! Không thể cập nhật phiên bản mới!");
                return(false);
            }

            string szipFilePath = sPath + "\\CRM_ver_" + verObj.VersionID + ".zip";

            UpdateStatusProgressBar(45, "Đang tải tập tin...");
            //Step 2: Download zip file from server and save in the Path
            if (SegmentDataCTL.DownloadFileFromServer(verObj.VersionID, szipFilePath) == false)
            {
                MessageBox.Show("Lỗi! Không thể tải tập tin!");
                return(false);
            }

            UpdateStatusProgressBar(20, "Đang cập nhật phiên bản mới...");
            //Step 3: Extract zip file
            try
            {
                string sOutputPath = sPath;
                ZipArchiveMOD.UnzipFile(szipFilePath, sOutputPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi! Không thể giải nVN tập tin! Chi tiết: " + ex.Message);
                return(false);
            }

            UpdateStatusProgressBar(0, "Hoàn tất");
            //Step 4: Write a new version to file
            string sfileVerPath = sPath + "\\version.dat";

            VersionCTL.WriteNewVersion(verObj, sfileVerPath);
            File.Delete(szipFilePath);
            MessageBox.Show("Cập nhật phiên bản mới thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return(true);
        }
        public void DownloadTheLastestVersion()
        {
            UpdateStatusProgressBar(0, "Preparing data...");

            //Step 0: Prepare data
            string sPath = Path.GetDirectoryName(Application.ExecutablePath);

            UpdateStatusProgressBar(10, "Getting lastest version...");
            //Step 1: Get the lastest version
            VersionOBJ verObj = VersionCTL.GetLastestVersion();

            if (verObj.VersionID == string.Empty)
            {
                MessageBox.Show("Error! Can't get new version!");
                return;
            }
            //string szipFilePath = sPath + "\\" + verObj.FileName;
            string szipFilePath = sPath + "\\CRM_Download.zip";

            UpdateStatusProgressBar(45, "Downloading file...");
            //Step 2: Download zip file from server and save in the Path
            if (SegmentDataCTL.DownloadFileFromServer(verObj.VersionID, szipFilePath) == false)
            {
                MessageBox.Show("Error! Can't download upload file!");
                return;
            }

            UpdateStatusProgressBar(20, "Updating file...");
            //Step 3: Extract zip file
            try
            {
                string sOutputPath = sPath + "\\tmp1";
                ZipArchiveMOD.UnzipFile(szipFilePath, sOutputPath);
            }
            catch
            {
                MessageBox.Show("Error! Can't extract zip file!");
                return;
            }

            UpdateStatusProgressBar(0, "Finished");
            MessageBox.Show("Download file successfully!");
            //Step 4: Copy and overwrite (maybe) to folder QuanLyDiem

            btn_Upload.Enabled   = true;
            btn_Download.Enabled = true;
        }