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

📄 fmain.cs.svn-base

📁 串口通信上位机源程序,可以修改串口,波特率,自动保存接收的数据.方便修改成个性化的串口通信工具
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlServerCe;
using System.IO;

namespace GuangMa
{
	/// <summary>
	/// 程序名称:成都飞机设计研究所固定资产条形码数据采集系统
	/// 程序设计:刘洪辉
	/// 日    期:2007-01
	/// </summary>
	public class FMain : System.Windows.Forms.Form
	{
		#region 系统产生代码
		private MyMenu myMenu1;
		private MyMenu myMenu2;
		private SqlCeConnection conn = null;
		private GuangMa.Scanning scan; //声明一个扫描类
		private Control FocusCtr;

		private System.Windows.Forms.ContextMenu MainMenu;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Panel p_Check;
		private System.Windows.Forms.TextBox t_CheckBarCode;
		private System.Windows.Forms.TextBox t_ContentInfo;
		private System.Windows.Forms.ContextMenu DataMenu;
		private System.Windows.Forms.MenuItem menuItem5;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.MenuItem menuItem7;
		private System.Windows.Forms.Panel p_Load;
		private System.Windows.Forms.Label l_Load;
		private System.Windows.Forms.Label l_TotalCount;
		private System.Windows.Forms.MenuItem menuItem8;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label lbl_w_copyright;
		private System.Windows.Forms.Label lbl_w_title;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Panel p_About;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.MenuItem menuItem4;
	
