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

📄 记分系统.cs

📁 射频卡读写程序,C#版
💻 CS
字号:
namespace 毕业设计
{
	using System;
	using System.Drawing;
	using System.Collections;
	using System.ComponentModel;
	using System.Windows.Forms;
	using System.Data;

	namespace 射频卡
	{
		/// <summary>
		/// 记分系统 的摘要说明。
		/// </summary>
		public class 记分系统 : System.Windows.Forms.Form
		{
			private System.Windows.Forms.ListBox lstLog;
			private System.Windows.Forms.StatusBar StatusBar;
			private System.Windows.Forms.StatusBarPanel Pan1;
			private System.Windows.Forms.StatusBarPanel Pan2;
			private System.Windows.Forms.StatusBarPanel Pan3;
			private System.Windows.Forms.StatusBarPanel Pan4;
			private System.Windows.Forms.Timer timer;
			private System.ComponentModel.IContainer components;

			OprationCard.OprationCrad Machine;
			
			public string course;
			int Step=0;
			bool newcard=true;

			public 记分系统()
			{
				//
				// 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.components = new System.ComponentModel.Container();
				this.lstLog = new System.Windows.Forms.ListBox();
				this.StatusBar = new System.Windows.Forms.StatusBar();
				this.Pan1 = new System.Windows.Forms.StatusBarPanel();
				this.Pan2 = new System.Windows.Forms.StatusBarPanel();
				this.Pan3 = new System.Windows.Forms.StatusBarPanel();
				this.Pan4 = new System.Windows.Forms.StatusBarPanel();
				this.timer = new System.Windows.Forms.Timer(this.components);
				((System.ComponentModel.ISupportInitialize)(this.Pan1)).BeginInit();
				((System.ComponentModel.ISupportInitialize)(this.Pan2)).BeginInit();
				((System.ComponentModel.ISupportInitialize)(this.Pan3)).BeginInit();
				((System.ComponentModel.ISupportInitialize)(this.Pan4)).BeginInit();
				this.SuspendLayout();
				// 
				// lstLog
				// 
				this.lstLog.ItemHeight = 12;
				this.lstLog.Location = new System.Drawing.Point(0, 0);
				this.lstLog.Name = "lstLog";
				this.lstLog.Size = new System.Drawing.Size(288, 160);
				this.lstLog.TabIndex = 0;
				// 
				// StatusBar
				// 
				this.StatusBar.Location = new System.Drawing.Point(0, 160);
				this.StatusBar.Name = "StatusBar";
				this.StatusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																							 this.Pan1,
																							 this.Pan2,
																							 this.Pan3,
																							 this.Pan4});
				this.StatusBar.ShowPanels = true;
				this.StatusBar.Size = new System.Drawing.Size(292, 22);
				this.StatusBar.TabIndex = 1;
				// 
				// Pan1
				// 
				this.Pan1.Text = "状态";
				this.Pan1.Width = 35;
				// 
				// Pan2
				// 
				this.Pan2.Text = "监测卡";
				// 
				// timer
				// 
				this.timer.Interval = 500;
				this.timer.Tick += new System.EventHandler(this.timer_Tick);
				// 
				// 记分系统
				// 
				this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
				this.ClientSize = new System.Drawing.Size(292, 182);
				this.Controls.Add(this.StatusBar);
				this.Controls.Add(this.lstLog);
				this.Name = "记分系统";
				this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
				this.Text = "记分系统";
				this.Closing += new System.ComponentModel.CancelEventHandler(this.记分系统_Closing);
				this.Load += new System.EventHandler(this.记分系统_Load);
				((System.ComponentModel.ISupportInitialize)(this.Pan1)).EndInit();
				((System.ComponentModel.ISupportInitialize)(this.Pan2)).EndInit();
				((System.ComponentModel.ISupportInitialize)(this.Pan3)).EndInit();
				((System.ComponentModel.ISupportInitialize)(this.Pan4)).EndInit();
				this.ResumeLayout(false);

			}
			#endregion

