Your warranties manager
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

gestionmagasinsdialog.cpp 3.2 KiB

vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
vor 10 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "gestionmagasinsdialog.h"
  2. #include "ui_gestionmagasinsdialog.h"
  3. #include <QDir>
  4. #include <QFile>
  5. #include <QtXml>
  6. #include <QInputDialog>
  7. #include <QMessageBox>
  8. GestionMagasinsDialog::GestionMagasinsDialog(QWidget *parent) :
  9. QDialog(parent),
  10. ui(new Ui::GestionMagasinsDialog)
  11. {
  12. ui->setupUi(this);
  13. QFile fichierMagasins(QDir::homePath()+"/deuchnord-hermes/manufacturers.xml");
  14. fichierMagasins.open(QFile::ReadOnly);
  15. if(fichierMagasins.isOpen())
  16. {
  17. QString contenuFichier = fichierMagasins.readAll();
  18. fichierMagasins.close();
  19. QDomDocument dom;
  20. dom.setContent(contenuFichier);
  21. QDomElement root = dom.firstChildElement();
  22. QDomElement manufacturer;
  23. QDomNode node = root.firstChild();
  24. while(!node.isNull())
  25. {
  26. manufacturer = node.toElement();
  27. if(manufacturer.tagName() == "manufacturer")
  28. ui->listMagasins->addItem(manufacturer.firstChild().toText().data());
  29. node = node.nextSibling();
  30. }
  31. fichierMagasins.close();
  32. }
  33. ui->listMagasins->setCurrentItem(ui->listMagasins->item(0));
  34. }
  35. void GestionMagasinsDialog::on_btnAjoutMagasin_clicked()
  36. {
  37. QString nom = QInputDialog::getText(this, "Ajouter un magasin", "Veuillez entrer le nom du nouveau magasin :");
  38. if(nom != "")
  39. {
  40. int nb = ui->listMagasins->count();
  41. bool alreadyHere = false;
  42. for(int i = 0; i < nb; i++)
  43. {
  44. QString magasin = ui->listMagasins->item(i)->text();
  45. if(magasin.toLower() == nom.toLower())
  46. alreadyHere = true;
  47. }
  48. if(alreadyHere)
  49. QMessageBox::warning(this, "Ajout impossible", "Le magasin est déjà présent dans la liste !");
  50. else
  51. ui->listMagasins->addItem(nom);
  52. }
  53. }
  54. void GestionMagasinsDialog::on_btnSupprMagasin_clicked()
  55. {
  56. if(QMessageBox::question(this, "Supprimer "+ui->listMagasins->currentItem()->text()+" ?", "Voulez-vous vraiment supprimer ce magasin ?<br />Tous les produits associés perdront cette information, <em>même si vous cliquez sur Annuler plus tard</em>.", QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes)
  57. {
  58. int row = ui->listMagasins->currentRow();
  59. delete ui->listMagasins->currentItem();
  60. emit magasinDeleted(row);
  61. }
  62. }
  63. void GestionMagasinsDialog::on_listMagasins_currentRowChanged()
  64. {
  65. ui->btnSupprMagasin->setEnabled(true);
  66. }
  67. void GestionMagasinsDialog::on_buttonBox_accepted()
  68. {
  69. QDomDocument dom("manufacturers");
  70. QDomElement rootElement = dom.createElement("manufacturers");
  71. dom.appendChild(rootElement);
  72. for(int i = 0; i < ui->listMagasins->count(); i++)
  73. {
  74. QDomElement manufacturer = dom.createElement("manufacturer");
  75. rootElement.appendChild(manufacturer);
  76. QListWidgetItem *item = ui->listMagasins->item(i);
  77. QDomText nomMagasin = dom.createTextNode(item->text());
  78. manufacturer.appendChild(nomMagasin);
  79. }
  80. QFile fileManu(QDir::homePath()+"/deuchnord-hermes/manufacturers.xml");
  81. if(fileManu.open(QFile::WriteOnly))
  82. {
  83. fileManu.write(dom.toString().toUtf8());
  84. fileManu.close();
  85. }
  86. }
  87. GestionMagasinsDialog::~GestionMagasinsDialog()
  88. {
  89. delete ui;
  90. }