les derniers changements ?
This commit is contained in:
parent
b42b82465a
commit
f388e5e488
@ -10,6 +10,7 @@
|
||||
#include "../errors/stockFull.hpp"
|
||||
#include "../errors/stockEmpty.hpp"
|
||||
#include "../errors/invalidItemType.hpp"
|
||||
#include "../errors/stockExisting.hpp"
|
||||
|
||||
StockController::StockController(AbstractView* view, Model* model) : view(view), model(model)
|
||||
{
|
||||
@ -108,12 +109,27 @@ void StockController::process()
|
||||
case Command::AddItemToStock:
|
||||
// Handle adding items to stock: stockName, itemTypeName, quantity
|
||||
if (commandArgs.size() >= 3) {
|
||||
if (model->getItemTypes().empty()) {
|
||||
view->displayError("❌ Aucun type d'article disponible");
|
||||
break;
|
||||
}
|
||||
if (model->getStocks().empty()) {
|
||||
view->displayError("❌ Aucun stock disponible");
|
||||
break;
|
||||
}
|
||||
std::string stockName = commandArgs[0];
|
||||
std::string itemTypeName = commandArgs[1];
|
||||
int quantity = std::stoi(commandArgs[2]);
|
||||
|
||||
bool success = model->addItemToStock(stockName, itemTypeName, quantity);
|
||||
view->displayAddItemResult(stockName, itemTypeName, quantity, success);
|
||||
|
||||
if (!success) {
|
||||
view->displayError("❌ Échec de l'ajout de l'article");
|
||||
}
|
||||
else{
|
||||
view->displayAddItemResult(stockName, itemTypeName, quantity, success);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case Command::Refresh:
|
||||
@ -204,16 +220,20 @@ void StockController::process()
|
||||
}
|
||||
catch (const StockFull& e) {
|
||||
// Gérer les exceptions et afficher un message d'erreur
|
||||
view->displayError("The Stock is full");
|
||||
view->displayError("❌ Stock plein: " + std::string(e.what()));
|
||||
}
|
||||
catch (const StockEmpty& e) {
|
||||
// Gérer les exceptions et afficher un message d'erreur
|
||||
view->displayError("The Stock is empty");
|
||||
view->displayError("❌ Stock vide: " + std::string(e.what()));
|
||||
}
|
||||
catch (const InvalidItemType& e) {
|
||||
// Gérer les exceptions et afficher un message d'erreur
|
||||
view->displayError("Invalid Item Type: " + std::string(e.what()));
|
||||
}
|
||||
catch (const StockExisting& e) {
|
||||
// Gérer les exceptions et afficher un message d'erreur
|
||||
view->displayError("❌ Stock existant: " + std::string(e.what()));
|
||||
}
|
||||
catch (const std::invalid_argument& e) {
|
||||
// Gérer les erreurs de conversion de chaînes en nombres
|
||||
view->displayError("Invalid argument: " + std::string(e.what()));
|
||||
|
2
src/errors/stockExisting.cpp
Normal file
2
src/errors/stockExisting.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#include "stockExisting.hpp"
|
||||
|
13
src/errors/stockExisting.hpp
Normal file
13
src/errors/stockExisting.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef STOCK_EXISTING_HPP
|
||||
#define STOCK_EXISTING_HPP
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
class StockExisting : public std::runtime_error {
|
||||
public:
|
||||
explicit StockExisting(const std::string& stockName)
|
||||
: std::runtime_error("Le stock '" + stockName + "' existe déjà.") {}
|
||||
};
|
||||
|
||||
#endif // STOCK_EXISTING_HPP
|
@ -1,5 +1,6 @@
|
||||
#include "model.hpp"
|
||||
#include "../errors/stockFull.hpp"
|
||||
#include "../errors/stockExisting.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
Model::Model()
|
||||
@ -19,6 +20,11 @@ void Model::addData(const std::string &data)
|
||||
|
||||
void Model::createStock(const std::string &name, int capacity, const std::string &comment)
|
||||
{
|
||||
if (findStockByName(name))
|
||||
{
|
||||
throw StockExisting(name);
|
||||
}
|
||||
|
||||
Stock newStock(name, capacity, comment, nextStockId++);
|
||||
stocks.push_back(newStock);
|
||||
}
|
||||
@ -37,6 +43,10 @@ void Model::createItemType(const std::string &name, const std::string &comment,
|
||||
|
||||
void Model::createItemType(const std::string &name, int id, const std::string &comment, int size)
|
||||
{
|
||||
if (findItemTypeByName(name))
|
||||
{
|
||||
throw std::invalid_argument("Item type name '" + name + "' already exists");
|
||||
}
|
||||
// Vérifier si l'ID existe déjà
|
||||
for (const auto& existingType : itemTypes) {
|
||||
if (existingType.getId() == id) {
|
||||
@ -98,7 +108,7 @@ bool Model::addItemToStock(const std::string &stockName, const std::string &item
|
||||
|
||||
if (itemType->getSize() * quantity + stock->getCurrentSize() > stock->getCapacity())
|
||||
{
|
||||
throw StockFull("Cannot add items, stock is full");
|
||||
return false; // Stock is full
|
||||
}
|
||||
|
||||
for (int i = 0; i < quantity; ++i)
|
||||
|
@ -79,6 +79,26 @@ ItemType Stock::getItem(int id) const
|
||||
throw std::runtime_error("Item not found");
|
||||
}
|
||||
|
||||
std::map<std::string, std::pair<ItemType, int>> Stock::getItemsWithQuantities() const
|
||||
{
|
||||
std::map<std::string, std::pair<ItemType, int>> itemsWithQuantities;
|
||||
|
||||
for (const auto& item : items) {
|
||||
std::string itemName = item.getName();
|
||||
|
||||
auto it = itemsWithQuantities.find(itemName);
|
||||
if (it != itemsWithQuantities.end()) {
|
||||
// Incrementer la quantité
|
||||
it->second.second++;
|
||||
} else {
|
||||
// Ajouter un nouveau type d'article avec quantité 1
|
||||
itemsWithQuantities.insert({itemName, std::make_pair(item, 1)});
|
||||
}
|
||||
}
|
||||
|
||||
return itemsWithQuantities;
|
||||
}
|
||||
|
||||
// Getters implementation
|
||||
std::string Stock::getName() const
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "itemType.hpp"
|
||||
|
||||
class Stock
|
||||
@ -15,6 +16,7 @@ public:
|
||||
void removeItem(int id);
|
||||
bool removeItem(const ItemType &item); // Nouvelle méthode
|
||||
ItemType getItem(int id) const;
|
||||
std::map<std::string, std::pair<ItemType, int>> getItemsWithQuantities() const;
|
||||
|
||||
// Getters
|
||||
std::string getName() const;
|
||||
|
1355
src/view/qtView.cpp
1355
src/view/qtView.cpp
File diff suppressed because it is too large
Load Diff
@ -69,7 +69,7 @@ private slots:
|
||||
void onDisplayMenuSelected();
|
||||
|
||||
// Application control
|
||||
void onRefresh();
|
||||
// Removed refresh functionality
|
||||
|
||||
// Virtual keyboard slots
|
||||
void onTextFieldFocused();
|
||||
@ -100,24 +100,34 @@ private:
|
||||
QWidget* createTitleAndButtonScreen(const QString& title, const QStringList& buttonTexts, const std::vector<std::function<void()>>& callbacks);
|
||||
QWidget* createFormScreen(const QString& title, const QStringList& labels, const QStringList& placeholders = QStringList());
|
||||
QWidget* createSelectionFormScreen(const QString& title, const QStringList& labels, const QStringList& fieldTypes);
|
||||
QWidget* createTactileQuantityScreen(const QString& title, const QStringList& labels, const QStringList& fieldTypes);
|
||||
QWidget* createStockSelectionScreen();
|
||||
QWidget* createItemTypeSelectionScreen();
|
||||
QWidget* createItemRemovalScreen();
|
||||
QWidget* createItemQuantityRemovalScreen(const QString& stockName, const QString& itemTypeName, int currentQuantity);
|
||||
QWidget* createStockDisplayScreen();
|
||||
QWidget* createItemTypeDisplayScreen();
|
||||
void refreshStockSelectionScreen();
|
||||
void refreshItemTypeSelectionScreen();
|
||||
void refreshItemRemovalScreen();
|
||||
void updateStockDisplayScreen(const std::vector<Stock>& stocks);
|
||||
void updateItemTypeDisplayScreen(const std::vector<ItemType>& itemTypes);
|
||||
void refreshComboBoxes(QWidget* screen);
|
||||
void resetFormFields(QWidget* screen);
|
||||
void confirmStockDeletion(const QString& stockName);
|
||||
void confirmItemTypeDeletion(const QString& itemTypeName);
|
||||
void showQuantityRemovalScreen(const QString& stockName, const QString& itemTypeName, int currentQuantity);
|
||||
void showStockItemsForRemoval(const QString& stockName);
|
||||
void addSuccessMessageToStockScreen(const QString& message);
|
||||
void addSuccessMessageToItemTypeScreen(const QString& message);
|
||||
|
||||
// Form execution methods
|
||||
void executeFormAction(QWidget* screen, const QString& title);
|
||||
void executeCreateStock(const QStringList& values);
|
||||
void executeDeleteStock(const QStringList& values);
|
||||
void executeCreateItemType(const QStringList& values);
|
||||
void executeDeleteItemType(const QStringList& values);
|
||||
void executeAddItem(const QStringList& values);
|
||||
void executeMoveItem(const QStringList& values);
|
||||
void executeRemoveItem(const QStringList& values);
|
||||
void executeShowStockContent(const QStringList& values);
|
||||
|
||||
// Direct action methods (without forms)
|
||||
@ -127,6 +137,8 @@ private:
|
||||
void onShowStatistics();
|
||||
|
||||
// Méthodes pour les notifications (plus de popups)
|
||||
void clearMessages();
|
||||
void displayNotify(const QString& message);
|
||||
void showMessage(const QString& message, bool isError = false);
|
||||
void displayResult(const QString& message); // Méthode pour afficher les résultats
|
||||
|
||||
@ -174,12 +186,15 @@ private:
|
||||
QWidget* m_createItemTypeScreen;
|
||||
QWidget* m_showItemTypesScreen;
|
||||
QWidget* m_deleteItemTypeScreen;
|
||||
QVBoxLayout* m_itemTypeSelectionLayout; // Layout pour les boutons de types d'articles
|
||||
QWidget* m_itemTypeDisplayWidget; // Widget pour l'affichage des types d'articles
|
||||
QVBoxLayout* m_itemTypeDisplayLayout; // Layout pour l'affichage des types d'articles
|
||||
|
||||
QWidget* m_addItemScreen;
|
||||
QWidget* m_moveItemScreen;
|
||||
QWidget* m_removeItemScreen;
|
||||
QWidget* m_removeItemQuantityScreen;
|
||||
QVBoxLayout* m_removeItemLayout; // Layout pour la liste des articles à retirer
|
||||
|
||||
QWidget* m_showStockContentScreen;
|
||||
QWidget* m_showCapacitiesScreen;
|
||||
@ -187,7 +202,6 @@ private:
|
||||
|
||||
// Bottom area
|
||||
QTextEdit* m_outputDisplay;
|
||||
QPushButton* m_refreshButton;
|
||||
|
||||
// Virtual keyboard
|
||||
VirtualKeyboard* m_virtualKeyboard;
|
||||
|
Loading…
x
Reference in New Issue
Block a user