Your warranties manager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gestionmagasinsdialog.cpp 3.0 KiB

10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
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. QDir dir(QDir::homePath()+"/.deuchnord-hermes");
  14. if(!dir.exists())
  15. dir.mkdir(QDir::homePath()+"/.deuchnord-hermes");
  16. QFile fichierMagasins(QDir::homePath()+"/.deuchnord-hermes/manufacturers.xml");
  17. fichierMagasins.open(QFile::ReadOnly);
  18. if(fichierMagasins.isOpen())
  19. {
  20. QString contenuFichier = fichierMagasins.readAll();
  21. fichierMagasins.close();
  22. QDomDocument dom;
  23. dom.setContent(contenuFichier);
  24. QDomElement root = dom.firstChildElement();
  25. QDomElement manufacturer;
  26. QDomNode node = root.firstChild();
  27. while(!node.isNull())
  28. {
  29. manufacturer = node.toElement();
  30. if(manufacturer.tagName() == "manufacturer")
  31. ui->listMagasins->addItem(manufacturer.firstChild().toText().data());
  32. node = node.nextSibling();
  33. }
  34. fichierMagasins.close();
  35. }
  36. ui->listMagasins->setCurrentItem(ui->listMagasins->item(0));
  37. }
  38. void GestionMagasinsDialog::on_btnAjoutMagasin_clicked()
  39. {
  40. QString nom = QInputDialog::getText(this, "Ajouter un magasin", "Veuillez entrer le nom du nouveau magasin :");
  41. if(nom != "")
  42. {
  43. int nb = ui->listMagasins->count();
  44. bool alreadyHere = false;
  45. for(int i = 0; i < nb; i++)
  46. {
  47. QString magasin = ui->listMagasins->item(i)->text();
  48. if(magasin.toLower() == nom.toLower())
  49. alreadyHere = true;
  50. }
  51. if(alreadyHere)
  52. QMessageBox::warning(this, "Ajout impossible", "Le magasin est déjà présent dans la liste !");
  53. else
  54. ui->listMagasins->addItem(nom);
  55. }
  56. }
  57. void GestionMagasinsDialog::on_btnSupprMagasin_clicked()
  58. {
  59. delete ui->listMagasins->currentItem();
  60. }
  61. void GestionMagasinsDialog::on_listMagasins_currentRowChanged()
  62. {
  63. ui->btnSupprMagasin->setEnabled(true);
  64. }
  65. void GestionMagasinsDialog::on_buttonBox_accepted()
  66. {
  67. QDomDocument dom("manufacturers");
  68. QDomElement rootElement = dom.createElement("manufacturers");
  69. dom.appendChild(rootElement);
  70. for(int i = 0; i < ui->listMagasins->count(); i++)
  71. {
  72. QDomElement manufacturer = dom.createElement("manufacturer");
  73. rootElement.appendChild(manufacturer);
  74. QListWidgetItem *item = ui->listMagasins->item(i);
  75. QDomText nomMagasin = dom.createTextNode(item->text());
  76. manufacturer.appendChild(nomMagasin);
  77. }
  78. QFile fileManu(QDir::homePath()+"/.deuchnord-hermes/manufacturers.xml");
  79. if(fileManu.open(QFile::WriteOnly))
  80. {
  81. fileManu.write(dom.toString().toUtf8());
  82. fileManu.close();
  83. }
  84. }
  85. GestionMagasinsDialog::~GestionMagasinsDialog()
  86. {
  87. delete ui;
  88. }