#include "mainwindow.h"
#include "myhelper.h"
#include <QApplication>
#include <QDebug>
#include "modeller_applog/applog.h" //日志
#include "sqliteassistant/sqliteassistant.h"    //数据库助手
#include "logindlg.h"   //登陆
#include <QProcess>
int LogKeepDay = 0; //日志保存天数,
//读取数据库信息
QString DataBase_ServerIP;
QString DataBase_ServerProt;
QString DataBase_ComName;
QString DataBase_ComBund;

SqliteAssistant *m_SqliteAssistant;

QString getInfo(const QString &cmd)
{
    QProcess p;				//启动外部程序
    p.start(cmd);			//一体式启动，不分离，主程序退出则启动程序退出,使用close关闭
    //p.startDetached(cmd)	//分离式启动，主程序退出后，外部程序继续运行。
    p.waitForFinished(-1);	//超时等待，设置为-1，直到执行完成。
    QString result = QString::fromLocal8Bit(p.readAllStandardOutput());
    QStringList list = cmd.split(" ");
    result = result.remove(list.last(), Qt::CaseInsensitive);
    result = result.replace("\r", "");
    result = result.replace("\n", "");
    result = result.simplified();
    p.close();
    return result;
}
//查询主板唯一标识
QString getBaseboardUuid()
{
     return getInfo("wmic csproduct get uuid");
}
//查询CPU***
QString getCpuProcessorid()
{
     return getInfo("wmic cpu get processorid");
}
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Singleton<AppLog>::getInstance().start();
    Singleton<AppLog>::getInstance().onClearLogFile("./log",LogKeepDay);
    m_SqliteAssistant = new SqliteAssistant();
    if(0!=m_SqliteAssistant->connectSql())
    {
        qDebug()<<"connectSql error";
    }
    else
    {
        qDebug()<<"connectSql ok";
    }
    DataBase_ServerIP = m_SqliteAssistant->Select_SystemConfigInfo("ServerIP");
    DataBase_ServerProt = m_SqliteAssistant->Select_SystemConfigInfo("ServerProt");
    DataBase_ComName = m_SqliteAssistant->Select_SystemConfigInfo("ComName");
    DataBase_ComBund = m_SqliteAssistant->Select_SystemConfigInfo("ComBund");
    qDebug()<<DataBase_ServerIP;
    qDebug()<<DataBase_ServerProt;
    qDebug()<<DataBase_ComName;
    qDebug()<<DataBase_ComBund;
    //qDebug()<<getCpuProcessorid();
    myHelper::SetStyle("blue");
    LoginDlg login;
    login.show();
    return a.exec();
}
