src/EditMisc.cpp

changeset 292
b6ec2e275736
parent 90
2396457a8167
child 385
09af9f46518f
equal deleted inserted replaced
291:daa667c1ad6d 292:b6ec2e275736
48 query.prepare("SELECT * FROM inventory_miscs WHERE record = :recno"); 48 query.prepare("SELECT * FROM inventory_miscs WHERE record = :recno");
49 query.bindValue(":recno", id); 49 query.bindValue(":recno", id);
50 query.exec(); 50 query.exec();
51 query.next(); 51 query.next();
52 52
53 ui->nameEdit->setText(query.value(1).toString()); 53 ui->nameEdit->setText(query.value("name").toString());
54 ui->typeEdit->setCurrentIndex(query.value(2).toInt()); 54 ui->typeEdit->setCurrentIndex(query.value("type").toInt());
55 ui->useEdit->setCurrentIndex(query.value(3).toInt()); 55 ui->useEdit->setCurrentIndex(query.value("use_use").toInt());
56 ui->timeEdit->setValue(query.value(4).toInt()); 56 ui->timeEdit->setValue(query.value("time").toInt());
57 ui->isweightEdit->setChecked(query.value(5).toInt() ? true:false); 57 ui->isweightEdit->setChecked(query.value("amount_is_weight").toInt() ? true:false);
58 ui->useforEdit->setPlainText(query.value(6).toString()); 58 ui->useforEdit->setPlainText(query.value("use_for").toString());
59 ui->notesEdit->setPlainText(query.value(7).toString()); 59 ui->notesEdit->setPlainText(query.value("notes").toString());
60 ui->alwaysEdit->setChecked(query.value(8).toInt() ? true:false); 60 ui->alwaysEdit->setChecked(query.value("always_on_stock").toInt() ? true:false);
61 ui->inventoryEdit->setValue(query.value(9).toDouble()); 61 ui->inventoryEdit->setValue(query.value("inventory").toDouble() * 1000.0);
62 ui->costEdit->setValue(query.value(10).toDouble()); 62 ui->costEdit->setValue(query.value("cost").toDouble());
63 ui->valueEdit->setValue(query.value(9).toDouble() * query.value(10).toDouble()); 63 ui->valueEdit->setValue(query.value("inventory").toDouble() * query.value("cost").toDouble());
64 if (query.value(11).toString().length() == 10) { 64 if (query.value("production_date").toString().length() == 10) {
65 ui->prodEdit->setDate(query.value(11).toDate()); 65 ui->prodEdit->setDate(query.value("production_date").toDate());
66 } else { 66 } else {
67 ui->prodEdit->clear(); 67 ui->prodEdit->clear();
68 } 68 }
69 if (query.value(12).toString().length() == 10) { 69 if (query.value("tht_date").toString().length() == 10) {
70 ui->thtEdit->setDate(query.value(12).toDate()); 70 ui->thtEdit->setDate(query.value("tht_date").toDate());
71 } else { 71 } else {
72 ui->thtEdit->clear(); 72 ui->thtEdit->clear();
73 } 73 }
74 } else { 74 } else {
75 /* Set some defaults */ 75 /* Set some defaults */
77 ui->useEdit->setCurrentIndex(0); 77 ui->useEdit->setCurrentIndex(0);
78 ui->timeEdit->setValue(0); 78 ui->timeEdit->setValue(0);
79 ui->prodEdit->clear(); 79 ui->prodEdit->clear();
80 ui->thtEdit->clear(); 80 ui->thtEdit->clear();
81 } 81 }
82 UnitSet();
82 TimeSet(); 83 TimeSet();
83 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditMisc::is_changed); 84 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditMisc::is_changed);
84 connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditMisc::is_changed); 85 connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditMisc::is_changed);
85 connect(ui->useEdit, &QComboBox::currentTextChanged, this, &EditMisc::is_changed); 86 connect(ui->useEdit, &QComboBox::currentTextChanged, this, &EditMisc::is_changed);
86 connect(ui->timeEdit, &QSpinBox::textChanged, this, &EditMisc::time_changed); 87 connect(ui->timeEdit, &QSpinBox::textChanged, this, &EditMisc::time_changed);
87 connect(ui->isweightEdit, &QCheckBox::stateChanged, this, &EditMisc::is_changed); 88 connect(ui->isweightEdit, &QCheckBox::stateChanged, this, &EditMisc::weight_changed);
88 connect(ui->useforEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); 89 connect(ui->useforEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
89 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); 90 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
90 connect(ui->alwaysEdit, &QCheckBox::stateChanged, this, &EditMisc::is_changed); 91 connect(ui->alwaysEdit, &QCheckBox::stateChanged, this, &EditMisc::is_changed);
91 connect(ui->inventoryEdit, &QDoubleSpinBox::textChanged, this, &EditMisc::is_changed); 92 connect(ui->inventoryEdit, &QDoubleSpinBox::textChanged, this, &EditMisc::is_changed);
92 connect(ui->costEdit, &QDoubleSpinBox::textChanged, this, &EditMisc::is_changed); 93 connect(ui->costEdit, &QDoubleSpinBox::textChanged, this, &EditMisc::is_changed);
93 connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditMisc::is_changed); 94 connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditMisc::is_changed);
95 connect(ui->prodButton1, SIGNAL(clicked()), this, SLOT(prod_date_today()));
96 connect(ui->prodButton2, SIGNAL(clicked()), this, SLOT(prod_date_clear()));
94 connect(ui->thtEdit, &QDateEdit::dateChanged, this, &EditMisc::is_changed); 97 connect(ui->thtEdit, &QDateEdit::dateChanged, this, &EditMisc::is_changed);
98 connect(ui->thtButton1, SIGNAL(clicked()), this, SLOT(tht_date_today()));
99 connect(ui->thtButton2, SIGNAL(clicked()), this, SLOT(tht_date_clear()));
95 100
96 ui->saveButton->setEnabled(false); 101 ui->saveButton->setEnabled(false);
97 ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && id >= 0) ? true:false); 102 ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && id >= 0) ? true:false);
98 } 103 }
99 104
206 this->close(); 211 this->close();
207 this->setResult(1); 212 this->setResult(1);
208 } 213 }
209 214
210 215
216 void EditMisc::UnitSet()
217 {
218 if (ui->isweightEdit->isChecked()) {
219 ui->inventoryEdit->setSuffix(tr(" gr"));
220 } else {
221 ui->inventoryEdit->setSuffix(tr(" ml"));
222 }
223 }
224
225
211 void EditMisc::TimeSet() 226 void EditMisc::TimeSet()
212 { 227 {
213 int time = ui->timeEdit->value(); 228 int time = ui->timeEdit->value();
214 QString w = QString(""); 229 QString w = QString("");
215 230
252 } 267 }
253 268
254 269
255 void EditMisc::is_changed() 270 void EditMisc::is_changed()
256 { 271 {
257 ui->valueEdit->setValue(ui->inventoryEdit->value() * ui->costEdit->value()); 272 ui->valueEdit->setValue((ui->inventoryEdit->value() / 1000.0) * ui->costEdit->value());
258 ui->saveButton->setEnabled(true); 273 ui->saveButton->setEnabled(true);
259 ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && this->recno >= 0) ? true:false); 274 ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && this->recno >= 0) ? true:false);
260 this->textIsChanged = true; 275 this->textIsChanged = true;
261 WindowTitle(); 276 WindowTitle();
277 }
278
279
280 void EditMisc::weight_changed()
281 {
282 UnitSet();
283 is_changed();
262 } 284 }
263 285
264 286
265 void EditMisc::time_changed() 287 void EditMisc::time_changed()
266 { 288 {
286 } 308 }
287 309
288 this->close(); 310 this->close();
289 this->setResult(1); 311 this->setResult(1);
290 } 312 }
313
314
315 void EditMisc::prod_date_clear()
316 {
317 ui->prodEdit->setDate(QDate());
318 is_changed();
319 }
320
321
322 void EditMisc::prod_date_today()
323 {
324 ui->prodEdit->setDate(QDate::currentDate());
325 is_changed();
326 }
327
328
329 void EditMisc::tht_date_clear()
330 {
331 ui->thtEdit->setDate(QDate());
332 is_changed();
333 }
334
335
336 void EditMisc::tht_date_today()
337 {
338 ui->thtEdit->setDate(QDate::currentDate());
339 is_changed();
340 }
341
342

mercurial