?? 格式化系統.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.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.ListBox LogLsit;
private System.Windows.Forms.Timer timer;
private System.ComponentModel.IContainer components;
OprationCard.OprationCrad Machine;
private int Step=0;
private 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.LogLsit = 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();
//
// LogLsit
//
this.LogLsit.ItemHeight = 12;
this.LogLsit.Location = new System.Drawing.Point(0, 0);
this.LogLsit.Name = "LogLsit";
this.LogLsit.Size = new System.Drawing.Size(288, 160);
this.LogLsit.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.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.LogLsit);
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 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.LogLsit.Items.Add(System.DateTime.Now.ToString()+":監測到射頻卡!");
this.LogLsit.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="格式化系統";
o.lbCardNo.Text="卡序列號:"+Machine.CardNo.ToString();
o.lbReason.Text="密碼驗證失敗";
o.ShowDialog();
}
}
if(this.Step==3)
{
this.timer.Enabled=false;
this.Step=4;
int cardno=0;
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.LogLsit.Items.Add(System.DateTime.Now.ToString()+":讀卡錯誤!!請換卡。。");
}
else
{
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.LogLsit.Items.Add(System.DateTime.Now.ToString()+":卡號為:"+cardno.ToString());
畢業設計.數據處理.數據處理 oo=new 畢業設計.數據處理.數據處理();
if(oo.Login(cardno.ToString())!=null)
{
if(MessageBox.Show("此卡已經注冊,是否格式化?","格式化卡",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2)==DialogResult.Yes)
{
while(true)
{
if(FormatCard())
{
this.LogLsit.Items.Add("格式化成功!");
break;
}
else
{
if(MessageBox.Show("格式化失敗,是否重試?","失敗",MessageBoxButtons.YesNo,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1)==DialogResult.Yes)
{
}
else
break;
}
}
}
}
else
{
if(MessageBox.Show("此卡未注冊,是否格式化?","格式化卡",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1)==DialogResult.Yes)
{
while(true)
{
if(FormatCard())
{
this.LogLsit.Items.Add("格式化成功!");
break;
}
else
{
if(MessageBox.Show("格式化失敗,是否重試?","失敗",MessageBoxButtons.YesNo,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1)==DialogResult.Yes)
{
}
else
break;
}
}
}
}
}
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.Step=0;
}
}
}
private void 發卡系統_Load(object sender, System.EventArgs e)
{
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);
}
}
private byte[] GetTime()
{
畢業設計.數據處理.數據處理 o=new 畢業設計.數據處理.數據處理();
return o.GetTime();
}
private bool PreparyWrite()
{
if(Machine.FindCard()==0)
{
if(Machine.LoadKey()==0)
{
if(Machine.Authentication()==0)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
private void 發卡系統_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Machine.Exit_Machine();
this.timer.Enabled=false;
this.Dispose(true);
}
private bool FormatCard()
{
byte[] Datass={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
if(PreparyWrite())
{
if(Machine.Write(Datass,8)==0)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -