Cont. DB project ------ An Online Retail DB APP

9 篇文章 1 订阅
8 篇文章 1 订阅

Cont.

在这里插入图片描述

Shop 之 查询show

def show_shops():
   cursor,db=connect_database()
   sql = "SELECT * FROM shop"
   results=""
   try:

      cursor.execute(sql)

      results = cursor.fetchall()
      for row in results:
         location = row[0]
         rating = row[1]
         shopName = row[2]
         id = row[3]

         print ("location=%s,rating=%s,shopName=%s,shopID=%s" % \
                (location,rating,shopName,id ))
   except:
      print ("Error: unable to fetch data")
   db.close()
   return results

Shop 之 添加

def addShop(shopMessage):
   cursor,db=connect_database()
   shopMessage=shopMessage.split(',')
   location=shopMessage[0]
   rating=shopMessage[1]
   shopName=shopMessage[2]
   shopID=shopMessage[3]

   sql= f"INSERT INTO shop\
         VALUES('{location}','{rating}','{shopName}','{shopID}');"
   print(sql)
   try:
      cursor.execute(sql)
      db.commit()
   except:
      print("insert error")
      db.rollback()
      return "insert error"

   db.close()
   return "insert success"

UI Button

class Main(QMainWindow):
    def __init__(self):
        super(Main, self).__init__()



        self.userId = None
        # build ui
        self.ui = Ui_Order_management_system()
        self.ui.setupUi(self)
        #show all shops
        self.ui.showShops_button.clicked.connect(self.show_shops_button)
        #add a shop
        self.ui.addShop_button.clicked.connect(self.getShopMessage)

Show shop button

  def show_shops_button(self):
        #clean this widget
        self.ui.shopManagement_table.setRowCount(0)
        #set widget colummn as 4
        self.ui.shopManagement_table.setColumnCount(4)
        self.ui.shopManagement_table.setHorizontalHeaderLabels(['Location','Rating','ShopName','ShopId'])
        #Horizontal autofill
        self.ui.shopManagement_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        items = functions.show_shops()

        for i in range(len(items)):
            item = items[i]
            row = self.ui.shopManagement_table.rowCount()
            self.ui.shopManagement_table.insertRow(row)
            for j in range(len(item)):
                item = QTableWidgetItem(str(items[i][j]))
                self.ui.shopManagement_table.setItem(row, j, item)

Show shop message

 def getShopMessage(self):
        text, ok = QInputDialog.getText(self, 'Text Input Dialog', 'input shop message format as (location,rating,shopName,shopID)')
        shopMessage=""
        if ok and text:
            shopMessage=str(text)
        message=functions.addShop(shopMessage)
        QMessageBox.about(self, "Message", message)

Summary:

  • show_shop_button按钮 & 函数
  • shop_add_button按钮 & 函数
  • show_shop function 函数
  • shop_add function 函数

未完待续……

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cmy_CTO

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值