⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appupdate.cs

📁 食堂就餐提醒系统(含源码) 为一个单位开发的
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.IO;
using System.Text;
using System.Net;
using System.Diagnostics;

using System.Threading;

namespace UpdateEr
{
	/// <summary>
	/// AppUpdate 的摘要说明。
	/// </summary>
	public class AppUpdate : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Timer timer;
		private System.Windows.Forms.Label label1;
		private System.ComponentModel.IContainer components;

		//
		private string configFile = Application.StartupPath + "\\System.Config";

		public AppUpdate()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			this.timer.Start();
			
			//配置文件路径
			Public.configFile = Application.StartupPath + "\\" + Public.configFile;
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		[STAThread]
		static void Main() {
			Application.Run(new AppUpdate());
		}

		//正在更新
		private void loadFile(){

			String temp = "";

			string server = "10.227.64.92";

			string fileUrlPath = "http://"+ server +"/AMS/ClientFiles/";

			try{
				WebRequest Wrequest     = WebRequest.Create("http://"+ server +"/AMS/AdminUpdate.htm");
				WebResponse Wresponse   = Wrequest.GetResponse();
				Stream Sm               = Wresponse.GetResponseStream();
				StreamReader Sr         = new StreamReader(Sm,Encoding.GetEncoding("GB2312"));
				temp                    = Sr.ReadToEnd().ToString();
				Sr.Close();
			}catch(Exception ex){
				MessageBox.Show("升级检查时遇到错误,请关闭窗口重试。\n\n错误信息:" + ex.Message.ToString());
				
				//下载完成,重新启动原程序
				System.Diagnostics.Process p = new Process();
				p.StartInfo.FileName = Application.StartupPath + "\\XFMAS.exe";
				p.Start();

				Application.Exit();
			}

			int    oneI    = temp.IndexOf("]");
			string softVer = temp.Substring(1,oneI-1).ToString();

			string dURL    = temp.Substring(oneI+2,temp.Length-1-oneI-2);

			string[] fileS = dURL.Split(',');

			try{
				for(int i=0;i<fileS.Length;i++){

					string fileName     = fileS[i].ToString();

					this.label2.Text    = "正在更新:" + fileName;

					//DB2005.DLL是数据库文件,不允许更新
					if(fileName != "" && !fileName.ToUpper().Equals("UPDATE.EXE")){
						string remoteUri = fileUrlPath + "/" + fileS[i].ToString();
						WebClient myWebClient = new WebClient();
						myWebClient.DownloadFile(remoteUri,fileName);
					}

				}

				//this.SaveUpdateSer(softVer);

				//下载完成,重新启动原程序
				System.Diagnostics.Process p = new Process();
				p.StartInfo.FileName = Application.StartupPath + "\\XFMAS.exe";
				p.Start();

			}catch(Exception ex){
				string upfile = fileUrlPath + "ClientUpdate.rar";
				if(MessageBox.Show("下载升级文件时出错,请退出系统并手动下载升级文件!\r\n\r\n升级方法:\r\n1、下载压缩文件:"+ upfile +";\r\n2、将文件解压缩到:"+ Application.StartupPath + "\\;\r\n3、重启软件。" +"" +"\r\n\r\n------------------------------------------\r\n错误信息:" + ex.Message.ToString(),"下载升级文件出错,请手动下载升级文件!") == DialogResult.OK){
					Process process = new Process();
					process.StartInfo.FileName = "iexplore.exe";
					process.StartInfo.Arguments = upfile;
					process.Start();
				}
			}

			Application.Exit();
		}

		//从网址中取出最后一个文件名,前提是这个网址中包含文件名
		private string GetFileName(string urlStr){
			if(urlStr.IndexOf("/") > 0){
				string[] str = urlStr.Split('/');
				return str[str.Length - 1];
			}

			return "";
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(AppUpdate));
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label2 = new System.Windows.Forms.Label();
			this.timer = new System.Windows.Forms.Timer(this.components);
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.groupBox1.Location = new System.Drawing.Point(8, 0);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(464, 40);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 16);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(440, 16);
			this.label2.TabIndex = 3;
			this.label2.Text = "准备升级中....";
			// 
			// timer
			// 
			this.timer.Interval = 30;
			this.timer.Tick += new System.EventHandler(this.timer_Tick);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 48);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(288, 16);
			this.label1.TabIndex = 1;
			this.label1.Text = "注意:升级过程中千万不能关闭窗口";
			// 
			// AppUpdate
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(480, 72);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "AppUpdate";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "系统升级....";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.AppUpdate_Closing);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 更新程序
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void timer_Tick(object sender, System.EventArgs e) {
			this.timer.Stop();
			Thread t = new Thread(new ThreadStart(this.loadFile));
			t.Start();
		}

		private void SaveUpdateSer(string softVer){
		
			Public.configXml.Rows[0]["SoftVer"] = softVer;

			//保存到XML
			SRXML.SaveDataTableToXML(Public.configXml,Public.configFile);
		}

		private void AppUpdate_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
			//e.Cancel = true;
			////MessageBox.Show("升级中,不能关闭窗口!");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -