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

📄 formmain.cs

📁 我在学习移动设备开发时
💻 CS
📖 第 1 页 / 共 3 页
字号:
			this.btSetting.Location = new System.Drawing.Point(2, 158);
			this.btSetting.Size = new System.Drawing.Size(60, 40);
			this.btSetting.Text = "Setting";
			this.btSetting.Click += new System.EventHandler(this.btSetting_Click);
			// 
			// btDnFile
			// 
			this.btDnFile.Location = new System.Drawing.Point(2, 119);
			this.btDnFile.Size = new System.Drawing.Size(60, 40);
			this.btDnFile.Text = "DnFile";
			this.btDnFile.Click += new System.EventHandler(this.btDnFile_Click);
			// 
			// btUpFile
			// 
			this.btUpFile.Location = new System.Drawing.Point(2, 80);
			this.btUpFile.Size = new System.Drawing.Size(60, 40);
			this.btUpFile.Text = "UpFile";
			this.btUpFile.Click += new System.EventHandler(this.btUpFile_Click);
			// 
			// btExit
			// 
			this.btExit.Location = new System.Drawing.Point(2, 41);
			this.btExit.Size = new System.Drawing.Size(60, 40);
			this.btExit.Text = "Exit";
			this.btExit.Click += new System.EventHandler(this.btExit_Click);
			// 
			// btLogIn
			// 
			this.btLogIn.Location = new System.Drawing.Point(2, 2);
			this.btLogIn.Size = new System.Drawing.Size(60, 40);
			this.btLogIn.Text = "LogIn";
			this.btLogIn.Click += new System.EventHandler(this.btLogIn_Click);
			// 
			// FormMain
			// 
			this.ClientSize = new System.Drawing.Size(634, 199);
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.tabControl1);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Text = "FormMain";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Load += new System.EventHandler(this.FormMain_Load);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>

		static void Main() 
		{
			Application.Run(new FormMain());
		}


		private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
		{   //处理tabControl1的selectindex的change事件
			switch(this.tabControl1.SelectedIndex)
			{
				case 0:
					//MessageBox.Show("Scan Product");
					//SaveScanData();
					this.textBoxShip.Focus();
					break;
				case 1:
					//MessageBox.Show("View Data");
					ViewData();
					break;
				default:
					break;

			}
			
		}

		private void textBoxShip_KeyPress(object sender, KeyPressEventArgs e)
		{
			if(e.KeyChar==13)
			{
				if(textBoxShip.Text.Trim()=="")
				{
					MessageBox.Show("Ship #: can not be empty!");
					this.textBoxShip.Focus();
					return;
				}
				else
				{
					this.textBoxType.Focus();
				}
			}
		}

		private void textBoxType_KeyPress(object sender, KeyPressEventArgs e)
		{   //type ={1..9}
			if(e.KeyChar==13)
			{
				//先检查Ship# 是否为空
				if(textBoxShip.Text.Trim()=="")
				{
					MessageBox.Show("Ship #: can not be empty!");
					this.textBoxShip.Focus();
					return;
				}
                //检查Type 是否是合法的值(0-9)
			    if(IsNumberChr(textBoxType.Text.Trim())==0)
			    {
					MessageBox.Show("Type must be value 0-9!");
					this.textBoxType.Text="";
					this.textBoxType.Focus();
					return;
			    }
			    else
				{
					this.textBoxScan.Focus();
				} 
			}
		}

		private void textBoxScan_KeyPress(object sender, KeyPressEventArgs e)
		{
			string ship;
			if(e.KeyChar==13)
			{
				//检查Ship# 的值是否为空
				if(textBoxShip.Text.Trim()=="")
				{
					MessageBox.Show("Ship #: can not be empty!");
					this.textBoxShip.Focus();
					return;
				}
				//检查Type 是否是合法的值(0-9)
				if(IsNumberChr(textBoxType.Text.Trim())==0)
				{
					MessageBox.Show("Type must be value 0-9!");
					this.textBoxType.Text="";
					this.textBoxType.Focus();
					return;
				}
				//检查Scanning的长度是否合法,如果合法,则按规则拆分各个字段的值
				if(textBoxScan.Text.Trim()=="")
				{
					MessageBox.Show("Scanning data: can not be empty!");
					this.textBoxScan.Focus();
					ClearTextBox();
					return;
				}
				else
				{
					ship=textBoxScan.Text.Trim();
					if(ship.Length==31)
					{
						ship=ship+"------";
					}
				}

				if(ship.Length!=37)
				{
					MessageBox.Show("Input must 37 char!");
					textBoxScan.Text="";
					textBoxScan.Focus();
					ClearTextBox();
					return;
				}
				//拆分textBoxScan的各个字段的值,并分别显示出来
				this.textBox1.Text=ship.Substring(0,6);
				this.textBox2.Text=ship.Substring(6,1);
				this.textBox3.Text=ship.Substring(7,6);
				this.textBox4.Text=ship.Substring(13,10);
				this.textBox5.Text=ship.Substring(23,3);
				this.textBox6.Text=ship.Substring(26,5);
				this.textBox7.Text=ship.Substring(31,1);
				this.textBox8.Text=ship.Substring(32,5);
				if((MessageBox.Show("Sure to Save?","Save Confirm",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1))==DialogResult.Yes)
				{
					SaveScanData();
				}

				this.textBoxShip.Text="";
				this.textBoxType.Text="";
				this.textBoxScan.Text="";
				this.textBoxShip.Focus();
			}
		}

		public static void ShowErrors(SqlCeException e) 
		{   //用于创建数据库时异常捕获
			SqlCeErrorCollection errorCollection = e.Errors;
			StringBuilder bld = new StringBuilder();
			foreach (SqlCeError err in errorCollection) 
			{
				bld.Append("\n Error Code: " + err.HResult.ToString("X"));
				bld.Append("\n Message   : " + err.Message);
				bld.Append("\n Minor Err.: " + err.NativeError);
				bld.Append("\n Source    : " + err.Source);               
				foreach (int numPar in err.NumericErrorParameters) 
				{
					if (0 != numPar) bld.Append("\n Num. Par. : " + numPar);
				}               
				foreach (string errPar in err.ErrorParameters) 
				{
					if (String.Empty != errPar) bld.Append("\n Err. Par. : " + errPar);
				}
				MessageBox.Show(bld.ToString());
				bld.Remove(0, bld.Length);
			}
		}

		private void FormMain_Load(object sender, System.EventArgs e)
		{
			//系统初始化过程,检查数据库是否存在,如果不存在册创建,否则打开当前的数据库
			this.textBoxShip.Focus();
			SqlCeConnection conn = null;
			if (File.Exists ("SqlCeDB.sdf")==false)
			{
				try 
				{
					SqlCeEngine engine = new SqlCeEngine ("Data Source =SqlCeDB.sdf");
					engine.CreateDatabase ();
					conn = new SqlCeConnection ("Data Source =SqlCeDB.sdf");
					conn.Open();
					SqlCeCommand cmd = conn.CreateCommand ();
					//cmd.CommandText = "CREATE TABLE up_data(CODE NVARCHAR(37), TYPE INT, PROD NVARCHAR(6), QUALITY NVARCHAR(7), SIZE NVARCHAR(10), PACKING_NO NVARCHAR(10), QUANTITY NVARCHAR(3),POSITION NVARCHAR(5), TOS NVARCHAR(10), FACTORY NVARCHAR(1), CUST NVARCHAR(5), RUN_CODE NVARCHAR(2), USERR NVARCHAR(4), DATE NVARCHAR(15), TIME NVARCHAR(10))";
					cmd.CommandText = "CREATE TABLE up_data(CODE NTEXT, TYPE INT, PROD NTEXT, QUALITY NTEXT, SIZE NTEXT, PACKING_NO NTEXT, QUANTITY NTEXT,POSITION NTEXT, TOS NTEXT, FACTORY NTEXT, CUST NTEXT, RUN_CODE NTEXT, USERR NTEXT, DATE NTEXT, TIME NTEXT)";
					cmd.ExecuteNonQuery();
					cmd.CommandText = "CREATE TABLE pass(USERR NTEXT,PASS NTEXT)";
					cmd.ExecuteNonQuery();
					cmd.CommandText = "INSERT INTO pass(USERR, PASS) VALUES ('admin','admin')";
					cmd.ExecuteNonQuery();
					cmd.CommandText = "INSERT INTO pass(USERR, PASS) VALUES ('huang','huang')";
					cmd.ExecuteNonQuery();
				}
				catch(SqlCeException ee) 
				{
					ShowErrors(ee);
				}
				finally 
				{
					if(conn.State == ConnectionState.Open)
					  conn.Close();
				}
			}
			this.btLogIn.Enabled=true;
			this.btExit.Enabled=false;
			this.btUpFile.Enabled=false;
			this.btDnFile.Enabled=false;
			this.btSetting.Enabled=false;
			this.UserName="";
			this.tabPage1.Visible=false;
			this.tabPage2.Visible=false;
		}

		private void btLogIn_Click(object sender, System.EventArgs e)
		{
		    //系统登录
			FormLogIn fLog=new FormLogIn();
			if (fLog.ShowDialog() == DialogResult.OK)
			{
                this.UserName=fLog.UName;
				this.btLogIn.Enabled=false;
				this.btExit.Enabled=true;
				this.btUpFile.Enabled=true;
				this.btDnFile.Enabled=true;
				this.btSetting.Enabled=true;
				this.tabPage1.Visible=true;
				this.tabPage2.Visible=true;
			}
			else
			{
                this.UserName="";
			}
			//fLog.Dispose();

		}

		private void btExit_Click(object sender, System.EventArgs e)
		{
			//退出系统登录
			this.btLogIn.Enabled=true;
			this.btExit.Enabled=false;
			this.btUpFile.Enabled=false;
			this.btDnFile.Enabled=false;
			this.btSetting.Enabled=false;
			this.UserName="";
			this.tabPage1.Visible=false;
			this.tabPage2.Visible=false;
		}

		private void btUpFile_Click(object sender, System.EventArgs e)
		{
		    //上传指定的文件到指定Ftp的服务器
		}

		private void btDnFile_Click(object sender, System.EventArgs e)
		{
		    //从指定的FTP服务器上下载指定的文件
		}

		private void btSetting_Click(object sender, System.EventArgs e)
		{
		    //设置系统相关的参数
		}
	}
}

⌨️ 快捷键说明

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