44 ui->webEdit->setText(query.value(6).toString()); |
42 ui->webEdit->setText(query.value(6).toString()); |
45 ui->emailEdit->setText(query.value(7).toString()); |
43 ui->emailEdit->setText(query.value(7).toString()); |
46 ui->phoneEdit->setText(query.value(8).toString()); |
44 ui->phoneEdit->setText(query.value(8).toString()); |
47 ui->notesEdit->setPlainText(query.value(9).toString()); |
45 ui->notesEdit->setPlainText(query.value(9).toString()); |
48 } |
46 } |
49 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(onTextChanged())); |
47 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); |
|
48 connect(ui->addressEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); |
|
49 connect(ui->cityEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); |
|
50 connect(ui->zipEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); |
|
51 connect(ui->countryEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); |
|
52 connect(ui->webEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); |
|
53 connect(ui->emailEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); |
|
54 connect(ui->phoneEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); |
|
55 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); |
50 } |
56 } |
51 |
57 |
52 |
58 |
53 EditSupplier::~EditSupplier() |
59 EditSupplier::~EditSupplier() |
54 { |
60 { |
56 delete ui; |
62 delete ui; |
57 emit entry_changed(); |
63 emit entry_changed(); |
58 } |
64 } |
59 |
65 |
60 |
66 |
|
67 /* |
|
68 * Window header, mark any change with '**' |
|
69 */ |
|
70 void EditSupplier::WindowTitle() |
|
71 { |
|
72 QString txt; |
|
73 |
|
74 if (this->recno < 0) { |
|
75 txt = QString(tr("BMSapp - Add new supplier")); |
|
76 } else { |
|
77 txt = QString(tr("BMSapp - Edit supplier %1").arg(this->recno)); |
|
78 } |
|
79 |
|
80 if (this->textIsChanged) { |
|
81 txt.append((QString(" **"))); |
|
82 } |
|
83 setWindowTitle(txt); |
|
84 } |
|
85 |
|
86 |
61 void EditSupplier::onOKButtonClicked() |
87 void EditSupplier::onOKButtonClicked() |
62 { |
88 { |
63 QSqlQuery query; |
89 QSqlQuery query; |
64 bool modified, valid; |
|
65 |
90 |
66 /* The notes field uses a signal textChanged() */ |
|
67 modified = (ui->nameEdit->isModified() || ui->addressEdit->isModified() || ui->cityEdit->isModified() || |
|
68 ui->zipEdit->isModified() || ui->countryEdit->isModified() || ui->webEdit->isModified() || |
|
69 ui->emailEdit->isModified() || ui->phoneEdit->isModified() || this->textIsChanged); |
|
70 |
|
71 valid = true; |
|
72 /* If there are errors in the form, show a message and do "return;" */ |
91 /* If there are errors in the form, show a message and do "return;" */ |
73 if (ui->nameEdit->text().length() < 2) { |
92 if (ui->nameEdit->text().length() < 2) { |
74 // QMessageBox msgBox; |
93 QMessageBox::warning(this, tr("Edit Supplier"), tr("Name empty or too short.")); |
75 // msgBox.setText("Name empty or too short."); |
|
76 // msgBox.exec(); |
|
77 return; |
94 return; |
78 } |
95 } |
79 |
96 |
80 if (modified && valid) { |
97 if (this->textIsChanged) { |
81 qDebug() << "EditSupplier do SQL"; |
|
82 if (this->recno == -1) { |
98 if (this->recno == -1) { |
83 query.prepare("INSERT INTO inventory_suppliers SET name = :name, address = :address, city = :city, zip = :zip, " |
99 query.prepare("INSERT INTO inventory_suppliers SET name = :name, address = :address, city = :city, zip = :zip, " |
84 "country = :country, website = :web, email = :email, phone = :phone, notes = :notes, uuid = :uuid"); |
100 "country = :country, website = :web, email = :email, phone = :phone, notes = :notes, uuid = :uuid"); |
85 } else { |
101 } else { |
86 query.prepare("UPDATE inventory_suppliers SET name = :name, address = :address, city = :city, zip = :zip, " |
102 query.prepare("UPDATE inventory_suppliers SET name = :name, address = :address, city = :city, zip = :zip, " |
100 } else { |
116 } else { |
101 query.bindValue(":recno", this->recno); |
117 query.bindValue(":recno", this->recno); |
102 } |
118 } |
103 query.exec(); |
119 query.exec(); |
104 if (query.lastError().isValid()) { |
120 if (query.lastError().isValid()) { |
105 qDebug() << query.lastError(); |
121 qDebug() << "EditSupplier" << query.lastError(); |
|
122 QMessageBox::warning(this, tr("Database error"), |
|
123 tr("MySQL error: %1\n%2\n%3") |
|
124 .arg(query.lastError().nativeErrorCode()) |
|
125 .arg(query.lastError().driverText()) |
|
126 .arg(query.lastError().databaseText())); |
|
127 } else { |
|
128 qDebug() << "EditSupplier Saved"; |
106 } |
129 } |
107 |
130 |
108 this->close(); |
131 this->close(); |
109 this->setResult(1); |
132 this->setResult(1); |
110 } else { |
133 } else { |