<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 431,  comments - 344,  trackbacks - 0
    今天幫叔叔家小弟寫了一個禮盒編號生成器,具體要求如下:


    編碼要求:
    1、編碼中不出現“4”、“3”等不吉利數字,缺碼編號;
    2、賣品第一個字母“L”表示禮盒裝、“B”表示標準裝。第二個字母是“A”到“Z”中的任意字母,可根據編碼需要任意選擇。四位數字為編號;
    3、賣品與贈品區別在于:賣品以“L”或者“B”開頭,贈品以“ZL”或者“ZB”開頭。

    例如:
    賣品禮盒裝編碼  L-A0001  L-D0001等
    賣品標準裝編碼  B-A0001  B-H0888等
    贈品禮盒裝編碼  ZL-A0001  ZL-D0001等
    贈品標準裝編碼  ZB-A0001  ZB-H0888等
     
    其中如果有3個3的號碼也留下來,不用去掉。 本來想用js來實現,但如果那樣只能把生成的結果寫給頁面上了,而且刷新就沒了。

    后來考慮了一下,選擇使用wxPython加上py2exe來做一個小的可執行文件,并把生成的編號放入txt文件中。 由于之前沒玩過wxPython,花了1個多小時終于搞定了!代碼如下:

    #encoding=utf-8
    from __future__ import with_statement
    import wx

    class ChoiceFrame(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, u'編碼生成器', size=(450, 150))
            icon=wx.EmptyIcon()
            icon.LoadFile("SetupIcon.ico",wx.BITMAP_TYPE_ICO)
            self.SetIcon(icon)
            panel = wx.Panel(self, -1)
           
            typeList = [u'賣品禮盒裝',u'賣品標準裝',u'贈品禮盒裝',u'贈品標準裝',]
            wx.StaticText(panel, -1, u"選擇種類:", pos=(10, 20))
            self.type = wx.Choice(panel, -1, (85, 20), choices=typeList)
            self.type.SetSelection(0)
           
            sampleList = [chr(i) for i in range(65,91)]
            wx.StaticText(panel, -1, u"選擇字母:", pos=(210, 20))
            self.choice = wx.Choice(panel, -1, (285, 20), choices=sampleList)
            self.choice.SetStringSelection('A')
           
            wx.StaticText(panel, -1, u"起始數字:", pos=(10, 50))
            self.start = wx.TextCtrl(panel, -1, "", pos=(80, 50))
           
            wx.StaticText(panel, -1, u"結束數字:", pos=(210, 50))
            self.end = wx.TextCtrl(panel, -1, "", pos=(280, 50))
           
            funbtn = wx.Button(panel, -1, u"運行", pos=(280, 90))
            self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)
           
            self.message = wx.StaticText(panel, -1, "", pos=(10, 90))
            self.message.SetForegroundColour("red")
           
        def OnFunButton(self, evt):
            self.message.SetLabel('')
            startNum = self.start.GetValue().strip()
            endNum = self.end.GetValue().strip()
            if not startNum.isdigit():
                self.message.SetLabel(u'*開始數字必須輸入整整數')
                return
            if not endNum.isdigit():
                self.message.SetLabel(u'*結束數字必須輸入整整數')
                return
            snum = int(startNum)
            enum = int(endNum)
            if enum <= snum:
                self.message.SetLabel(u'*結束數字必須大于開始數字')
                return
            if enum >= 10000:
                self.message.SetLabel(u'*結束數字必須小于10000')
                return
            type = self.type.GetSelection()
            choice = self.choice.GetStringSelection()

            if (type == 0):
                type = "L-"
            elif (type == 1):
                type = "B-"
            elif (type == 2):
                type = "ZL-"
            elif (type == 3):
                type = "ZB-"
           
            startCode = self.getCode(snum, type, choice)
            endCode = self.getCode(enum, type, choice)
               
            with open(startCode + "-" + endCode + ".txt", 'w') as f:
                for i in range(snum, enum+1):
                    code = self.getCode(i, type, choice)
                   
                    num4 = code.count('4')
                    if num4 > 0:
                        continue
                    num3 = code.count('3')
                    if num3 >0 and num3 < 3:
                        continue
                    f.write(code)
                    f.write('\n')
            self.message.SetLabel(u'編號生成成功!!!')
           
        def getCode(self, i, type, choice):
            code = i
            if i < 10:
                code = '000' + str(i)
            elif i < 100:
                code = '00' + str(i)
            elif i < 1000:
                code = '0' + str(i)
            return type + choice+ str(code)
       
    if __name__ == '__main__':
        app = wx.PySimpleApp()
        ChoiceFrame().Show()
        app.MainLoop()

     

    生成exe的代碼如下:

    #encoding=utf-8
    from distutils.core import setup
    import py2exe

    options = {"py2exe":  
                {   "compressed": 1,  
                    "bundle_files": 1
                }  
              } 
             
    setup(
        options = options,
        zipfile = None,
        windows=[{"script": "GeneratorCode.py", "icon_resources": [(1, "SetupIcon.ico")]}]
    )


    posted on 2009-08-19 22:30 周銳 閱讀(792) 評論(0)  編輯  收藏 所屬分類: Python
    主站蜘蛛池模板: 亚洲av无码片区一区二区三区| 亚洲国产精品SSS在线观看AV| 亚洲乱码一二三四五六区| 在线涩涩免费观看国产精品 | 在线观看成人免费| 亚洲制服丝袜一区二区三区| 最近中文字幕无免费| 亚洲国产成人精品电影| 免费大片黄在线观看yw| 亚洲国产中文在线视频| 中文字幕影片免费在线观看 | 亚洲理论精品午夜电影| 亚洲一区二区三区免费在线观看 | 在线免费观看h片| 亚洲av综合色区| 麻豆高清免费国产一区| 亚洲伊人色一综合网| 午夜成年女人毛片免费观看| 亚洲av无码专区在线观看亚| 国产一区二区免费在线| 国产精品视频全国免费观看| 亚洲成A人片在线观看无码不卡| 99在线观看免费视频| 中文字幕无码亚洲欧洲日韩| 免费中文字幕不卡视频| a级毛片免费全部播放无码| 综合自拍亚洲综合图不卡区| 成人免费a级毛片| 美女被艹免费视频| 亚洲综合日韩久久成人AV| 久久九九AV免费精品| 亚洲最大无码中文字幕| 中文字幕亚洲天堂| 2019中文字幕免费电影在线播放| 日本亚洲免费无线码| 亚洲国产一区明星换脸| 免费A级毛片无码A∨免费| 国产青草亚洲香蕉精品久久| 亚洲综合在线另类色区奇米| 67194成是人免费无码| 一级有奶水毛片免费看|