Example #1
0
        void timer_Tick(object sender, EventArgs e)
        {
            Timer timer = (Timer)sender;

            timer.Stop();
            timer.Enabled = false;

            try
            {
                this.Cursor = Cursors.WaitCursor;
                this.DoUpgrade();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Text);
            }
            finally
            {
                this.Cursor = Cursors.Default;

                //运行程序
                UpdateXmlDataContract myInfo = this.ReadLocalInformation();
                if (!string.IsNullOrEmpty(myInfo.ExeFile) && System.IO.File.Exists(myInfo.ExeFile))
                {
                    try
                    {
                        if (PublicFunction.IsAppOnRunning(myInfo.ProcessName.Replace(".exe", "")) == false)
                        {
                            System.Diagnostics.Process.Start(myInfo.ExeFile);
                        }
                    }
                    catch (Exception ex)
                    { }
                    //this.Close();

                    Timer timer2 = new Timer();
                    timer2.Interval = 1000;
                    timer2.Tick    += timer2_Tick;
                    timer2.Enabled  = true;
                    timer2.Start();
                }
            }
        }
Example #2
0
        /// <summary>
        /// 升级程序
        /// </summary>
        void DoUpgrade()
        {
            this.progressBar1.Value = 0;
            this.txtMsg.Clear();

            this.AppendMessage("初始化升级信息...");
            if (this.CheckLicense() == false)
            {
                this.AppendMessage("初始化升级程序出错,请联系管理员.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("初始化升级程序出错,请联系管理员.");
                }
                return;
            }
            if (PublicFunction.IsAppOnRunning() == true)
            {
                this.AppendMessage("升级程序运行中,请不要重复运行.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("升级程序运行中,请不要重复运行.");
                }
                this.Close();
            }

            UpdateXmlDataContract myInfo = this.ReadLocalInformation();

            if (string.IsNullOrEmpty(myInfo.ProductCode))
            {
                this.AppendMessage("加载升级信息出错,请联系管理员.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("加载升级信息出错,请联系管理员.");
                }
                return;
            }

            if (!string.IsNullOrEmpty(PublicSetting.ProductCodeExt) && myInfo.ProductCode != PublicSetting.ProductCodeExt)
            {
                this.Close();
            }

            this.SetProgressValue(5);
            this.AppendMessage("读取升级列表中...");

            ProductManager productMan = new ProductManager();
            DataTable      dtProduct  = productMan.GetProduct(myInfo.ProductCode);

            //myInfo.ServerVersion = productMan.GetVersion(myInfo.ProductCode);
            myInfo.ServerVersion     = Convert.ToInt32(dtProduct.Rows[0]["PRODUCT_VERSION"]);
            myInfo.ServerVersionText = dtProduct.Rows[0]["PRODUCT_VERSION2"].ToString();
            if (myInfo.ServerVersion == myInfo.LocalVersion)
            {
                this.SetProgressValue(100);
                this.AppendMessage("当前已是最新版本.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    if (ShowCompleteMessage() == true)
                    {
                        MessageBox.Show("当前已是最新版本.");
                    }
                    return;
                }
                else
                {
                    this.Close();
                    return;
                }
            }

            //删除运行中的进程
            PublicFunction.KillProcess(myInfo.ProcessName);
            if (!string.IsNullOrEmpty(PublicSetting.ProcessNameExt))
            {
                PublicFunction.KillProcess(PublicSetting.ProcessNameExt);
            }

            //开始下载
            this.SetProgressValue(10);
            this.AppendMessage("开始下载升级文件...");
            System.Threading.Thread.Sleep(2000);
            string msg = "";

            VersionFileManager versionFileMan = new VersionFileManager();
            DataTable          dtFileVersion  = versionFileMan.GetDownLoadList(myInfo.LocalVersion);
            string             strRemarks     = string.Empty;
            string             strRemark      = string.Empty;
            List <string>      listRemark     = new List <string>();

            foreach (DataRow row in dtFileVersion.Rows)
            {
                strRemark = row["Remark"].ToString().Trim();
                if (strRemark.Length > 0 && !listRemark.Contains(strRemark))
                {
                    listRemark.Add(strRemark);
                    strRemarks = strRemark.Length == 0 ? strRemark : (strRemarks + Environment.NewLine + strRemark);
                }
            }
            if (strRemarks.Length > 0)
            {
                txtUpdateRemark.Text = strRemarks;
                Application.DoEvents();
            }
            int iCount = dtFileVersion.Rows.Count;

            this.progressBar1.Maximum = iCount;
            for (int i = 0; i < iCount; i++)
            {
                DataRow row = dtFileVersion.Rows[i];
                this.SetProgressValue(i + 1);
                this.AppendMessage("文件下载中..." + row["FILE_NAME"]);//下载文件
                if (this.WriteFile(versionFileMan.GetFile(row["obj_no"].ToString()), row["FILE_PATH"].ToString()) == false)
                {
                    if (msg.Length > 0)
                    {
                        msg += ";文件下载失败->";
                    }
                    msg += row["FILE_NAME"].ToString();
                }
            }

            /*
             * List<VersionFileDataContract> fileList = versionMan.GetDownLoadList(myInfo.ProductCode, myInfo.ServerVersion);
             *
             * for (int i = 0; i < fileList.Count; i++)
             * {
             *  this.SetProgressValue(10 + (i + 1) * 100 / fileList.Count * 9 / 10);
             *  this.AppendMessage("文件下载中..." + fileList[i].FileName);
             *  //下载文件
             *  if (this.WriteFile(versionMan.GetFile(fileList[i]), fileList[i].FileName) == false)
             *  {
             *      if (msg.Length > 0)
             *          msg += ";文件下载失败->";
             *      msg += fileList[i].FileName;
             *  }
             * }
             */
            if (string.IsNullOrEmpty(msg))
            {
                this.AppendMessage("系统升级完成!");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    if (ShowCompleteMessage() == true)
                    {
                        MessageBox.Show("系统升级完成!");
                    }
                }
                try
                {
                    //升级信息保存到本地
                    this.UpdateUpgradeInformation(myInfo);
                    //System.Diagnostics.Process.Start
                }
                catch (Exception ex)
                { }
            }
            else
            {
                this.AppendMessage("升级失败,参考信息:" + msg);
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("升级失败,参考信息:" + msg);
                }
            }
        }
