DIY水果店收银软件

时间:2021-01-15 22:59:02

先前在水果店买单,看见人家是通过将水果编码,结账的时候输入水果的ID就可以了。其实这个软件不难,主要就是UI+逻辑实现+database,于是自己就动手写了个。

One------UI界面:

client.py:

# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(488, 435)
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(20, 40, 75, 23))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.lineEdit = QtGui.QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(100, 40, 311, 21))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        self.listWidget = QtGui.QListWidget(Dialog)
        self.listWidget.setGeometry(QtCore.QRect(170, 90, 281, 241))
        self.listWidget.setObjectName(_fromUtf8("listWidget"))
        self.pushButton_2 = QtGui.QPushButton(Dialog)
        self.pushButton_2.setGeometry(QtCore.QRect(90, 90, 75, 23))
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.pushButton_3 = QtGui.QPushButton(Dialog)
        self.pushButton_3.setGeometry(QtCore.QRect(20, 370, 75, 23))
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.lineEdit_2 = QtGui.QLineEdit(Dialog)
        self.lineEdit_2.setGeometry(QtCore.QRect(110, 370, 113, 20))
        self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
        self.pushButton_4 = QtGui.QPushButton(Dialog)
        self.pushButton_4.setGeometry(QtCore.QRect(310, 370, 75, 23))
        self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("收银", "收银", None))
        self.pushButton.setText(_translate("Dialog", "编号:", None))
        self.pushButton_2.setText(_translate("Dialog", "已点:", None))
        self.pushButton_3.setText(_translate("Dialog", "总价:", None))
        self.pushButton_4.setText(_translate("Dialog", "确定", None))

DIY水果店收银软件

Two------Database:

  这部分主要是参考前面 《Python抓取CSV文件中数据【V2】

DIY水果店收银软件

Three------逻辑实现:

readerprice.py:

def readerprice(IDnum):
        try:
                mycon = pymysql.connect(host='127.0.0.1', user='******', passwd='******',
                                        db='fruits', port=3306, charset='utf8')
                mycur =mycon.cursor()
                mycur.execute('select * from friuts where(`friuts`.`ID` =  \'' + str(IDnum) + '\')')
                mydata = mycur.fetchall()
                mycon.commit()
                for data in mydata:
                    _name = data[0]
                    _singleprice = data[2]
                    return [_name, _singleprice]
        except Exception as e:
                print (e)
        finally:
                mycon.close()

cashier.py:

# -*- coding: utf-8 -*-
from client import *
from PyQt4 import QtCore,QtGui
import sys
from readerprice import *

totalprice = 0


class Cashier(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.show_isadded)
        self.show_isadded()
        self.ui.lineEdit_2.setText('')
        QtCore.QObject.connect(self.ui.pushButton_4, QtCore.SIGNAL('clicked()'), self.allprice)
        self.allprice()

    def show_isadded(self):
        if len(self.ui.lineEdit.text()) != 0:
                global totalprice
                idnum = int(self.ui.lineEdit.text())
                name, singleprice = readerprice(idnum)
                totalprice = totalprice + singleprice
                additm = name + "---" + str(idnum) + "---" + str(singleprice)
                self.ui.listWidget.addItem(additm)
                self.ui.lineEdit.setText('')
                self.ui.lineEdit.setFocus()

    def allprice(self):
        self.ui.lineEdit_2.setText(str(totalprice))


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    mm = Cashier()
    mm.show()
    sys.exit(app.exec_())


Results:

DIY水果店收银软件