예제 #1
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();
        }
예제 #2
0
        private void button_Save_Click(object sender, EventArgs e)
        {
            if (DialogResult.No == MessageBox.Show("请确认要保存该工作人员信息", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
            {
                MessageBox.Show("取消当前保存操作", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string szNewPwd = MyTools.OpenString_To_HideString((textBox_pwd.Text + "        ").Substring(0, 8), MyStart.gszPwdKey);

            string szSql;
            string szTitle;
            string szErr = "";
            int    iRst;

            string[] szItem = comboBox_Cert.Text.Split(',');
            try
            {
                if (textBox_login.Enabled)//add
                {
                    szTitle = "工作人员基本信息-新增";
                    szSql   = "select * from sys_users where USER_LOGIN='******'";
                    DataSet ds = new DataSet();
                    iRst = MyStart.oMyDb.ReadData(szSql, "tableA", ref ds, ref szErr);
                    if (iRst < 0)
                    {
                        MessageBox.Show("查询信息出错(错误原因:" + szErr + ")", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        MyIniFile.WriteLog(szTitle, "SQL=" + szSql + ",Err=" + szErr);
                        goto Eend;
                    }
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        MessageBox.Show("登录帐号不能重复,请重新输入", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        MyIniFile.WriteLog(szTitle, "SQL=" + szSql + ",Err=登录帐号不能重复,请重新输入");
                        textBox_login.SelectAll();
                        textBox_login.Focus();
                        goto Eend;
                    }

                    szSql = "INSERT INTO sys_users(USER_LOGIN,USER_PWD,USER_TYPE,USER_NAME,USER_SEX,USER_BIRTH,CERT_TYPE,CERT_ID,"
                            + "USER_ADDR,USER_DPT,USER_POS,USER_TEL,USER_MOBILE,CITY,RMRK,USER_STAT,ADD_DT,USER_APP) VALUES "
                            + "('" + textBox_login.Text.Trim() + "','" + szNewPwd + "',2,'"
                            + textBox_Name.Text.Trim() + "','" + comboBox_Sex.Text.Trim() + "','" + dateTimePicker_birth.Value + "',"
                            + Convert.ToInt16(szItem[0]) + ",'" + textBox_Cert.Text.Trim() + "','" + textBox_Addr.Text.Trim() + "','"
                            + textBox_Dpt.Text.Trim() + "','" + textBox_Position.Text.Trim() + "','" + textBox_Tel.Text.Trim() + "','"
                            + textBox_Cell.Text.Trim() + "','ZHONGSHAN','" + textBox_Desc.Text.Trim() + "','USED',curtime(),'000000000000000000000000000000001')";
                }
                else//edit
                {
                    szTitle = "工作人员基本信息-修改";
                    szSql   = "UPDATE sys_users SET USER_PWD = '" + szNewPwd
                              + "',USER_SEX = '" + comboBox_Sex.Text.Trim()
                              + "',USER_BIRTH = '" + dateTimePicker_birth.Value
                              + "',CERT_TYPE = " + Convert.ToInt16(szItem[0])
                              + ",CERT_ID = '" + textBox_Cert.Text.Trim()
                              + "',USER_ADDR = '" + textBox_Addr.Text.Trim()
                              + "',USER_DPT = '" + textBox_Dpt.Text.Trim()
                              + "',USER_POS = '" + textBox_Position.Text.Trim()
                              + "',USER_TEL = '" + textBox_Tel.Text.Trim()
                              + "',USER_MOBILE = '" + textBox_Cell.Text.Trim()
                              + "',RMRK = '" + textBox_Desc.Text.Trim()
                              + "' WHERE USER_ID=" + textBox_Code.Text.Trim();
                }
                iRst = MyStart.oMyDb.WriteData(szSql, ref szErr);
                if (iRst < 1)
                {
                    MessageBox.Show("保存出错(错误原因:" + szErr + ")", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MyIniFile.WriteLog(szTitle, "SQL=" + szSql + ",Err=" + szErr);
                }
                else
                {
                    szSql = "编号" + mszCode + "-姓名" + mszName;
                    MyFunc.WriteToDbLog(szTitle, szSql, "MSG", MyStart.giUserID);

                    MessageBox.Show("保存成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    GridDataRefresh();
                    //dataGridView1.Refresh();
                    MyIniFile.WriteLog(szTitle, "SQL=" + szSql + ",OK");
                }
                groupBoxInf.Enabled  = false;
                groupBoxList.Enabled = true;

                textBox_Code.Text = mszCode;
                textBox_Name.Text = mszName;
                textBox_Desc.Text = mszInf;
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存失败( " + ex.Message + " )", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
Eend:
            MyStart.oMyDb.Close();
        }