コード例 #1
0
        private void button_MinusValue_Click(object sender, EventArgs e)
        {
            float fValue   = 0.00f;
            float fBalance = 0;

            textBox_Value.Text  = textBox_Value.Text.Trim();
            textBox_Value2.Text = textBox_Value2.Text.Trim();
            try
            {
                fValue = float.Parse(textBox_Value.Text.Trim());
            }
            catch
            {
                MessageBox.Show("取款金额错误!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBox_Value.Focus();
                return;
            }

            if (textBox_Value.Text != textBox_Value2.Text)
            {
                MessageBox.Show("两次输入的取款金额不相等!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBox_Value.Focus();
                return;
            }

            if (fValue == 0)
            {
                MessageBox.Show("取款金额不能为0!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBox_Value.Focus();
                return;
            }

            //// 检查密码
            //if ( CardPwd != textBox_Pwd.Text.Trim())
            //{
            //    MessageBox.Show("取款密码错误!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    textBox_Pwd.Focus();
            //    return;
            //}

            // 检查余额是否足够
            if (mszFlag.ToUpper() == "FIRM_CARD")
            {
                fBalance = float.Parse(textBox_FinishBalance.Text.Trim());
            }
            else
            {
                fBalance = float.Parse(textBox_OldBalance.Text.Trim());
            }

            if (fValue > fBalance)
            {
                MessageBox.Show("取款金额不足够!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBox_Value.Focus();
                return;
            }

            // 取得TradeID
            if (!myRdr.ComOpen(frm_Main.sRdPort))
            {
                MessageBox.Show("打开串口失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                myRdr.ComClose();
                return;
            }

            int iReaderTradeID = 0;

            if (!myRdr.GetTradeID(ref iReaderTradeID))
            {
                MessageBox.Show("交易失败:不能从读写器获取交易流水。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                myRdr.ComClose();
                return;
            }
            myRdr.ComClose();

            //银石后台
            objHttp = new EbHttpClass();

            fValue *= -1;
            string szSysID = iReaderTradeID.ToString();
            string szErr   = "";
            bool   bRst    = false;

            if (mszFlag.ToUpper() == "USER_CARD")
            {
                bRst = objHttp.OperUserMoney("MinusVal", textBox_UserCardID.Text, fValue, szSysID, textBox_Pwd.Text.Trim(), ref szErr);
            }
            else
            {
                bRst = objHttp.OperFirmMoney(sStoreCard.Substring(1), textBox_UserCardID.Text, fValue, szSysID, textBox_Pwd.Text.Trim(), ref szErr);
            }

            if (bRst)
            {
                string sSql  = "";
                string szInf = "";
                float  f     = 0;
                int    i;

                // 余额显示
                fValue *= -1;
                f       = fBalance - fValue;
                textBox_NewBalance.Text = f.ToString("0.00");

                // 写入数据库
                if (mszFlag.ToUpper() == "USER_CARD")
                {
                    // 写入数据库
                    sSql = "INSERT INTO rec_user (Card_No, Oper_Time, Oper_Type,Oper_SubType, Before_Val, Chg_Val, After_Val, Oper_ID, Tmn_ID, Sys_ID) VALUE(" +
                           "'" + textBox_UserCardID.Text + "'," +
                           "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                           "'CASH','" + comboBox_Type.Text.Trim() + "',";
                    f     = float.Parse(textBox_OldBalance.Text);
                    f    *= 100;
                    i     = (int)(f + 0.5);
                    sSql += i.ToString() + ",";

                    f     = float.Parse(textBox_Value.Text);
                    f    *= 100;
                    i     = (int)(f + 0.5);
                    sSql += i.ToString() + ",";

                    f     = float.Parse(textBox_NewBalance.Text);
                    f    *= 100;
                    i     = (int)(f + 0.5);
                    sSql += i.ToString() + "," +
                            MyStart.giUserID + "," +
                            "'" + frm_Main.POS_ID + "'," +
                            iReaderTradeID.ToString() + ")";
                }
                else
                {
                    sSql = "INSERT INTO rec_firm (Card_No, Rmrk, STORE_ID, Oper_Time, Oper_Type,Oper_SubType, Before_Val, Chg_Val, After_Val, Oper_ID, Tmn_ID, Sys_ID) VALUE(" +
                           "'" + textBox_UserCardID.Text + "'," +
                           "'" + sStoreCard + "'," +
                           sStoreID + "," +
                           "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                           "'CASH','" + comboBox_Type.Text.Trim() + "',";

                    f     = float.Parse(textBox_OldBalance.Text);
                    f    *= 100;
                    i     = (int)(f + 0.5);
                    sSql += i.ToString() + ",";

                    f     = float.Parse(textBox_Value.Text);
                    f    *= 100;
                    i     = (int)(f + 0.5);
                    sSql += i.ToString() + ",";

                    f     = float.Parse(textBox_NewBalance.Text);
                    f    *= 100;
                    i     = (int)(f + 0.5);
                    sSql += i.ToString() + "," +
                            MyStart.giUserID + "," +
                            "'" + frm_Main.POS_ID + "'," + szSysID.ToString() + ")";
                }

                int iRst = MyStart.oMyDb.WriteData(sSql, ref szInf);
                if (iRst <= 0)
                {
                    textBox_Result.Text = "取款成功! 但写数据库失败(" + szInf + ")";
                }
                else
                {
                    textBox_Result.Text = "取款成功!";
                }
                // log
                if (mszFlag.ToUpper() == "USER_CARD")
                {
                    MyFunc.WriteToDbLog("买方资金-退款", "买方卡号=" + textBox_UserCardID.Text + ",取款=" + textBox_Value.Text + "元,时间=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "MSG", MyStart.giUserID);
                }
                else
                {
                    MyFunc.WriteToDbLog("卖方资金-提款", "卖方卡号=" + textBox_UserCardID.Text + ",取款=" + textBox_Value.Text + "元,时间=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "MSG", MyStart.giUserID);
                }

                MyStart.oMyDb.Close();

                //打印票据
                button_Print_Click(sender, e);
                button_Print_Click(sender, e);
            }
            else
            {
                textBox_Result.Text     = "取款失败 = " + szErr;
                textBox_NewBalance.Text = textBox_FinishBalance.Text;
            }

            groupBox_ThirdStep.Enabled  = false;
            groupBox_FourthStep.Visible = true;
            groupBox_FourthStep.Enabled = true;
            button_Retry.Focus();
        }
コード例 #2
0
ファイル: frm_Card_AddVal.cs プロジェクト: wl2019/EB_for_YTB
        private void button_AddValue_Click(object sender, EventArgs e)
        {
            float fi = 0;

            textBox_Value.Text  = textBox_Value.Text.Trim();
            textBox_Value2.Text = textBox_Value2.Text.Trim();
            if (textBox_Value.Text == "")
            {
                MessageBox.Show("请输入充值金额。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (textBox_Value.Text != textBox_Value2.Text)
            {
                MessageBox.Show("两次输入的充值金额不相等。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try
            {
                fi = float.Parse(textBox_Value.Text);
            }
            catch
            {
                MessageBox.Show("请输入正确的充值金额。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // 取得TradeID
            if (!myRdr.ComOpen(frm_Main.sRdPort))
            {
                MessageBox.Show("打开串口失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                myRdr.ComClose();
                return;
            }

            int iReaderTradeID = 0;

            if (!myRdr.GetTradeID(ref iReaderTradeID))
            {
                MessageBox.Show("交易失败:不能从读写器获取交易流水。", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                myRdr.ComClose();
                return;
            }
            myRdr.ComClose();

            string   szSysID    = iReaderTradeID.ToString();
            string   sErrMsg    = "";
            string   sSql       = "";
            DateTime dTradeTime = DateTime.Now;

            bool bRst = objHttp.OperUserMoney("AddVal", textBox_CardID.Text, fi, szSysID, "", ref sErrMsg);

            if (bRst)
            {
                fi += float.Parse(textBox_OldBalance.Text);
                textBox_NewBalance.Text = fi.ToString("0.00");

                // 写入数据库
                sSql = "INSERT INTO rec_user (Card_No, Oper_Time, Oper_Type,Oper_SubType, Before_Val, Chg_Val, After_Val, Oper_ID, Tmn_ID, Sys_ID) VALUE(" +
                       "'" + textBox_CardID.Text + "'," +
                       "'" + dTradeTime.ToString("yyyy-MM-dd HH:mm:ss") + "'," +
                       "'ADD','" + comboBox_Type.Text.Trim() + "',";
                float f = float.Parse(textBox_OldBalance.Text);
                f *= 100;
                int i = (int)(f + 0.5);
                sSql += i.ToString() + ",";

                f     = float.Parse(textBox_Value.Text);
                f    *= 100;
                i     = (int)(f + 0.5);
                sSql += i.ToString() + ",";

                f     = fi;
                f    *= 100;
                i     = (int)(f + 0.5);
                sSql += i.ToString() + "," +
                        MyStart.giUserID + "," +
                        "'" + frm_Main.POS_ID + "'," +
                        iReaderTradeID.ToString() + ")";

                int iRst = MyStart.oMyDb.WriteData(sSql, ref sErrMsg);
                if (iRst <= 0)
                {
                    textBox_Result.Text = "充值成功!但写数据库失败( " + sErrMsg + " )";
                }
                else
                {
                    textBox_Result.Text = "充值成功!";
                }

                // log
                MyFunc.WriteToDbLog("买方资金-充值", "买方卡号=" + textBox_CardID.Text + ",充值=" + textBox_Value.Text + "元,类型=" + comboBox_Type.Text.Trim() + ",时间 =" + dTradeTime.ToString("yyyy-MM-dd HH:mm:ss"), "MSG", MyStart.giUserID);

                //打印票据
                button_Print_Click(sender, e);
                button_Print_Click(sender, e);
            }
            else
            {
                textBox_Result.Text     = "充值失败 = szErr";
                textBox_NewBalance.Text = textBox_OldBalance.Text;
            }
            MyStart.oMyDb.Close();

            groupBox_SecondStep.Enabled = false;
            groupBox_ThirdStep.Visible  = true;

            button_Retry.Focus();
        }