#include "mainForm.h"
#include "ui_mainForm.h"
#include <QTcpSocket>
#include <QDebug>

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

    ui->host->setText("127.0.0.1");
    ui->port->setText("34953");

    ui->sendData->setText(R"({"fm_cmd": "put_store_info","fm_ver": "1.0","store_info":{"operator_id": "00000002","pos_id": "1","store_id": "208888","business_date": "20150701"}})");
}

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

void MainForm::on_btnSendData_clicked()
{
    QTcpSocket socket;
    socket.connectToHost(ui->host->text(), ui->port->text().toInt());

    if(socket.waitForConnected())
    {
        socket.write(ui->sendData->toPlainText().toLatin1());
        if(socket.waitForBytesWritten())
        {
            if(socket.waitForReadyRead())
            {
                ui->label->setText(QString(socket.readAll()));
            }
        }
    }
}
