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

📄 downloaddlg.cs

📁 一个WINCE下用ado.net连接数据库的例子 作者:tanis
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;


namespace AutoRefresh
{


	/// <summary>
	/// Form3 的摘要说明。
	/// </summary>
	public class Form3 : System.Windows.Forms.Form
	{
		public System.Windows.Forms.ProgressBar prsBar1;
		private System.Windows.Forms.Button btnStop;
		private System.Windows.Forms.Timer timer1;
		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.TextBox lbOutPut;
		private bool bRun = false;
		private System.Windows.Forms.Label lbCap;

		public bool bAbort = false;
	    public int  iPos;
		public string slbOutPut = null;
		public string slbCap = null;
		public Form3()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			lbCap.Text =  "正在更新程序....";
			prsBar1.Enabled = true;
			timer1.Enabled = false;
			bRun = false;
			bAbort = false;


			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

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

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.prsBar1 = new System.Windows.Forms.ProgressBar();
			this.timer1 = new System.Windows.Forms.Timer();
			this.lbCap = new System.Windows.Forms.Label();
			this.btnStop = new System.Windows.Forms.Button();
			this.btnStart = new System.Windows.Forms.Button();
			this.lbOutPut = new System.Windows.Forms.TextBox();
			// 
			// prsBar1
			// 
			this.prsBar1.Location = new System.Drawing.Point(8, 48);
			this.prsBar1.Size = new System.Drawing.Size(224, 16);
			this.prsBar1.ParentChanged += new System.EventHandler(this.progressBar1_ParentChanged);
			// 
			// timer1
			// 
			this.timer1.Interval = 500;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// lbCap
			// 
			this.lbCap.Location = new System.Drawing.Point(16, 16);
			this.lbCap.Size = new System.Drawing.Size(200, 20);
			this.lbCap.ParentChanged += new System.EventHandler(this.label1_ParentChanged);
			// 
			// btnStop
			// 
			this.btnStop.Location = new System.Drawing.Point(128, 88);
			this.btnStop.Size = new System.Drawing.Size(72, 32);
			this.btnStop.Text = "终止";
			this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
			// 
			// btnStart
			// 
			this.btnStart.Location = new System.Drawing.Point(32, 88);
			this.btnStart.Size = new System.Drawing.Size(72, 32);
			this.btnStart.Text = "开始";
			this.btnStart.Click += new System.EventHandler(this.button1_Click);
			// 
			// lbOutPut
			// 
			this.lbOutPut.ForeColor = System.Drawing.Color.Red;
			this.lbOutPut.Location = new System.Drawing.Point(8, 136);
			this.lbOutPut.Multiline = true;
			this.lbOutPut.ReadOnly = true;
			this.lbOutPut.ScrollBars = System.Windows.Forms.ScrollBars.Both;
			this.lbOutPut.Size = new System.Drawing.Size(224, 96);
			this.lbOutPut.Text = "";
			// 
			// Form3
			// 
			this.ClientSize = new System.Drawing.Size(242, 239);
			this.Controls.Add(this.lbOutPut);
			this.Controls.Add(this.btnStart);
			this.Controls.Add(this.btnStop);
			this.Controls.Add(this.lbCap);
			this.Controls.Add(this.prsBar1);
			this.Text = "下载窗口";
			this.Load += new System.EventHandler(this.Form3_Load);

		}
		#endregion

		private void progressBar1_ParentChanged(object sender, System.EventArgs e)
		{
		
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
		//	if(prsBar1.Value == 100)
        //       prsBar1.Value = 0;

			prsBar1.Value = iPos;
			if(slbCap != null)
				lbCap.Text = slbCap;
			if(slbOutPut != null)
				lbOutPut.Text = slbOutPut;

		}

		private void Form3_Load(object sender, System.EventArgs e)
		{
		
		}

		private void btnStop_Click(object sender, System.EventArgs e)
		{
			this.bAbort = true;
			this.lbOutPut.Text += "用户终止!\r\n";
            bRun = false;
			btnStop.Enabled = false;
			btnStart.Enabled = true;
			this.prsBar1.Value = 0;
			timer1.Enabled = false;
		}
		public  void doDownload()
		{
			//to fetch the new program to the files.
			bAbort = false;
			slbCap =  "开始更新程序....";	
			slbOutPut = "";
			
			while(bRun)
			{
				System.Threading.Thread.Sleep(1000);
                //to verify

				slbCap = "验证用户名和密码....";
				Verifier verifier = new Verifier();
				bool brlt = false;
			
				try
				{
					brlt = verifier.start();
				}
				catch(Exception)
				{
					brlt = false;
				}
				if(brlt == true)
				{
					slbOutPut += "用户名密码验证通过!\r\n";
				}
				else
				{
					slbOutPut += "用户名或密码错误!\r\n";
					this.iPos = 0;
					return ;
				}

				if(this.bAbort == true)
				{
					return;
				}


				// to download
				brlt = false;
				slbCap = "开始下载文件....";
				try
				{
					LoadFile loadfile = new LoadFile(this);
					brlt = loadfile.Start();
				}
				catch(Exception)
				{
					brlt = false;
				}
				if(brlt == true)
				{
					slbOutPut += "文件下载成功!\r\n";
				}
				else
				{
					slbOutPut += "文件下载失败!\r\n";
					this.iPos = 0 ;
					return;
				}
                
				if(this.bAbort == true)
				{
					return;
				}
				//to update local files
				brlt = false;
				slbCap = "开始更新本地文件....";
				try
				{
					UpdateLocalFiles upFile = new UpdateLocalFiles();
					brlt = upFile.start();
				}
				catch
				{
					brlt = false;
				}

				if(brlt == true)
				{
					slbOutPut += "本地文件更新成功!\r\n";
				}
				else
				{
					slbOutPut += "本地文件更新失败!\r\n";
				}
				this.iPos = 0 ;
				return;
			}	

		}

		private void button1_Click(object sender, System.EventArgs e)
		{

			timer1.Enabled = true;		
			bRun = true;
			System.Threading.Thread oThread = new System.Threading.Thread(new ThreadStart(this.doDownload));
			oThread.Start();
			btnStart.Enabled = false;
			btnStop.Enabled = true;

		}

		private void label1_ParentChanged(object sender, System.EventArgs e)
		{
		
		}
		

	}
}

⌨️ 快捷键说明

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