📄 frmappupdatelist.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Data;
using Jinrm.FileSystem;
using GzglClient.BLL;
namespace GzglClient.Froms
{
/// <summary>
/// frmAppUpdateList 的摘要说明。
/// </summary>
public class frmAppUpdateList : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ColumnHeader columnHeader1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.ListView AppUpdate;
private PinkieControls.ButtonXP btnUpdate;
private System.Windows.Forms.Label LabUpdate;
private System.Windows.Forms.ColumnHeader columnHeader2;
private PinkieControls.ButtonXP btnDownLoad;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label LabUpdateVersion;
private bool flag = false;
private System.Windows.Forms.Label LabLoad;//线程状态标志
private bool UppSuess = false;
public frmAppUpdateList()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.AppUpdate = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.LabUpdate = new System.Windows.Forms.Label();
this.btnUpdate = new PinkieControls.ButtonXP();
this.btnDownLoad = new PinkieControls.ButtonXP();
this.LabUpdateVersion = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.LabLoad = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.LabLoad);
this.groupBox1.Controls.Add(this.AppUpdate);
this.groupBox1.Location = new System.Drawing.Point(8, 32);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(472, 184);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "需要更新的项目";
//
// AppUpdate
//
this.AppUpdate.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.AppUpdate.Dock = System.Windows.Forms.DockStyle.Fill;
this.AppUpdate.FullRowSelect = true;
this.AppUpdate.GridLines = true;
this.AppUpdate.Location = new System.Drawing.Point(3, 17);
this.AppUpdate.Name = "AppUpdate";
this.AppUpdate.Size = new System.Drawing.Size(466, 164);
this.AppUpdate.TabIndex = 1;
this.AppUpdate.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "文件名";
this.columnHeader1.Width = 340;
//
// columnHeader2
//
this.columnHeader2.Text = "完成";
//
// LabUpdate
//
this.LabUpdate.Location = new System.Drawing.Point(8, 224);
this.LabUpdate.Name = "LabUpdate";
this.LabUpdate.Size = new System.Drawing.Size(144, 16);
this.LabUpdate.TabIndex = 2;
this.LabUpdate.Text = "已经下载()项,共()项";
//
// btnUpdate
//
this.btnUpdate.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(212)), ((System.Byte)(208)), ((System.Byte)(200)));
this.btnUpdate.DefaultScheme = true;
this.btnUpdate.DialogResult = System.Windows.Forms.DialogResult.None;
this.btnUpdate.Enabled = false;
this.btnUpdate.Hint = "";
this.btnUpdate.Location = new System.Drawing.Point(368, 240);
this.btnUpdate.Name = "btnUpdate";
this.btnUpdate.Scheme = PinkieControls.ButtonXP.Schemes.Blue;
this.btnUpdate.Size = new System.Drawing.Size(75, 26);
this.btnUpdate.TabIndex = 8;
this.btnUpdate.Text = "更新";
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
//
// btnDownLoad
//
this.btnDownLoad.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(212)), ((System.Byte)(208)), ((System.Byte)(200)));
this.btnDownLoad.DefaultScheme = true;
this.btnDownLoad.DialogResult = System.Windows.Forms.DialogResult.None;
this.btnDownLoad.Hint = "";
this.btnDownLoad.Location = new System.Drawing.Point(280, 240);
this.btnDownLoad.Name = "btnDownLoad";
this.btnDownLoad.Scheme = PinkieControls.ButtonXP.Schemes.Blue;
this.btnDownLoad.Size = new System.Drawing.Size(72, 26);
this.btnDownLoad.TabIndex = 10;
this.btnDownLoad.Text = "下载";
this.btnDownLoad.Click += new System.EventHandler(this.btnDownLoad_Click);
//
// LabUpdateVersion
//
this.LabUpdateVersion.Location = new System.Drawing.Point(96, 8);
this.LabUpdateVersion.Name = "LabUpdateVersion";
this.LabUpdateVersion.Size = new System.Drawing.Size(100, 16);
this.LabUpdateVersion.TabIndex = 12;
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.TabIndex = 11;
this.label1.Text = "更新版本号:";
//
// LabLoad
//
this.LabLoad.Location = new System.Drawing.Point(128, 80);
this.LabLoad.Name = "LabLoad";
this.LabLoad.Size = new System.Drawing.Size(216, 24);
this.LabLoad.TabIndex = 15;
this.LabLoad.Text = "正在下载请稍候。。。。";
this.LabLoad.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.LabLoad.Visible = false;
//
// frmAppUpdateList
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(492, 283);
this.Controls.Add(this.LabUpdateVersion);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnDownLoad);
this.Controls.Add(this.btnUpdate);
this.Controls.Add(this.LabUpdate);
this.Controls.Add(this.groupBox1);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(500, 310);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(500, 310);
this.Name = "frmAppUpdateList";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系统升级--下载文件";
this.Closing += new System.ComponentModel.CancelEventHandler(this.frmAppUpdateList_Closing);
this.Load += new System.EventHandler(this.frmAppUpdateList_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnUpdate_Click(object sender, System.EventArgs e)
{
//声明一个程序信息类
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
//设置外部程序名
Info.FileName = "GzglClientUpdate.exe";
//设置外部程序的启动参数(命令行参数)为test.txt
Info.Arguments = "test.txt";
//设置外部程序工作目录为 C:\
Info.WorkingDirectory = Application.StartupPath + "\\";
//声明一个程序类
System.Diagnostics.Process Proc ;
try
{
//启动外部程序
Proc = System.Diagnostics.Process.Start(Info);
Application.Exit();
}
catch
{
MessageBox.Show("启动更新程序失败!");
}
}
private void btnDownLoad_Click(object sender, System.EventArgs e)
{
if(!flag)
{
Thread tr = new Thread(new ThreadStart(GetUpdate));
tr.IsBackground = true;
tr.Start();
}
else
{
MessageBox.Show("更新已开始执行,请勿重复操作!");
}
//GetUpdate();
}
#region 委托开始
delegate void StartF();//ReceF
private void StartPrint()
{
StartF SF = new StartF(StartPrintMain);
this.BeginInvoke(SF);
}
private void StartPrintMain()
{
this.Cursor = Cursors.WaitCursor;
btnDownLoad.Enabled = false;
LabLoad.Visible = true;
}
delegate void EndF();//ReceF
private void EndPrint()
{
EndF EF = new EndF(EndPrintMain);
this.BeginInvoke(EF);
}
private void EndPrintMain()
{
this.Cursor = Cursors.Default;
btnDownLoad.Enabled = true;
LabLoad.Visible = false;
}
#endregion
private void GetUpdate()
{
flag = true;
StartPrint();
string updatePath = Application.StartupPath + "//Update//";//下载目录
System.Net.WebClient myWebClient = new System.Net.WebClient();
#region 下载辅助更新程序
try
{
myWebClient.DownloadFile(AllStr.DownLoadUrl+"//GzglClientUpdate.exe",updatePath + "//GzglClientUpdate.exe");
string pathy = Application.StartupPath + "//Update//GzglClientUpdate.exe";
string pathx = Application.StartupPath + "//GzglClientUpdate.exe";
System.IO.File.Copy(pathy,pathx,true);
AppUpdate.Items[0].SubItems.Add("100%") ;
}
catch
{
AppUpdate.Items[0].SubItems.Add("失败") ;
MessageBox.Show("下载遇到错误,请至<http://218.92.102.27/gzAppUpdate>下载补丁程序,谢谢!");
return;
}
try
{
myWebClient.DownloadFile(AllStr.DownLoadUrl+"//App.zip",updatePath + "//App.zip");
AppUpdate.Items[1].SubItems.Add("100%") ;
}
catch
{
AppUpdate.Items[1].SubItems.Add("失败") ;
MessageBox.Show("下载遇到错误,请至<http://218.92.102.27/gzAppUpdate>下载补丁程序,谢谢!");
return;
}
btnUpdate.Enabled = true;
#endregion
EndPrint();
flag = false;
}
private void frmAppUpdateList_Load(object sender, System.EventArgs e)
{
#region 信息提示
string ClientUpdateFilePath = Application.StartupPath + "//Update//Updatelist.xml";//客户端更新文件路径
DataSet ds = new DataSet();
ds.ReadXml(ClientUpdateFilePath);
LabUpdateVersion.Text = ds.Tables[0].Rows[1]["SettingValue"].ToString();
AppUpdate.Items.Add("GzglClientUpdate.exe");
AppUpdate.Items.Add("App.zip");
LabUpdate.Text = "已经下载(0)项,共(2)项";
#endregion
}
private void frmAppUpdateList_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(!UppSuess)
{
DialogResult result = MessageBox.Show(this, "是否继续更新!", "有更新版本,必须更新!", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if(result == DialogResult.Yes)
{
e.Cancel = true;
}
else
{
Application.Exit();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -