コード例 #1
0
  public void editUser(String name, String password, String rights) throws InvalidPacketException {
    QByteArray data = new QByteArray();
    QByteArray value = new QByteArray(name + "\n" + password + "\n" + rights);
    QDataStream s = new QDataStream(data, QIODevice.OpenModeFlag.WriteOnly);

    s.writeInt(value.length());
    data.append(value);
    data.prepend(USER);

    sendData(data);

    while (socket.bytesAvailable() < 1) socket.waitForReadyRead(10000);

    if (socket.read(1).at(0) != 4) throw new InvalidPacketException();
  }
コード例 #2
0
  public void editProduct(String pId, String pName, String pPrice) throws InvalidPacketException {
    QByteArray data = new QByteArray();
    QByteArray value = new QByteArray(pId + "\n" + pName + "\n" + pPrice);
    QDataStream s = new QDataStream(data, QIODevice.OpenModeFlag.WriteOnly);

    s.writeInt(value.length());
    data.append(value);
    data.prepend(PRODUCT);

    sendData(data);

    while (socket.bytesAvailable() < 1) socket.waitForReadyRead(10000);

    if (socket.read(1).at(0) != 4) throw new InvalidPacketException();
  }
コード例 #3
0
  public String addVoucher(double value) throws InvalidPacketException {
    QByteArray data = new QByteArray();
    QByteArray v = new QByteArray(value + "");
    QDataStream s = new QDataStream(data, QIODevice.OpenModeFlag.WriteOnly);

    s.writeInt(v.length());
    data.append(v);
    data.prepend(VOUCHER);

    sendData(data);

    while (socket.bytesAvailable() < 5) // int
    socket.waitForReadyRead(10000);

    if (socket.read(1).at(0) != 4) throw new InvalidPacketException();

    int length = (new QDataStream(socket)).readInt();
    while (socket.bytesAvailable() < length) socket.waitForReadyRead(10000);

    return socket.read(length).toString();
  }