zoukankan      html  css  js  c++  java
  • 程序自动更新版本

    增加了程序自动更新版本的功能,实现方式如下:

    后台数据库中用一张表来保存程序的版本信息,该表的字段很简单,如下:

    复制代码
    CREATE TABLE [dbo].[sys_AutoUpdate](
     [UID] [int] IDENTITY(1,1) NOT NULL,
     [SystemName] [varchar](50) NULL,
     [SystemVersion] [varchar](10) NULL,
     [Remark] [text] NULL,
     [UpdateDate] [datetime] NULL,
     [UpdatePath] [varchar](500) NULL)
    复制代码

    在之前的项目里面增加了一个新的项目,主要用来实现更新,通过"参数设置"界面维护必须要的信息,如更新的文件列表,
    更新的路径,需要更新的程序名称,版本以及描述信息等等,如下图:

    将需要更新的文件放置更新的目录中,这样客户端才可以得到最新的文件,程序里面会记录着每次的版本号,如下代码:

    复制代码
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using Allen.Model;
     6 
     7 namespace Allen.Tools.Common
     8 {
     9     /// <summary>
    10     /// 这个类很重要,主要用来保存 一些临时信息,可以在整个项目中使用
    11     /// </summary>
    12     public sealed class AllenSingleton
    13     {         
    14         private static volatile AllenSingleton instance;
    15         private static object syncRoot = new Object();
    16 
    17         private AllenSingleton() { }
    18         public static AllenSingleton Instance
    19         {
    20             get
    21             {
    22                 if (instance == null)
    23                 {
    24                     lock (syncRoot)
    25                     {
    26                         if (instance == null)
    27                             instance = new AllenSingleton();
    28                     }
    29                 }
    30                 return instance;
    31             }
    32         }
    33 
    34         public string strCon = Allen.Model.ConnectionModel.ConnectionString1;
    35         public string UserID;
    36         public string Password;
    37         public string UserDep;
    38         public string ServerID;
    39         public string Lang;                
    40         public FrmMain m_FrmMain;
    41         public string Company;
    42         public string AppConfigFile;
    43         public Dictionary<string, string> DicLang;       
    44         public string Role;
    45         public string RoleName; 
    46                 public string currentlyVersion = "1.001";
    47         public string SystemName = "Allen.Tools";
    48 
    49      
    50         public string AllowCreate;
    51         public string AllowDelete;
    52         public string AllowEdit;
    53         public string AllowPrint;
    54        
    55 
    56         //public static class GlobalData
    57         //{
    58         //    public static Dictionary<string, Action> dict = new Dictionary<string, Action>();
    59         //}
    60 
    61 
    62     }
    63 }
    复制代码

    客户端在登录的时候进行版本检查:

    复制代码
     1  double NewVer = Convert.ToDouble(new BLL.sys_AutoUpdateManager().GetSystemVersionInfo(allensingleton.SystemName).Rows[0]["SystemVersion"].ToString());
     2                     double CurrVer = Convert.ToDouble(allensingleton.currentlyVersion);
     3                     if (NewVer > CurrVer)
     4                     {
     5 
     6                         DialogResult dr = MessageBox.Show("发现新的版本,是否要更新该软件?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
     7                         if (dr == DialogResult.OK)
     8                         {
     9                             Process.Start(Application.StartupPath+"\\AutoUpdate.exe");
    10                             Thread.Sleep(500);
    11                             this.Dispose();
    12                             this.Close();
    13                         }
    14                     }
    复制代码

    如果版本低于服务器上面的版本,那么则启动更新程序:

    待更新结束之后再重新打开最新版本的程序,主程序和更新程序放在同一目录里面。


     

     
    分类: C#WinForm
    标签: WinForm框架
  • 相关阅读:
    linux——系统内核参数优化
    nginx 开启高效文件传输模式
    nginx——Nginx 处理事件模型
    Nginx 单个进程允许的最大连接数
    nginx传世经典
    Python中常见的数据类型总结(二)
    Python中常见的数据类型总结(一)
    Web压力测试工具 webbench
    性能测试概念点分析与过程讲解(四)--抓包
    性能测试概念点分析与过程讲解(三)
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2684484.html
Copyright © 2011-2022 走看看