Exemple #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;
        }
        public void UploadNewVersion()
        {
            DateTime startDT = DateTime.Now;

            try
            {
                UpdateStatusProgressBar(0, "Preparing data...");

                //Step 0: Prepare data
                string sPath        = Path.GetDirectoryName(Application.ExecutablePath);
                string szipFilePath = sPath + "\\" + txt_FileName.Text;

                UpdateStatusProgressBar(0, "Creating new zip file...");

                //Step 1: Create new zip file (includes list of update files)
                try
                {
                    string sUpdateFolder = sPath;
                    ZipArchiveMOD.CreateArchive(szipFilePath, sUpdateFolder, this.lstUploadFiles, true);
                }
                catch (Exception ex1)
                {
                    MessageBox.Show("Error! Create zip file: " + ex1.Message);
                    btn_Upload.Enabled   = true;
                    btn_Download.Enabled = true;

                    return;
                }

                UpdateStatusProgressBar(45, "Inserting version...");

                //Step 2: Insert version
                VersionOBJ verObj = new VersionOBJ();
                verObj.VersionID   = txt_VersionID.Text;
                verObj.VersionName = txt_VersionName.Text;
                verObj.FileName    = txt_FileName.Text;
                //FileInfo fi = new FileInfo(szipFilePath);
                //verObj.FileSize = fi.Length;
                verObj.FileSize    = (new FileInfo(szipFilePath)).Length;
                verObj.VersionType = "TH-CRM";
                verObj.Notes       = txt_Notes.Text;

                UpdateStatusProgressBar(0, "Inserting version...");

                if (VersionCTL.InsertNewVersion(verObj) == false)
                {
                    MessageBox.Show("Error! Insert Version");
                    btn_Upload.Enabled   = true;
                    btn_Download.Enabled = true;
                    return;
                }

                UpdateStatusProgressBar(0, "Uploading file to server...");

                //Step 3: Upload file to server
                if (SegmentDataCTL.UploadFileToServer(szipFilePath, verObj.VersionID, verObj.Notes))
                {
                    DateTime endDT = DateTime.Now;
                    //DateTime delta = endDT - startDT;
                    long totalSecond = 0;
                    if (endDT.Second > startDT.Second)
                    {
                        totalSecond = (endDT.Hour - startDT.Hour) * 60 * 60 + (endDT.Minute - startDT.Minute) * 60 + (endDT.Second - startDT.Second);
                    }
                    else
                    {
                        totalSecond = (endDT.Hour - startDT.Hour) * 60 * 60 + (endDT.Minute - startDT.Minute - 1) * 60 + (endDT.Second + 60 - startDT.Second);
                    }

                    UpdateStatusProgressBar(25, "Finished");

                    MessageBox.Show("Files uploaded successfully! Total second: " + totalSecond.ToString());
                }
                else
                {
                    MessageBox.Show("Error! Upload file!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

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

            //thread.Abort();
        }