Example #3
0
        void DoUpgrade()
        {
            this.progressBar1.Value = 0;
            this.txtMsg.Clear();

            this.AppendMessage("初始化升级信息...");
            if (this.CheckLicense() == false)
            {
                this.AppendMessage("初始化升级程序出错,请联系管理员.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("初始化升级程序出错,请联系管理员.");
                }
                return;
            }
            if (PublicFunction.IsAppOnRunning() == true)
            {
                this.AppendMessage("升级程序运行中,请不要重复运行.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("升级程序运行中,请不要重复运行.");
                }
                this.Close();
            }

            UpdateDataContract myInfo = this.ReadLocalInformation();

            if (string.IsNullOrEmpty(myInfo.ProductCode))
            {
                this.AppendMessage("加载升级信息出错,请联系管理员.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("加载升级信息出错,请联系管理员.");
                }
                return;
            }

            if (!string.IsNullOrEmpty(PublicSetting.ProductCodeExt) && myInfo.ProductCode != PublicSetting.ProductCodeExt)
            {
                this.Close();
            }

            this.SetProgressValue(5);
            this.AppendMessage("读取升级列表中...");

            VersionManager versionMan = new VersionManager();

            myInfo.ServerVersion = versionMan.GetServerVersion(myInfo);
            if (myInfo.ServerVersion == myInfo.LocalVersion)
            {
                this.SetProgressValue(100);
                this.AppendMessage("当前已是最新版本.");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    if (ShowCompleteMessage() == true)
                    {
                        MessageBox.Show("当前已是最新版本.");
                    }
                    return;
                }
                else
                {
                    this.Close();
                    return;
                }
            }

            //删除运行中的进程
            PublicFunction.KillProcess(myInfo.ProcessName);
            if (!string.IsNullOrEmpty(PublicSetting.ProcessNameExt))
            {
                PublicFunction.KillProcess(PublicSetting.ProcessNameExt);
            }

            //开始下载
            this.SetProgressValue(10);
            this.AppendMessage("开始下载升级文件...");
            System.Threading.Thread.Sleep(2000);
            string msg = "";
            List <VersionFileDataContract> fileList = versionMan.GetDownLoadList(myInfo.ProductCode, myInfo.ServerVersion);

            for (int i = 0; i < fileList.Count; i++)
            {
                this.SetProgressValue(10 + (i + 1) * 100 / fileList.Count * 9 / 10);
                this.AppendMessage("文件下载中..." + fileList[i].FileName);
                //下载文件
                if (this.WriteFile(versionMan.GetFile(fileList[i]), fileList[i].FileName) == false)
                {
                    if (msg.Length > 0)
                    {
                        msg += ";文件下载失败->";
                    }
                    msg += fileList[i].FileName;
                }
            }

            if (string.IsNullOrEmpty(msg))
            {
                this.AppendMessage("系统升级完成!");
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    if (ShowCompleteMessage() == true)
                    {
                        MessageBox.Show("系统升级完成!");
                    }
                }
                try
                {
                    //升级信息保存到本地
                    this.UpdateUpgradeInformation(myInfo);
                    //System.Diagnostics.Process.Start
                }
                catch (Exception ex)
                { }
            }
            else
            {
                this.AppendMessage("升级失败,参考信息:" + msg);
                if (string.IsNullOrEmpty((PublicSetting.ProductCodeExt)))
                {
                    MessageBox.Show("升级失败,参考信息:" + msg);
                }
            }
        }