<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 周銳 閱讀(777) 評論(0)  編輯  收藏 所屬分類: Python
    主站蜘蛛池模板: 人妻无码久久一区二区三区免费| 亚洲人成毛片线播放| 亚洲人成免费网站| 暖暖免费中文在线日本| 亚洲av无码一区二区三区人妖| 精品多毛少妇人妻AV免费久久| baoyu777永久免费视频| 99re8这里有精品热视频免费| 真人做人试看60分钟免费视频| 黄瓜视频高清在线看免费下载| 免费黄色一级毛片| 日韩在线天堂免费观看 | 大地资源中文在线观看免费版| 国产1024精品视频专区免费| 亚洲黄黄黄网站在线观看| 亚洲在成人网在线看| 久久亚洲精品专区蓝色区| 亚洲国产系列一区二区三区| 亚洲AV无码一区二区乱子仑| 久久青草91免费观看| 免费在线观看日韩| 亚洲中字慕日产2020| 亚洲人av高清无码| 污污污视频在线免费观看| 国产92成人精品视频免费| 亚洲午夜久久久久久噜噜噜| 亚洲人成色4444在线观看| 一区二区三区福利视频免费观看| 永久免费的网站在线观看| 亚洲码国产精品高潮在线| 日韩精品亚洲专区在线影视| 日本免费人成在线网站| 精品亚洲综合在线第一区| 亚洲性无码av在线| 中文字幕无码毛片免费看| 免费日本黄色网址| 亚洲四虎永久在线播放| 亚洲午夜精品一区二区麻豆| 热re99久久6国产精品免费| 精品亚洲视频在线观看| 日韩成人精品日本亚洲|