		public FMain()
		{
			InitializeComponent();
			//实例化扫描类
			scan = new GuangMa.Scanning(this);
			//添加扫描事件
			scan.Scanned += new GuangMa.Scanning.ScannedEventHandler(scan_Scanned);
		}
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}
		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.MainMenu = new System.Windows.Forms.ContextMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem8 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.p_Check = new System.Windows.Forms.Panel();
			this.l_TotalCount = new System.Windows.Forms.Label();
			this.t_ContentInfo = new System.Windows.Forms.TextBox();
			this.t_CheckBarCode = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.DataMenu = new System.Windows.Forms.ContextMenu();
			this.menuItem5 = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this.menuItem7 = new System.Windows.Forms.MenuItem();
			this.p_Load = new System.Windows.Forms.Panel();
			this.l_Load = new System.Windows.Forms.Label();
			this.p_About = new System.Windows.Forms.Panel();
			this.label7 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.lbl_w_copyright = new System.Windows.Forms.Label();
			this.lbl_w_title = new System.Windows.Forms.Label();
			// 
			// MainMenu
			// 
			this.MainMenu.MenuItems.Add(this.menuItem1);
			this.MainMenu.MenuItems.Add(this.menuItem2);
			this.MainMenu.MenuItems.Add(this.menuItem8);
			this.MainMenu.MenuItems.Add(this.menuItem3);
			this.MainMenu.MenuItems.Add(this.menuItem4);
			// 
			// menuItem1
			// 
			this.menuItem1.Text = "资产盘查";
			// 
			// menuItem2
			// 
			this.menuItem2.Text = "数据传输";
			// 
			// menuItem8
			// 
			this.menuItem8.Text = "清除数据";
			// 
			// menuItem3
			// 
			this.menuItem3.Text = "关于我们";
			// 
			// menuItem4
			// 
			this.menuItem4.Text = "退出系统";
			// 
			// p_Check
			// 
			this.p_Check.Controls.Add(this.l_TotalCount);
			this.p_Check.Controls.Add(this.t_ContentInfo);
			this.p_Check.Controls.Add(this.t_CheckBarCode);
			this.p_Check.Controls.Add(this.label2);
			this.p_Check.Size = new System.Drawing.Size(240, 192);
			this.p_Check.Visible = false;
			// 
			// l_TotalCount
			// 
			this.l_TotalCount.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold);
			this.l_TotalCount.Location = new System.Drawing.Point(8, 173);
			this.l_TotalCount.Size = new System.Drawing.Size(200, 20);
			this.l_TotalCount.Text = "ESC返回  盘查数量:100";
			// 
			// t_ContentInfo
			// 
			this.t_ContentInfo.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold);
			this.t_ContentInfo.Location = new System.Drawing.Point(8, 32);
			this.t_ContentInfo.Multiline = true;
			this.t_ContentInfo.ReadOnly = true;
			this.t_ContentInfo.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.t_ContentInfo.Size = new System.Drawing.Size(224, 136);
			this.t_ContentInfo.Text = "";
			// 
			// t_CheckBarCode
			// 
			this.t_CheckBarCode.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold);
			this.t_CheckBarCode.Location = new System.Drawing.Point(56, 3);
			this.t_CheckBarCode.Size = new System.Drawing.Size(176, 26);
			this.t_CheckBarCode.Text = "";
			this.t_CheckBarCode.KeyDown += new System.Windows.Forms.KeyEventHandler(this.t_CheckBarCode_KeyDown);
			this.t_CheckBarCode.LostFocus += new System.EventHandler(this.t_CheckBarCode_LostFocus);
			this.t_CheckBarCode.GotFocus += new System.EventHandler(this.t_CheckBarCode_GotFocus);
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold);
			this.label2.Location = new System.Drawing.Point(8, 11);
			this.label2.Size = new System.Drawing.Size(64, 20);
			this.label2.Text = "条码:";
			// 
			// DataMenu
			// 
			this.DataMenu.MenuItems.Add(this.menuItem5);
			this.DataMenu.MenuItems.Add(this.menuItem6);
			this.DataMenu.MenuItems.Add(this.menuItem7);
			// 
			// menuItem5
			// 
			this.menuItem5.Text = "导入数据";
			// 
			// menuItem6
			// 
			this.menuItem6.Text = "导出数据";
			// 
			// menuItem7
			// 
			this.menuItem7.Text = "回主菜单";
			// 
			// p_Load
			// 
			this.p_Load.BackColor = System.Drawing.Color.LemonChiffon;
			this.p_Load.Controls.Add(this.l_Load);
			this.p_Load.Location = new System.Drawing.Point(24, 224);
			this.p_Load.Size = new System.Drawing.Size(200, 40);
			// 
			// l_Load
			// 
			this.l_Load.Location = new System.Drawing.Point(8, 12);
			this.l_Load.Size = new System.Drawing.Size(184, 20);
			// 
			// p_About
			// 
			this.p_About.BackColor = System.Drawing.Color.Gainsboro;
			this.p_About.Controls.Add(this.label7);
			this.p_About.Controls.Add(this.label6);
			this.p_About.Controls.Add(this.label3);
			this.p_About.Controls.Add(this.label5);
			this.p_About.Controls.Add(this.label4);
			this.p_About.Controls.Add(this.lbl_w_copyright);
			this.p_About.Controls.Add(this.lbl_w_title);
			this.p_About.Location = new System.Drawing.Point(256, 0);
			this.p_About.Size = new System.Drawing.Size(240, 192);
			this.p_About.Visible = false;
			this.p_About.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.p_About_KeyPress);
			this.p_About.GotFocus += new System.EventHandler(this.p_About_GotFocus);
			// 
			// label7
			// 
			this.label7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
			this.label7.Location = new System.Drawing.Point(16, 173);
			this.label7.Size = new System.Drawing.Size(184, 16);
			this.label7.Text = "按任意键返回...";
			// 
			// label6
			// 
			this.label6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
			this.label6.Location = new System.Drawing.Point(16, 118);
			this.label6.Size = new System.Drawing.Size(184, 16);
			this.label6.Text = "程序设计:刘洪辉";
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
			this.label3.Location = new System.Drawing.Point(16, 100);
			this.label3.Size = new System.Drawing.Size(176, 16);
			this.label3.Text = "邮编:610041 ";
			// 
			// label5
			// 
			this.label5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
			this.label5.Location = new System.Drawing.Point(16, 82);
			this.label5.Size = new System.Drawing.Size(176, 16);
			this.label5.Text = "传真:028-85257196 ";
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
			this.label4.Location = new System.Drawing.Point(16, 64);
			this.label4.Size = new System.Drawing.Size(176, 16);
			this.label4.Text = "电话:028-85257986 ";
			// 
			// lbl_w_copyright
			// 
			this.lbl_w_copyright.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
			this.lbl_w_copyright.Location = new System.Drawing.Point(16, 136);
			this.lbl_w_copyright.Size = new System.Drawing.Size(216, 32);
			this.lbl_w_copyright.Text = "版权所有:2006-2007 成都光码信息系统有限公司";
			// 
			// lbl_w_title
			// 
			this.lbl_w_title.Font = new System.Drawing.Font("华文行楷", 16.5F, System.Drawing.FontStyle.Regular);
			this.lbl_w_title.Location = new System.Drawing.Point(8, 8);
			this.lbl_w_title.Size = new System.Drawing.Size(216, 56);
			this.lbl_w_title.Text = "成都飞机设计研究所固定资产采集系统";
			// 
			// FMain
			// 
			this.ClientSize = new System.Drawing.Size(594, 304);
			this.ControlBox = false;
			this.Controls.Add(this.p_About);
			this.Controls.Add(this.p_Load);
			this.Controls.Add(this.p_Check);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Text = "成都飞机设计研究所固定资产采集系统";
			this.Load += new System.EventHandler(this.FMain_Load);
			this.Activated += new System.EventHandler(this.FMain_Activated);
			this.Deactivate += new System.EventHandler(this.FMain_Deactivate);

		}
		#endregion

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

		static void Main() 
		{
			Application.Run(new FMain());
		}
		#endregion
		#region 主窗口代码
		private void FMain_Load(object sender, System.EventArgs e)
		{
			//系统主菜单
			myMenu1 = new MyMenu(MainMenu, "〖主菜单〗");
			this.Controls.Add(this.myMenu1);
			myMenu1.MenuSelected += new GuangMa.MyMenu.MenuSelectedEventHandler(myMenu1_MenuSelected);
			myMenu1.KeyDown += new KeyEventHandler(myMenu1_KeyDown);
			myMenu1.GotFocus += new EventHandler(myMenu1_GotFocus);
			this.myMenu1.Focus();

			//数据传输菜单
			myMenu2 = new MyMenu(DataMenu, "〖数据传输〗");
			this.Controls.Add(this.myMenu2);
			myMenu2.MenuSelected += new GuangMa.MyMenu.MenuSelectedEventHandler(myMenu2_MenuSelected);
			myMenu2.KeyDown += new KeyEventHandler(myMenu2_KeyDown);
			myMenu2.GotFocus += new EventHandler(myMenu2_GotFocus);
			myMenu2.Visible = false;

			//显示背光灯
			Scanning.InitialDisplay();

			//初始化数据库
			SqlCeManage.InitialDatabase();
			
			try
			{
				//创建SQLCe数据库连接
				conn = new SqlCeConnection ("Data Source=" + SqlCeManage.DatabaseName);
				conn.Open();
			}
			catch
			{
				MessageBox.Show("数据库正在使用中或不存在!");
				Application.Exit();
			}
			
			this.setAllText(this);
		}
		private void setAllText(Control ctr)
		{
			foreach(Control ctrItem in ctr.Controls)
			{
				if(ctrItem.GetType() == typeof(TextBox) || 
					ctrItem.GetType() == typeof(Panel) )
				{
					//设置所有文本框和Panel的按键事件
					ctrItem.KeyPress += new KeyPressEventHandler(ctrItem_KeyPress);
					ctrItem.KeyDown += new KeyEventHandler(ctrItem_KeyDown);
				}

				//判断是否还有子控件
				if(ctrItem.Controls.Count > 0)
				{
					//递归函数调用
					this.setAllText(ctrItem);
				}
			}
		}
		private void ctrItem_KeyPress(object sender, KeyPressEventArgs e)
		{
			//设置按键音
			Scanning.Beep(60,1000);
		}
		private void ctrItem_KeyDown(object sender, KeyEventArgs e)
		{
			if(e.KeyCode == Keys.Up || 
			   e.KeyCode == Keys.Down)
				
			{
				//设置按键音
				Scanning.Beep(60,1000);
			}
		}
		private void myMenu1_MenuSelected(object sender, MenuItem e)
		{
			//进入盘查功能
			if(e.Equals(menuItem1))
			{
				this.myMenu1.Visible = false;
				this.p_Check.Visible = true;
				this.t_CheckBarCode.Text = "";
				this.t_ContentInfo.Text = "";
				this.t_CheckBarCode.Focus();
				this.TotalCount();  //统计已经盘查的资产数量
			}

			//进入数据传输功能
			if(e.Equals(menuItem2))
			{
				this.myMenu1.Visible = false;
				this.myMenu2.Visible = true;
				this.myMenu2.Focus();
			}

			//清除数据
			if(e.Equals(menuItem8))
			{
				this.ClearData();  //清除数据函数
				this.myMenu1.Focus();
			}
			
			//关于我们
			if(e.Equals(menuItem3))
			{
				this.p_About.Visible = true;
				this.p_About.Location = new Point(0,0);
				this.p_About.Focus();
			}

			//退出系统
			if(e.Equals(menuItem4))
			{
				Application.Exit();
			}
		}
		private void myMenu1_KeyDown(object sender, KeyEventArgs e)
		{
			if(e.KeyCode == Keys.Up ||

⌨️ 快捷键说明

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