Qt银行管理系统——初始界面功能函数_其他

2.功能函数

(2)其他功能函数
另外所有功能函数的过程都大差不差,所以我总结其中一个功能函数,那就选查询余额,因为查询余额稍微复杂一些些,毕竟要返回余额到客户端

客户端新建一个类balance来存放

balance.h

#ifndef BALANCE_H
#define BALANCE_H

#include <QWidget>
#include <QDialog>

namespace Ui {
class Balance ;
}

class Balance : public QDialog
{
Q_OBJECT

public :
explicit Balance ( QWidget *parent = 0 );
~ Balance ();

private slots :
void on_ExitButton_clicked ();

void on_checkButton_clicked ();     //确认查询按钮

private :
Ui :: Balance * ui ;
};

#endif // BALANCE_H


balance.cpp

#include "balance.h"
#include "ui_balance.h"
#include "share.h"        //存方全局变量的类,这里要用到已经连接上的客户端
extern Cilent *MyClient;
extern QString username;
extern QString reciveData;

Balance::Balance(QWidget *parent) :
QDialog(parent),
ui(new Ui::Balance)
{
ui->setupUi(this);

}

Balance::~Balance()
{
delete ui;
}

/******************构造函数用不改,只添加两个按钮的槽函数就行*******************/
void Balance::on_ExitButton_clicked()    //返回
{
this->close();
}

void Balance::on_checkButton_clicked()        //确认查询,向服务器发送数据
{
QString name =ui->nameEdit->text();
QString str = QString("3,%1").arg(name);        //功能函数标志位为3,将要查询的客户的name封装并发送到服务器
MyClient-> TCPwrite(str);
}

//下面附这个的ui界面




服务器的处理
case 3:balanceChoice();break;//查询余额

.............................................

void MyServerWindow :: balanceChoice ()
{
section1 = Bag . section ( "," , 1 , 1 );
QString TempStr = QString ( "用户名%1" ). arg ( section1 );
qDebug ()<< TempStr . toUtf8 (). data ();
QString sendStr = mysql -> balanceChoice ( section1 );        //通过mysql类的查询函数,传回客户余额。
QString sendbuf = QString ( "余额还剩%1元,0" ). arg ( sendStr );        //发回给客户端的信息,后面的标志位无用,为了严谨,补个数字
qDebug ()<< "sendbuf " << sendbuf ;
ServerWrite ( sendbuf );
}

...........................................................

QString Banksql::balanceChoice(QString username)
{
QString str = QString("select * from customer where name='%1'").arg(username);
QSqlQuery query;
query.exec(str);
while(query.next())
{
qDebug()<<"余额"<<query.value(4).toString();        //value函数就是返回查询到的信息,value(0)表示第1列的数据,往往是ID(我第一列是ID,我第四列才是Banlance
//附上一张数据库的图


return query.value(4).toString();
}
return "choice error";
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值