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

📄 update.ascx.cs

📁 这是我编的一小软件。请等级等待指教。呵呵。ASP的
💻 CS
字号:
namespace Seaskyer.WebApp.skyNews.Pages.AdminMSC
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using Seaskyer.FSO;
	using Seaskyer.Strings;
	using Seaskyer.WebApp.Utility;

	/// <summary>
	///		Update : 在线升级程序。
	/// </summary>
	public class Update : basePage
	{
		protected Panel Panel1, Panel2;
		protected TextBox updateServer;
		protected Label label, Label1, Label2, Label3, Label4;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.Button Submit1;
		protected System.Web.UI.WebControls.Button BeginUpdate;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if( !user.IsAdmin )
			{
				base.strError.Add("您无权执行 “" + lang.AppName + "” 操作,详情请与管理员联系!");
				return;
			}
			
			initPage();

			Panel1.Visible = true;
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		void initPage()
		{
			Panel1.Visible = false;
			Panel2.Visible = false;
		}

		protected void Submit_OnClick(object sender, System.EventArgs e)
		{
			initPage();

			// 连接服务器
			try
			{
				user.xfilePath	= "http://" + updateServer.Text + "/" + productName + "/" + user.dataType + "/Update.cfg";
				user.xPath		= "Update/Information";

				DataTable dt = user.ConvertXmlToDataTable();

				if( dt.Rows.Count == 1 )
				{
					if( dt.Rows[0]["version"].ToString() == user.GetVersion )
					{
						Page.RegisterStartupScript("error", "<script>alert('您当前的版本已经是最新,无须升级!');</script>");
						Panel1.Visible = true;
					}
					else
					{
						Label1.Text	= user.GetVersion;
						Label2.Text	= dt.Rows[0]["version"].ToString();
						Label3.Text	= dt.Rows[0]["totalSize"].ToString();
						Label4.Text	= dt.Rows[0]["description"].ToString();

			
						Panel2.Visible = true;
					}
				}

				dt.Clear();
				dt.Dispose();
			}
			catch( Exception exc )
			{
				if( exc.Message.IndexOf("404") > 0 ) 
				{
					user.MessageShowBack("升级失败,找不到服务器上的升级文件。", Page);
					Panel1.Visible = true;
				}
				else
				{
					user.MessageShowBack("" + exc.Message + "\\n\\n请确定您已经联网,或检查升级服务器的IP地址是否正确", Page);
					Panel1.Visible = true;
				}
			}

		}

		protected void BeginUpdate_OnClick(object sender, EventArgs e)
		{
			initPage();

			string tempFolder = Function.GetRealPath(Label2.Text + ".upf");

			try
			{
				user.xfilePath	= "http://" + updateServer.Text + "/" + productName + "/" + user.dataType + "/Update.cfg";
				user.xPath		= "Update/download/file";

				DataTable dt = user.ConvertXmlToDataTable();

				if( !FObject.IsExist(tempFolder, FsoMethod.Folder) )
				{
					FObject.Create(tempFolder, FsoMethod.Folder);
				}

				for( int i = 0; i < dt.Rows.Count; i++ )
				{
					// 下载升级文件
					WebUtility.RemoteGetFile(dt.Rows[i]["@url"].ToString(), tempFolder + "/temp_" + i + ".upf");

					// 覆盖文件
					FObject.CopyFile(tempFolder + "temp_" + i + ".upf", Server.MapPath(dt.Rows[i]["@rName"].ToString()));
				}

				FObject.Delete(tempFolder, FsoMethod.Folder);

				dt.Clear();
				dt.Dispose();

				user.MessageShow("恭喜您,在线升级成功。建议您退出并重新登陆系统。", Page);
				label.Text		= Label4.Text;
				label.Visible	= true;
			}
			catch
			{
				if( FObject.IsExist(tempFolder, FsoMethod.Folder) )
				{
					FObject.Delete(tempFolder, FsoMethod.Folder);
				}
				Panel1.Visible = true;
				user.MessageShowBack("下载升级包时发生错误,升级失败。", Page);
			}
		}
	}
}

⌨️ 快捷键说明

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