0% found this document useful (0 votes)
16 views2 pages

Product Management System Controller

Uploaded by

fofo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Product Management System Controller

Uploaded by

fofo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

from controllers.

productsController import ProductsController


from [Link] import QMessageBox, QTableWidgetItem
#from ui.product_dialog import ProductDialog
from [Link] import Product

class MainController:
def __init__(self,view):
[Link] = view
self.products_controller = ProductsController() # ‫إنشاء كائن من‬
ProductsController
self.load_products()

# self.categories_controller = CategoriesController()

def load_products(self):
products = self.products_controller.load_products()
[Link](0)
for row, product in enumerate(products):
[Link](row)
[Link](row, 1,
QTableWidgetItem([Link]))
[Link](row, 2,
QTableWidgetItem(str([Link])))
# ‫ تخزين‬ProductID ‫في عمود غير مرئي (يمكنك استخدام طريقة مختلفة للتخزين إذا‬
)‫لزم الأمر‬
[Link](row, 0,
QTableWidgetItem(str([Link])))

def add_product(self):
row_count = [Link]()
# ‫إضافة عمود جديد‬
[Link](row_count)

def save_product(self):
for row in range([Link]()):
column1 = [Link](row, 1).text()
column2 = [Link](row, 2).text()
product = Product(ProductName=column1,price=column2)
confirm_addProduct = [Link]([Link], 'Confirm Deletion',
f'‫{ هل انت متأكد انك تريد اضافة‬column1} ‫'؟‬,
[Link] | [Link], [Link])
if confirm_addProduct == [Link]:
self.products_controller.add_product(product)
self.load_products()

def update_product(self):
print('update data')
row = [Link]()
if row >= 0:
product_id = float([Link](row, 0).text())
product_name = [Link](row, 1).text()
price = float([Link](row, 2).text())

# ‫ العثور على‬ProductID ‫ بناًء على‬ProductName

#product_id =
self.products_controller.find_product_id_by_name(product_name)
#if product_id is not None:
product = Product( ProductID=product_id, ProductName=product_name,
price=price)

confirm_update = [Link]([Link], 'Confirm Update',


f'‫هل انت متأكد انك تريد تحديث‬
{product_name} ‫'؟‬,
[Link] | [Link],
[Link])
if confirm_update == [Link]:
self.products_controller.update_product(product)
self.load_products()

def delete_product(self):
row = [Link]()
product_name = [Link](row, 1).text()
confirm_delete = [Link]([Link], 'Confirm Deletion',
f'‫هل انت متأكد انك تريد حذف‬
{product_name} ‫'؟‬,
[Link] | [Link],
[Link])
if confirm_delete == [Link]:
self.products_controller.delete_product(product_name)
self.load_products()

You might also like