条码生成器,工厂生产烧录SN用临时写的
By
瞌睡蟲子
at 2023-01-17 • 0人收藏 • 725人看过
由于SN是随机生成没法顺序生产,为了规避人工输入错误,只能用扫码枪扫条码烧录。临时整了个工具。
main.aardio
//文件对话框 import fonts.fontAwesome; import win.ui; /*DSG{{*/ var winform = win.form(text="条码生成器";right=399;bottom=447;bgcolor=16777215;border="dialog frame";max=false;min=false) winform.add( btnIFileOpenDir={cls="plus";text="打开目录";left=288;top=16;right=400;bottom=46;align="left";color=3947580;dr=1;dt=1;font=LOGFONT(h=-13);iconStyle={align="left";font=LOGFONT(h=-13;name='FontAwesome');padding={left=8}};iconText='\uF07C';notify=1;textPadding={left=25};z=1}; button={cls="button";text="下一条";left=272;top=48;right=384;bottom=80;z=3}; checkbox={cls="checkbox";text="记录历史位置";left=32;top=56;right=136;bottom=72;checked=1;z=12}; editPath={cls="plus";left=24;top=16;right=272;bottom=42;align="right";border={bottom=1;color=-6908266};dl=1;dr=1;dt=1;editable=1;font=LOGFONT(h=-13);textPadding={top=6;bottom=2};z=2}; edit_mac={cls="edit";left=72;top=408;right=336;bottom=432;edge=1;readonly=1;z=9}; edit_num={cls="edit";text="-";left=176;top=56;right=240;bottom=80;align="right";color=16711680;disabled=1;edge=1;font=LOGFONT(h=-14;weight=700);readonly=1;z=13}; edit_sn={cls="edit";left=72;top=232;right=336;bottom=256;edge=1;readonly=1;z=6}; plus_mac={cls="plus";left=32;top=264;right=384;bottom=400;repeat="scale";z=7}; plus_sn={cls="plus";left=32;top=88;right=384;bottom=224;repeat="scale";z=4}; static={cls="static";text="第";left=160;top=56;right=184;bottom=80;color=255;font=LOGFONT(h=-14;weight=700);transparent=1;z=10}; static2={cls="static";text="条";left=240;top=56;right=264;bottom=80;color=255;font=LOGFONT(h=-14;weight=700);transparent=1;z=11}; static_mac={cls="static";text="MAC:";left=32;top=416;right=80;bottom=432;color=255;font=LOGFONT(weight=700);transparent=1;z=8}; static_sn={cls="static";text="SN:";left=32;top=240;right=72;bottom=256;color=255;font=LOGFONT(weight=700);transparent=1;z=5} ) /*}}*/ import fsys.dlg; import win.dlg.message; import config; winform.bindConfig( config.winform,{ edit = "text"; radiobutton = "checked"; checkbox = "checked"; combobox = "selIndex"; plus ={ ["^chk"] = "checked"; ["^edit"] = "text"; }; } ); winform.btnIFileOpenDir.oncommand = function(id,event){ var path = fsys.dlg.open('Excel文件(*.xlsx)|*.xlsx|',,,winform); if(path){ winform.editPath.text = path; winform.edit_sn.text = ""; winform.edit_mac.text = ""; winform.plus_sn.background = null; winform.plus_mac.background = null; winform.edit_num.text = "-"; index = 1; xlsData = readExcel(winform.editPath.text,0); } } winform.btnIFileOpenDir.skin({ color={ active=0xFF00FF00; default=0xFF3C3C3C; disabled=0xFF6D6D6D; hover=0xFFFF0000 } }) // 获取excel数据 function readExcel(xlsPath,sheetName=0){ import py3; import web.json; import py3.lib.xls; var xls = py3.lib.xls.Excel07(); var objExcelWorkBook = xls.OpenExcel(xlsPath); if(type(sheetName) == "number"){ sheetName = xls.GetSheetsName()[sheetName]; } var row = xls.GetRowsCount(sheetName); var data = xls.ReadRange(sheetName,"A2:B"+tostring(row)); xls.CloseExcel(); return data; } // 生产条码 function createBmp(str){ import libzint; var zsd = libzint(); //参考 https://www.chengxu.xyz/t/365 zsd.symbology = 0x14/*_BARCODE_CODE128*/; zsd.borderWidth = 2; zsd.foregroundColor = 0x9613B2; zsd.height = 50; if( zsd.encode(str) ){ error(zsd.err); } return zsd.saveBitmap() ; } var xlsData = null; var index = 0; import console; winform.button.oncommand = function(id,event){ if(winform.editPath.text == ""){ winform.msgFrown("请先选择Excel文件!",1000); winform.btnIFileOpenDir.oncommand(); return ; }elseif(not io.exist(winform.editPath.text)){ winform.msgFrown("Excel文件不存在,请重新选择!",1000); winform.btnIFileOpenDir.oncommand(); return ; } if(xlsData == null){ xlsData = readExcel(winform.editPath.text,0); } index += 1; var data = xlsData[index]; winform.edit_sn.text = data[0]; winform.plus_sn.background = createBmp(winform.edit_sn.text); winform.edit_mac.text = data[1]; winform.plus_mac.background = createBmp(winform.edit_mac.text); winform.edit_num.text = index; } if(winform.checkbox.checked){ if(#winform.edit_sn.text){ winform.plus_sn.background = createBmp(winform.edit_sn.text); } if(#winform.edit_mac.text){ winform.plus_mac.background = createBmp(winform.edit_mac.text); } if(#winform.edit_num.text && winform.edit_num.text != "-"){ index = tonumber(winform.edit_num.text); } }else { winform.edit_sn.text = ""; winform.edit_mac.text = ""; winform.plus_sn.background = null; winform.plus_mac.background = null; winform.edit_num.text = "-"; } winform.show(); win.loopMessage();
python的excel库。放在aardio\lib\py3\lib下面
1 个回复 | 最后更新于 2023-01-17
登录后方可回帖
感谢分享,新年快乐