Пример #1
0
 private void btnUpdateVersion_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Khi cập nhật phiên bản mới chương trình sẽ bị đóng lại, và tự khởi động lại khi cập nhật xong dữ liệu. Bạn chắc chắn muốn cập nhật ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         frmUpdateVersion f = new frmUpdateVersion();
         f.Show();
     }
 }
Пример #2
0
        private void CheckForUpdate()
        {
            int ver_new = 0, ver_old = 0;

            try
            {
                string remotePath  = HOST_ADDRESS + "/" + UPDATE_FILE_VERSION;
                string version_new = System.IO.Path.GetTempPath() + TEMP_DIR + "\\" + UPDATE_FILE_VERSION;

                if (File.Exists(version_new))
                {
                    File.Delete(version_new);
                }

                CreateTempDirectory();
                DownloadFile(remotePath, version_new);


                var fileContent = System.IO.File.ReadAllLines(version_new);
                ver_new = int.Parse(fileContent[0]);//lay version moi nhat tu server

                fileContent = System.IO.File.ReadAllLines(UPDATE_FILE_VERSION_LOCAL);
                ver_old     = int.Parse(fileContent[0]); //lay version hien tai may tram

                if (ver_new > ver_old)                   //neu co version moi
                {
                    if (MessageBox.Show("Đã có phiên bản cập nhật mới, bạn có muốn cập nhật ngay bây giờ hay không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        frmUpdateVersion f = new frmUpdateVersion();
                        f.Show();
                    }
                    else
                    {
                        this.Close();
                    }
                }
            }
            catch
            {
                this.Close();
            }
        }