Example #1
0
        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;
            }

            if (szInf.Substring(0, 1).CompareTo(MyStart.gszCardYtbFirst) != 0)
            {
                MessageBox.Show("卡号错误(买方卡号第一位是" + MyStart.gszCardYtbFirst + "),请换卡",
                                "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                myRdr.ComClose();
                ((Button)sender).Enabled = true;
                button_Card.Focus();
                return;
            }
            textBox_Card.Text = szInf.Substring(0, 16);
            myRdr.ComClose();
            ((Button)sender).Enabled = true;
        }
Example #2
0
        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();
        }
Example #3
0
        private void button_CheckCard_Click(object sender, EventArgs e)
        {
            string szInf   = "";
            string sCardID = "";
            string sSql    = "";

            if (!frm_Main.bHaveRd)
            {
                if (textBox_CardID.Text.Trim() != "")
                {
                    sCardID = textBox_CardID.Text;
                }
                else
                {
                    MessageBox.Show("没有连接读写器,也没有输入卡号,不能执行查询功能!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                if (!myRdr.ComOpen(frm_Main.sRdPort))
                {
                    myRdr.ComClose();
                    if (textBox_CardID.Text.Trim() != "")
                    {
                        sCardID = textBox_CardID.Text;
                    }
                    else
                    {
                        MessageBox.Show("打开串口失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    if (!myRdr.ReadCardInf(out szInf))
                    {
                        if (textBox_CardID.Text.Trim() != "")
                        {
                            sCardID = textBox_CardID.Text;
                        }
                        else
                        {
                            MessageBox.Show("读卡失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            myRdr.ComClose();
                            return;
                        }
                    }
                    else
                    {
                        sCardID = szInf.Substring(0, 16);
                    }
                }
                myRdr.ComClose();
            }
            textBox_CardID.Text = sCardID;

            if (mszFlag.ToUpper() == "USER_CARD")
            {
                if (sCardID.Substring(0, 1) == MyStart.gszCardFirmFirst)
                {
                    MessageBox.Show("这不是用户卡,请更换!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                sSql = "SELECT * FROM base_ucard WHERE user_card = '" + sCardID + "'";
            }
            else
            {
                if (sCardID.Substring(0, 1) == MyStart.gszCardFirmFirst)
                {
                    MessageBox.Show("这不是商户结算卡,请更换!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                sSql = "SELECT * FROM mng_card WHERE store_card = '" + sCardID + "' and  CARD_TYPE = 3";
            }

            DataSet odt     = null;
            string  sErrMsg = "";
            int     iRt     = MyStart.oMyDb.ReadData(sSql, "TableA", ref odt, ref sErrMsg);

            if (iRt != 0)
            {
                MessageBox.Show("查询数据库时出现错误 = " + sErrMsg, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                goto Eend;
            }

            if (odt.Tables[0].Rows.Count <= 0)
            {
                MessageBox.Show("该卡片尚未投入使用, 请更换!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                goto Eend;
            }

            if (mszFlag.ToUpper() == "USER_CARD")
            {
                dateTimePicker1.Focus();
            }
            else  // 商户卡
            {
                sStoreID = odt.Tables[0].Rows[0]["STORE_ID"].ToString().Trim();

                odt  = null;
                sSql = "SELECT * FROM mng_card WHERE STORE_ID = " + sStoreID + " and  CARD_TYPE = 1";
                iRt  = MyStart.oMyDb.ReadData(sSql, "TableA", ref odt, ref sErrMsg);

                if (iRt != 0)
                {
                    MessageBox.Show("查询数据库时出现错误 = " + sErrMsg, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    goto Eend;
                }

                if (odt.Tables[0].Rows.Count <= 0)
                {
                    MessageBox.Show("该结算卡没有关联商户卡, 请检查!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    goto Eend;
                }
            }
            groupBox_1.Enabled   = false;
            button_Retry.Enabled = true;
            groupBox_2.Visible   = true;
            dateTimePicker1.Focus();

Eend:
            MyStart.oMyDb.Close();
        }
Example #4
0
        private void button_CheckCard_Click(object sender, EventArgs e)
        {
            string  szInf   = "";
            string  sCardID = "";
            DataSet odt     = null;

            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;
            }

            ((Button)sender).Enabled = false;
            if (!myRdr.ReadCardInf(out szInf))
            {
                if (textBox_CardID.Text.Trim() != "")
                {
                    sCardID = textBox_CardID.Text;
                }
                else
                {
                    MessageBox.Show("读卡失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ((Button)sender).Enabled = true;
                    myRdr.ComClose();
                    return;
                }
            }
            else
            {
                sCardID = szInf.Substring(0, 16);
            }
            myRdr.ComClose();
            ((Button)sender).Enabled = true;
            textBox_CardID.Text      = sCardID;

            if (sCardID.Substring(0, 1) == MyStart.gszCardFirmFirst)
            {
                MessageBox.Show("不接受商户卡的充值,请换卡!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            odt = null;
            string sErrMsg = "";
            string sSql    = "";

            try
            {
                sSql = "SELECT * FROM base_ucard WHERE user_card = '" + sCardID + "'";

                int iRst = MyStart.oMyDb.ReadData(sSql, "TableA", ref odt, ref sErrMsg);
                if (iRst != 0)
                {
                    MessageBox.Show("后台查询卡余额失败( " + sErrMsg + " )", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    goto Eend;
                }

                if (odt.Tables[0].Rows.Count <= 0)
                {
                    MessageBox.Show("没有此用户卡的信息,请更换。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    goto Eend;
                }
                sUserName = odt.Tables[0].Rows[0]["user_name"].ToString().Trim();

                //银石后台
                objHttp = new EbHttpClass();
                string szErr       = "";
                int    CardBalance = 0;
                int    iTrade      = 0;

                bool bRst = objHttp.QryCard(sCardID, ref CardBalance, ref iTrade, ref szErr);
                if (!bRst)
                {
                    MessageBox.Show("后台查询卡余额失败( " + szErr + " )", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    goto Eend;
                }

                float fi = CardBalance;
                fi = fi / 100;
                textBox_OldBalance.Text = fi.ToString("0.00");

                groupBox_FirstStep.Enabled  = false;
                groupBox_SecondStep.Visible = true;
                button_Retry.Enabled        = true;
                textBox_Value.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show("查询卡片余额失败( " + ex.Message + " )", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

Eend:
            if (odt != null)
            {
                odt.Clear();
            }

            MyStart.oMyDb.Close();
        }
Example #5
0
        private void button_CheckCard_Click(object sender, EventArgs e)
        {
            string szInf   = "";
            string sCardID = "";
            string sSql    = "";

            if (!frm_Main.bHaveRd)
            {
                if (textBox_CardID.Text.Trim() != "")
                {
                    sCardID = textBox_CardID.Text;
                }
                else
                {
                    MessageBox.Show("没有连接读写器,也没有输入卡号,不能执行查询功能!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                if (!myRdr.ComOpen(frm_Main.sRdPort))
                {
                    myRdr.ComClose();
                    if (textBox_CardID.Text.Trim() != "")
                    {
                        sCardID = textBox_CardID.Text;
                    }
                    else
                    {
                        MessageBox.Show("打开串口失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    if (!myRdr.ReadCardInf(out szInf))
                    {
                        if (textBox_CardID.Text.Trim() != "")
                        {
                            sCardID = textBox_CardID.Text;
                        }
                        else
                        {
                            MessageBox.Show("读卡失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            myRdr.ComClose();
                            return;
                        }
                    }
                    else
                    {
                        sCardID = szInf.Substring(0, 16);
                    }
                }
                myRdr.ComClose();
            }
            textBox_CardID.Text = sCardID;

            sSql = "SELECT * FROM mng_card WHERE store_card = '" + sCardID + "' and CARD_STAT = 'BGN'";
            DataSet odt     = null;
            string  sErrMsg = "";
            int     iRt     = MyStart.oMyDb.ReadData(sSql, "TableA", ref odt, ref sErrMsg);

            if (iRt != 0)
            {
                MessageBox.Show("查询数据库时出现错误 = " + sErrMsg, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                goto Eend;
            }

            if (odt.Tables[0].Rows.Count <= 0)
            {
                MessageBox.Show("未找到该卡片的信息, 请更换!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                goto Eend;
            }

            sStoreID             = odt.Tables[0].Rows[0]["STORE_ID"].ToString().Trim();
            sCardType            = odt.Tables[0].Rows[0]["CARD_TYPE"].ToString().Trim();
            groupBox_1.Enabled   = false;
            button_Retry.Enabled = true;
            groupBox_2.Visible   = true;
            dateTimePicker1.Focus();

Eend:
            MyStart.oMyDb.Close();
        }
Example #6
0
        private void button_CheckCard_Click(object sender, EventArgs e)
        {
            string  szInf   = "";
            string  sCardID = "";
            DataSet odt     = null;
            string  sErrMsg = "";

            if (!frm_Main.bHaveRd)
            {
                if (textBox_CardID.Text.Trim() != "")
                {
                    sCardID = textBox_CardID.Text;
                }
                else
                {
                    MessageBox.Show("没有连接读写器,也没有输入卡号,不能执行查询余额功能!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                if (!myRdr.ComOpen(frm_Main.sRdPort))
                {
                    myRdr.ComClose();
                    if (textBox_CardID.Text.Trim() != "")
                    {
                        sCardID = textBox_CardID.Text;
                    }
                    else
                    {
                        MessageBox.Show("打开串口失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    if (!myRdr.ReadCardInf(out szInf))
                    {
                        if (textBox_CardID.Text.Trim() != "")
                        {
                            sCardID = textBox_CardID.Text;
                        }
                        else
                        {
                            MessageBox.Show("读卡失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            myRdr.ComClose();
                            goto Eend;
                        }
                    }
                    else
                    {
                        sCardID = szInf.Substring(0, 16);
                    }
                }
                myRdr.ComClose();
            }
            textBox_CardID.Text = sCardID;

            if (sCardID.Substring(0, 1) == MyStart.gszCardFirmFirst)
            {
                MessageBox.Show("不接受商户卡查询余额,请换卡!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                goto Eend;
            }

            try
            {
                string sSql = "";
                if (mszFlag.ToUpper() == "FIRM_CARD")
                {
                    sSql = "SELECT * FROM mng_card WHERE STORE_CARD = '" + sCardID + "' AND card_type = 3";
                }
                else  // if (mszFlag.ToUpper() == "USER_CARD")
                {
                    sSql = "SELECT * FROM base_ucard WHERE user_card = '" + sCardID + "'";
                }

                int iRst = MyStart.oMyDb.ReadData(sSql, "TableA", ref odt, ref sErrMsg);
                if (iRst != 0)
                {
                    MessageBox.Show("后台查询卡余额失败( " + sErrMsg + " )", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    goto Eend;
                }

                if (odt.Tables[0].Rows.Count <= 0)
                {
                    if (mszFlag.ToUpper() == "FIRM_CARD")
                    {
                        MessageBox.Show("这是错误的商户结算卡,请更换。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else  // if (mszFlag.ToUpper() == "USER_CARD")
                    {
                        MessageBox.Show("没有此用户卡的信息,请更换。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    goto Eend;
                }

                if (mszFlag.ToUpper() == "FIRM_CARD")
                {
                    sUserName = odt.Tables[0].Rows[0]["STORE_PERSON"].ToString().Trim();
                }
                else  // if (mszFlag.ToUpper() == "USER_CARD")
                {
                    sUserName = odt.Tables[0].Rows[0]["user_name"].ToString().Trim();
                }

                //银石后台
                objHttp = new EbHttpClass();
                string szErr       = "";
                int    iValue      = 0;
                int    iTrade      = 0;
                int    CardBalance = 0;
                float  fi          = 0.00f;

                if (mszFlag.ToUpper() == "FIRM_CARD")
                {
                    iTrade = 1;
                }
                else
                {
                    iTrade = 0;
                }

                bool bRst = objHttp.QryCard(sCardID, ref iValue, ref iTrade, ref szErr);
                if (!bRst)
                {
                    MessageBox.Show("后台查询卡余额失败( " + szErr + " )", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //return;
                }
                else
                {
                    if (mszFlag.ToUpper() == "FIRM_CARD")
                    {
                        fi = iValue;
                        fi = fi / 100;
                        textBox_FinishBalance.Text = fi.ToString("0.00");

                        if (iTrade > 0)
                        {
                            fi = iTrade;
                        }
                        else
                        {
                            fi = 0;
                        }
                        fi = fi / 100;
                        textBox_UnFinishBalance.Text = fi.ToString("0.00");

                        CardBalance             = iValue + iTrade;
                        fi                      = CardBalance;
                        fi                      = fi / 100;
                        textBox_OldBalance.Text = fi.ToString("0.00");
                        MyFunc.WriteToDbLog("卖方资金-余额查询", " ", "MSG", MyStart.giUserID);
                    }
                    else
                    {
                        textBox_FinishBalance.Text   = "";
                        textBox_UnFinishBalance.Text = "";
                        fi = iValue;
                        fi = fi / 100;
                        textBox_OldBalance.Text = fi.ToString("0.00");
                        MyFunc.WriteToDbLog("买方资金-余额查询", " ", "MSG", MyStart.giUserID);
                    }

                    if (checkBox1.Checked)
                    {
                        int i = 0;
                        // 打印票据
                        MyTools.sPrintTopic = "余额查询票据";
                        MyTools.sPrintID    = "";

                        MyTools.oPrintData      = new string[10];
                        MyTools.oPrintData[i++] = "卡片号码:" + textBox_CardID.Text;
                        MyTools.oPrintData[i++] = "持卡人名:" + sUserName;
                        MyTools.oPrintData[i++] = "--------------------------------------";
                        MyTools.oPrintData[i++] = "可取金额:" + textBox_FinishBalance.Text;
                        MyTools.oPrintData[i++] = "未结余额:" + textBox_UnFinishBalance.Text;
                        MyTools.oPrintData[i++] = "合计余额:" + textBox_OldBalance.Text;

                        MyTools.iPrintData = i;
                        MyTools.PrintTicket();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("查询失败 = " + ex.Message, "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

Eend:
            if (odt != null)
            {
                odt.Clear();
            }
            MyStart.oMyDb.Close();

            button_CheckCard.Focus();
        }
Example #7
0
        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;
        }
Example #8
0
        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();
        }