<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日韩精品一区二区三区| 亚洲AV永久纯肉无码精品动漫| 亚洲日韩国产一区二区三区在线 | 成人免费视频网站www| 国产性生交xxxxx免费| 国产亚洲精品精华液| 亚洲国产精品ⅴa在线观看| 久操视频免费观看| 免费成人黄色大片| 自拍日韩亚洲一区在线| 久久国产精品免费视频| 亚洲视频.com| 国产一级高青免费| 亚洲电影一区二区| 怡红院免费全部视频在线视频| 免费一级毛片免费播放| 一个人免费观看视频在线中文| 永久免费无码网站在线观看| 亚洲男人电影天堂| 久久久久国产免费| 亚洲婷婷在线视频| 2021在线观看视频精品免费| 亚洲综合校园春色| 免费观看亚洲人成网站| 亚洲AV无码成人精品区狼人影院 | 免费在线观看自拍性爱视频| 午夜免费福利网站| 视频免费1区二区三区| 在线观看人成视频免费| 亚洲av无码国产综合专区| 亚洲国产精品免费在线观看| 亚洲精品美女久久777777| 国产成人免费在线| 国产亚洲漂亮白嫩美女在线| 国产一级高清免费观看| a级毛片在线免费| 亚洲人精品亚洲人成在线|