			private void 记分系统_Load(object sender, System.EventArgs e)
			{
				this.Text="记分系统--"+this.course;
				Machine=new OprationCard.OprationCrad();
				Machine.port=1;
				Machine.HZ=115200;
				DataSet o=new DataSet();
				try
				{
					o.ReadXml("Machine.config");
					if(o.Tables[0].Rows[0][0].ToString()=="COM1")
					{
						Machine.port=0;
					}
					if(o.Tables[0].Rows[0][0].ToString()=="COM2")
					{
						Machine.port=1;
					}
					if(o.Tables[0].Rows[0][0].ToString()=="COM3")
					{
						Machine.port=2;
					}
					if(o.Tables[0].Rows[0][0].ToString()=="COM4")
					{
						Machine.port=3;	
					}			
					if(o.Tables[0].Rows[0][0].ToString()=="COM5")
					{
						Machine.port=4;	
					}

					if(o.Tables[0].Rows[0][0].ToString()=="COM6")
					{
						Machine.port=5;	
					}		
					if(o.Tables[0].Rows[0][0].ToString()=="COM7")
					{
						Machine.port=6;	
					}				
					if(o.Tables[0].Rows[0][0].ToString()=="COM8")
					{
						Machine.port=7;	
					}
					Machine.HZ=System.Convert.ToInt32(o.Tables[0].Rows[0][1].ToString());
					Machine.Mode=System.Convert.ToInt32(o.Tables[0].Rows[0][3].ToString());//模式0
					Machine.SecNo=System.Convert.ToInt32(o.Tables[0].Rows[0][2].ToString());//第二扇区

					Machine.HZ=Convert.ToInt32(o.Tables[0].Rows[0][1].ToString());

					毕业设计.射频卡.初始化状态 status=new 毕业设计.射频卡.初始化状态();
					if(Machine.Init_Machine()<=0)
					{
						status.lbStatus.Text="设备初始化失败,请检查电源和端口!";
					}
					else
					{
						status.lbStatus.Text="设备初始化成功!";

						if(Machine.SetTime(GetTime())==0)
							status.lbStatus.Text+="\r\n时间设置成功!";
						if(Machine.LoadKey()!=0)
							status.lbStatus.Text+="\r\n载入密码失败!";
						else
						{
							status.lbStatus.Text+="\r\n装入密码成功!";
							this.timer.Enabled=true;
						}
					}
					status.Show();
				}
				catch
				{
					MessageBox.Show("配置文件丢失,请配置程序!");
					this.Dispose(true);
					毕业设计.射频卡.读卡器配置 oo=new 毕业设计.射频卡.读卡器配置();
					oo.ShowDialog(this.Parent);
					this.Dispose(true);
				}



			}
			private byte[] GetTime()
			{
				毕业设计.数据处理.数据处理 o=new 毕业设计.数据处理.数据处理();
				return o.GetTime();
			}

			private void timer_Tick(object sender, System.EventArgs e)
			{
				毕业设计.射频卡.读卡结果 o=new 毕业设计.射频卡.读卡结果();
				o.Title="不能记分的卡";
				if(this.Step==0)
				{
					if(Machine.FindCard()==0)
					{
						if(this.newcard)
						{
							this.newcard=false;
							this.lstLog.Items.Add(System.DateTime.Now.ToString()+":监测到射频卡!");
							this.lstLog.Items.Add(System.DateTime.Now.ToString()+":卡序列号--"+Machine.CardNo.ToString());
							this.Step=1;
						}
						else
							this.Step=0;
					}
					else
					{
						this.newcard=true;
						this.Step=0;
					}
				}

				if(this.Step==1)
				{
					if(Machine.LoadKey()==0)
					{
						this.Step=2;
					}
					else
					{
						this.Step=0;
					}
				}

				if(this.Step==2)
				{
					if(Machine.Authentication()==0)
					{	
						this.Text="卡序列号--"+Machine.CardNo.ToString();
						this.Step=3;
					}
					else
					{
						this.Step=0;
						this.Text="记分系统--"+this.course;
						
						o.lbCardNo.Text="卡序列号:"+Machine.CardNo.ToString();
						o.lbReason.Text="密码验证失败";
						o.ShowDialog();
					}
				}
			
				if(this.Step==3)
				{
					byte[] Datas={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
					if(Machine.Read(Datas,8)!=0)
					{
						this.Step=0;
						this.lstLog.Items.Add(System.DateTime.Now.ToString()+":读卡错误!!请换卡。。");
					}
					else
					{
						this.Step=4;
						string s="";
						for(int i=0;i<Datas.Length;i++)
							s+=Datas[i];	
						int cardno=0;
						for(int i=0;i<Datas.Length;i++)
						{
							int t=System.Convert.ToInt32(Datas[15-i]);
							t-=48;
							if(t>=0)
								cardno=cardno*10+t;
						}
						this.lstLog.Items.Add(System.DateTime.Now.ToString()+":卡号为:"+cardno.ToString());
						毕业设计.数据处理.数据处理 oo=new 毕业设计.数据处理.数据处理();
						string userid=oo.Login(cardno.ToString());
						if(oo.Login(cardno.ToString())!=null)
						{
							this.lstLog.Items.Add(System.DateTime.Now.ToString()+":成功登录系统!");
							this.timer.Enabled=false;
							if(MessageBox.Show("是否输入成绩?","输入成绩",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1)==DialogResult.Yes)
							{
								毕业设计.软件系统.数据输入 input=new 毕业设计.软件系统.数据输入();
								input.course=this.course;
								input.txtsno.Text=userid;
								input.txtsno.Enabled=false;
								input.ShowDialog(this);
							}
							this.timer.Enabled=true;
						}
					}
				}

				if(this.Step==4)
				{
					if(Machine.FindCard()==0&&Machine.LoadKey()==0&&Machine.Authentication()==0)
					{
						this.Step=4;
					}
					else
					{
						this.Text="记分系统--"+this.course;
						this.Step=0;
					}
				}
			}

			private void 记分系统_Closing(object sender, System.ComponentModel.CancelEventArgs e)
			{
				Machine.Exit_Machine();
				this.timer.Enabled=false;
				this.Dispose(true);
			}
		}


	}
}

⌨️ 快捷键说明

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