private void frm_Card_QryTrade_FormClosing(object sender, FormClosingEventArgs e) { if (myRdr.ComIsOpen) { myRdr.ComClose(); } }
public void GetPsamCardID() { CIcRdr myRdr = new CIcRdr(); string sPort = ""; bHaveRd = false; for (int i = 1; i < 20; i++) { sPort = "Com" + i.ToString(); if (!myRdr.ComOpen(sPort)) { continue; } //Application.DoEvents(); if (!myRdr.Link()) { myRdr.ComClose(); continue; } if (!myRdr.GetPsamID()) { myRdr.ComClose(); continue; } bHaveRd = true; sRdPort = sPort; myRdr.ComClose(); break; } }
private void button_Card_Click(object sender, EventArgs e) { ((Button)sender).Enabled = false; CIcRdr myRdr = new CIcRdr(); //string szErr = ""; if (!myRdr.ComOpen(frm_Main.sRdPort)) { MessageBox.Show("连接读卡器失败,请检查连接", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); ((Button)sender).Enabled = true; button_Card.Focus(); return; } //Application.DoEvents(); if (!myRdr.Link()) { MessageBox.Show("连接读卡器失败,请联系供应商", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); myRdr.ComClose(); ((Button)sender).Enabled = true; button_Card.Focus(); return; } //Application.DoEvents(); string szInf; if (!myRdr.ReadCardInf(out szInf)) { MessageBox.Show("读卡失败,请重新放卡", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); myRdr.ComClose(); ((Button)sender).Enabled = true; button_Card.Focus(); return; } myRdr.ComClose(); if (szInf.Substring(0, 1).CompareTo(MyStart.gszCardFirmFirst) != 0) //not firm card { if (szInf.Substring(0, 1).CompareTo(MyStart.gszCardYtbFirst) != 0) //not user card { MessageBox.Show("卡号错误(既不是卖方卡,也不是结算卡),请换卡", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); ((Button)sender).Enabled = true; button_Card.Focus(); return; } else { textBox_Card.Text = szInf.Substring(0, 16); } } else { textBox_Card.Text = szInf.Substring(1, 15); } ((Button)sender).Enabled = true; button_Qry_Click(sender, e); }
private void ReadCardNo(string szCardFlag, Button btnObj, TextBox EditObj) { CIcRdr myRdr = new CIcRdr(); //string szErr = ""; if (!myRdr.ComOpen(frm_Main.sRdPort)) { MessageBox.Show("连接读卡器失败,请检查连接", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); btnObj.Focus(); return; } //Application.DoEvents(); if (!myRdr.Link()) { MessageBox.Show("连接读卡器失败,请联系供应商", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); myRdr.ComClose(); btnObj.Focus(); return; } //Application.DoEvents(); string szInf; if (!myRdr.ReadCardInf(out szInf)) { MessageBox.Show("读卡失败,请重新放卡", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); myRdr.ComClose(); btnObj.Focus(); return; } if (szInf.Substring(0, 1).CompareTo(szCardFlag) != 0) { if (mszFlag.ToUpper() == "USER_CARD") { MessageBox.Show("卡号错误(不是买方卡),请换卡", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (mszFlag.ToUpper() == "FIRM_CARD") { if (szCardFlag == MyStart.gszCardYtbFirst) { MessageBox.Show("卡号错误(不是卖方结算卡),请换卡", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("卡号错误(不是卖方卡),请换卡", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } myRdr.ComClose(); btnObj.Focus(); return; } EditObj.Text = szInf.Substring(0, 16);//szInf.Substring(1, 15); // myRdr.ComClose(); }
private void button_CheckUserCard_Click(object sender, EventArgs e) { string szInf = ""; bool IsUser = false; bool IsCust = false; string sCardID = ""; if (!frm_Main.bHaveRd) { MessageBox.Show("没有连接读写器,不能执行取款功能!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!myRdr.ComOpen(frm_Main.sRdPort)) { MessageBox.Show("打开串口失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); myRdr.ComClose(); return; } if (!myRdr.ReadCardInf(out szInf)) { if (textBox_UserCardID.Text.Trim() != "") { sCardID = textBox_UserCardID.Text.Trim(); } else { MessageBox.Show("读卡失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); myRdr.ComClose(); return; } } else { sCardID = szInf.Substring(0, 16); } myRdr.ComClose(); textBox_UserCardID.Text = sCardID; //sCardID = textBox_UserCardID.Text; if (sCardID.Substring(0, 1) == MyStart.gszCardFirmFirst) { MessageBox.Show("这是卖方卡,请换卡!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int iB = 0; int iT = 0; float fi = 0; if (mszFlag.ToUpper() == "USER_CARD") { if (!CheckUserCard(sCardID, ref IsUser, ref CardPwd, ref CardHidePwd, ref szInf)) { MyStart.oMyDb.Close(); MessageBox.Show("读数据库错误 = " + szInf, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!IsUser) { MyStart.oMyDb.Close(); MessageBox.Show("所使用的卡不是买方卡,请更换!" + szInf, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!GetCardBalance(sCardID, ref iB, ref iT, ref szInf)) { MyStart.oMyDb.Close(); MessageBox.Show("读数据库错误 = " + szInf, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else // (mszFlag.ToUpper() == "FIRM_CARD") { if (!CheckCustCard(sCardID, ref IsCust, ref CardPwd, ref CardHidePwd, ref szInf)) { MyStart.oMyDb.Close(); MessageBox.Show("读数据库错误 = " + szInf, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!IsCust) { MyStart.oMyDb.Close(); MessageBox.Show("所使用的卡不是卖方卡,请更换!" + szInf, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } iT = 1; // 查未结算金额 if (!GetCardBalance(sCardID, ref iB, ref iT, ref szInf)) { MyStart.oMyDb.Close(); MessageBox.Show("读数据库错误 = " + szInf, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } MyStart.oMyDb.Close(); fi = iB; fi /= 100; textBox_FinishBalance.Text = fi.ToString("0.00"); fi = iT; fi /= 100; textBox_UnFinishBalance.Text = fi.ToString("0.00"); fi = (iB + iT); fi /= 100; textBox_OldBalance.Text = fi.ToString("0.00"); groupBox_FirstStep.Enabled = false; groupBox_ThirdStep.Enabled = true; button_Retry.Enabled = true; textBox_Value.Focus(); }
private void ReadCardNo(string szType, Button objBtn, TextBox objText) { objBtn.Enabled = false; CIcRdr myRdr = new CIcRdr(); //string szErr = ""; if (!frm_Main.bHaveRd) { MessageBox.Show("没有连接读卡器,请检查。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); objBtn.Enabled = true; objBtn.Focus(); return; } if (!myRdr.ComOpen(frm_Main.sRdPort)) { MessageBox.Show("连接读卡器失败,请检查连接", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); objBtn.Enabled = true; objBtn.Focus(); return; } //Application.DoEvents(); if (!myRdr.Link()) { MessageBox.Show("连接读卡器失败,请联系供应商", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); myRdr.ComClose(); objBtn.Enabled = true; objBtn.Focus(); return; } //Application.DoEvents(); string szInf; if (!myRdr.ReadCardInf(out szInf)) { MessageBox.Show("读卡失败,请重新放卡", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); myRdr.ComClose(); objBtn.Enabled = true; objBtn.Focus(); return; } string szTypeDesc = "买方卡"; if (szType.CompareTo(MyStart.gszCardFirmFirst) == 0) { szTypeDesc = "卖方卡"; } if (szInf.Substring(0, 1).CompareTo(szType) != 0) { MessageBox.Show("卡号错误(不是" + szTypeDesc + ",卡号第一位应是" + szType + ")," + ",请换卡", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); myRdr.ComClose(); objBtn.Enabled = true; objBtn.Focus(); return; } if (szType.CompareTo(MyStart.gszCardFirmFirst) == 0) { objText.Text = szInf.Substring(1, 15); } else { objText.Text = szInf.Substring(0, 16); } myRdr.ComClose(); objBtn.Enabled = true; }
private void button_CheckUserCard_Click(object sender, EventArgs e) { string szInf = ""; bool IsCust = false; string sCardID = ""; if (!frm_Main.bHaveRd) { if (textBox_UserCardID.Text.Trim() != "") { sCardID = textBox_UserCardID.Text; } else { MessageBox.Show("没有连接读写器,也没有输入卡号,不能执行结算功能!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { if (!myRdr.ComOpen(frm_Main.sRdPort)) { myRdr.ComClose(); if (textBox_UserCardID.Text.Trim() != "") { sCardID = textBox_UserCardID.Text; } else { MessageBox.Show("打开串口失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { if (!myRdr.ReadCardInf(out szInf)) { if (textBox_UserCardID.Text.Trim() != "") { sCardID = textBox_UserCardID.Text; } else { MessageBox.Show("读卡失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); myRdr.ComClose(); return; } } else { sCardID = szInf.Substring(0, 16); } } myRdr.ComClose(); } textBox_UserCardID.Text = sCardID; if (sCardID.Substring(0, 1) == MyStart.gszCardFirmFirst) { MessageBox.Show("不能使用卖方卡结算,请换卡!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int iB = 0; int iT = 0; float fi = 0; if (!CheckCustCard(sCardID, ref IsCust, ref CardPwd, ref CardHidePwd, ref szInf)) { MessageBox.Show("读数据库错误 = " + szInf, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); goto Eend; } if (!IsCust) { MessageBox.Show("所使用的卡不是结算卡,请更换!" + szInf, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); goto Eend; } iT = 1; // 查未结算金额 if (!GetCardBalance(sCardID, ref iB, ref iT, ref szInf)) { MessageBox.Show("读数据库错误 = " + szInf, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); goto Eend; } fi = iB; fi /= 100; textBox_FinishBalance.Text = fi.ToString("0.00"); fi = iT; fi /= 100; textBox_UnFinishBalance.Text = fi.ToString("0.00"); fi = (iB + iT); fi /= 100; textBox_OldBalance.Text = fi.ToString("0.00"); groupBox_FirstStep.Enabled = false; groupBox_ThirdStep.Enabled = true; button_Retry.Enabled = true; if (iT <= 0) { button_JK.Enabled = false; textBox_Pwd.Enabled = false; button_Retry.Focus(); } else { button_JK.Enabled = true; textBox_Pwd.Enabled = true; textBox_Pwd.Focus(); } Eend: MyStart.oMyDb.Close(); }