/****************************** * 说明:自动升级中间程序 * 创建人:龚宇超 * 创建日期:2018-02-23 * 修改人: * 修改日期: * 修改备注: * 版本:1.0.0.0 ******************************/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Lskj.AutoUpdate; using System.Net; using System.IO; namespace Lskj.Update { /// /// 自动升级中间程序 /// public partial class frmMain : Form { bool isMes = false; string updateUrl = string.Empty; public frmMain() : this("", "", "") { } public frmMain(string _isMes, string server, string database) { InitializeComponent(); if (!string.IsNullOrEmpty(server) && !string.IsNullOrEmpty(database)) { SQLUtil.mConnStr = string.Format("Server={0};Database={1};Persist Security Info=True;User ID=lserpAdmin;Password=lserp110;Connection Timeout=5;pooling=false", server, database); updateUrl = SQLUtil.ExecuteDataTable("select UpdateAddress from p_systemtab").Rows[0][0] + ""; } isMes = (_isMes + "").Equals("1"); this.Hide(); this.StartBackGroundDownLoad(); } /// /// 说明:后台下载 /// 创建人:龚宇超 /// 创建日期:2018-02-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void StartBackGroundDownLoad() { if (string.IsNullOrEmpty(updateUrl)) { bool isUpdateSucess = false; ProcessManager pm = new ProcessManager(); pm.InitUpdateEnvironment(); IAutoUpdater updater = new AutoUpdater(); try { updater.Update(); isUpdateSucess = true; } catch (Exception ex) { MessageBox.Show("更新失败\r\n" + ex.Message); } finally { if (!isUpdateSucess) { try { updater.RollBack(); } catch (Exception) { } } pm.StartProcess(isMes); } } else { bool isUpdateSucess = false; ProcessManager pm = new ProcessManager(); pm.InitUpdateEnvironment(); IAutoUpdater updater = new AutoUpdater(updateUrl, false); try { updater.Update(); isUpdateSucess = true; } catch (Exception ex) { MessageBox.Show("更新失败\r\n" + ex.Message); } finally { if (!isUpdateSucess) { try { updater.RollBack(); } catch (Exception) { } } if (string.IsNullOrEmpty(updateUrl)) pm.StartProcess(isMes); else pm.CloseExe(ConstModel.LS_UPDATE_NAME); } } } private void frmMain_Load(object sender, EventArgs e) { } } }