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.
 
 
 

92 lines
2.5 KiB

  1. #include "gestionmagasinsdialog.h"
  2. #include "ui_gestionmagasinsdialog.h"
  3. #include <QDir>
  4. #include <QFile>
  5. #include <QtXml>
  6. #include <QInputDialog>
  7. GestionMagasinsDialog::GestionMagasinsDialog(QWidget *parent) :
  8. QDialog(parent),
  9. ui(new Ui::GestionMagasinsDialog)
  10. {
  11. ui->setupUi(this);
  12. QDir dir(QDir::homePath()+"/.deuchnord-hermes");
  13. if(!dir.exists())
  14. dir.mkdir(QDir::homePath()+"/.deuchnord-hermes");
  15. QFile fichierMagasins(QDir::homePath()+"/.deuchnord-hermes/manufacturers.xml");
  16. fichierMagasins.open(QFile::ReadOnly);
  17. if(fichierMagasins.isOpen())
  18. {
  19. QString contenuFichier = fichierMagasins.readAll();
  20. fichierMagasins.close();
  21. QDomDocument dom;
  22. dom.setContent(contenuFichier);
  23. QDomElement root = dom.firstChildElement();
  24. QDomElement manufacturer;
  25. QDomNode node = root.firstChild();
  26. while(!node.isNull())
  27. {
  28. manufacturer = node.toElement();
  29. if(manufacturer.tagName() == "manufacturer")
  30. ui->listMagasins->addItem(manufacturer.firstChild().toText().data());
  31. node = node.nextSibling();
  32. }
  33. fichierMagasins.close();
  34. }
  35. ui->listMagasins->setCurrentItem(ui->listMagasins->item(0));
  36. }
  37. void GestionMagasinsDialog::on_btnAjoutMagasin_clicked()
  38. {
  39. ui->listMagasins->addItem(QInputDialog::getText(this, "Ajouter un magasin", "Veuillez entrer le nom du nouveau magasin :"));
  40. }
  41. void GestionMagasinsDialog::on_btnSupprMagasin_clicked()
  42. {
  43. delete ui->listMagasins->currentItem();
  44. }
  45. void GestionMagasinsDialog::on_listMagasins_currentRowChanged()
  46. {
  47. ui->btnSupprMagasin->setEnabled(true);
  48. }
  49. void GestionMagasinsDialog::on_buttonBox_accepted()
  50. {
  51. QDomDocument dom("manufacturers");
  52. QDomElement rootElement = dom.createElement("manufacturers");
  53. dom.appendChild(rootElement);
  54. for(int i = 0; i < ui->listMagasins->count(); i++)
  55. {
  56. QDomElement manufacturer = dom.createElement("manufacturer");
  57. rootElement.appendChild(manufacturer);
  58. QListWidgetItem *item = ui->listMagasins->item(i);
  59. QDomText nomMagasin = dom.createTextNode(item->text());
  60. manufacturer.appendChild(nomMagasin);
  61. }
  62. QFile fileManu(QDir::homePath()+"/.deuchnord-hermes/manufacturers.xml");
  63. if(fileManu.open(QFile::WriteOnly))
  64. {
  65. fileManu.write(dom.toString().toUtf8());
  66. fileManu.close();
  67. }
  68. }
  69. GestionMagasinsDialog::~GestionMagasinsDialog()
  70. {
  71. delete ui;
  72. }