2022年C#升级WinForm系统的完全代码教学内容 .pdf





《2022年C#升级WinForm系统的完全代码教学内容 .pdf》由会员分享,可在线阅读,更多相关《2022年C#升级WinForm系统的完全代码教学内容 .pdf(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、C#升 级 W i nFor m系 统的 完 全 代 码名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 14 页 -C#winform 升级的详细代码以我以前做过的人事系统(HrManager.exe)为例:客户端安装目录下,添加一个xml 文件,命名为:update.xml。update.xml 的内容如下:192.168.6.223UpGrade HrManager.exe 1.5.1.0 以下是更新升级程序的说明以及源代码:在Visual Studio 2010中(VS2005以上版本也可以),新建 winForms应用程序,命名为Update,删除自动生成的 Form1
2、窗体。新建窗体 FrmUpdate。在 FrmUpdate中放入三个控件:Button:btnUpdate(更新按钮)。ProgressBar:progressBar1(进度条)。RichTextBox:rchtxtInfo。如下图所示:名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 14 页 -在 Update 的应用程序的 binDebug 下,添加一个 xml 文件,命名为update.xml。binDebugupdate.xml的内容如下:192.168.6.223UpGrade HrManager.exe 1.6.1.0 排班时间.doc Vers=1.0.0.0 名师
3、资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 14 页 -其中 Url代表服务器地址,AppName:应用程序名,AppVersion:应用程序版本File 需要更新的文件窗体FrmUpdate的代码如下(窗体自动生成的代码不显示,只用绑定btnUpdate按钮的Click事件btnUpdate_Click 即可)。源代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;
4、using System.Text;using System.Windows.Forms;using System.Xml;using System.IO;using System.Net;using System.Diagnostics;namespace Update publicpartialclassFrmUpdate:Form public FrmUpdate()InitializeComponent();progressBar1.Visible=false;/进?度条?控?件t 隐t 藏?/按?钮 更1新?的?Click事o?件t/privatevoid btnUpdate_Cli
5、ck(object sender,EventArgs e)名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 14 页 -string appName=GetAppName();/应?|用?程?序进?程?名?KillAppProcess(appName);/如?果?应?|用?程?序正y在2运?行D,?则强?行D关?闭?。?FolderBrowserDialog fbd=new FolderBrowserDialog();fbd.Description=请?选?择?程?序所 在2的?目?录?;fbd.SelectedPath=E:Hr;if (fbd.ShowDialog()=Dial
6、ogResult.OK)/查|看?选?择?的?目?录?是o?否?含?有?DHrManager.exeif (!File.Exists(fbd.SelectedPath+appName)MessageBox.Show(目录错误.请选择应用程序所在的目录,提示o?);return;string url=GetUrl();if (!Directory.Exists(url)/查|看?本?机2客a户?端?能1否?连?接?服t 务?器?目?录?MessageBox.Show(无法连接到服务器.,提示);return;/服t 务?器?的?update.xml与?客a 户?端?的?update.xml 比
7、较?版?本?号?是o?否?一?致?string serverVersion=GetServerVersion();名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 14 页 -string clientVersion=GetClientVersion(fbd.SelectedPath);rchtxtInfo.Text=服务器版本:+serverVersion+n客户端版本:+clientVersion+n;Application.DoEvents();if (serverVersion=clientVersion)rchtxtInfo.Text=rchtxtInfo.Text+已经
8、是最新版本,不需要更新.n;Application.DoEvents();return;/本?地?版?本?与?服t 务?器?版?本?不?一?致?需要a 更1新?this.Cursor=Cursors.WaitCursor;progressBar1.Visible=true;/滚?动?¥条?显?示o?List list=GetUpdateFiles();for (int i=0;i list.Count;i+)if (DownUpdateFile(url+listi,fbd.SelectedPath+listi)=false)rchtxtInfo.Text=rchtxtInfo.Text+更新中
9、出现错误.;this.Cursor=Cursors.Default;return;rchtxtInfo.Text=rchtxtInfo.Text+全部更新已完成.;/更1新?本?地?客a 户?端?下?的?update.xml的?版?本?号?,?与?服t 务?端?版?本?号?一?致?名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 14 页 -UpdateLocalXml(fbd.SelectedPath+update.xml,serverVersion);progressBar1.Visible=false;/滚?动?¥条?隐t 藏?this.Cursor=Cursors.Defa
10、ult;/更1新?本?地?的?配?置?文?件t 的?版?本?号?,使o1版?本?号?与?服t 务?器?版?本?一?致?,这a样 下?次?就a 不?必?更1新?了?/本?地?xml 的?完ao 全?路?径?/服t 务?器?版?本?号?privatevoid UpdateLocalXml(string xmlFile,string version)XmlDocument doc=new XmlDocument();doc.Load(xmlFile);XmlNode rootNode=doc.DocumentElement;for (int i=0;i rootNode.ChildNodes.Cou
11、nt;i+)if (rootNode.ChildNodesi.Name=Application)rootNode.ChildNodesi.ChildNodes1.InnerText=version;break;doc.Save(xmlFile);/如?果?应?|用?程?序正y在2运?行D,?则强?行D关?闭?。?然?后?才?能1更1新?名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 14 页 -/privatevoid KillAppProcess(string appName)Process allProcess=Process.GetProcesses();foreach (
12、Process p in allProcess)/MessageBox.Show(p.ProcessName);/进?程?名?称?没?有?D.exeif (p.ProcessName.ToLower()+.exe =appName.ToLower()for (int i=0;i p.Threads.Count;i+)p.Threadsi.Dispose();p.Kill();/获?得?服t 务?器?下?载?地?址?/privatestring GetUrl()XmlDocument doc=new XmlDocument();doc.Load(AppDomain.CurrentDomain.B
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年C#升级WinForm系统的完全代码教学内容 2022 C# 升级 WinForm 系统 完全 代码 教学内容

限制150内