-
Notifications
You must be signed in to change notification settings - Fork 0
/
hlastlots.cpp
157 lines (115 loc) · 4.66 KB
/
hlastlots.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "hlastlots.h"
#include "ui_hlastlots.h"
#include <QSqlDatabase>
#include <QSqlQueryModel>
#include <QSqlQuery>
#include <QSqlTableModel>
#include <QCompleter>
#include <QDebug>
#include <QSqlError>
#include <QMessageBox>
HLastLots::HLastLots(QWidget *parent, QSqlDatabase pdb, double qrecipe, QString product) :
QWidget(parent),
ui(new Ui::HLastLots)
{
ui->setupUi(this);
ui->leQua->setText(QString::number(qrecipe,'f',3));
db=pdb;
ui->cbLastLots->addItem("Tutti",100000);
ui->cbLastLots->addItem("Ultimi 5 lotti",5);
ui->cbLastLots->addItem("Ultimi 10 lotti",10);
ui->cbLastLots->addItem("Ultimi 50 lotti",50);
ui->cbLastLots->setCurrentIndex(1);
ui->cbUI->addItem("KG",1);
ui->cbUI->addItem("Pz.",2);
ui->cbUI->setCurrentIndex(0);
prodModel=new QSqlTableModel(0,db);
prodModel->setTable("prodotti");
prodModel->setFilter("attivo=1 and tipo in(1,2,3,4,5)");
prodModel->setSort(1,Qt::AscendingOrder);
prodModel->select();
ui->cbProducts->setModel(prodModel);
ui->cbProducts->setModelColumn(2);
int row=ui->cbProducts->findText(product);
ui->cbProducts->setCurrentIndex(row);
QCompleter *compprods=new QCompleter();
compprods->setCompletionColumn(2);
compprods->setModel(prodModel);
compprods->setCompletionMode(QCompleter::PopupCompletion);
compprods->setCaseSensitivity(Qt::CaseInsensitive);
ui->cbProducts->setCompleter(compprods);
lastLots();
connect(ui->cbProducts,SIGNAL(currentIndexChanged(int)),this,SLOT(lastLots()));
connect(ui->cbLastLots,SIGNAL(currentIndexChanged(int)),this,SLOT(lastLots()));
}
void HLastLots::lastLots()
{
int prd =ui->cbProducts->model()->index(ui->cbProducts->currentIndex(),0).data(0).toInt();
int quanti=ui->cbLastLots->currentData().toInt();
qDebug()<<"quanti"<<quanti;
QSqlQuery qlots(db);
QSqlQueryModel *qmLots=new QSqlQueryModel(0);
QString sql="select lotdef.ID,lotdef.lot,lotdef.prodotto,prodotti.descrizione,prodotti.allergenico from lotdef,prodotti where lotdef.prodotto=:prd and prodotti.ID=lotdef.prodotto and lotdef.attivo>0 ORDER by data DESC LIMIT :quanti";
qlots.prepare(sql);
qlots.bindValue(":prd",prd);
qlots.bindValue(":quanti",quanti);
qlots.exec();
qDebug()<<qlots.lastError().text()<<"quanti"<<quanti;
qmLots->setQuery(qlots);
ui->lvLastLots->clearSelection();
ui->lvLastLots->setModel(qmLots);
ui->lvLastLots->setModelColumn(1);
ui->lvLastLots->setCurrentIndex(ui->lvLastLots->model()->index(0,0));
}
HLastLots::~HLastLots()
{
delete ui;
}
void HLastLots::on_pushButton_2_clicked()
{
close();
}
void HLastLots::on_pushButton_clicked()
{
int idlotto = ui->lvLastLots->model()->index(ui->lvLastLots->currentIndex().row(),0).data(0).toInt();
QString desclotto=ui->lvLastLots->model()->index(ui->lvLastLots->currentIndex().row(),1).data(0).toString();
QString idprodotto=ui->lvLastLots->model()->index(ui->lvLastLots->currentIndex().row(),2).data(0).toString();
QString descprodotto=ui->lvLastLots->model()->index(ui->lvLastLots->currentIndex().row(),3).data(0).toString();
bool ballergene =ui->lvLastLots->model()->index(ui->lvLastLots->currentIndex().row(),4).data(0).toBool();
bool ok;
double quantitaeff=ui->leQua->text().toDouble(&ok);
if (!ok)
{
QMessageBox::warning(this,QApplication::applicationName(),"Quantità errata!",QMessageBox::Ok);
ui->leQua->setText(QString());
quantitaeff=0.0;
return;
}
QString sallergene;
if(ballergene)
{sallergene="1";}
else
{sallergene="0";}
QStandardItem* sidProdotto=new QStandardItem(idprodotto);
QStandardItem* sdescprodotto=new QStandardItem(descprodotto);
QStandardItem* squaRicetta=new QStandardItem("");
QStandardItem* sidLotto=new QStandardItem(QString::number(idlotto));
QStandardItem* sLotto=new QStandardItem(desclotto);
QStandardItem* quaEff=new QStandardItem(QString::number(quantitaeff,'f',3));
QStandardItem* allergene=new QStandardItem(sallergene);
if(ballergene)
{
sdescprodotto->setForeground(QColor("red"));
sdescprodotto->setIcon(QIcon(":/Resources/Flag-red64.png"));
}
QList<QStandardItem*> list;
list.append(sidProdotto);
list.append(sdescprodotto);
list.append(squaRicetta);
list.append(sidLotto);
list.append(sLotto);
list.append(quaEff);
list.append(allergene);
emit rowAdded(list);
close();
}