📄 读卡器操作.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.Button btnSetTime;
private System.Windows.Forms.Button btnInit;
private System.Windows.Forms.Button btnShowTime;
private System.Windows.Forms.Button btnShowDay;
private System.Windows.Forms.Button btnShowNum;
private System.Windows.Forms.TextBox txtShowNum;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.ListBox lstLog;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
OprationCard.OprationCrad Machine;
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.btnSetTime = new System.Windows.Forms.Button();
this.btnInit = new System.Windows.Forms.Button();
this.btnShowTime = new System.Windows.Forms.Button();
this.btnShowDay = new System.Windows.Forms.Button();
this.btnShowNum = new System.Windows.Forms.Button();
this.lstLog = new System.Windows.Forms.ListBox();
this.txtShowNum = new System.Windows.Forms.TextBox();
this.btnExit = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnSetTime
//
this.btnSetTime.Enabled = false;
this.btnSetTime.Location = new System.Drawing.Point(112, 16);
this.btnSetTime.Name = "btnSetTime";
this.btnSetTime.TabIndex = 1;
this.btnSetTime.Text = "时间设置";
this.btnSetTime.Click += new System.EventHandler(this.btnSetTime_Click);
//
// btnInit
//
this.btnInit.Location = new System.Drawing.Point(8, 16);
this.btnInit.Name = "btnInit";
this.btnInit.TabIndex = 4;
this.btnInit.Text = "初始化串口";
this.btnInit.Click += new System.EventHandler(this.btnInit_Click);
//
// btnShowTime
//
this.btnShowTime.Enabled = false;
this.btnShowTime.Location = new System.Drawing.Point(8, 56);
this.btnShowTime.Name = "btnShowTime";
this.btnShowTime.TabIndex = 6;
this.btnShowTime.Text = "显示时间";
this.btnShowTime.Click += new System.EventHandler(this.btnShowTime_Click);
//
// btnShowDay
//
this.btnShowDay.Enabled = false;
this.btnShowDay.Location = new System.Drawing.Point(112, 56);
this.btnShowDay.Name = "btnShowDay";
this.btnShowDay.TabIndex = 7;
this.btnShowDay.Text = "显示日期";
this.btnShowDay.Click += new System.EventHandler(this.btnShowDay_Click);
//
// btnShowNum
//
this.btnShowNum.Enabled = false;
this.btnShowNum.Location = new System.Drawing.Point(112, 96);
this.btnShowNum.Name = "btnShowNum";
this.btnShowNum.TabIndex = 8;
this.btnShowNum.Text = "显示数字";
this.btnShowNum.Click += new System.EventHandler(this.btnShowNum_Click);
//
// lstLog
//
this.lstLog.ItemHeight = 12;
this.lstLog.Location = new System.Drawing.Point(200, 0);
this.lstLog.Name = "lstLog";
this.lstLog.Size = new System.Drawing.Size(152, 172);
this.lstLog.TabIndex = 9;
//
// txtShowNum
//
this.txtShowNum.Enabled = false;
this.txtShowNum.Location = new System.Drawing.Point(8, 96);
this.txtShowNum.MaxLength = 8;
this.txtShowNum.Name = "txtShowNum";
this.txtShowNum.Size = new System.Drawing.Size(80, 21);
this.txtShowNum.TabIndex = 10;
this.txtShowNum.Text = "输入数字";
this.txtShowNum.Enter += new System.EventHandler(this.txtShowNum_Enter);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(112, 136);
this.btnExit.Name = "btnExit";
this.btnExit.TabIndex = 11;
this.btnExit.Text = "退出操作";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnClose
//
this.btnClose.Enabled = false;
this.btnClose.Location = new System.Drawing.Point(8, 136);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 12;
this.btnClose.Text = "关闭串口";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// 读卡器操作
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(352, 174);
this.ControlBox = false;
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.txtShowNum);
this.Controls.Add(this.lstLog);
this.Controls.Add(this.btnShowNum);
this.Controls.Add(this.btnShowDay);
this.Controls.Add(this.btnShowTime);
this.Controls.Add(this.btnInit);
this.Controls.Add(this.btnSetTime);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "读卡器操作";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "读卡器操作";
this.Load += new System.EventHandler(this.读卡器操作_Load);
this.ResumeLayout(false);
}
#endregion
private void txtShowNum_Enter(object sender, System.EventArgs e)
{
this.txtShowNum.Text="";
this.btnShowNum.Enabled=true;
}
private void btnInit_Click(object sender, System.EventArgs e)
{
if(Machine.Init_Machine()<=0)
{
this.lstLog.Items.Add("串口初始化失败!");
}
else
{
this.lstLog.Items.Add("串口初始化成功!");
this.btnClose.Enabled=true;
this.btnSetTime.Enabled=true;
this.btnShowDay.Enabled=true;
this.btnShowTime.Enabled=true;
this.btnShowNum.Enabled=false;
this.txtShowNum.Enabled=true;
this.btnExit.Enabled=false;
this.btnInit.Enabled=false;
}
}
private void 读卡器操作_Load(object sender, System.EventArgs e)
{
Machine=new OprationCard.OprationCrad();
DataSet o=new DataSet();
try
{
o.ReadXml("Config.xml");
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());//第二扇区
}
catch
{
this.lstLog.Items.Add("配置文件丢失,请配置程序!");
MessageBox.Show("配置文件丢失,请配置程序!");
this.Dispose(true);
毕业设计.射频卡.读卡器配置 oo=new 毕业设计.射频卡.读卡器配置();
oo.ShowDialog(this.Parent);
}
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnClose_Click(object sender, System.EventArgs e)
{
if(Machine.Exit_Machine()==0)
{
this.btnClose.Enabled=false;;
this.btnSetTime.Enabled=false;
this.btnShowDay.Enabled=false;
this.btnShowTime.Enabled=false;
this.btnShowNum.Enabled=false;
this.txtShowNum.Enabled=false;
this.btnExit.Enabled=true;
this.btnInit.Enabled=true;
}
else
{
}
}
private void btnSetTime_Click(object sender, System.EventArgs e)
{
if(Machine.SetTime(GetTime())==0)
{
this.lstLog.Items.Add("设置系统时间成功!");
}
else
{
this.lstLog.Items.Add("设置系统时间失败!");
}
}
private byte[] GetTime()
{
毕业设计.数据处理.数据处理 o=new 毕业设计.数据处理.数据处理();
return o.GetTime();
}
private void btnShowTime_Click(object sender, System.EventArgs e)
{
if(Machine.ShowTimeMode(1)==0)
{
this.lstLog.Items.Add("显示时间设置成功!");
}
else
{
this.lstLog.Items.Add("显示时间设置失败!");
}
}
private void btnShowDay_Click(object sender, System.EventArgs e)
{
if(Machine.ShowTimeMode(0)==0)
{
this.lstLog.Items.Add("显示日期设置成功!");
}
else
{
this.lstLog.Items.Add("显示日期设置失败!");
}
}
private void btnShowNum_Click(object sender, System.EventArgs e)
{
sbyte[] data={0,0,0,0,0,0,0,0};
for(int i=0;i<txtShowNum.Text.Length;i++)
{
data[i]=System.Convert.ToSByte(System.Convert.ToInt32(this.txtShowNum.Text.ToString()[i]));
}
if(Machine.ShowNumber(data)==0)
{
this.lstLog.Items.Add("显示数字设置成功!");
}
else
{
this.lstLog.Items.Add("显示数字设置失败!");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -