关于微信账单分析报表程序


                                                  关于微信账单分析报表程序
          摘要:学习了一个月左右的Qt,想实际编写一个小程序,偶然产生一个想法,根据记账APP,可以分析各类消费数据,但是微信账单不存在分析类功能,所以编写这样一个程序,套用了网上的一些模板代码,以及Qt自带典例,进行修改,本程序仍存在一些小问题,没有想到解决办法,待日后更深刻理解后,重新拾起再行修改。
          创作思路:
        1.编写界面框架:添加注册、登陆、忘记密码、退出等基础模块
        2.编写数据库模型框架:文档信息、注册人员信息表、所导入微信账单数据、以及数据修改查找功能
        3.加载数据图表功能:根据所导入数据,进行简单运算,绘制成图表,饼状图、以及柱形图

在加载数据的时候,通过读取文本文件,提取所需信息,从而创建表,插入数据以及对数据的处理

 

 

                                                                           主界面框架界面


      

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
//主界面
#include <QMainWindow>
#include <QCloseEvent>
#include <QSqlQuery>
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
     static MainWindow* getIntance();
   // explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
     QString name;//注册者姓名
     QString passward;注册者密码
     QString identify;注册者编号
     QSqlQuery *query;

  //   void closeEvent(QCloseEvent *event);

private slots:
    void on_pushButton_clicked();//注册按键

    void on_pushButton_2_clicked();//登陆按键

    void on_pushButton_3_clicked();//忘记密码按键

    void on_pushButton_4_clicked();//退出按键

private:
    explicit MainWindow(QWidget *parent = 0);
    static MainWindow* MW;
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"register.h"
#include"logging.h"
#include <QInputDialog>
#include "mysql.h"
#include <QSqlQuery>
#include<QDebug>
#include "sqlmodel.h"

//主窗口
MainWindow * MainWindow::MW=NULL;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QFont labelFont,buttonFont;//设置字体
    labelFont.setFamily("华文行楷");
    ui->label->setFont(labelFont);
    buttonFont.setPointSize(18);
    buttonFont.setBold(true);
    ui->pushButton->setFont(buttonFont);
    ui->pushButton_2->setFont(buttonFont);
    ui->pushButton_3->setFont(buttonFont);
    ui->pushButton_4->setFont(buttonFont);
}


MainWindow *MainWindow::getIntance()
{
    if(MW == NULL)
    {
        MW = new MainWindow();
    }
    return MW;
}
MainWindow::~MainWindow()
{
    MySql* mysql = new MySql;
    mysql->deleteDatas();
    delete mysql;

    qDebug()<<"delete";
    delete ui;


}


void MainWindow::on_pushButton_clicked()//注册
{
      Register *reg = new Register(this);//弹出注册窗口
      reg->resize(390,300);
      reg->setWindowModality(Qt::WindowModal);
      reg->setWindowTitle("注册");
      reg->show();

}

void MainWindow::on_pushButton_2_clicked()//登陆
{
    logging *log = new logging(this);//弹出登陆窗口
    log->resize(300,190);
    log->setWindowModality(Qt::WindowModal);
    log->setWindowTitle("登陆");
    log->show();
}

void MainWindow::on_pushButton_3_clicked()//忘记密码
{
    bool ok;
    QInputDialog ecf;
    name = ecf.getText(this,tr("忘记密码"),tr("请输入用户名:"),QLineEdit::Normal,NULL,&ok);
    identify=ecf.getText(this,tr("忘记密码"),tr("请输入证件号:"),QLineEdit::Normal,NULL,&ok);
    MySql mysql;
    bool ret=mysql.forgetpassward(name,identify);
    if(!ret)
        {
            QMessageBox::information(this,tr("消息"),tr("消息不匹配!"),QMessageBox::Ok);
            return;
        }
    QMessageBox::information(this,tr("消息"),tr("请妥善保管您的密码:%1").arg(passward),QMessageBox::Ok);
    return;
}

void MainWindow::on_pushButton_4_clicked()//退出
{


   //这里是想退出的时候删除掉之前创建的表,却保证每一次都产生唯一的表,保证数据的唯一性
   //如果不删除表,会造成再登陆账户使用原来的表,新添加的数据会产生冲突
    MySql* mysql = new MySql;
    mysql->closedb();
    mysql->deleteDatas();
    mysql->deleteProcessTables(sqlmodel::minMonth,sqlmodel::maxMonth,sqlmodel::Months);
    delete mysql;

    query=new QSqlQuery;
    while(query->next()){
        static QString deletestrnumberall = QString("drop table MonthTradeTypeNumberall%1").arg(sqlmodel::Months);
        static QString deletestrAmountOfMoneyall = QString("drop table MonthTradeTypeAmountOfMoneyall%1").arg(sqlmodel::Months);
        static QString deletestrIncomeall = QString("drop table MonthIncomeall%1").arg(sqlmodel::Months);
        static QString deletestrSpendingall = QString("drop table MonthSpendingall%1").arg(sqlmodel::Months);

        query->exec(deletestrnumberall);
        query->exec(deletestrAmountOfMoneyall);
        query->exec(deletestrIncomeall);
        query->exec(deletestrSpendingall);
    }
    close();
}



                                                                                    注册界面

 

#ifndef REGISTER_H
#define REGISTER_H

#include <QMainWindow>
#include<QPushButton>
#include<QMessageBox>
#include"mysql.h"
#include <QProgressDialog>

//注册界面


namespace Ui {
class Register;
}

class Register : public QMainWindow
{
    Q_OBJECT

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

private slots:
    void on_yesOrNoBox_clicked(QAbstractButton *button);//只有一组按钮

private:
    Ui::Register *ui;
};

#endif // REGISTER_H
#include "register.h"
#include "ui_register.h"

Register::Register(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Register)
{
    ui->setupUi(this);
    ui->passwd->setEchoMode(QLineEdit::Password);//设置为密码模式不可见
    ui->passwd2->setEchoMode(QLineEdit::Password);
}

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


//检测是否为空,以及密码两行是否正确
void Register::on_yesOrNoBox_clicked(QAbstractButton *button)//注册
{
    if(ui->yesOrNoBox->button(QDialogButtonBox::Ok) == button)
    {
        if((ui->name->text() == "") || (ui->ID->text() == "") || (ui->passwd->text() == "") || (ui->passwd2->text() == ""))
        {
            QMessageBox::information(this, tr("警告"), tr("输入不能为空!!"), QMessageBox::Ok);
            return;
        }
        if(ui->passwd->text() != ui->passwd2->text())
        {
            QMessageBox::information(this, tr("警告"), tr("输入密码错误!!"), QMessageBox::Ok);
            return;
        }

        QString name = ui->name->text();
        QString ids = ui->ID->text();
        int id = ids.toInt();
        QString teacher = ui->passwd->text();

        QProgressDialog dialog(tr("正在注册"),tr("取消"), 0, 3000, this);
        dialog.setWindowTitle(tr("进度"));
        dialog.setWindowModality(Qt::WindowModal);
        dialog.show();
        for(int k = 0; k < 3000; k++)
        {
            dialog.setValue(k);
            QCoreApplication::processEvents();
            if(dialog.wasCanceled())
            {
                break;
            }
        }
        dialog.setValue(3000);



//检查用户信息表中是否存在,如存在不能注册,不存在可以正常注册
//并会弹出提示框
        MySql* mysql = new MySql;
        bool ret = mysql->initcourses(id,name,teacher);
        if(ret == false)
        {
            QMessageBox::information(this, tr("消息"), tr("用户已被注册!"), QMessageBox::Ok);
            this->close();
            return;
        }
        QMessageBox::information(this, tr("消息"), tr("注册成功!"), QMessageBox::Ok);
        this->close();
    }
    else if(ui->yesOrNoBox->button(QDialogButtonBox::Cancel) == button)
    {
        this->close();
        QProgressDialog dialog(tr("正在返回主界面"),tr("取消"), 0, 3000, this);
        dialog.setWindowTitle(tr("进度"));
        dialog.setWindowModality(Qt::WindowModal);
        dialog.show();
        for(int k = 0; k < 3000; k++)
        {
            dialog.setValue(k);
            QCoreApplication::processEvents();
            if(dialog.wasCanceled())
            {
                break;
            }
        }
        dialog.setValue(3000);
    }
}


                                                 登陆界面

 

#ifndef LOGGING_H
#define LOGGING_H
#include <QMainWindow>
#include <QPushButton>
#include <QMessageBox>
#include <QProgressDialog>
#include "mysql.h"


//登陆界面


#include <QAbstractButton>
namespace Ui {
class logging;
}

class logging : public QMainWindow
{
    Q_OBJECT

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

private slots:
    void on_yesOrNoBox_clicked(QAbstractButton *button);


private:
    Ui::logging *ui;
};

#endif // LOGGING_H
#include "logging.h"
#include "ui_logging.h"
#include <QCompleter>
#include <QMessageBox>
#include"sqlmodel.h"
//登陆界面
logging::logging(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::logging)
{


//这里原本添加了一个自动补全功能,后来没有用上
    ui->setupUi(this);
    QStringList wordlist;
    wordlist<<"数学"<<"英语"<<"计算机";
    QCompleter *completer = new QCompleter(wordlist,this);
    completer->setCaseSensitivity(Qt::CaseInsensitive);
    ui->lineinput->setCompleter(completer);
    ui->passward->setEchoMode(QLineEdit::Password);  //密码方式显示文本
}

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


//如果账号密码相同则可以登陆弹出数据模型界面
//如不匹配则返回上一个窗口
void logging::on_yesOrNoBox_clicked(QAbstractButton *button)
{
    if(ui->yesOrNoBox->button(QDialogButtonBox::Ok)==button)
        {
            if((ui->lineinput->text()=="")||(ui->passward->text()==""))
                {
                    QMessageBox::information(this,tr("警告"),tr("输入不能为空!"),QMessageBox::Ok);
                    return;
                }
            QString name= ui->lineinput->text();
            QString password=ui->passward->text();

            QProgressDialog dialog(tr("正在登录"),tr("取消"),0,3000,this);
            dialog.setWindowTitle(tr("进度"));
            dialog.setWindowModality(Qt::WindowModal);
            dialog.show();
            for(int k=0;k<3000;k++)
                {
                    dialog.setValue(k);
                    QCoreApplication::processEvents();
                    if(dialog.wasCanceled())
                        {
                            break;
                        }
                }
            dialog.setValue(3000);

            MySql *mysql=new MySql;
            bool ret=mysql->loguser(name,password);
            if(!ret)
                {
                    QMessageBox::information(this,tr("消息"),tr("帐号密码不匹配!"),QMessageBox::Ok);
                    this->close();
                  //  Mparent->show();   //回到上一个窗口
                    return;
                }
            QMessageBox::information(this,tr("消息"),tr("登录成功!"),QMessageBox::Ok);
            this->close();
            sqlmodel *sql=new sqlmodel(this);

//            sql->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);

            sql->show();
            return;
           }
    else if(ui->yesOrNoBox->button(QDialogButtonBox::Cancel)==button)
        {
            this->close();
            QProgressDialog dialog(tr("正在返回主界面"),tr("取消"),0,3000,this);
            dialog.setWindowTitle(tr("进度"));
            dialog.setWindowModality(Qt::WindowModal);
            dialog.show();
            for(int k=0;k<3000;k++)
                {
                    dialog.setValue(k);
                    QCoreApplication::processEvents();
                    if(dialog.wasCanceled())
                        {
                            break;
                        }
                }
            dialog.setValue(3000);
        }
}




这里忘记密码和退出就不介绍了,代码再mainWindow里面

下面介绍数据库的使用

#ifndef MYSQL_H
#define MYSQL_H
#include<QSqlTableModel>
#include <QSql>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>
#include <QMessageBox>
#include "mainwindow.h"
class QSqlTableModel;
class MySql
{
public:
    MySql();
    void initsql();//配置数据库
    bool loguser(QString name,QString passward);//检验账号密码
    void createtable();            //建用户信息密码表
    void createnewtable();         //创建数据表微信账单所包含的信息
    bool forgetpassward(QString name,QString identify);//忘记密码处理
    void dataProcessingTable(int minMonth,int maxMonth,int Months);//删除所有数据表
    void theDataProcess(int minMonth,int maxMonth,int Months);//数据计算

//bool inituser(int id,QString name,QString teacher);
bool initcourses(int id,QString name,QString teacher);//添加注册信息
void initdatas(int id,QString TradingHours ,QString TradeType ,QString CounterParty,QString Goods ,
                       QString IncomeAndExpenses ,QString Sum ,QString MethodOfPayment ,
                       QString TheCurrentState ,QString TransactionNumber,
                       QString GoodsNumber ,QString Note );//添加微信账单所包含的信息
void deleteDatas();//清除数据表(微信账单的所有数据)
//void deleteProcessTable(int months);
void deleteProcessTables(int minMonth,int maxMonth,int Months );//清除所产生的分析数据
void closedb();//关闭数据库



private:
    QSqlQuery *query;
    QSqlTableModel *model;
    QSqlDatabase db;

};

#endif // MYSQL_H
#include "mysql.h"
//数据库
MySql::MySql()
{

}

void MySql::initsql()
{

//由于Qt自带数据库驱动支持QSQLITE,所以选择这个数据库,基本连接方式,翻书参考教程
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setHostName("127.0.0.1");//本地主机
    db.setUserName("root");
    db.setPassword("123456");
    db.setDatabaseName("Stu.db");//数据库名称”Stu“

//数据库打开,则控制台输出"Database connected successfully!"否则弹出警告窗口

    if(db.open())
    {
        qDebug()<<"Database connected successfully!";

        return;
    }
    else
    {
        QMessageBox::critical(0,"Cannot open database","Unable to establish a database connection.",QMessageBox::Cancel);
    }

}

bool MySql::loguser(QString name,QString passward)
{

//检测账号密码是否正确
//运用查找语句以及数据表的数据对比,有的地方需要格式转换如toInt(),toString()需要什么种类的数据
//自行筛选转换
    bool check = false;
    query=new QSqlQuery;
    query->exec("select * from courses");

    while(query->next()){
        qDebug()<<query->value(0).toInt()<<query->value(1).toString()<<query->value(2).toString();
        if((name==query->value(1).toString())&&(passward==query->value(2).toString()))
        {
                  check =true;
        }
    }
    if(check==true){
        return true;
    }
    else
        return false;
}

void MySql::createtable()
{

    QSqlQuery query;

     //创建表,这张表用来储存用户信息
     // 创建courses表
    query.exec("create table courses (id int primary key, "
                       "name varchar, teacher varchar)");



}

void MySql::createnewtable()
{
    QSqlQuery query;
    //创建数据表datas
    //这张表用来储存从微信账单中读出的每一条数据,
  bool ret =    query.exec("create table datas (id int primary key, "
                       "TradingHours varchar, TradeType varchar,CounterParty varchar,Goods varchar,"
               "IncomeAndExpenses varchar,Sum varchar,MethodOfPayment varchar,"
               "TheCurrentState varchar,TransactionNumber varchar,"
               "GoodsNumber varchar,Note varchar)");
  qDebug()<<ret<<"datas";

}

bool MySql::forgetpassward(QString name, QString identify)
{

//这里是密码找回功能,如忘记密码,提供账号以及编号可获取密码
    bool check = false;
    query=new QSqlQuery;
    query->exec("select * from courses");
    QString ids = identify;
    int id = ids.toInt();

    while(query->next()){
        qDebug()<<query->value(0).toInt()<<query->value(1).toString()<<query->value(2).toString();
        if((name==query->value(1).toString())||(id==query->value(0).toInt()))
        {
                  check =true;
                  MainWindow *MW=MainWindow::getIntance();
                  MW->passward=query->value(2).toString();
        }
    }
    if(check==true){
        return true;
    }
    else
        return false;
}

void MySql::dataProcessingTable(int minMonth, int maxMonth, int Months)//创建数据处理表
{
    QSqlQuery query;
//这里是创建数据处理表,每一份微信账单可能有1-4个月份,因此根据月份不同自动识别创建表
//有类型数据表,类型价格表,收入价格表,支出价格表
//创建表都是重复过程代码量有些长,看第一个case(1)就好了
    switch(Months){
    case (1):{
       static QString strnumber1 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                              "transfer int,other int,transferTheRefund int,"
                              "changeWithDraeal int,scanningQrCodeToPay int,"
                              "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(minMonth);
       static QString strAmountOfMoney1 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                              "transfer double,other double,transferTheRefund double,"
                              "changeWithDraeal double,scanningQrCodeToPay double,"
                              "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(minMonth);
       static QString strIncome1 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(minMonth);
       static QString strSpending1 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(minMonth);


    bool strn1 =    query.exec(strnumber1);
    bool stra1 =    query.exec(strAmountOfMoney1);
    bool stri1 =    query.exec(strIncome1);
    bool strs1 =    query.exec(strSpending1);
        qDebug()<<strn1<<stra1<<stri1<<strs1<<"成功创建四个处理数据表单";

    } break;
    case(2):{

        //总表
        static QString strnumberall = QString("create table MonthTradeTypeNumberall%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(Months);
        static QString strAmountOfMoneyall = QString("create table MonthTradeTypeAmountOfMoneyall%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(Months);
        static QString strIncomeall = QString("create table MonthIncomeall%1(id int primary key,IncomeNumber double)").arg(Months);
        static QString strSpendingall = QString("create table MonthSpendingall%1(id int primary key,IncomeNumber double)").arg(Months);




        //小月份
        static QString strnumber1 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(minMonth);
        static QString strAmountOfMoney1 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(minMonth);
        static QString strIncome1 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(minMonth);
        static QString strSpending1 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(minMonth);



        //大月份
        static QString strnumber2 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(maxMonth);
        static QString strAmountOfMoney2 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(maxMonth);
        static QString strIncome2 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(maxMonth);
        static QString strSpending2 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(maxMonth);

        query.exec(strnumberall);
        query.exec(strAmountOfMoneyall);
        query.exec(strIncomeall);
        query.exec(strSpendingall);




        query.exec(strnumber1);
        query.exec(strAmountOfMoney1);
        query.exec(strIncome1);
        query.exec(strSpending1);
        query.exec(strnumber2);
        query.exec(strAmountOfMoney2);
        query.exec(strIncome2);
        query.exec(strSpending2);

    }break;
    case(3):{

        //总表
        static QString strnumberall = QString("create table MonthTradeTypeNumberall%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(Months);
        static QString strAmountOfMoneyall = QString("create table MonthTradeTypeAmountOfMoneyall%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(Months);
        static QString strIncomeall = QString("create table MonthIncomeall%1(id int primary key,IncomeNumber double)").arg(Months);
        static QString strSpendingall = QString("create table MonthSpendingall%1(id int primary key,IncomeNumber double)").arg(Months);


        //小月份
        static QString strnumber1 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(minMonth);
        static QString strAmountOfMoney1 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(minMonth);
        static QString strIncome1 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(minMonth);
        static QString strSpending1 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(minMonth);



        //中月份
        static QString strnumber2 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(minMonth+1);
        static QString strAmountOfMoney2 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(minMonth+1);
        static QString strIncome2 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(minMonth+1);
        static QString strSpending2 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(minMonth+1);




        //大月份
        static QString strnumber3 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(maxMonth);
        static QString strAmountOfMoney3 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(maxMonth);
        static QString strIncome3 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(maxMonth);
        static QString strSpending3 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(maxMonth);

        query.exec(strnumberall);
        query.exec(strAmountOfMoneyall);
        query.exec(strIncomeall);
        query.exec(strSpendingall);


        query.exec(strnumber1);
        query.exec(strAmountOfMoney1);
        query.exec(strIncome1);
        query.exec(strSpending1);
        query.exec(strnumber2);
        query.exec(strAmountOfMoney2);
        query.exec(strIncome2);
        query.exec(strSpending2);
        query.exec(strnumber3);
        query.exec(strAmountOfMoney3);
        query.exec(strIncome3);
        query.exec(strSpending3);



    } break;
    case(4):{



        //总表
        static QString strnumberall = QString("create table MonthTradeTypeNumberall%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(Months);
        static QString strAmountOfMoneyall = QString("create table MonthTradeTypeAmountOfMoneyall%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(Months);
        static QString strIncomeall = QString("create table MonthIncomeall%1(id int primary key,IncomeNumber double)").arg(Months);
        static QString strSpendingall = QString("create table MonthSpendingall%1(id int primary key,IncomeNumber double)").arg(Months);


        //小1月
        static QString strnumber1 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(minMonth);
        static QString strAmountOfMoney1 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(minMonth);
        static QString strIncome1 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(minMonth);
        static QString strSpending1 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(minMonth);




        //小2月
        static QString strnumber2 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(minMonth+1);
        static QString strAmountOfMoney2 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(minMonth+1);
        static QString strIncome2 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(minMonth+1);
        static QString strSpending2 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(minMonth+1);




        //大3月
        static QString strnumber3 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(maxMonth-1);
        static QString strAmountOfMoney3 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(maxMonth-1);
        static QString strIncome3 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(maxMonth-1);
        static QString strSpending3 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(maxMonth-1);

        //大4月
        static QString strnumber4 = QString("create table MonthTradeTypeNumber%1(id int primary key,consumption int,"
                               "transfer int,other int,transferTheRefund int,"
                               "changeWithDraeal int,scanningQrCodeToPay int,"
                               "weChatLuckyMoney int,ChangeToPrepaidPhone int)").arg(maxMonth);
        static QString strAmountOfMoney4 = QString("create table MonthTradeTypeAmountOfMoney%1(id int primary key,consumption double,"
                               "transfer double,other double,transferTheRefund double,"
                               "changeWithDraeal double,scanningQrCodeToPay double,"
                               "weChatLuckyMoney double,ChangeToPrepaidPhone double)").arg(maxMonth);
        static QString strIncome4 = QString("create table MonthIncome%1(id int primary key,IncomeNumber double)").arg(maxMonth);
        static QString strSpending4 = QString("create table MonthSpending%1(id int primary key,IncomeNumber double)").arg(maxMonth);




        query.exec(strnumberall);
        query.exec(strAmountOfMoneyall);
        query.exec(strIncomeall);
        query.exec(strSpendingall);




        query.exec(strnumber1);
        query.exec(strAmountOfMoney1);
        query.exec(strIncome1);
        query.exec(strSpending1);
        query.exec(strnumber2);
        query.exec(strAmountOfMoney2);
        query.exec(strIncome2);
        query.exec(strSpending2);
        query.exec(strnumber3);
        query.exec(strAmountOfMoney3);
        query.exec(strIncome3);
        query.exec(strSpending3);
        query.exec(strnumber4);
        query.exec(strAmountOfMoney4);
        query.exec(strIncome4);
        query.exec(strSpending4);


    } break;

    }

}

void MySql::theDataProcess(int minMonth, int maxMonth, int Months)
{


//这里是对创建完的数据分析表进行运算添加数据,为后面的图表做数据基础准备
//这里只是运用了累加的方法处理数据,可以进行适当拓展,只要提供EXCEL表格公式
//是可以实现多功能运算
    query=new QSqlQuery;
    qDebug()<<"theDataProcess";


    if(Months==1){
        int c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0;
        int a1=1;
        double d1=0,d2=0,d3=0,d4=0,d5=0,d6=0,d7=0,d8=0;
        double e1=0,e2=0;
       qDebug()<<"1";
       query->exec("select * from datas");
       while(query->next()){




       if(query->value(5)=="收入"){
           e1+=query->value(6).toString().remove(0,1).toDouble();

       }else if (query->value(5)!="") {
           e2+=query->value(6).toString().remove(0,1).toDouble();
       }
       if(query->value(2).toString()=="商户消费")
       {
           c1++;//consumption

          d1+=query->value(6).toString().remove(0,1).toDouble();

       }else if (query->value(2).toString()=="转账") {

           c2++;//transfer

           d2+=query->value(6).toString().remove(0,1).toDouble();

       }else if (query->value(2).toString()=="转账-退款") {
\
           c3++;//transferTheRefund
           d3+=query->value(6).toString().remove(0,1).toDouble();
          // qDebug()<<d3;
       }else if (query->value(2).toString()=="零钱提现") {

           c4++;//changeWithDraeal
           d4+=query->value(6).toString().remove(0,1).toDouble();
         //  qDebug()<<d4;
       }else if (query->value(2).toString()=="扫二维码付款") {

           c5++;//scanningQrCodeToPay
           d5+=query->value(6).toString().remove(0,1).toDouble();
         //  qDebug()<<d5;
       }else if (query->value(2).toString()=="微信红包") {

           c6++;//weChatLuckyMoney
           d6+=query->value(6).toString().remove(0,1).toDouble();
          // qDebug()<<d6;
       }else if (query->value(2).toString()=="零钱充值") {

           c7++;//ChangeToPrepaidPhone
           d7+=query->value(6).toString().remove(0,1).toDouble();
         //  qDebug()<<d7;
       }else if(query->value(2).toString()!=""){
           c8++;//other
           d8+=query->value(6).toString().remove(0,1).toDouble();
         //  qDebug()<<d8;
             }
       }




       query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(a1)
                   .arg(c1).arg(c2).arg(c8).arg(c3).arg(c4).arg(c5).arg(c6).arg(c7));
       qDebug()<<QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(a1)
                 .arg(c1).arg(c2).arg(c8).arg(c3).arg(c4).arg(c5).arg(c6).arg(c7);
       qDebug()<<d1<<d2<<d3<<d4<<d5<<d6<<d7<<d8;

       query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(a1)
                   .arg(d1).arg(d2).arg(d8).arg(d3).arg(d4).arg(d5).arg(d6).arg(d7));
       qDebug()<<QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(a1)
                 .arg(d1).arg(d2).arg(d8).arg(d3).arg(d4).arg(d5).arg(d6).arg(d7);


       query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(minMonth).arg(a1)
                   .arg(e1));
       query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(minMonth).arg(a1)
                   .arg(e2));
       qDebug()<<QString("insert into MonthIncome%1 values('%2','%3')").arg(minMonth).arg(a1)
                 .arg(e1);
       qDebug()<<QString("insert into MonthSpending%1 values('%2','%3')").arg(minMonth).arg(a1)
                 .arg(e2);
       qDebug()<<"收入"<<e1<<"支出"<<e2;



    }

    if(Months==2){


        int c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0;//类型统计数目表
        int f1=0,f2=0,f3=0,f4=0,f5=0,f6=0,f7=0,f8=0;
        int all1=0,all2=0,all3=0,all4=0,all5=0,all6=0,all7=0,all8=0;

        int a1=1;
        double d1=0,d2=0,d3=0,d4=0,d5=0,d6=0,d7=0,d8=0;//类型统计钱数表
        double g1=0,g2=0,g3=0,g4=0,g5=0,g6=0,g7=0,g8=0;
        double alm1,alm2,alm3,alm4,alm5,alm6,alm7,alm8;

        double e1=0,e2=0;//收入总钱数e1,支出总钱数e2
        double h1=0,h2=0;
        double almm1=0,almm2=0;

        qDebug()<<"2";
        query->exec("select * from datas");
        while(query->next()){
            if(   qAbs(query->value(1).toString().mid(4,3).remove(QChar ('/')).toInt())==minMonth)
            {
                if(query->value(5)=="收入"){
                    e1+=query->value(6).toString().remove(0,1).toDouble();

                }else if (query->value(5)!="") {
                    e2+=query->value(6).toString().remove(0,1).toDouble();
                }
                if(query->value(2).toString()=="商户消费")
                {
                    c1++;//consumption
                //  qDebug()<<query->value(6).toString().remove(0,1).toDouble();
                   d1+=query->value(6).toString().remove(0,1).toDouble();
                //  qDebug()<<d1;
                }else if (query->value(2).toString()=="转账") {

                    c2++;//transfer
                    //qDebug()<<query->value(6).toString().remove(0,1).toDouble();
                    d2+=query->value(6).toString().remove(0,1).toDouble();
                    //qDebug()<<d2;
                }else if (query->value(2).toString()=="转账-退款") {
         \
                    c3++;//transferTheRefund
                    d3+=query->value(6).toString().remove(0,1).toDouble();
                   // qDebug()<<d3;
                }else if (query->value(2).toString()=="零钱提现") {

                    c4++;//changeWithDraeal
                    d4+=query->value(6).toString().remove(0,1).toDouble();
                  //  qDebug()<<d4;
                }else if (query->value(2).toString()=="扫二维码付款") {

                    c5++;//scanningQrCodeToPay
                    d5+=query->value(6).toString().remove(0,1).toDouble();
                  //  qDebug()<<d5;
                }else if (query->value(2).toString()=="微信红包") {

                    c6++;//weChatLuckyMoney
                    d6+=query->value(6).toString().remove(0,1).toDouble();
                   // qDebug()<<d6;
                }else if (query->value(2).toString()=="零钱充值") {

                    c7++;//ChangeToPrepaidPhone
                    d7+=query->value(6).toString().remove(0,1).toDouble();
                  //  qDebug()<<d7;
                }else if(query->value(2).toString()!=""){
                    c8++;//other
                    d8+=query->value(6).toString().remove(0,1).toDouble();
                  //  qDebug()<<d8;
                      }
                }




            else if(qAbs(query->value(1).toString().mid(4,3).remove(QChar ('/')).toInt())==maxMonth)
            {
            if(query->value(5)=="收入"){
                h1+=query->value(6).toString().remove(0,1).toDouble();

            }else if (query->value(5)!="") {
                h2+=query->value(6).toString().remove(0,1).toDouble();
            }
            if(query->value(2).toString()=="商户消费")
            {
                f1++;//consumption

               g1+=query->value(6).toString().remove(0,1).toDouble();

            }else if (query->value(2).toString()=="转账") {

                f2++;//transfer

                g2+=query->value(6).toString().remove(0,1).toDouble();
    
            }else if (query->value(2).toString()=="转账-退款") {
     \
                f3++;//transferTheRefund
                g3+=query->value(6).toString().remove(0,1).toDouble();
   
            }else if (query->value(2).toString()=="零钱提现") {

                f4++;//changeWithDraeal
                g4+=query->value(6).toString().remove(0,1).toDouble();
     
            }else if (query->value(2).toString()=="扫二维码付款") {

                f5++;//scanningQrCodeToPay
                g5+=query->value(6).toString().remove(0,1).toDouble();
         
            }else if (query->value(2).toString()=="微信红包") {

                f6++;//weChatLuckyMoney
                g6+=query->value(6).toString().remove(0,1).toDouble();
           
            }else if (query->value(2).toString()=="零钱充值") {

                f7++;//ChangeToPrepaidPhone
                g7+=query->value(6).toString().remove(0,1).toDouble();
        
            }else if(query->value(2).toString()!=""){
                f8++;//other
                g8+=query->value(6).toString().remove(0,1).toDouble();
           
                  }
            }

            }

        all1=c1+f1;
        all2=c2+f2;
        all3=c3+f3;
        all4=c4+f4;
        all5=c5+f5;
        all6=c6+f6;
        all7=c7+f7;
        all8=c8+f8;

        alm1=d1+g1;
        alm2=d2+g2;
        alm3=d3+g3;
        alm4=d4+g4;
        alm5=d5+g5;
        alm6=d6+g6;
        alm7=d7+g7;
        alm8=d8+g8;

        almm1=e1+h1;
        almm2=e2+h2;
       //小月份
        query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(a1)
                    .arg(c1).arg(c2).arg(c8).arg(c3).arg(c4).arg(c5).arg(c6).arg(c7));
        query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(a1)
                    .arg(d1).arg(d2).arg(d8).arg(d3).arg(d4).arg(d5).arg(d6).arg(d7));
        query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(minMonth).arg(a1)
                    .arg(e1));
        query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(minMonth).arg(a1)
                   .arg(e2));


        //大月份
       query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(maxMonth).arg(a1)
                                .arg(f1).arg(f2).arg(f8).arg(f3).arg(f4).arg(f5).arg(f6).arg(f7));
       query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(maxMonth).arg(a1)
                   .arg(alm1).arg(alm2).arg(alm8).arg(alm3).arg(alm4).arg(alm5).arg(alm6).arg(alm7));
       query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(maxMonth).arg(a1)
                   .arg(h1));
       query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(maxMonth).arg(a1)
                  .arg(h2));


       //总表
       query->exec(QString("insert into MonthTradeTypeNumberall%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(Months).arg(a1)
                                .arg(all1).arg(all2).arg(all8).arg(all3).arg(all4).arg(all5).arg(all6).arg(all7));
       query->exec(QString("insert into MonthTradeTypeAmountOfMoneyall%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(Months).arg(a1)
                   .arg(g1).arg(g2).arg(g8).arg(g3).arg(g4).arg(g5).arg(g6).arg(g7));
       query->exec(QString("insert into MonthIncomeall%1 values('%2','%3')").arg(Months).arg(a1)
                   .arg(almm1));
       query->exec(QString("insert into MonthSpendingall%1 values('%2','%3')").arg(Months).arg(a1)
                  .arg(almm2));



    }
    if(Months==3){

        int z1=1;

        int a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0,a8=0;//类型统计数目表
        int b1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0,b8=0;
        int c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0;
        int all1=0,all2=0,all3=0,all4=0,all5=0,all6=0,all7=0,all8=0;


        double f1=0,f2=0,f3=0,f4=0,f5=0,f6=0,f7=0,f8=0;//类型统计钱数表
        double g1=0,g2=0,g3=0,g4=0,g5=0,g6=0,g7=0,g8=0;
        double h1=0,h2=0,h3=0,h4=0,h5=0,h6=0,h7=0,h8=0;
        double alm1,alm2,alm3,alm4,alm5,alm6,alm7,alm8;


        double j1=0,j2=0;//收入总钱数e1,支出总钱数e2
        double k1=0,k2=0;
        double l1=0,l2=0;
        double almm1=0,almm2=0;

        qDebug()<<"3";
        query->exec("select * from datas");
        while(query->next()){
            if( qAbs(query->value(1).toString().mid(4,3).remove(QChar ('/')).toInt())==minMonth)
            {
                if(query->value(5)=="收入"){
                    j1+=query->value(6).toString().remove(0,1).toDouble();

                }else if (query->value(5)!="") {
                    j2+=query->value(6).toString().remove(0,1).toDouble();
                }
                if(query->value(2).toString()=="商户消费")
                {
                    a1++;//consumption
           
                   f1+=query->value(6).toString().remove(0,1).toDouble();
          
                }else if (query->value(2).toString()=="转账") {

                    a2++;//transfer
                
                    f2+=query->value(6).toString().remove(0,1).toDouble();
             
                }else if (query->value(2).toString()=="转账-退款") {
         \
                    a3++;//transferTheRefund
                    f3+=query->value(6).toString().remove(0,1).toDouble();
            
                }else if (query->value(2).toString()=="零钱提现") {

                    a4++;//changeWithDraeal
                    f4+=query->value(6).toString().remove(0,1).toDouble();
           
                }else if (query->value(2).toString()=="扫二维码付款") {

                    a5++;//scanningQrCodeToPay
                    f5+=query->value(6).toString().remove(0,1).toDouble();
              
                }else if (query->value(2).toString()=="微信红包") {

                    a6++;//weChatLuckyMoney
                    f6+=query->value(6).toString().remove(0,1).toDouble();
               
                }else if (query->value(2).toString()=="零钱充值") {

                    a7++;//ChangeToPrepaidPhone
                    f7+=query->value(6).toString().remove(0,1).toDouble();
               
                }else if(query->value(2).toString()!=""){
                    a8++;//other
                    f8+=query->value(6).toString().remove(0,1).toDouble();
            
                      }
                }




            else if(qAbs(query->value(1).toString().mid(4,3).remove(QChar ('/')).toInt())==(minMonth)+1)
            {
            if(query->value(5)=="收入"){
                k1+=query->value(6).toString().remove(0,1).toDouble();

            }else if (query->value(5)!="") {
                k2+=query->value(6).toString().remove(0,1).toDouble();
            }
            if(query->value(2).toString()=="商户消费")
            {
     
               g1+=query->value(6).toString().remove(0,1).toDouble();
        
            }else if (query->value(2).toString()=="转账") {

                b2++;//transfer
             
                g2+=query->value(6).toString().remove(0,1).toDouble();
              
            }else if (query->value(2).toString()=="转账-退款") {
     \
                b3++;//transferTheRefund
                g3+=query->value(6).toString().remove(0,1).toDouble();
              
            }else if (query->value(2).toString()=="零钱提现") {

                b4++;//changeWithDraeal
                g4+=query->value(6).toString().remove(0,1).toDouble();
           
            }else if (query->value(2).toString()=="扫二维码付款") {

                b5++;//scanningQrCodeToPay
                g5+=query->value(6).toString().remove(0,1).toDouble();
           
            }else if (query->value(2).toString()=="微信红包") {

                b6++;//weChatLuckyMoney
                g6+=query->value(6).toString().remove(0,1).toDouble();
          
            }else if (query->value(2).toString()=="零钱充值") {

                b7++;//ChangeToPrepaidPhone
                g7+=query->value(6).toString().remove(0,1).toDouble();
            
            }else if(query->value(2).toString()!=""){
                b8++;//other
                g8+=query->value(6).toString().remove(0,1).toDouble();
              
                  }
            }
            else if (qAbs(query->value(1).toString().mid(4,3).remove(QChar ('/')).toInt())==maxMonth) {

                if(query->value(5)=="收入"){
                    l1+=query->value(6).toString().remove(0,1).toDouble();

                }else if (query->value(5)!="") {
                    l2+=query->value(6).toString().remove(0,1).toDouble();
                }
                if(query->value(2).toString()=="商户消费")
                {
                    c1++;//consumption
      
                    h1+=query->value(6).toString().remove(0,1).toDouble();
          
                }else if (query->value(2).toString()=="转账") {

                    c2++;//transfer
        
                    h2+=query->value(6).toString().remove(0,1).toDouble();
         
                }else if (query->value(2).toString()=="转账-退款") {
         \
                    c3++;//transferTheRefund
                    h3+=query->value(6).toString().remove(0,1).toDouble();
          
                }else if (query->value(2).toString()=="零钱提现") {

                    c4++;//changeWithDraeal
                    h4+=query->value(6).toString().remove(0,1).toDouble();
             
                }else if (query->value(2).toString()=="扫二维码付款") {

                    c5++;//scanningQrCodeToPay
                    h5+=query->value(6).toString().remove(0,1).toDouble();
             
                }else if (query->value(2).toString()=="微信红包") {

                    c6++;//weChatLuckyMoney
                    h6+=query->value(6).toString().remove(0,1).toDouble();
           
                }else if (query->value(2).toString()=="零钱充值") {

                    c7++;//ChangeToPrepaidPhone
                    h7+=query->value(6).toString().remove(0,1).toDouble();
             
                }else if(query->value(2).toString()!=""){
                    c8++;//other
                    h8+=query->value(6).toString().remove(0,1).toDouble();
       
                      }




            }

            }

        all1=a1+b1+c1;
        all2=a2+b2+c2;
        all3=a3+b3+c3;
        all4=a4+b4+c4;
        all5=a5+b5+c5;
        all6=a6+b6+c6;
        all7=a7+b7+c7;
        all8=a8+b8+c8;

        alm1=f1+g1+h1;
        alm2=f2+g2+h2;
        alm3=f3+g3+h3;
        alm4=f4+g4+h4;
        alm5=f5+g5+h5;
        alm6=f6+g6+h6;
        alm7=f7+g7+h7;
        alm8=f8+g8+h8;

        almm1=j1+k1+l1;
        almm2=j2+k2+l2;



        //小月份
        query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(z1)
                    .arg(a1).arg(a2).arg(a8).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7));
        query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(z1)
                    .arg(f1).arg(f2).arg(f8).arg(f3).arg(f4).arg(f5).arg(f6).arg(f7));
        query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(minMonth).arg(z1)
                    .arg(j1));
        query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(minMonth).arg(z1)
                   .arg(j2));


        //中月份
       query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth+1).arg(z1)
                                .arg(b1).arg(b2).arg(b8).arg(b3).arg(b4).arg(b5).arg(b6).arg(b7));
       query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth+1).arg(z1)
                   .arg(g1).arg(g2).arg(g8).arg(g3).arg(g4).arg(g5).arg(g6).arg(g7));
       query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(minMonth+1).arg(z1)
                   .arg(k1));
       query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(minMonth+1).arg(z1)
                  .arg(k2));


       //大月份
       query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(maxMonth).arg(z1)
                                .arg(c1).arg(c2).arg(c8).arg(c3).arg(c4).arg(c5).arg(c6).arg(c7));
       query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(maxMonth).arg(z1)
                   .arg(h1).arg(h2).arg(h8).arg(h3).arg(h4).arg(h5).arg(h6).arg(h7));
       query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(maxMonth).arg(z1)
                   .arg(l1));
       query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(maxMonth).arg(z1)
                  .arg(l2));


       //总月份
       query->exec(QString("insert into MonthTradeTypeNumberall%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(Months).arg(z1)
                                .arg(c1).arg(c2).arg(c8).arg(c3).arg(c4).arg(c5).arg(c6).arg(c7));
       query->exec(QString("insert into MonthTradeTypeAmountOfMoneyall%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(Months).arg(z1)
                   .arg(h1).arg(h2).arg(h8).arg(h3).arg(h4).arg(h5).arg(h6).arg(h7));
       query->exec(QString("insert into MonthIncomeall%1 values('%2','%3')").arg(Months).arg(z1)
                   .arg(l1));
       query->exec(QString("insert into MonthSpendingall%1 values('%2','%3')").arg(Months).arg(z1)
                  .arg(l2));






    }
    if(Months==4){


        int z1=1;

        int a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0,a8=0;//类型统计数目表
        int b1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0,b8=0;
        int c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0;
        int d1=0,d2=0,d3=0,d4=0,d5=0,d6=0,d7=0,d8=0;
        int t1=0,t2=0,t3=0,t4=0,t5=0,t6=0,t7=0,t8=0;


        double f1=0,f2=0,f3=0,f4=0,f5=0,f6=0,f7=0,f8=0;//类型统计钱数表
        double g1=0,g2=0,g3=0,g4=0,g5=0,g6=0,g7=0,g8=0;
        double h1=0,h2=0,h3=0,h4=0,h5=0,h6=0,h7=0,h8=0;
        double i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0;
        double u1=0,u2=0,u3=0,u4=0,u5=0,u6=0,u7=0,u8=0;


        double j1=0,j2=0;//收入总钱数e1,支出总钱数e2
        double k1=0,k2=0;
        double l1=0,l2=0;
        double m1=0,m2=0;
        double v1=0,v2=0;

        qDebug()<<"4";
        query->exec("select * from datas");
        while(query->next()){

 
            if(qAbs(query->value(1).toString().mid(4,3).remove(QChar('/')).toInt())==minMonth)
            {
            
                if(query->value(5)=="收入"){
                    j1+=query->value(6).toString().remove(0,1).toDouble();

                }else if (query->value(5)!="") {
                    j2+=query->value(6).toString().remove(0,1).toDouble();
                }
                if(query->value(2).toString()=="商户消费")
                {
                    a1++;//consumption
   
                   f1+=query->value(6).toString().remove(0,1).toDouble();
            
                }else if (query->value(2).toString()=="转账") {

                    a2++;//transfer
       
                    f2+=query->value(6).toString().remove(0,1).toDouble();
           
                }else if (query->value(2).toString()=="转账-退款") {
         \
                    a3++;//transferTheRefund
                    f3+=query->value(6).toString().remove(0,1).toDouble();
     
                }else if (query->value(2).toString()=="零钱提现") {

                    a4++;//changeWithDraeal
                    f4+=query->value(6).toString().remove(0,1).toDouble();
               
                }else if (query->value(2).toString()=="扫二维码付款") {

                    a5++;//scanningQrCodeToPay
                    f5+=query->value(6).toString().remove(0,1).toDouble();
         
                }else if (query->value(2).toString()=="微信红包") {

                    a6++;//weChatLuckyMoney
                    f6+=query->value(6).toString().remove(0,1).toDouble();
       
                }else if (query->value(2).toString()=="零钱充值") {

                    a7++;//ChangeToPrepaidPhone
                    f7+=query->value(6).toString().remove(0,1).toDouble();
          
                }else if(query->value(2).toString()!=""){
                    a8++;//other
                    f8+=query->value(6).toString().remove(0,1).toDouble();
        
                      }
                }




            else if(qAbs(query->value(1).toString().mid(4,3).remove(QChar ('/')).toInt())==(minMonth)+1)
            {

     
            if(query->value(5)=="收入"){
                k1+=query->value(6).toString().remove(0,1).toDouble();

            }else if (query->value(5)!="") {
                k2+=query->value(6).toString().remove(0,1).toDouble();
            }
            if(query->value(2).toString()=="商户消费")
            {
                b1++;//consumption

               g1+=query->value(6).toString().remove(0,1).toDouble();
 
            }else if (query->value(2).toString()=="转账") {

                b2++;//transfer
  
                g2+=query->value(6).toString().remove(0,1).toDouble();

            }else if (query->value(2).toString()=="转账-退款") {
     \
                b3++;//transferTheRefund
                g3+=query->value(6).toString().remove(0,1).toDouble();
    
            }else if (query->value(2).toString()=="零钱提现") {

                b4++;//changeWithDraeal
                g4+=query->value(6).toString().remove(0,1).toDouble();
            
            }else if (query->value(2).toString()=="扫二维码付款") {

                b5++;//scanningQrCodeToPay
                g5+=query->value(6).toString().remove(0,1).toDouble();
          
            }else if (query->value(2).toString()=="微信红包") {

                b6++;//weChatLuckyMoney
                g6+=query->value(6).toString().remove(0,1).toDouble();
            
            }else if (query->value(2).toString()=="零钱充值") {

                b7++;//ChangeToPrepaidPhone
                g7+=query->value(6).toString().remove(0,1).toDouble();
            
            }else if(query->value(2).toString()!=""){
                b8++;//other
                g8+=query->value(6).toString().remove(0,1).toDouble();
         
                  }
            }
            else if (qAbs(query->value(1).toString().mid(4,3).remove(QChar ('/')).toInt())==(maxMonth-1)) {


           
                if(query->value(5)=="收入"){
                    l1+=query->value(6).toString().remove(0,1).toDouble();

                }else if (query->value(5)!="") {
                    l2+=query->value(6).toString().remove(0,1).toDouble();
                }
                if(query->value(2).toString()=="商户消费")
                {
                    c1++;//consumption
          
                    h1+=query->value(6).toString().remove(0,1).toDouble();
      
                }else if (query->value(2).toString()=="转账") {

                    c2++;//transfer
         
                    h2+=query->value(6).toString().remove(0,1).toDouble();
              
                }else if (query->value(2).toString()=="转账-退款") {
         \
                    c3++;//transferTheRefund
                    h3+=query->value(6).toString().remove(0,1).toDouble();
                 
                }else if (query->value(2).toString()=="零钱提现") {

                    c4++;//changeWithDraeal
                    h4+=query->value(6).toString().remove(0,1).toDouble();
             
                }else if (query->value(2).toString()=="扫二维码付款") {

                    c5++;//scanningQrCodeToPay
                    h5+=query->value(6).toString().remove(0,1).toDouble();
         
                }else if (query->value(2).toString()=="微信红包") {

                    c6++;//weChatLuckyMoney
                    h6+=query->value(6).toString().remove(0,1).toDouble();
            
                }else if (query->value(2).toString()=="零钱充值") {

                    c7++;//ChangeToPrepaidPhone
                    h7+=query->value(6).toString().remove(0,1).toDouble();
            
                }else if(query->value(2).toString()!=""){
                    c8++;//other
                    h8+=query->value(6).toString().remove(0,1).toDouble();
           
                      }




            }

        else if(qAbs(query->value(1).toString().mid(4,3).remove(QChar ('/')).toInt())==maxMonth){

                if(query->value(5)=="收入"){
                    m1+=query->value(6).toString().remove(0,1).toDouble();

                }else if (query->value(5)!="") {
                    m2+=query->value(6).toString().remove(0,1).toDouble();
                }
                if(query->value(2).toString()=="商户消费")
                {
                    d1++;//consumption
 
                    i1+=query->value(6).toString().remove(0,1).toDouble();
        
                }else if (query->value(2).toString()=="转账") {

                    d2++;//transfer
      
                    i2+=query->value(6).toString().remove(0,1).toDouble();
       
                }else if (query->value(2).toString()=="转账-退款") {
         \
                    d3++;//transferTheRefund
                    i3+=query->value(6).toString().remove(0,1).toDouble();
            
                }else if (query->value(2).toString()=="零钱提现") {

                    d4++;//changeWithDraeal
                    i4+=query->value(6).toString().remove(0,1).toDouble();
      
                }else if (query->value(2).toString()=="扫二维码付款") {

                    d5++;//scanningQrCodeToPay
                    i5+=query->value(6).toString().remove(0,1).toDouble();
         
                }else if (query->value(2).toString()=="微信红包") {

                    d6++;//weChatLuckyMoney
                    i6+=query->value(6).toString().remove(0,1).toDouble();
  
                }else if (query->value(2).toString()=="零钱充值") {

                    d7++;//ChangeToPrepaidPhone
                    i7+=query->value(6).toString().remove(0,1).toDouble();
       
                }else if(query->value(2).toString()!=""){
                    d8++;//other
                    i8+=query->value(6).toString().remove(0,1).toDouble();
            
                      }
        }
}



        t1=a1+b1+c1+d1;
        t2=a2+b2+c2+d2;
        t3=a3+b3+c3+d3;
        t4=a4+b4+c4+d4;
        t5=a5+b5+c5+d5;
        t6=a6+b6+c6+d6;
        t7=a7+b7+c7+d7;
        t8=a8+b8+c8+d8;

        u1=f1+g1+h1+i1;
        u2=f2+g2+h2+i2;
        u3=f3+g3+h3+i3;
        u4=f4+g4+h4+i4;
        u5=f5+g5+h5+i5;
        u6=f6+g6+h6+i6;
        u7=f7+g7+h7+i7;
        u8=f8+g8+h8+i8;

        v1=j1+k1+l1+m1;
        v2=j2+k2+l2+m2;
     //总月份

  qDebug()<<t1<<t2<<t3<<t4<<t5<<t6<<t7<<t8;
  qDebug()<<u1<<u2<<u3<<u4<<u5<<u6<<u7<<u8;
  qDebug()<<v1<<v2<<"总的钱数";
  qDebug()<<j1<<k1<<l1<<m1;
  qDebug()<<j1<<k2<<l2<<m2;
  qDebug()<<"各项钱数";




        //小月份
        query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(z1)
                    .arg(a1).arg(a2).arg(a8).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7));
        query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth).arg(z1)
                    .arg(f1).arg(f2).arg(f8).arg(f3).arg(f4).arg(f5).arg(f6).arg(f7));
        query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(minMonth).arg(z1)
                    .arg(j1));
        query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(minMonth).arg(z1)
                   .arg(j2));


        //中月份
       query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth+1).arg(z1)
                                .arg(b1).arg(b2).arg(b8).arg(b3).arg(b4).arg(b5).arg(b6).arg(b7));
       query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(minMonth+1).arg(z1)
                   .arg(g1).arg(g2).arg(g8).arg(g3).arg(g4).arg(g5).arg(g6).arg(g7));
       query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(minMonth+1).arg(z1)
                   .arg(k1));
       query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(minMonth+1).arg(z1)
                  .arg(k2));


       //大月份
       query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(maxMonth-1).arg(z1)
                                .arg(c1).arg(c2).arg(c8).arg(c3).arg(c4).arg(c5).arg(c6).arg(c7));
       query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(maxMonth-1).arg(z1)
                   .arg(h1).arg(h2).arg(h8).arg(h3).arg(h4).arg(h5).arg(h6).arg(h7));
       query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(maxMonth-1).arg(z1)
                   .arg(l1));
       query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(maxMonth-1).arg(z1)
                  .arg(l2));


       //最大月份
       query->exec(QString("insert into MonthTradeTypeNumber%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(maxMonth).arg(z1)
                                .arg(d1).arg(d2).arg(d8).arg(d3).arg(d4).arg(d5).arg(d6).arg(d7));
       query->exec(QString("insert into MonthTradeTypeAmountOfMoney%1 values('%2','%3','%4','%5','%6','%7','%8','%9','%10')").arg(maxMonth).arg(z1)
                   .arg(i1).arg(i2).arg(i8).arg(i3).arg(i4).arg(i5).arg(i6).arg(i7));
       query->exec(QString("insert into MonthIncome%1 values('%2','%3')").arg(maxMonth).arg(z1)
                   .arg(m1));
       query->exec(QString("insert into MonthSpending%1 values('%2','%3')").arg(maxMonth).arg(z1)
                  .arg(m2));

//zong
       query->exec(QString("insert into MonthTradeTypeNumberall4 values('1','%2','%3','%4','%5','%6','%7','%8','%9')")
                                .arg(t1).arg(t2).arg(t8).arg(t3).arg(t4).arg(t5).arg(t6).arg(t7));
       query->exec(QString("insert into MonthTradeTypeAmountOfMoneyall4 values('1','%2','%3','%4','%5','%6','%7','%8','%9')")
                   .arg(u1).arg(u2).arg(u8).arg(u3).arg(u4).arg(u5).arg(u6).arg(u7));
       query->exec(QString("insert into MonthIncomeall%1 values('%2','%3')").arg(Months).arg(z1)
                   .arg(v1));
       query->exec(QString("insert into MonthSpendingall%1 values('%2','%3')").arg(Months).arg(z1)
                  .arg(v2));




       query->exec(QString("select * from MonthTradeTypeAmountOfMoneyall%1").arg(Months));
       if(query->first()){

           qDebug()<<query->value(1).toDouble();
           qDebug()<<query->value(2).toDouble();
           qDebug()<<query->value(3).toDouble();
           qDebug()<<query->value(4).toDouble();
           qDebug()<<query->value(5).toDouble();
           qDebug()<<query->value(6).toDouble();
           qDebug()<<query->value(7).toDouble();
           qDebug()<<query->value(8).toDouble();


  }

       query->exec(QString("select * from MonthTradeTypeNumberall%1").arg(Months));
       if(query->first()){

           qDebug()<<query->value(1).toInt();
           qDebug()<<query->value(2).toInt();
           qDebug()<<query->value(3).toInt();
           qDebug()<<query->value(4).toInt();
           qDebug()<<query->value(5).toInt();
           qDebug()<<query->value(6).toInt();
           qDebug()<<query->value(7).toInt();
           qDebug()<<query->value(8).toInt();


  }






    }









}

bool MySql::initcourses(int id, QString name, QString teacher)
{

//添加用户信息数据
    query=new QSqlQuery;
    QString str=QString("insert into courses values('%1','%2','%3')").arg(id).arg(name).arg(teacher);
    bool ret=query->exec(str);
    return ret;
}

void MySql::initdatas(int id, QString TradingHours, QString TradeType, QString CounterParty, QString Goods, QString IncomeAndExpenses, QString Sum,
                 QString MethodOfPayment, QString TheCurrentState, QString TransactionNumber, QString GoodsNumber, QString Note)
{

//添加用户数据
    query=new QSqlQuery;
    QString str = QString("insert into datas values('%1','%2','%3','%4','%5','%6','%7','%8','%9','%10','%11','%12')").arg(id).arg(TradingHours).arg(TradeType).arg(CounterParty).arg(Goods).arg(IncomeAndExpenses).arg(Sum)
            .arg(MethodOfPayment).arg(TheCurrentState).arg(TransactionNumber).arg(GoodsNumber).arg(Note);

    query->exec(str);



}

void MySql::deleteDatas()
{


//这里是删除数据表
    query=new QSqlQuery;
    static QString str = QString("drop table datas");
    bool ti = query->exec(str);
    qDebug()<<str<<"deleteDatas"<<ti;
 bool str1 =   query->exec("drop table MonthTradeTypeNumber4");
 bool str2 =   query->exec("drop table MonthTradeTypeAmountOfMoney4");
  bool str3 =  query->exec("drop table MonthIncome4");
  bool str4 =  query->exec("drop table MonthSpending4");

  qDebug()<<str1<<str2<<str3<<str4;


}



void MySql::deleteProcessTables(int minMonth, int maxMonth, int Months)
{

//这里是删除产生的数据处理的表
    query=new QSqlQuery;
    qDebug()<<"deleteProcessTables"<<minMonth<<maxMonth<<Months;


    if(Months==1){
       static QString deletestrnumber1 = QString("drop table MonthTradeTypeNumber%1").arg(minMonth);
       static QString deletestrAmountOfMoney1 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(minMonth);
       static QString deletestrIncome1 = QString("drop table MonthIncome%1").arg(minMonth);
       static QString deletestrSpending1 = QString("drop table MonthSpending%1").arg(minMonth);

       static QString str = QString("drop table datas");



    bool strn1 =    query->exec(deletestrnumber1);
    bool stra1 =    query->exec(deletestrAmountOfMoney1);
    bool stri1 =    query->exec(deletestrIncome1);
    bool strs1 =    query->exec(deletestrSpending1);

    bool ti = query->exec(str);
    qDebug()<<strn1<<stra1<<stri1<<strs1<<"成功清除四个处理数据表单"<<ti;


    }
    if(Months==2){

        //总表
        static QString deletestrnumberall = QString("drop table MonthTradeTypeNumberall%1").arg(Months);
        static QString deletestrAmountOfMoneyall = QString("drop table MonthTradeTypeAmountOfMoneyall%1").arg(Months);
        static QString deletestrIncomeall = QString("drop table MonthIncomeall%1").arg(Months);
        static QString deletestrSpendingall = QString("drop table MonthSpendingall%1").arg(Months);




        //小月份
        static QString deletestrnumber1 = QString("drop table MonthTradeTypeNumber%1").arg(minMonth);
        static QString deletestrAmountOfMoney1 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(minMonth);
        static QString deletestrIncome1 = QString("drop table MonthIncome%1").arg(minMonth);
        static QString deletestrSpending1 = QString("drop table MonthSpending%1").arg(minMonth);



        //大月份
        static QString deletestrnumber2 = QString("drop table MonthTradeTypeNumber%1").arg(maxMonth);
        static QString deletestrAmountOfMoney2 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(maxMonth);
        static QString deletestrIncome2 = QString("drop table MonthIncome%1").arg(maxMonth);
        static QString deletestrSpending2 = QString("drop table MonthSpending%1").arg(maxMonth);

        query->exec(deletestrnumberall);
        query->exec(deletestrAmountOfMoneyall);
        query->exec(deletestrIncomeall);
        query->exec(deletestrSpendingall);




        query->exec(deletestrnumber1);
        query->exec(deletestrAmountOfMoney1);
        query->exec(deletestrIncome1);
        query->exec(deletestrSpending1);
        query->exec(deletestrnumber2);
        query->exec(deletestrAmountOfMoney2);
        query->exec(deletestrIncome2);
        query->exec(deletestrSpending2);

        static QString str = QString("drop table datas");

        bool ti = query->exec(str);

    }
   if(Months==3){

        //总表
        static QString deletestrnumberall = QString("drop table MonthTradeTypeNumberall%1").arg(Months);
        static QString deletestrAmountOfMoneyall = QString("drop table MonthTradeTypeAmountOfMoneyall%1").arg(Months);
        static QString deletestrIncomeall = QString("drop table MonthIncomeall%1").arg(Months);
        static QString deletestrSpendingall = QString("drop table MonthSpendingall%1").arg(Months);


        //小月份
        static QString deletestrnumber1 = QString("drop table MonthTradeTypeNumber%1").arg(minMonth);
        static QString deletestrAmountOfMoney1 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(minMonth);
        static QString deletestrIncome1 = QString("drop table MonthIncome%1").arg(minMonth);
        static QString deletestrSpending1 = QString("drop table MonthSpending%1").arg(minMonth);



        //中月份
        static QString deletestrnumber2 = QString("drop table MonthTradeTypeNumber%1").arg(minMonth+1);
        static QString deletestrAmountOfMoney2 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(minMonth+1);
        static QString deletestrIncome2 = QString("drop table MonthIncome%1").arg(minMonth+1);
        static QString deletestrSpending2 = QString("drop table MonthSpending%1").arg(minMonth+1);




        //大月份
        static QString deletestrnumber3 = QString("drop table MonthTradeTypeNumber%1").arg(maxMonth);
        static QString deletestrAmountOfMoney3 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(maxMonth);
        static QString deletestrIncome3 = QString("drop table MonthIncome%1").arg(maxMonth);
        static QString deletestrSpending3 = QString("drop table MonthSpending%1").arg(maxMonth);

        query->exec(deletestrnumberall);
        query->exec(deletestrAmountOfMoneyall);
        query->exec(deletestrIncomeall);
        query->exec(deletestrSpendingall);


        query->exec(deletestrnumber1);
        query->exec(deletestrAmountOfMoney1);
        query->exec(deletestrIncome1);
        query->exec(deletestrSpending1);
        query->exec(deletestrnumber2);
        query->exec(deletestrAmountOfMoney2);
        query->exec(deletestrIncome2);
        query->exec(deletestrSpending2);
        query->exec(deletestrnumber3);
        query->exec(deletestrAmountOfMoney3);
        query->exec(deletestrIncome3);
        query->exec(deletestrSpending3);


        static QString str = QString("drop table datas");

        bool ti = query->exec(str);



    }
    if(Months==4){

  qDebug()<<"case 4";

        //总表
        static QString deletestrnumberall = QString("drop table MonthTradeTypeNumberall%1").arg(Months);
        static QString deletestrAmountOfMoneyall = QString("drop table MonthTradeTypeAmountOfMoneyall%1").arg(Months);
        static QString deletestrIncomeall = QString("drop table MonthIncomeall%1").arg(Months);
        static QString deletestrSpendingall = QString("drop table MonthSpendingall%1").arg(Months);


        //小1月
        static QString deletestrnumber1 = QString("drop table MonthTradeTypeNumber%1").arg(minMonth);
        static QString deletestrAmountOfMoney1 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(minMonth);
        static QString deletestrIncome1 = QString("drop table MonthIncome%1").arg(minMonth);
        static QString deletestrSpending1 = QString("drop table MonthSpending%1").arg(minMonth);




        //小2月
        static QString deletestrnumber2 = QString("drop table MonthTradeTypeNumber%1").arg(minMonth+1);
        static QString deletestrAmountOfMoney2 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(minMonth+1);
        static QString deletestrIncome2 = QString("drop table MonthIncome%1").arg(minMonth+1);
        static QString deletestrSpending2 = QString("drop table MonthSpending%1").arg(minMonth+1);




        //大3月
        static QString deletestrnumber3 = QString("drop table MonthTradeTypeNumber%1").arg(maxMonth-1);
        static QString deletestrAmountOfMoney3 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(maxMonth-1);
        static QString deletestrIncome3 = QString("drop table MonthIncome%1").arg(maxMonth-1);
        static QString deletestrSpending3 = QString("drop table MonthSpending%1").arg(maxMonth-1);

        //大4月
        static QString deletestrnumber4 = QString("drop table MonthTradeTypeNumber%1").arg(maxMonth);
        static QString deletestrAmountOfMoney4 = QString("drop table MonthTradeTypeAmountOfMoney%1").arg(maxMonth);
        static QString deletestrIncome4 = QString("drop table MonthIncome%1").arg(maxMonth);
        static QString deletestrSpending4 = QString("drop table MonthSpending%1").arg(maxMonth);




     bool str1=   query->exec(deletestrnumberall);
     bool str2=   query->exec(deletestrAmountOfMoneyall);
     bool str3=   query->exec(deletestrIncomeall);
     bool str4=   query->exec(deletestrSpendingall);


qDebug()<<str1<<str2<<str3<<str4;

        query->exec(deletestrnumber1);
        query->exec(deletestrAmountOfMoney1);
        query->exec(deletestrIncome1);
        query->exec(deletestrSpending1);
        query->exec(deletestrnumber2);
        query->exec(deletestrAmountOfMoney2);
        query->exec(deletestrIncome2);
        query->exec(deletestrSpending2);
        query->exec(deletestrnumber3);
        query->exec(deletestrAmountOfMoney3);
        query->exec(deletestrIncome3);
        query->exec(deletestrSpending3);
        query->exec(deletestrnumber4);
        query->exec(deletestrAmountOfMoney4);
        query->exec(deletestrIncome4);
        query->exec(deletestrSpending4);


        static QString str = QString("drop table datas");

        bool ti = query->exec(str);



    }

    }




void MySql::closedb()
{

//数据库的关闭
    db.close();
}


 

数据库模型界面

 

数据库模型代码

这一块主要使用了书上的模块,修改查询Qt自带模块,大家可以翻书查阅,对于文件信息读取那,运用了QFile类读取文本文件,从读取的文本中自动分析月份,以及调用数据库,对数据的处理。


 

#ifndef SQLMODEL_H
#define SQLMODEL_H
#include <QSqlTableModel>
#include <QMainWindow>
#include <QMessageBox>
#include <QSqlError>
#include"mysql.h"
#include <QSqlQuery>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QStatusBar>
#include <QtCharts/QChartView>
#include "donutbreakdowncharts.h"
#include "barchart.h"


//数据库模型界面


class QSqlTableModel;
namespace Ui {
class sqlmodel;
}

class sqlmodel : public QMainWindow
{
    Q_OBJECT

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

   void closeEvent(QCloseEvent *event);

    static QString tempall;

//这里定义好静态变量月份起止,以及存在几个月份
    static int minMonth;
    static int maxMonth;
    static int Months;
    static  QString setTables;
private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void on_pushButton_3_clicked();

    void on_pushButton_4_clicked();

    void on_pushButton_5_clicked();

    void on_pushButton_6_clicked();

    void on_pushButton_7_clicked();



    void on_pushButton_8_clicked();

    void on_pushButton_11_clicked();

    void on_pushButton_9_clicked();

    void on_pushButton_12_clicked();

private:
    Ui::sqlmodel *ui;
    QSqlTableModel *model;
    QSqlTableModel *model1;
    QSqlTableModel *model2;
    QSqlTableModel *model3;

    barChart *bar;

    QSqlQuery *query;
    DonutBreakdownCharts *donutBreakdown;



};


#endif // SQLMODEL_H
#include "sqlmodel.h"
#include "ui_sqlmodel.h"
#include <QFileDialog>
#include <QDebug>
#include <QTextStream>
#include"mysql.h"
#include <QProgressDialog>
#include "themewidget.h"
#include "barchart.h"

//数据库模型界面
QString sqlmodel::tempall = "";
int sqlmodel::maxMonth=0;
int sqlmodel::minMonth=0;
int sqlmodel::Months=0;
QString sqlmodel::setTables = "";
sqlmodel::sqlmodel(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::sqlmodel)
{
    ui->setupUi(this);

//界面一 读取微信账单用户数据
    model = new QSqlTableModel(this);
    model->setTable("courses");
    model->select();
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    ui->tableView->setModel(model);

   setTables= QString("MonthTradeTypeNumber%1").arg(sqlmodel::minMonth);
    qDebug()<<setTables<<"2";


//界面二读取用户注册信息界面
   model1 = new QSqlTableModel(this);


    model1->setTable("datas");
    model1->select();
    ui->tableView_2->setModel(model1);
    ui->textEdit->setText(tempall);




}

sqlmodel::~sqlmodel()
{
    delete ui;
    qDebug()<<"sqlmodel";
    MySql* mysql = new MySql;
    mysql->deleteDatas();
    mysql->deleteProcessTables(sqlmodel::minMonth,sqlmodel::maxMonth,sqlmodel::Months);
    delete mysql;
}

void sqlmodel::closeEvent(QCloseEvent *event)
{

//窗口关闭函数,因为原来想通过关闭这个窗口,删除产生的数据表,为再次登陆做基础准备
//但是由于不明原因删除不掉数据表,从而会导致重新加载数据会产生冲突


    qDebug()<<"关闭函数";


    MySql* mysql = new MySql;
    mysql->deleteDatas();
    mysql->deleteProcessTables(sqlmodel::minMonth,sqlmodel::maxMonth,sqlmodel::Months);
    mysql->closedb();
    QFile::remove("Stu.db");
    delete mysql;
     event->accept();


}

void sqlmodel::on_pushButton_clicked()
{
    QString TradeType = ui->lineEdit->text();

    // 根据姓名进行筛选,一定要使用单引号
    model1->setFilter(QString("TradeType = '%1'").arg(TradeType));
    model1->select();
}

void sqlmodel::on_pushButton_2_clicked()
{
   // qDebug()<<setTables<<"3";
    model1->setTable("datas");
    model1->select();

}

void sqlmodel::on_pushButton_3_clicked()
{
    // 开始事务操作
    model1->database().transaction();
    if (model1->submitAll()) {
        if(model1->database().commit()) // 提交
            QMessageBox::information(this, tr("tableModel"),
                                     tr("数据修改成功!"));
    } else {
        model1->database().rollback(); // 回滚
        QMessageBox::warning(this, tr("tableModel"),
                             tr("数据库错误: %1").arg(model1->lastError().text()),
                             QMessageBox::Ok);
    }
}

void sqlmodel::on_pushButton_4_clicked()
{
      model1->revertAll();
}

void sqlmodel::on_pushButton_5_clicked()
{
    // 获得表的行数
    int rowNum = model->rowCount();
    int id = 10;

    // 添加一行
    model1->insertRow(rowNum);
    model1->setData(model1->index(rowNum, 0), id);
}

void sqlmodel::on_pushButton_6_clicked()
{
    // 获取选中的行
    int curRow = ui->tableView_2->currentIndex().row();

    // 删除该行
    model1->removeRow(curRow);
    int ok = QMessageBox::warning(this,tr("删除当前行!"),
                                  tr("你确定删除当前行吗?"), QMessageBox::Yes, QMessageBox::No);
    if(ok == QMessageBox::No)
    { // 如果不删除,则撤销
        model1->revertAll();
    } else { // 否则提交,在数据库中删除该行
        model1->submitAll();
    }
}

void sqlmodel::on_pushButton_7_clicked()
{


//加载文件窗口,典型调用文件对话框选择所需文件
//读取微信账单,主要思路来源于网上修改,读取文本文件,读取每一行然后存入数据表
//因为17行之后才是数据的读取,所以17行之前是用户的信息,
//在这里通过对字符串的读取分析来自动存储
    QFileDialog* fd = new QFileDialog(this);//创建打开文件对话框

    QString fileName = fd->getOpenFileName(this,tr("Open File"),"/home",tr("Excel(*.csv)"));

    if(fileName == "")

          return;

    QDir dir = QDir::current();

    QFile file(dir.filePath(fileName));

    if(!file.open(QIODevice::ReadOnly))

         qDebug()<<"OPEN FILE FAILED";

    QTextStream * out = new QTextStream(&file);//文本流

    QStringList tempOption = out->readAll().split("\n",QString::SkipEmptyParts);//每行以\n区分
//    QString tempOption0 = out->readAll();//每行以\n区分

    QProgressDialog dialog(tr("正在加载"),tr("取消"), 0, tempOption.count(), this);
    dialog.setCancelButton(0);
    dialog.setWindowTitle(tr("进度"));
    dialog.setWindowModality(Qt::WindowModal);
    dialog.show();
      MySql* mysql = new MySql;
    for(int i = 0 ; i <tempOption.count() ; i++)

    {

         QStringList tempbar = tempOption.at(i).split(",");//一行中的单元格以,区分
// QString tempbar0 = tempOption0.at(i);//一行中的单元格以,区分
       //  ...//省略具体对数据的操作
         if(i==2){
             qDebug()<<tempbar.join("");
             QString temdispose=tempbar.join("");
             qDebug()<<temdispose.mid(11,2).toInt()<<temdispose.mid(38,2).toInt();

             minMonth=temdispose.mid(11,2).toInt();
             maxMonth=temdispose.mid(38,2).toInt();
             Months=maxMonth-minMonth+1;
             qDebug()<<minMonth<<maxMonth<<Months;
             mysql->dataProcessingTable(minMonth,maxMonth,Months);
             setTables= QString("MonthTradeTypeNumber%1").arg(sqlmodel::minMonth);
             qDebug()<<setTables<<"1";
         }



         static int id=1;
         if(i<=15){


         QString tem=tempbar.join("");
         tempall.append(tem);

         ui->textEdit->append(tempall);
         if(i==15){
  //         qDebug()<< tempall;
         ui->textEdit->setText(tempall);
         }
         }
         if(i>=17){


           mysql->initdatas(id,tempbar.at(0),tempbar.at(1),tempbar.at(2),tempbar.at(3),tempbar.at(4)
                            ,tempbar.at(5),tempbar.at(6),tempbar.at(7),tempbar.at(8)
                            ,tempbar.at(9),tempbar.at(10));





           //处理数据

          id++;
//           for (int i = 0; i < tempbar.size(); ++i)

//                     qDebug() << tempbar.at(i) << endl;
         }
//         qDebug()<<tempbar;

             dialog.setValue(i);
             QCoreApplication::processEvents();
             if(dialog.wasCanceled())
             {
                 break;
             }



         }
      dialog.setValue(tempOption.count());
     QMessageBox::information(this,tr("加载"),tr("加载成功!"),QMessageBox::Ok);
     ui->pushButton_8->setEnabled(true);
     ui->pushButton_9->setEnabled(true);
//     ui->pushButton_10->setEnabled(true);


//         ui->textEdit->setText(tempbar);


   ui->pushButton_7->setEnabled(false);


   //数据表处理
    mysql->theDataProcess(minMonth,maxMonth,Months);
  //  query=new QSqlQuery;


    switch(Months){


    case(1):{
//        int a1 = 11;

        ui->comboBox->addItem(QString("%1Month").arg(minMonth));

//        QComboBox *themeComboBox = new QComboBox();

//        themeComboBox->addItem(QString("%1Month").arg(minMonth), a1);
//       // qDebug()<<"11""createThemeBox";
//        return themeComboBox;


    }break;
    case(2):{
//        int b1 = 21,b2 = 22,b3 = 23;
        ui->comboBox->addItem(QString("%1Month").arg(minMonth));
        ui->comboBox->addItem(QString("%1Month").arg(maxMonth));
        ui->comboBox->addItem("AllMonth");
//        QComboBox *themeComboBox = new QComboBox();
//        themeComboBox->addItem(QString("%1Month").arg(minMonth), b1);
//        themeComboBox->addItem(QString("%1Month").arg(maxMonth), b2);
//        themeComboBox->addItem("AllMonth", b3);
//         return themeComboBox;
    }break;
    case(3):{



        ui->comboBox->addItem(QString("%1Month").arg(minMonth));
        ui->comboBox->addItem(QString("%1Month").arg(minMonth+1));
        ui->comboBox->addItem(QString("%1Month").arg(maxMonth));
        ui->comboBox->addItem("AllMonth");
    }break;

    case(4):{

//        qDebug()<<"123123";
//        int d1 = 41,d2 = 42,d3 = 43,d4 = 44,d5 = 45;
//        QComboBox *themeComboBox = new QComboBox();
//        themeComboBox->addItem(QString("%1Month").arg(minMonth), d1);
//        themeComboBox->addItem(QString("%1Month").arg(minMonth+1), d2);
//        themeComboBox->addItem(QString("%1Month").arg(maxMonth-1), d3);
//        themeComboBox->addItem(QString("%1Month").arg(maxMonth), d4);
//        themeComboBox->addItem("AllMonth", d5);
//        return themeComboBox;

        ui->comboBox->addItem(QString("%1Month").arg(minMonth));
        ui->comboBox->addItem(QString("%1Month").arg(minMonth+1));
        ui->comboBox->addItem(QString("%1Month").arg(maxMonth-1));
        ui->comboBox->addItem(QString("%1Month").arg(maxMonth));
        ui->comboBox->addItem("AllMonth");


    }break;

    }

    file.close();//操作完成后记得关闭文件



}





void sqlmodel::on_pushButton_8_clicked()
{

    QString str = ui->comboBox->currentText();
ThemeWidget *widg = new ThemeWidget(str,sqlmodel::minMonth,sqlmodel::maxMonth,sqlmodel::Months) ;
widg->resize(1600,1000);
widg->show();
}

void sqlmodel::on_pushButton_11_clicked()
{


        model3 = new QSqlTableModel(this);
        model3->setTable(QString("MonthTradeTypeAmountOfMoneyall4"));
        model3->select();
        ui->tableView_3->setModel(model3);
}

void sqlmodel::on_pushButton_9_clicked()
{
    barChart *bar =new barChart(sqlmodel::minMonth,sqlmodel::maxMonth,sqlmodel::Months);


}

void sqlmodel::on_pushButton_12_clicked()
{
    QSqlQuery query;
    qDebug()<<"on_pushButton_12_clicked"<<minMonth<<maxMonth<<Months;

     bool str1 =   query.exec("drop table MonthTradeTypeNumber4");
     bool str2 =   query.exec("drop table MonthTradeTypeAmountOfMoney4");
     bool str3 =  query.exec("drop table MonthIncome4");
     bool str4 =  query.exec("drop table MonthSpending4");

     qDebug()<<str1<<str2<<str3<<str4;
}

最后一部分是数据图表的显示,模型来自Qt自典例documentbreakdown、chartthemes、lineandbar可以通过查阅帮助文档理解模型的使用,我所做的就是创建接口将数据传输上去从而实现图表功能





 

#ifndef BARCHART_H
#define BARCHART_H

#include <QMainWindow>
#include <QChart>
#include <QSqlQuery>

#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtCharts/QChartView>
#include <QtCharts/QBarSeries>
#include <QtCharts/QBarSet>
#include <QtCharts/QLegend>
#include <QtCharts/QBarCategoryAxis>



//柱状图
QT_CHARTS_BEGIN_NAMESPACE
class QChart;
QT_CHARTS_END_NAMESPACE


QT_CHARTS_USE_NAMESPACE

class barChart : public QMainWindow
{
    Q_OBJECT
public:
    explicit barChart(int minMonth, int maxMonth, int Months,QWidget *parent = nullptr);
    QChart *dataChart(int minMonth, int maxMonth, int Months)const;
    QSqlQuery  *query;

signals:

public slots:
};

#endif // BARCHART_H
#include "barchart.h"
//柱状图


//柱状图初始化
barChart::barChart(int minMonth, int maxMonth, int Months, QWidget *parent) : QMainWindow(parent)
{

    //dataChart(minMonth,maxMonth,Months);
//    dataChart(minMonth,maxMonth,Months)->createDefaultAxes();
    QChartView *chartView = new QChartView(dataChart(minMonth,maxMonth,Months));//放置图表
    chartView->setRenderHint(QPainter::Antialiasing);
    chartView->resize(1600,1000);
    chartView->show();
}

QChart *barChart::dataChart(int minMonth, int maxMonth, int Months) const//创建图表
{
    QSqlQuery  *query = new QSqlQuery;

    switch (Months){


        case(1):{

        //![1]




            QBarSet *set1 = new QBarSet("商户消费");
            QBarSet *set2 = new QBarSet("转账");
            QBarSet *set3 = new QBarSet("其他");
            QBarSet *set4 = new QBarSet("转账-退款");
            QBarSet *set5 = new QBarSet("零钱提现");
            QBarSet *set6 = new QBarSet("扫二维码付款");
            QBarSet *set7 = new QBarSet("微信红包");
            QBarSet *set8 = new QBarSet("零钱充值");


            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(minMonth));
            if(query->first())
        {
            *set1 << query->value(1).toDouble();
            *set2 << query->value(2).toDouble();
            *set3 << query->value(3).toDouble();
            *set4 << query->value(4).toDouble();
            *set5 << query->value(5).toDouble();
            *set6 << query->value(6).toDouble();
            *set7 << query->value(7).toDouble();
            *set8 << query->value(8).toDouble();

            }



        //![1]

        //![2]
            QBarSeries *series = new QBarSeries();

            series->append(set1);
            series->append(set2);
            series->append(set3);
            series->append(set4);
            series->append(set5);
            series->append(set6);
            series->append(set7);
            series->append(set8);

        //![2]

        //![3]
            QChart *chart = new QChart();
            chart->addSeries(series);
            chart->setTitle("交易类型各类型金额统计表");
            chart->setAnimationOptions(QChart::SeriesAnimations);
        //![3]

        //![4]
            QStringList categories;
            categories << QString("%1Month").arg(minMonth);
            QBarCategoryAxis *axis = new QBarCategoryAxis();
            axis->append(categories);
            chart->createDefaultAxes();
            chart->setAxisX(axis, series);
        //![4]

        //![5]
            chart->legend()->setVisible(true);
            chart->legend()->setAlignment(Qt::AlignBottom);
        //![5]


            return chart;
//                    ![6]

//                    ![6]
    };
        case(2):{
        //![1]




            QBarSet *set1 = new QBarSet("商户消费");
            QBarSet *set2 = new QBarSet("转账");
            QBarSet *set3 = new QBarSet("其他");
            QBarSet *set4 = new QBarSet("转账-退款");
            QBarSet *set5 = new QBarSet("零钱提现");
            QBarSet *set6 = new QBarSet("扫二维码付款");
            QBarSet *set7 = new QBarSet("微信红包");
            QBarSet *set8 = new QBarSet("零钱充值");



            double a1,a2,a3,a4,a5,a6,a7,a8;
            double b1,b2,b3,b4,b5,b6,b7,b8;
            double c1,c2,c3,c4,c5,c6,c7,c8;


            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(minMonth));
            if(query->first())
            {
             a1=query->value(1).toDouble();
             a2=query->value(2).toDouble();
             a3=query->value(3).toDouble();
             a4=query->value(4).toDouble();
             a5=query->value(5).toDouble();
             a6=query->value(6).toDouble();
             a7=query->value(7).toDouble();
             a8=query->value(8).toDouble();


            }
            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(maxMonth));
            if(query->first())
            {
                b1=query->value(1).toDouble();
                b2=query->value(2).toDouble();
                b3=query->value(3).toDouble();
                b4=query->value(4).toDouble();
                b5=query->value(5).toDouble();
                b6=query->value(6).toDouble();
                b7=query->value(7).toDouble();
                b8=query->value(8).toDouble();


            }
            query->exec(QString("select * from MonthTradeTypeAmountOfMoneyall%1").arg(Months));
            if(query->first())
            {


                c1=query->value(1).toDouble();
                c2=query->value(2).toDouble();
                c3=query->value(3).toDouble();
                c4=query->value(4).toDouble();
                c5=query->value(5).toDouble();
                c6=query->value(6).toDouble();
                c7=query->value(7).toDouble();
                c8=query->value(8).toDouble();

            }






            *set1 << a1<<b1<<c1;
            *set2 << a2<<b2<<c2;
            *set3 << a3<<b3<<c3;
            *set4 << a4<<b4<<c4;
            *set5 << a5<<b5<<c5;
            *set6 << a6<<b6<<c6;
            *set7 << a7<<b7<<c7;
            *set8 << a8<<b8<<c8;

        //![1]

        //![2]
            QBarSeries *series = new QBarSeries();

            series->append(set1);
            series->append(set2);
            series->append(set3);
            series->append(set4);
            series->append(set5);
            series->append(set6);
            series->append(set7);
            series->append(set8);

        //![2]

        //![3]
            QChart *chart = new QChart();
            chart->addSeries(series);
            chart->setTitle("交易类型各类型金额统计表");
            chart->setAnimationOptions(QChart::SeriesAnimations);
        //![3]

        //![4]
            QStringList categories;
            categories << QString("%1Month").arg(minMonth)<<QString("%2Month").arg(maxMonth)<<"AllMonths";
            QBarCategoryAxis *axis = new QBarCategoryAxis();
            axis->append(categories);
            chart->createDefaultAxes();
            chart->setAxisX(axis, series);
        //![4]

        //![5]
            chart->legend()->setVisible(true);
            chart->legend()->setAlignment(Qt::AlignBottom);
        //![5]
             a1=0;a2=0;a3=0;a4=0;a5=0;a6=0;a7=0;a8=0;
             b1=0;b2=0;b3=0;b4=0;b5=0;b6=0;b7=0;b8=0;
             c1=0;c2=0;c3=0;c4=0;c5=0;c6=0;c7=0;c8=0;


            return chart;
    };
        case(3):{
        //![1]




            QBarSet *set1 = new QBarSet("商户消费");
            QBarSet *set2 = new QBarSet("转账");
            QBarSet *set3 = new QBarSet("其他");
            QBarSet *set4 = new QBarSet("转账-退款");
            QBarSet *set5 = new QBarSet("零钱提现");
            QBarSet *set6 = new QBarSet("扫二维码付款");
            QBarSet *set7 = new QBarSet("微信红包");
            QBarSet *set8 = new QBarSet("零钱充值");



            double a1,a2,a3,a4,a5,a6,a7,a8;
            double b1,b2,b3,b4,b5,b6,b7,b8;
            double c1,c2,c3,c4,c5,c6,c7,c8;
            double d1,d2,d3,d4,d5,d6,d7,d8;


            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(minMonth));
            if(query->first())
            {
             a1=query->value(1).toDouble();
             a2=query->value(2).toDouble();
             a3=query->value(3).toDouble();
             a4=query->value(4).toDouble();
             a5=query->value(5).toDouble();
             a6=query->value(6).toDouble();
             a7=query->value(7).toDouble();
             a8=query->value(8).toDouble();


            }
            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(minMonth+1));
            if(query->first())
            {
                b1=query->value(1).toDouble();
                b2=query->value(2).toDouble();
                b3=query->value(3).toDouble();
                b4=query->value(4).toDouble();
                b5=query->value(5).toDouble();
                b6=query->value(6).toDouble();
                b7=query->value(7).toDouble();
                b8=query->value(8).toDouble();


            }
            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(maxMonth));
            if(query->first())
            {


                c1=query->value(1).toDouble();
                c2=query->value(2).toDouble();
                c3=query->value(3).toDouble();
                c4=query->value(4).toDouble();
                c5=query->value(5).toDouble();
                c6=query->value(6).toDouble();
                c7=query->value(7).toDouble();
                c8=query->value(8).toDouble();

            }
            query->exec(QString("select * from MonthTradeTypeAmountOfMoneyall%1").arg(Months));
            if(query->first())
            {


                d1=query->value(1).toDouble();
                d2=query->value(2).toDouble();
                d3=query->value(3).toDouble();
                d4=query->value(4).toDouble();
                d5=query->value(5).toDouble();
                d6=query->value(6).toDouble();
                d7=query->value(7).toDouble();
                d8=query->value(8).toDouble();

            }






            *set1 << a1<<b1<<c1<<d1;
            *set2 << a2<<b2<<c2<<d2;
            *set3 << a3<<b3<<c3<<d3;
            *set4 << a4<<b4<<c4<<d4;
            *set5 << a5<<b5<<c5<<d5;
            *set6 << a6<<b6<<c6<<d6;
            *set7 << a7<<b7<<c7<<d7;
            *set8 << a8<<b8<<c8<<d8;

        //![1]

        //![2]
            QBarSeries *series = new QBarSeries();

            series->append(set1);
            series->append(set2);
            series->append(set3);
            series->append(set4);
            series->append(set5);
            series->append(set6);
            series->append(set7);
            series->append(set8);

        //![2]

        //![3]
            QChart *chart = new QChart();
            chart->addSeries(series);
            chart->setTitle("交易类型各类型金额统计表");
            chart->setAnimationOptions(QChart::SeriesAnimations);
        //![3]

        //![4]
            QStringList categories;
            categories << QString("%1Month").arg(minMonth)<< QString("%2Month").arg(minMonth+1)<<QString("%3Month").arg(maxMonth)<<"AllMonths";
            QBarCategoryAxis *axis = new QBarCategoryAxis();
            axis->append(categories);
            chart->createDefaultAxes();
            chart->setAxisX(axis, series);
        //![4]

        //![5]
            chart->legend()->setVisible(true);
            chart->legend()->setAlignment(Qt::AlignBottom);
        //![5]


            a1=0;a2=0;a3=0;a4=0;a5=0;a6=0;a7=0;a8=0;
            b1=0;b2=0;b3=0;b4=0;b5=0;b6=0;b7=0;b8=0;
            c1=0;c2=0;c3=0;c4=0;c5=0;c6=0;c7=0;c8=0;
            d1=0;d2=0;d3=0;d4=0;d5=0;d6=0;d7=0;d8=0;

            return chart;
    };
        case(4):{
        //![1]




            QBarSet *set1 = new QBarSet("商户消费");
            QBarSet *set2 = new QBarSet("转账");
            QBarSet *set3 = new QBarSet("其他");
            QBarSet *set4 = new QBarSet("转账-退款");
            QBarSet *set5 = new QBarSet("零钱提现");
            QBarSet *set6 = new QBarSet("扫二维码付款");
            QBarSet *set7 = new QBarSet("微信红包");
            QBarSet *set8 = new QBarSet("零钱充值");



            double a1,a2,a3,a4,a5,a6,a7,a8;
            double b1,b2,b3,b4,b5,b6,b7,b8;
            double c1,c2,c3,c4,c5,c6,c7,c8;
            double d1,d2,d3,d4,d5,d6,d7,d8;
            double e1,e2,e3,e4,e5,e6,e7,e8;


            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(minMonth));
            if(query->first())
            {
             a1=query->value(1).toDouble();
             a2=query->value(2).toDouble();
             a3=query->value(3).toDouble();
             a4=query->value(4).toDouble();
             a5=query->value(5).toDouble();
             a6=query->value(6).toDouble();
             a7=query->value(7).toDouble();
             a8=query->value(8).toDouble();


            }
            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(minMonth+1));
            if(query->first())
            {
                b1=query->value(1).toDouble();
                b2=query->value(2).toDouble();
                b3=query->value(3).toDouble();
                b4=query->value(4).toDouble();
                b5=query->value(5).toDouble();
                b6=query->value(6).toDouble();
                b7=query->value(7).toDouble();
                b8=query->value(8).toDouble();


            }
            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(maxMonth-1));
            if(query->first())
            {


                c1=query->value(1).toDouble();
                c2=query->value(2).toDouble();
                c3=query->value(3).toDouble();
                c4=query->value(4).toDouble();
                c5=query->value(5).toDouble();
                c6=query->value(6).toDouble();
                c7=query->value(7).toDouble();
                c8=query->value(8).toDouble();

            }
            query->exec(QString("select * from MonthTradeTypeAmountOfMoney%1").arg(maxMonth));
            if(query->first())
            {


                d1=query->value(1).toDouble();
                d2=query->value(2).toDouble();
                d3=query->value(3).toDouble();
                d4=query->value(4).toDouble();
                d5=query->value(5).toDouble();
                d6=query->value(6).toDouble();
                d7=query->value(7).toDouble();
                d8=query->value(8).toDouble();

            }
            query->exec(QString("select * from MonthTradeTypeAmountOfMoneyall%1").arg(Months));
            if(query->first())
            {


                e1=query->value(1).toDouble();
                e2=query->value(2).toDouble();
                e3=query->value(3).toDouble();
                e4=query->value(4).toDouble();
                e5=query->value(5).toDouble();
                e6=query->value(6).toDouble();
                e7=query->value(7).toDouble();
                e8=query->value(8).toDouble();

            }






            *set1 << a1<<b1<<c1<<d1<<e1;
            *set2 << a2<<b2<<c2<<d2<<e2;
            *set3 << a3<<b3<<c3<<d3<<e3;
            *set4 << a4<<b4<<c4<<d4<<e4;
            *set5 << a5<<b5<<c5<<d5<<e5;
            *set6 << a6<<b6<<c6<<d6<<e6;
            *set7 << a7<<b7<<c7<<d7<<e7;
            *set8 << a8<<b8<<c8<<d8<<e8;

        //![1]

        //![2]
            QBarSeries *series = new QBarSeries();

            series->append(set1);
            series->append(set2);
            series->append(set3);
            series->append(set4);
            series->append(set5);
            series->append(set6);
            series->append(set7);
            series->append(set8);

        //![2]

        //![3]
            QChart *chart = new QChart();
            chart->addSeries(series);
            chart->setTitle("交易类型各类型金额统计表");
            chart->setAnimationOptions(QChart::SeriesAnimations);
        //![3]

        //![4]
            QStringList categories;
            categories << QString("%1Month").arg(minMonth)<< QString("%2Month").arg(minMonth+1)<< QString("%3Month").arg(maxMonth-1)<<QString("%4Month").arg(maxMonth)<<"AllMonths";
            QBarCategoryAxis *axis = new QBarCategoryAxis();
            axis->append(categories);
            chart->createDefaultAxes();
            chart->setAxisX(axis, series);
        //![4]

        //![5]
            chart->legend()->setVisible(true);
            chart->legend()->setAlignment(Qt::AlignBottom);
        //![5]


//            a1=0;a2=0;a3=0;a4=0;a5=0;a6=0;a7=0;a8=0;
//            b1=0;b2=0;b3=0;b4=0;b5=0;b6=0;b7=0;b8=0;
//            c1=0;c2=0;c3=0;c4=0;c5=0;c6=0;c7=0;c8=0;
//            d1=0;d2=0;d3=0;d4=0;d5=0;d6=0;d7=0;d8=0;
//            e1=0;e2=0;e3=0;e4=0;e5=0;e6=0;e7=0;e8=0;

            return chart;
    };

    }

}
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Charts module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef DONUTBREAKDOWNCHART_H
#define DONUTBREAKDOWNCHART_H


//饼状图
#include <QtCharts/QChart>
#include <QtCharts/QPieSeries>

QT_CHARTS_USE_NAMESPACE

class DonutBreakdownCharts : public QChart
{
public:
    DonutBreakdownCharts(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
    void addBreakdownSeries(QPieSeries *series, QColor color);

private:
    void recalculateAngles();
    void updateLegendMarkers();

private:
    QPieSeries *m_mainSeries;
};

#endif // DONUTBREAKDOWNCHART_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Charts module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "donutbreakdowncharts.h"
#include "mainslice.h"
#include <QtCharts/QPieSlice>
#include <QtCharts/QPieLegendMarker>
//饼状图
QT_CHARTS_USE_NAMESPACE

//![1]
DonutBreakdownCharts::DonutBreakdownCharts(QGraphicsItem *parent, Qt::WindowFlags wFlags)
    : QChart(QChart::ChartTypeCartesian, parent, wFlags)
{
    // create the series for main center pie
    m_mainSeries = new QPieSeries();
    m_mainSeries->setPieSize(0.7);
    QChart::addSeries(m_mainSeries);
}
//![1]

//![2]
void DonutBreakdownCharts::addBreakdownSeries(QPieSeries *breakdownSeries, QColor color)
{
    QFont font("Arial", 10);

    // add breakdown series as a slice to center pie
    MainSlice *mainSlice = new MainSlice(breakdownSeries);
    mainSlice->setName(breakdownSeries->name());
    mainSlice->setValue(breakdownSeries->sum());
    m_mainSeries->append(mainSlice);

    // customize the slice
    mainSlice->setBrush(color);
    mainSlice->setLabelVisible();
    mainSlice->setLabelColor(Qt::white);
    mainSlice->setLabelPosition(QPieSlice::LabelInsideHorizontal);
    mainSlice->setLabelFont(font);

    // position and customize the breakdown series
    breakdownSeries->setPieSize(0.7);
    breakdownSeries->setHoleSize(0.6);
    breakdownSeries->setLabelsVisible();
    const auto slices = breakdownSeries->slices();
    for (QPieSlice *slice : slices) {
        color = color.lighter(115);
        slice->setBrush(color);
        slice->setLabelFont(font);
    }

    // add the series to the chart
    QChart::addSeries(breakdownSeries);

    // recalculate breakdown donut segments
    recalculateAngles();

    // update customize legend markers
    updateLegendMarkers();
}
//![2]

//![3]
void DonutBreakdownCharts::recalculateAngles()
{
    qreal angle = 0;
    const auto slices = m_mainSeries->slices();
    for (QPieSlice *slice : slices) {
        QPieSeries *breakdownSeries = qobject_cast<MainSlice *>(slice)->breakdownSeries();
        breakdownSeries->setPieStartAngle(angle);
        angle += slice->percentage() * 360.0; // full pie is 360.0
        breakdownSeries->setPieEndAngle(angle);
    }
}
//![3]

//![4]
void DonutBreakdownCharts::updateLegendMarkers()
{
    // go through all markers
    const auto allseries = series();
    for (QAbstractSeries *series : allseries) {
        const auto markers = legend()->markers(series);
        for (QLegendMarker *marker : markers) {
            QPieLegendMarker *pieMarker = qobject_cast<QPieLegendMarker *>(marker);
            if (series == m_mainSeries) {
                // hide markers from main series
                pieMarker->setVisible(false);
            } else {
                // modify markers from breakdown series
                pieMarker->setLabel(QString("%1 %2%")
                                    .arg(pieMarker->slice()->label())
                                    .arg(pieMarker->slice()->percentage() * 100, 0, 'f', 2));
                pieMarker->setFont(QFont("Arial", 10));
            }
        }
    }
}
//![4]
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Charts module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef MAINSLICE_H
#define MAINSLICE_H



//饼状图


#include <QtCharts/QPieSlice>
#include <QtCharts/QPieSeries>

QT_CHARTS_USE_NAMESPACE

class MainSlice : public QPieSlice
{
    Q_OBJECT
public:
    MainSlice(QPieSeries *breakdownSeries, QObject *parent = 0);

    QPieSeries *breakdownSeries() const;

    void setName(QString name);
    QString name() const;

public Q_SLOTS:
    void updateLabel();

private:
    QPieSeries *m_breakdownSeries;
    QString m_name;
};

#endif // MAINSLICE_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Charts module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//饼状图
#include "mainslice.h"

QT_CHARTS_USE_NAMESPACE

//![1]
MainSlice::MainSlice(QPieSeries *breakdownSeries, QObject *parent)
    : QPieSlice(parent),
      m_breakdownSeries(breakdownSeries)
{
    connect(this, &MainSlice::percentageChanged, this, &MainSlice::updateLabel);
}
//![1]

QPieSeries *MainSlice::breakdownSeries() const
{
    return m_breakdownSeries;
}

void MainSlice::setName(QString name)
{
    m_name = name;
}

QString MainSlice::name() const
{
    return m_name;
}

//![2]
void MainSlice::updateLabel()
{
    this->setLabel(QString("%1 %2%").arg(m_name).arg(percentage() * 100, 0, 'f', 2));
}
//![2]

#include "moc_mainslice.cpp"

/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Charts module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef THEMEWIDGET_H
#define THEMEWIDGET_H


//换肤窗口界面


#include <QtWidgets/QWidget>
#include <QtCharts/QChartGlobal>
#include "donutbreakdowncharts.h"
#include "mainslice.h"

QT_BEGIN_NAMESPACE
class QComboBox;
class QCheckBox;
QT_END_NAMESPACE

QT_CHARTS_BEGIN_NAMESPACE
class QChartView;
class QChart;
QT_CHARTS_END_NAMESPACE

typedef QPair<QPointF, QString> Data;
typedef QList<Data> DataList;
typedef QList<DataList> DataTable;

QT_CHARTS_USE_NAMESPACE

class ThemeWidget: public QWidget
{
    Q_OBJECT
public:
    explicit ThemeWidget(QString Month,int minMonth, int maxMonth, int Months, QWidget *parent = 0);
    ~ThemeWidget();

private Q_SLOTS:
    void updateUI();

private:
    DataTable generateRandomData(int listCount, int valueMax, int valueCount) const;
    QComboBox *createThemeBox() const;
    QComboBox *createAnimationBox(int minMonth, int maxMonth, int Months) const;
    QComboBox *createLegendBox() const;
    void connectSignals();
    DonutBreakdownCharts *createAreaChart(QString Month,int minMonth, int maxMonth, int Months) const;

private:
    int m_listCount;
    int m_valueMax;
    int m_valueCount;
    QList<QChartView *> m_charts;
    DataTable m_dataTable;

    QComboBox *m_themeComboBox;
    QCheckBox *m_antialiasCheckBox;
    QComboBox *m_animatedComboBox;

    DonutBreakdownCharts *donutBreakdown11;

    DonutBreakdownCharts *donutBreakdown21;
    DonutBreakdownCharts *donutBreakdown22;
    DonutBreakdownCharts *donutBreakdown23;

    DonutBreakdownCharts *donutBreakdown31;
    DonutBreakdownCharts *donutBreakdown32;
    DonutBreakdownCharts *donutBreakdown33;
    DonutBreakdownCharts *donutBreakdown34;

    DonutBreakdownCharts *donutBreakdown41;
    DonutBreakdownCharts *donutBreakdown42;
    DonutBreakdownCharts *donutBreakdown43;
    DonutBreakdownCharts *donutBreakdown44;
    DonutBreakdownCharts *donutBreakdown45;

};

#endif /* THEMEWIDGET_H */
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Charts module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "themewidget.h"

#include <QtCharts/QChartView>
#include <QtCharts/QPieSeries>
#include <QtCharts/QPieSlice>
#include <QtCharts/QAbstractBarSeries>
#include <QtCharts/QPercentBarSeries>
#include <QtCharts/QStackedBarSeries>
#include <QtCharts/QBarSeries>
#include <QtCharts/QBarSet>
#include <QtCharts/QLineSeries>
#include <QtCharts/QSplineSeries>
#include <QtCharts/QScatterSeries>
#include <QtCharts/QAreaSeries>
#include <QtCharts/QLegend>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QFormLayout>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QLabel>
#include <QtCore/QTime>
#include <QtCharts/QBarCategoryAxis>
#include<QDebug>
#include "donutbreakdowncharts.h"
#include <QSqlQuery>

//主题窗口
ThemeWidget::ThemeWidget(QString Month, int minMonth, int maxMonth, int Months, QWidget *parent) :
    QWidget(parent),
    m_listCount(3),
    m_valueMax(10),
    m_valueCount(7),
    m_dataTable(generateRandomData(m_listCount, m_valueMax, m_valueCount)),
    m_themeComboBox(createThemeBox()),
    m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
    m_animatedComboBox(createAnimationBox(minMonth,maxMonth,Months))

{
    connectSignals();


    // create layout
    QGridLayout *baseLayout = new QGridLayout();
    QHBoxLayout *settingsLayout = new QHBoxLayout();
    settingsLayout->addWidget(new QLabel("Theme:"));
    settingsLayout->addWidget(m_themeComboBox);
    settingsLayout->addWidget(new QLabel("Animation:"));
    settingsLayout->addWidget(m_animatedComboBox);

    settingsLayout->addStretch();
    baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);

    //create charts

    QChartView *chartView;
    chartView = new QChartView(createAreaChart(Month,minMonth,maxMonth,Months));
    baseLayout->addWidget(chartView, 1, 0);
    m_charts << chartView;



    setLayout(baseLayout);

    // Set defaults
    m_antialiasCheckBox->setChecked(true);
    updateUI();
}

ThemeWidget::~ThemeWidget()
{
}

void ThemeWidget::connectSignals()
{
    connect(m_themeComboBox,
            static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
            this, &ThemeWidget::updateUI);
//    connect(m_antialiasCheckBox, &QCheckBox::toggled, this, &ThemeWidget::updateUI);
//    connect(m_animatedComboBox,
//            static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
//            this, &ThemeWidget::updateUI);

}

DonutBreakdownCharts *ThemeWidget::createAreaChart(QString Month, int minMonth, int maxMonth, int Months) const
{




     QSqlQuery  *query = new QSqlQuery;
     switch (Months) {

     case(1):{


        // qDebug()<<minMonth<<query->value(1).toInt()<<query->value(5).toInt();

          QPieSeries *series1 = new QPieSeries();
          QPieSeries *series2 = new QPieSeries();
          QPieSeries *series3 = new QPieSeries();
         query->exec(QString("select * from MonthTradeTypeNumber%1").arg(minMonth));
         if(query->first()){

 //         static QPieSeries *series1 = new QPieSeries();
 //         static QPieSeries *series2 = new QPieSeries();
 //         static QPieSeries *series3 = new QPieSeries();
         series1->setName("第一类");
         series1->append("商户消费", query->value(1).toInt());
         series1->append("零钱提现", query->value(5).toInt());
 //        qDebug()<<"第一类""商户消费""零钱提现";
 //        qDebug()<<minMonth<<query->value(1).toInt()<<query->value(5).toInt();




         series2->setName("第二类");
         series2->append("转账", query->value(2).toInt());
         series2->append("转账-退款", query->value(4).toInt());
         series2->append("零钱充值", query->value(8).toInt());
 //        qDebug()<<"第二类""转账""转账-退款""零钱充值";
 //        qDebug()<<query->value(2).toInt()<<query->value(4).toInt()<<query->value(8).toInt();


         series3->setName("第三类");
         series3->append("扫二维码付款", query->value(6).toInt());
         series3->append("微信红包", query->value(7).toInt());
         series3->append("其它", query->value(3).toInt());

 //         qDebug()<<"第三类""扫二维码付款""微信红包""其它";
 //         qDebug()<<query->value(6).toInt()<<query->value(7).toInt()<<query->value(3).toInt();
          }
         DonutBreakdownCharts *donutBreakdown11 = new DonutBreakdownCharts();
         donutBreakdown11->setAnimationOptions(QChart::AllAnimations);
         donutBreakdown11->setTitle(QString("%1Month交易类型数目表").arg(minMonth));
         donutBreakdown11->legend()->setAlignment(Qt::AlignRight);
         donutBreakdown11->addBreakdownSeries(series1, Qt::red);
         donutBreakdown11->addBreakdownSeries(series2, Qt::darkGreen);
         donutBreakdown11->addBreakdownSeries(series3, Qt::darkBlue);

return donutBreakdown11;

      }
   case(2):{

         if(Month==QString("%1Month").arg(minMonth)){


         QPieSeries *series1 = new QPieSeries();
         QPieSeries *series2 = new QPieSeries();
         QPieSeries *series3 = new QPieSeries();
        query->exec(QString("select * from MonthTradeTypeNumber%1").arg(minMonth));
        if(query->first()){


        series1->setName("第一类");
        series1->append("商户消费", query->value(1).toInt());
        series1->append("零钱提现", query->value(5).toInt());




        series2->setName("第二类");
        series2->append("转账", query->value(2).toInt());
        series2->append("转账-退款", query->value(4).toInt());
        series2->append("零钱充值", query->value(8).toInt());



        series3->setName("第三类");
        series3->append("扫二维码付款", query->value(6).toInt());
        series3->append("微信红包", query->value(7).toInt());
        series3->append("其它", query->value(3).toInt());

         }
        DonutBreakdownCharts *donutBreakdown21 = new DonutBreakdownCharts();
        donutBreakdown21->setAnimationOptions(QChart::AllAnimations);
        donutBreakdown21->setTitle(QString("%1Month交易类型数目表").arg(minMonth));
        donutBreakdown21->legend()->setAlignment(Qt::AlignRight);
        donutBreakdown21->addBreakdownSeries(series1, Qt::red);
        donutBreakdown21->addBreakdownSeries(series2, Qt::darkGreen);
        donutBreakdown21->addBreakdownSeries(series3, Qt::darkBlue);


        return donutBreakdown21;
        }



         else if (Month==QString("%1Month").arg(maxMonth)) {


        QPieSeries *series21 = new QPieSeries();
        QPieSeries *series22 = new QPieSeries();
        QPieSeries *series23 = new QPieSeries();
       query->exec(QString("select * from MonthTradeTypeNumber%1").arg(maxMonth));
       if(query->first()){
       series21->setName("第一类");
       series21->append("商户消费", query->value(1).toInt());
       series21->append("零钱提现", query->value(5).toInt());

       series22->setName("第二类");
       series22->append("转账", query->value(2).toInt());
       series22->append("转账-退款", query->value(4).toInt());
       series22->append("零钱充值", query->value(8).toInt());

       series23->setName("第三类");
       series23->append("扫二维码付款", query->value(6).toInt());
       series23->append("微信红包", query->value(7).toInt());
       series23->append("其它", query->value(3).toInt());


        }
       DonutBreakdownCharts *donutBreakdown22 = new DonutBreakdownCharts();
       donutBreakdown22->setAnimationOptions(QChart::AllAnimations);
       donutBreakdown22->setTitle(QString("%1Month交易类型数目表").arg(maxMonth));
       donutBreakdown22->legend()->setAlignment(Qt::AlignRight);
       donutBreakdown22->addBreakdownSeries(series21, Qt::red);
       donutBreakdown22->addBreakdownSeries(series22, Qt::darkGreen);
       donutBreakdown22->addBreakdownSeries(series23, Qt::darkBlue);

       return donutBreakdown22;

         }


         else {


       QPieSeries *series31 = new QPieSeries();
       QPieSeries *series32 = new QPieSeries();
       QPieSeries *series33 = new QPieSeries();
      query->exec(QString("select * from MonthTradeTypeNumberall%1").arg(Months));
      if(query->first()){


      series31->setName("第一类");
      series31->append("商户消费", query->value(1).toInt());
      series31->append("零钱提现", query->value(5).toInt());





      series32->setName("第二类");
      series32->append("转账", query->value(2).toInt());
      series32->append("转账-退款", query->value(4).toInt());
      series32->append("零钱充值", query->value(8).toInt());



      series33->setName("第三类");
      series33->append("扫二维码付款", query->value(6).toInt());
      series33->append("微信红包", query->value(7).toInt());
      series33->append("其它", query->value(3).toInt());


       }
      DonutBreakdownCharts *donutBreakdown23 = new DonutBreakdownCharts();
      donutBreakdown23->setAnimationOptions(QChart::AllAnimations);
      donutBreakdown23->setTitle(QString("总交易类型数目表"));
      donutBreakdown23->legend()->setAlignment(Qt::AlignRight);
      donutBreakdown23->addBreakdownSeries(series31, Qt::red);
      donutBreakdown23->addBreakdownSeries(series32, Qt::darkGreen);
      donutBreakdown23->addBreakdownSeries(series33, Qt::darkBlue);



     return donutBreakdown23;
         }

     }
   case(3):{

        if(Month==QString("%1Month").arg(minMonth)){
         QPieSeries *series11 = new QPieSeries();
         QPieSeries *series12 = new QPieSeries();
         QPieSeries *series13 = new QPieSeries();
        query->exec(QString("select * from MonthTradeTypeNumber%1").arg(minMonth));
        if(query->first()){

//         static QPieSeries *series1 = new QPieSeries();
//         static QPieSeries *series2 = new QPieSeries();
//         static QPieSeries *series3 = new QPieSeries();
        series11->setName("第一类");
        series11->append("商户消费", query->value(1).toInt());
        series11->append("零钱提现", query->value(5).toInt());
//        qDebug()<<"第一类""商户消费""零钱提现";
//        qDebug()<<minMonth<<query->value(1).toInt()<<query->value(5).toInt();




        series12->setName("第二类");
        series12->append("转账", query->value(2).toInt());
        series12->append("转账-退款", query->value(4).toInt());
        series12->append("零钱充值", query->value(8).toInt());
//        qDebug()<<"第二类""转账""转账-退款""零钱充值";
//        qDebug()<<query->value(2).toInt()<<query->value(4).toInt()<<query->value(8).toInt();


        series13->setName("第三类");
        series13->append("扫二维码付款", query->value(6).toInt());
        series13->append("微信红包", query->value(7).toInt());
        series13->append("其它", query->value(3).toInt());
         }
        DonutBreakdownCharts *donutBreakdown31 = new DonutBreakdownCharts();
        donutBreakdown31->setAnimationOptions(QChart::AllAnimations);
        donutBreakdown31->setTitle(QString("%1Month交易类型数目表").arg(minMonth));
        donutBreakdown31->legend()->setAlignment(Qt::AlignRight);
        donutBreakdown31->addBreakdownSeries(series11, Qt::red);
        donutBreakdown31->addBreakdownSeries(series12, Qt::darkGreen);
        donutBreakdown31->addBreakdownSeries(series13, Qt::darkBlue);


        return donutBreakdown31;
        }


        else if (Month==QString("%1Month").arg(minMonth+1)) {


        QPieSeries *series21 = new QPieSeries();
        QPieSeries *series22 = new QPieSeries();
        QPieSeries *series23 = new QPieSeries();
       query->exec(QString("select * from MonthTradeTypeNumber%1").arg(minMonth+1));
       if(query->first()){


       series21->setName("第一类");
       series21->append("商户消费", query->value(1).toInt());
       series21->append("零钱提现", query->value(5).toInt());





       series22->setName("第二类");
       series22->append("转账", query->value(2).toInt());
       series22->append("转账-退款", query->value(4).toInt());
       series22->append("零钱充值", query->value(8).toInt());



       series23->setName("第三类");
       series23->append("扫二维码付款", query->value(6).toInt());
       series23->append("微信红包", query->value(7).toInt());
       series23->append("其它", query->value(3).toInt());


        }
       DonutBreakdownCharts *donutBreakdown32 = new DonutBreakdownCharts();
       donutBreakdown32->setAnimationOptions(QChart::AllAnimations);
       donutBreakdown32->setTitle(QString("%1Month交易类型数目表").arg(minMonth+1));
       donutBreakdown32->legend()->setAlignment(Qt::AlignRight);
       donutBreakdown32->addBreakdownSeries(series21, Qt::red);
       donutBreakdown32->addBreakdownSeries(series22, Qt::darkGreen);
       donutBreakdown32->addBreakdownSeries(series23, Qt::darkBlue);

       return donutBreakdown32;
        }


        else if (Month==QString("%1Month").arg(maxMonth)) {


       QPieSeries *series31 = new QPieSeries();
       QPieSeries *series32 = new QPieSeries();
       QPieSeries *series33 = new QPieSeries();
      query->exec(QString("select * from MonthTradeTypeNumber%1").arg(maxMonth));
      if(query->first()){


      series31->setName("第一类");
      series31->append("商户消费", query->value(1).toInt());
      series31->append("零钱提现", query->value(5).toInt());





      series32->setName("第二类");
      series32->append("转账", query->value(2).toInt());
      series32->append("转账-退款", query->value(4).toInt());
      series32->append("零钱充值", query->value(8).toInt());



      series33->setName("第三类");
      series33->append("扫二维码付款", query->value(6).toInt());
      series33->append("微信红包", query->value(7).toInt());
      series33->append("其它", query->value(3).toInt());


       }
      DonutBreakdownCharts *donutBreakdown33 = new DonutBreakdownCharts();
      donutBreakdown33->setAnimationOptions(QChart::AllAnimations);
      donutBreakdown33->setTitle(QString("%1Month交易类型数目表").arg(maxMonth));
      donutBreakdown33->legend()->setAlignment(Qt::AlignRight);
      donutBreakdown33->addBreakdownSeries(series31, Qt::red);
      donutBreakdown33->addBreakdownSeries(series32, Qt::darkGreen);
      donutBreakdown33->addBreakdownSeries(series33, Qt::darkBlue);

      return donutBreakdown33;

        }


        else {


      QPieSeries *series40 = new QPieSeries();
      QPieSeries *series41 = new QPieSeries();
      QPieSeries *series42 = new QPieSeries();
     query->exec(QString("select * from MonthTradeTypeNumberall%1").arg(Months));
     if(query->first()){


     series40->setName("第一类");
     series40->append("商户消费", query->value(1).toInt());
     series40->append("零钱提现", query->value(5).toInt());





     series41->setName("第二类");
     series41->append("转账", query->value(2).toInt());
     series41->append("转账-退款", query->value(4).toInt());
     series41->append("零钱充值", query->value(8).toInt());



     series42->setName("第三类");
     series42->append("扫二维码付款", query->value(6).toInt());
     series42->append("微信红包", query->value(7).toInt());
     series42->append("其它", query->value(3).toInt());


      }
     DonutBreakdownCharts *donutBreakdown34 = new DonutBreakdownCharts();
     donutBreakdown34->setAnimationOptions(QChart::AllAnimations);
     donutBreakdown34->setTitle(QString("总交易类型数目表"));
     donutBreakdown34->legend()->setAlignment(Qt::AlignRight);
     donutBreakdown34->addBreakdownSeries(series40, Qt::red);
     donutBreakdown34->addBreakdownSeries(series41, Qt::darkGreen);
     donutBreakdown34->addBreakdownSeries(series42, Qt::darkBlue);



      return donutBreakdown34;


}
     }
     case(4):{



         if(Month==QString("%1Month").arg(minMonth)){


         QPieSeries *series11 = new QPieSeries();
         QPieSeries *series12 = new QPieSeries();
         QPieSeries *series13 = new QPieSeries();
        query->exec(QString("select * from MonthTradeTypeNumber%1").arg(minMonth));
        if(query->first()){


        series11->setName("第一类");
        series11->append("商户消费", query->value(1).toInt());
        series11->append("零钱提现", query->value(5).toInt());




        series12->setName("第二类");
        series12->append("转账", query->value(2).toInt());
        series12->append("转账-退款", query->value(4).toInt());
        series12->append("零钱充值", query->value(8).toInt());


        series13->setName("第三类");
        series13->append("扫二维码付款", query->value(6).toInt());
        series13->append("微信红包", query->value(7).toInt());
        series13->append("其它", query->value(3).toInt());

         }
        DonutBreakdownCharts *donutBreakdown41 = new DonutBreakdownCharts;

        donutBreakdown41->setAnimationOptions(QChart::AllAnimations);
        donutBreakdown41->setTitle(QString("%1Month交易类型数目表").arg(minMonth));
        donutBreakdown41->legend()->setAlignment(Qt::AlignRight);
        donutBreakdown41->addBreakdownSeries(series11, Qt::red);
        donutBreakdown41->addBreakdownSeries(series12, Qt::darkGreen);
        donutBreakdown41->addBreakdownSeries(series13, Qt::darkBlue);



        return donutBreakdown41;
         }


         else if (Month==QString("%1Month").arg(minMonth+1)) {


        QPieSeries *series21 = new QPieSeries();
        QPieSeries *series22 = new QPieSeries();
        QPieSeries *series23 = new QPieSeries();
       query->exec(QString("select * from MonthTradeTypeNumber%1").arg(minMonth+1));
       if(query->first()){


       series21->setName("第一类");
       series21->append("商户消费", query->value(1).toInt());
       series21->append("零钱提现", query->value(5).toInt());





       series22->setName("第二类");
       series22->append("转账", query->value(2).toInt());
       series22->append("转账-退款", query->value(4).toInt());
       series22->append("零钱充值", query->value(8).toInt());



       series23->setName("第三类");
       series23->append("扫二维码付款", query->value(6).toInt());
       series23->append("微信红包", query->value(7).toInt());
       series23->append("其它", query->value(3).toInt());


        }
       DonutBreakdownCharts *donutBreakdown42 = new DonutBreakdownCharts ;
       donutBreakdown42->setAnimationOptions(QChart::AllAnimations);
       donutBreakdown42->setTitle(QString("%1Month交易类型数目表").arg(minMonth+1));
       donutBreakdown42->legend()->setAlignment(Qt::AlignRight);
       donutBreakdown42->addBreakdownSeries(series21, Qt::red);
       donutBreakdown42->addBreakdownSeries(series22, Qt::darkGreen);
       donutBreakdown42->addBreakdownSeries(series23, Qt::darkBlue);


       return   donutBreakdown42;
         }



         else if (Month==QString("%1Month").arg(maxMonth-1)) {



       QPieSeries *series31 = new QPieSeries();
       QPieSeries *series32 = new QPieSeries();
       QPieSeries *series33 = new QPieSeries();
      query->exec(QString("select * from MonthTradeTypeNumber%1").arg(maxMonth-1));
      if(query->first()){


      series31->setName("第一类");
      series31->append("商户消费", query->value(1).toInt());
      series31->append("零钱提现", query->value(5).toInt());





      series32->setName("第二类");
      series32->append("转账", query->value(2).toInt());
      series32->append("转账-退款", query->value(4).toInt());
      series32->append("零钱充值", query->value(8).toInt());



      series33->setName("第三类");
      series33->append("扫二维码付款", query->value(6).toInt());
      series33->append("微信红包", query->value(7).toInt());
      series33->append("其它", query->value(3).toInt());


       }
      DonutBreakdownCharts *donutBreakdown43 =new DonutBreakdownCharts;
      donutBreakdown43->setAnimationOptions(QChart::AllAnimations);
      donutBreakdown43->setTitle(QString("%1Month交易类型数目表").arg(maxMonth-1));
      donutBreakdown43->legend()->setAlignment(Qt::AlignRight);
      donutBreakdown43->addBreakdownSeries(series31, Qt::red);
      donutBreakdown43->addBreakdownSeries(series32, Qt::darkGreen);
      donutBreakdown43->addBreakdownSeries(series33, Qt::darkBlue);

      return donutBreakdown43;
         }



         else if (Month==QString("%1Month").arg(maxMonth)) {



      QPieSeries *series40 = new QPieSeries();
      QPieSeries *series41 = new QPieSeries();
      QPieSeries *series42 = new QPieSeries();
     query->exec(QString("select * from MonthTradeTypeNumber%1").arg(maxMonth));
     if(query->first()){


     series40->setName("第一类");
     series40->append("商户消费", query->value(1).toInt());
     series40->append("零钱提现", query->value(5).toInt());





     series41->setName("第二类");
     series41->append("转账", query->value(2).toInt());
     series41->append("转账-退款", query->value(4).toInt());
     series41->append("零钱充值", query->value(8).toInt());



     series42->setName("第三类");
     series42->append("扫二维码付款", query->value(6).toInt());
     series42->append("微信红包", query->value(7).toInt());
     series42->append("其它", query->value(3).toInt());


      }
     DonutBreakdownCharts *donutBreakdown44 =new DonutBreakdownCharts;
     donutBreakdown44->setAnimationOptions(QChart::AllAnimations);
     donutBreakdown44->setTitle(QString("%1Month交易类型数目表").arg(maxMonth));
     donutBreakdown44->legend()->setAlignment(Qt::AlignRight);
     donutBreakdown44->addBreakdownSeries(series40, Qt::red);
     donutBreakdown44->addBreakdownSeries(series41, Qt::darkGreen);
     donutBreakdown44->addBreakdownSeries(series42, Qt::darkBlue);



         return  donutBreakdown44;
         }




         else {


     QPieSeries *series50 = new QPieSeries();
     QPieSeries *series51 = new QPieSeries();
     QPieSeries *series52 = new QPieSeries();
 bool str =   query->exec(QString("select * from MonthTradeTypeNumberall%1").arg(Months));
 qDebug()<<str;
    if(query->first()){


    series50->setName("第一类");
    series50->append("商户消费", query->value(1).toInt());
    series50->append("零钱提现", query->value(5).toInt());





    series51->setName("第二类");
    series51->append("转账", query->value(2).toInt());
    series51->append("转账-退款", query->value(4).toInt());
    series51->append("零钱充值", query->value(8).toInt());



    series52->setName("第三类");
    series52->append("扫二维码付款", query->value(6).toInt());
    series52->append("微信红包", query->value(7).toInt());
    series52->append("其它", query->value(3).toInt());



    qDebug()<<"123111111111"<<"总表数据"<<query->value(1).toInt()<<query->value(5).toInt();
     }
    DonutBreakdownCharts *donutBreakdown45 = new DonutBreakdownCharts;
    donutBreakdown45->setAnimationOptions(QChart::AllAnimations);
    donutBreakdown45->setTitle(QString("总交易类型数目表"));
    donutBreakdown45->legend()->setAlignment(Qt::AlignRight);
    donutBreakdown45->addBreakdownSeries(series50, Qt::red);
    donutBreakdown45->addBreakdownSeries(series51, Qt::darkGreen);
    donutBreakdown45->addBreakdownSeries(series52, Qt::darkBlue);


       return donutBreakdown45;

     }
    }


}
}

DataTable ThemeWidget::generateRandomData(int listCount, int valueMax, int valueCount) const
{
    DataTable dataTable;

    // set seed for random stuff
    qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));

    // generate random data
    for (int i(0); i < listCount; i++) {
        DataList dataList;
        qreal yValue(0);
        for (int j(0); j < valueCount; j++) {
            yValue = yValue + (qreal)(qrand() % valueMax) / (qreal) valueCount;
            QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
                          yValue);
            QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
            dataList << Data(value, label);
        }
        dataTable << dataList;
    }

    return dataTable;
}

QComboBox *ThemeWidget::createThemeBox() const
{

 // settings layout
    QComboBox *themeComboBox = new QComboBox();
    themeComboBox->addItem("Light", QChart::ChartThemeLight);
    themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
    themeComboBox->addItem("Dark", QChart::ChartThemeDark);
    themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
    themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
    themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
    themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
    themeComboBox->addItem("Qt", QChart::ChartThemeQt);
    return themeComboBox;
}

QComboBox *ThemeWidget::createAnimationBox(int minMonth, int maxMonth, int Months) const
{
    // settings layout
    switch(Months){


    case(1):{
        int a1 = 11;



        QComboBox *themeComboBox = new QComboBox();
        themeComboBox->addItem(QString("%1Month").arg(minMonth), a1);
       // qDebug()<<"11""createThemeBox";
        return themeComboBox;


    }
    case(2):{
        int b1 = 21,b2 = 22,b3 = 23;


        QComboBox *themeComboBox = new QComboBox();
        themeComboBox->addItem(QString("%1Month").arg(minMonth), b1);
        themeComboBox->addItem(QString("%1Month").arg(maxMonth), b2);
        themeComboBox->addItem("AllMonth", b3);
         return themeComboBox;

         }
    case(3):{
        int c1 = 31,c2 = 32,c3 = 33,c4 = 34;
        QComboBox *themeComboBox = new QComboBox();
        themeComboBox->addItem(QString("%1Month").arg(minMonth), c1);
        themeComboBox->addItem(QString("%1Month").arg(minMonth+1), c2);
        themeComboBox->addItem(QString("%1Month").arg(maxMonth), c3);
        themeComboBox->addItem("AllMonth", c4);
        return themeComboBox;
             }

    case(4):{

        qDebug()<<"123123";
        int d1 = 41,d2 = 42,d3 = 43,d4 = 44,d5 = 45;
        QComboBox *themeComboBox = new QComboBox();
        themeComboBox->addItem(QString("%1Month").arg(minMonth), d1);
        themeComboBox->addItem(QString("%1Month").arg(minMonth+1), d2);
        themeComboBox->addItem(QString("%1Month").arg(maxMonth-1), d3);
        themeComboBox->addItem(QString("%1Month").arg(maxMonth), d4);
        themeComboBox->addItem("AllMonth", d5);
        return themeComboBox;


              }

    }
}







void ThemeWidget::updateUI()
{
    QChart::ChartTheme theme = static_cast<QChart::ChartTheme>(
                m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt());

    const auto charts = m_charts;
    if (m_charts.at(0)->chart()->theme() != theme) {
        for (QChartView *chartView : charts)
            chartView->chart()->setTheme(theme);

        QPalette pal = window()->palette();
        if (theme == QChart::ChartThemeLight) {
            pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        } else if (theme == QChart::ChartThemeDark) {
            pal.setColor(QPalette::Window, QRgb(0x121218));
            pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
        } else if (theme == QChart::ChartThemeBlueCerulean) {
            pal.setColor(QPalette::Window, QRgb(0x40434a));
            pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
        } else if (theme == QChart::ChartThemeBrownSand) {
            pal.setColor(QPalette::Window, QRgb(0x9e8965));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        } else if (theme == QChart::ChartThemeBlueNcs) {
            pal.setColor(QPalette::Window, QRgb(0x018bba));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        } else if (theme == QChart::ChartThemeHighContrast) {
            pal.setColor(QPalette::Window, QRgb(0xffab03));
            pal.setColor(QPalette::WindowText, QRgb(0x181818));
        } else if (theme == QChart::ChartThemeBlueIcy) {
            pal.setColor(QPalette::Window, QRgb(0xcee7f0));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        } else {
            pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        }
        window()->setPalette(pal);
    }

    bool checked = m_antialiasCheckBox->isChecked();
    for (QChartView *chart : charts)
        chart->setRenderHint(QPainter::Antialiasing, checked);

    QChart::AnimationOptions options(
                m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
    if (m_charts.at(0)->chart()->animationOptions() != options) {
        for (QChartView *chartView : charts)
            chartView->chart()->setAnimationOptions(options);
    }


}

 

 

发布了4 篇原创文章 · 获赞 0 · 访问量 615
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览