生产制造追溯系统之在线打印功能
前言
很久没有写博客了(大概有4个月的样子了吧),从2015年8月份开始一直忙于公司的系统,直到2016年6月底全部上线;包含4个厂区,每个厂区都是上千人的规模,而负责搞这个项目的算上我只有2个人,说多了都是泪:
美工?没有
测试人员?没有
dba?没有
架构师?没有
运维?继续没有
估计大家都没遇见过这样的工作吧?哈哈.
历经艰难、跟各个部门(ie、pe、生产、pmc、qa等)唇枪舌战、好在在6月底总算是全部上线,总算是一点欣慰,毕竟决定了接手这个项目,那就要用心去做,只有用心了才能做好。
吐槽完毕,下面开始说正事儿
********我是华丽的分割线************************************************
公司的系统上线之后,我也稍微可以缓口气了,加班稍微少了一点,一般到了下午6点半就能下班,所以我还是决定将2015年初整理的这套项目拿出来继续优化,该项目已web模式为主、客户端模式为辅,互相结合使用;目前主要包含以下几个主要功能模块:
本文主要说一下打印的问题,在生产制造业中条码打印是非常频繁的,也是必不可少的;我曾经亲身经历过这么一件事情:生产线在进行包装的时候,打印了两张卡通标签,但是操作员在将卡通标签贴在盒子上的时候贴反了,也就是说标签上面的序列号与盒子里面装的实物完全对不上,为此在海关被拦截了,当时厂里派了qa、生产、货仓与it一同去海关处解决这个问题,我刚好在其中,整个过程是非常繁琐的,为此公司高层也要求必须杜绝这种品质事件,故我们也是采用了"在线打印"的方式进行包装,并且只有qa才有标签重打的权限。
这个故事反应了生产线的真实现象,所以我这边采用如下方式完成打印:
function printlabel(box) { var api = '<%=mts.utility.mtstool.getapi() %>'; var lurl = api + "?type=3&action=get_carton_sn&carton_sn=" + box; $.ajax({ url: lurl, cache: false, datatype: "text", success: function (data) { if (data == null || data == undefined) { alert(""); return; } var arr = data.split("|"); if (arr[0] == "0") { alert(arr[2]); return; } var t = eval("(" + arr[2] + ")"); // try { var labelid = $("#hid_labelid").val(); window.external.printlabel("", t.key, t.value, ",", labelid); } catch (e) { }; } }); }
以上代码是web应用程序中的脚本,主要是通过api获取需要打印的数据,这里返回的是text类型,其实也可以返回json格式的数据;用户完成包装之后系统会按照包装规则产生一个唯一的卡通箱号,那么这个箱号就作为api的参数 carton_sn= box传进去,根据该箱号返回真实的包装数据;然后通过window.external调用客户端的打印函数。
通过如下代码获取本地默认打印机:
//获取默认打印机 system.drawing.printing.printdocument pringdocument = new system.drawing.printing.printdocument(); string pring_name = pringdocument.printersettings.printername;//打印机名
因为我这里的客户端程序就是对web程式加壳了,通过这个客户端程序就可以方便的获取本地默认打印机,采用这种方式比在网页中安装 activex 控件要爽的多,谁用谁知道.
网页传过来的参数以键值对为标准:
string[] keys = key.split(splitkey.tochararray(), stringsplitoptions.none); string[] values = value.split(splitkey.tochararray(), stringsplitoptions.none);
我这里调用bartender进行打印,代码如下:
format = (bartender.formatclass)engine.formats.open(filename); format.setnamedsubstringvalue(key, value); format.printsetup.printer = printername; bartender.messages msg = null; format.print("0", false, 1, out msg);
以下代码是code 128格式的条码:
public class code128 { private datatable m_code128 = new datatable(); private uint m_height = 40; /// <summary> /// 高度 /// </summary> public uint height { get { return m_height; } set { m_height = value; } } private font m_valuefont = null; /// <summary> /// 是否显示可见号码 如果为null不显示号码 /// </summary> public font valuefont { get { return m_valuefont; } set { m_valuefont = value; } } private byte m_magnify = 0; /// <summary> /// 放大倍数 /// </summary> public byte magnify { get { return m_magnify; } set { m_magnify = value; } } /// <summary> /// 条码类别 /// </summary> public enum encode { code128a, code128b, code128c, ean128 } public code128() { m_code128.columns.add("id"); m_code128.columns.add("code128a"); m_code128.columns.add("code128b"); m_code128.columns.add("code128c"); m_code128.columns.add("bandcode"); m_code128.casesensitive = true; #region 数据表 m_code128.rows.add("0", " ", " ", "00", "212222"); m_code128.rows.add("1", "!", "!", "01", "222122"); m_code128.rows.add("2", "\"", "\"", "02", "222221"); m_code128.rows.add("3", "#", "#", "03", "121223"); m_code128.rows.add("4", "$", "$", "04", "121322"); m_code128.rows.add("5", "%", "%", "05", "131222"); m_code128.rows.add("6", "&", "&", "06", "122213"); m_code128.rows.add("7", "'", "'", "07", "122312"); m_code128.rows.add("8", "(", "(", "08", "132212"); m_code128.rows.add("9", ")", ")", "09", "221213"); m_code128.rows.add("10", "*", "*", "10", "221312"); m_code128.rows.add("11", "+", "+", "11", "231212"); m_code128.rows.add("12", ",", ",", "12", "112232"); m_code128.rows.add("13", "-", "-", "13", "122132"); m_code128.rows.add("14", ".", ".", "14", "122231"); m_code128.rows.add("15", "/", "/", "15", "113222"); m_code128.rows.add("16", "0", "0", "16", "123122"); m_code128.rows.add("17", "1", "1", "17", "123221"); m_code128.rows.add("18", "2", "2", "18", "223211"); m_code128.rows.add("19", "3", "3", "19", "221132"); m_code128.rows.add("20", "4", "4", "20", "221231"); m_code128.rows.add("21", "5", "5", "21", "213212"); m_code128.rows.add("22", "6", "6", "22", "223112"); m_code128.rows.add("23", "7", "7", "23", "312131"); m_code128.rows.add("24", "8", "8", "24", "311222"); m_code128.rows.add("25", "9", "9", "25", "321122"); m_code128.rows.add("26", ":", ":", "26", "321221"); m_code128.rows.add("27", ";", ";", "27", "312212"); m_code128.rows.add("28", "<", "<", "28", "322112"); m_code128.rows.add("29", "=", "=", "29", "322211"); m_code128.rows.add("30", ">", ">", "30", "212123"); m_code128.rows.add("31", "?", "?", "31", "212321"); m_code128.rows.add("32", "@", "@", "32", "232121"); m_code128.rows.add("33", "a", "a", "33", "111323"); m_code128.rows.add("34", "b", "b", "34", "131123"); m_code128.rows.add("35", "c", "c", "35", "131321"); m_code128.rows.add("36", "d", "d", "36", "112313"); m_code128.rows.add("37", "e", "e", "37", "132113"); m_code128.rows.add("38", "f", "f", "38", "132311"); m_code128.rows.add("39", "g", "g", "39", "211313"); m_code128.rows.add("40", "h", "h", "40", "231113"); m_code128.rows.add("41", "i", "i", "41", "231311"); m_code128.rows.add("42", "j", "j", "42", "112133"); m_code128.rows.add("43", "k", "k", "43", "112331"); m_code128.rows.add("44", "l", "l", "44", "132131"); m_code128.rows.add("45", "m", "m", "45", "113123"); m_code128.rows.add("46", "n", "n", "46", "113321"); m_code128.rows.add("47", "o", "o", "47", "133121"); m_code128.rows.add("48", "p", "p", "48", "313121"); m_code128.rows.add("49", "q", "q", "49", "211331"); m_code128.rows.add("50", "r", "r", "50", "231131"); m_code128.rows.add("51", "s", "s", "51", "213113"); m_code128.rows.add("52", "t", "t", "52", "213311"); m_code128.rows.add("53", "u", "u", "53", "213131"); m_code128.rows.add("54", "v", "v", "54", "311123"); m_code128.rows.add("55", "w", "w", "55", "311321"); m_code128.rows.add("56", "x", "x", "56", "331121"); m_code128.rows.add("57", "y", "y", "57", "312113"); m_code128.rows.add("58", "z", "z", "58", "312311"); m_code128.rows.add("59", "[", "[", "59", "332111"); m_code128.rows.add("60", "\\", "\\", "60", "314111"); m_code128.rows.add("61", "]", "]", "61", "221411"); m_code128.rows.add("62", "^", "^", "62", "431111"); m_code128.rows.add("63", "_", "_", "63", "111224"); m_code128.rows.add("64", "nul", "`", "64", "111422"); m_code128.rows.add("65", "soh", "a", "65", "121124"); m_code128.rows.add("66", "stx", "b", "66", "121421"); m_code128.rows.add("67", "etx", "c", "67", "141122"); m_code128.rows.add("68", "eot", "d", "68", "141221"); m_code128.rows.add("69", "enq", "e", "69", "112214"); m_code128.rows.add("70", "ack", "f", "70", "112412"); m_code128.rows.add("71", "bel", "g", "71", "122114"); m_code128.rows.add("72", "bs", "h", "72", "122411"); m_code128.rows.add("73", "ht", "i", "73", "142112"); m_code128.rows.add("74", "lf", "j", "74", "142211"); m_code128.rows.add("75", "vt", "k", "75", "241211"); m_code128.rows.add("76", "ff", "i", "76", "221114"); m_code128.rows.add("77", "cr", "m", "77", "413111"); m_code128.rows.add("78", "so", "n", "78", "241112"); m_code128.rows.add("79", "si", "o", "79", "134111"); m_code128.rows.add("80", "dle", "p", "80", "111242"); m_code128.rows.add("81", "dc1", "q", "81", "121142"); m_code128.rows.add("82", "dc2", "r", "82", "121241"); m_code128.rows.add("83", "dc3", "s", "83", "114212"); m_code128.rows.add("84", "dc4", "t", "84", "124112"); m_code128.rows.add("85", "nak", "u", "85", "124211"); m_code128.rows.add("86", "syn", "v", "86", "411212"); m_code128.rows.add("87", "etb", "w", "87", "421112"); m_code128.rows.add("88", "can", "x", "88", "421211"); m_code128.rows.add("89", "em", "y", "89", "212141"); m_code128.rows.add("90", "sub", "z", "90", "214121"); m_code128.rows.add("91", "esc", "{", "91", "412121"); m_code128.rows.add("92", "fs", "|", "92", "111143"); m_code128.rows.add("93", "gs", "}", "93", "111341"); m_code128.rows.add("94", "rs", "~", "94", "131141"); m_code128.rows.add("95", "us", "del", "95", "114113"); m_code128.rows.add("96", "fnc3", "fnc3", "96", "114311"); m_code128.rows.add("97", "fnc2", "fnc2", "97", "411113"); m_code128.rows.add("98", "shift", "shift", "98", "411311"); m_code128.rows.add("99", "codec", "codec", "99", "113141"); m_code128.rows.add("100", "codeb", "fnc4", "codeb", "114131"); m_code128.rows.add("101", "fnc4", "codea", "codea", "311141"); m_code128.rows.add("102", "fnc1", "fnc1", "fnc1", "411131"); m_code128.rows.add("103", "starta", "starta", "starta", "211412"); m_code128.rows.add("104", "startb", "startb", "startb", "211214"); m_code128.rows.add("105", "startc", "startc", "startc", "211232"); m_code128.rows.add("106", "stop", "stop", "stop", "2331112"); #endregion } /// <summary> /// 获取128图形 /// </summary> /// <param name="p_text">文字</param> /// <param name="p_code">编码</param> /// <returns>图形</returns> public bitmap getcodeimage(string p_text, encode p_code) { string _viewtext = p_text; string _text = ""; ilist<int> _textnumb = new list<int>(); int _examine = 0; //首位 switch (p_code) { case encode.code128c: _examine = 105; if (!((p_text.length & 1) == 0)) throw new exception("128c长度必须是偶数"); while (p_text.length != 0) { int _temp = 0; try { int _codenumb128 = int32.parse(p_text.substring(0, 2)); } catch { throw new exception("128c必须是数字!"); } _text += getvalue(p_code, p_text.substring(0, 2), ref _temp); _textnumb.add(_temp); p_text = p_text.remove(0, 2); } break; case encode.ean128: _examine = 105; if (!((p_text.length & 1) == 0)) throw new exception("ean128长度必须是偶数"); _textnumb.add(102); _text += "411131"; while (p_text.length != 0) { int _temp = 0; try { int _codenumb128 = int32.parse(p_text.substring(0, 2)); } catch { throw new exception("128c必须是数字!"); } _text += getvalue(encode.code128c, p_text.substring(0, 2), ref _temp); _textnumb.add(_temp); p_text = p_text.remove(0, 2); } break; default: if (p_code == encode.code128a) { _examine = 103; } else { _examine = 104; } while (p_text.length != 0) { int _temp = 0; string _valuecode = getvalue(p_code, p_text.substring(0, 1), ref _temp); if (_valuecode.length == 0) throw new exception("无效的字符集!" + p_text.substring(0, 1).tostring()); _text += _valuecode; _textnumb.add(_temp); p_text = p_text.remove(0, 1); } break; } if (_textnumb.count == 0) throw new exception("错误的编码,无数据"); _text = _text.insert(0, getvalue(_examine)); //获取开始位 for (int i = 0; i != _textnumb.count; i++) { _examine += _textnumb[i] * (i + 1); } _examine = _examine % 103; //获得严效位 _text += getvalue(_examine); //获取严效位 _text += "2331112"; //结束位 bitmap _codeimage = getimage(_text); getviewtext(_codeimage, _viewtext); return _codeimage; } /// <summary> /// 获取目标对应的数据 /// </summary> /// <param name="p_code">编码</param> /// <param name="p_value">数值 a b 30</param> /// <param name="p_setid">返回编号</param> /// <returns>编码</returns> private string getvalue(encode p_code, string p_value, ref int p_setid) { if (m_code128 == null) return ""; datarow[] _row = m_code128.select(p_code.tostring() + "='" + p_value + "'"); if (_row.length != 1) throw new exception("错误的编码" + p_value.tostring()); p_setid = int32.parse(_row[0]["id"].tostring()); return _row[0]["bandcode"].tostring(); } /// <summary> /// 根据编号获得条纹 /// </summary> /// <param name="p_codeid"></param> /// <returns></returns> private string getvalue(int p_codeid) { datarow[] _row = m_code128.select("id='" + p_codeid.tostring() + "'"); if (_row.length != 1) throw new exception("验效位的编码错误" + p_codeid.tostring()); return _row[0]["bandcode"].tostring(); } /// <summary> /// 获得条码图形 /// </summary> /// <param name="p_text">文字</param> /// <returns>图形</returns> private bitmap getimage(string p_text) { char[] _value = p_text.tochararray(); int _width = 0; for (int i = 0; i != _value.length; i++) { _width += int32.parse(_value[i].tostring()) * (m_magnify + 1); } bitmap _codeimage = new bitmap(_width, (int)m_height); graphics _garphics = graphics.fromimage(_codeimage); //pen _pen; int _lenex = 0; for (int i = 0; i != _value.length; i++) { int _valuenumb = int32.parse(_value[i].tostring()) * (m_magnify + 1); //获取宽和放大系数 if (!((i & 1) == 0)) { //_pen = new pen(brushes.white, _valuenumb); _garphics.fillrectangle(brushes.white, new rectangle(_lenex, 0, _valuenumb, (int)m_height)); } else { //_pen = new pen(brushes.black, _valuenumb); _garphics.fillrectangle(brushes.black, new rectangle(_lenex, 0, _valuenumb, (int)m_height)); } //_garphics.(_pen, new point(_lenex, 0), new point(_lenex, m_height)); _lenex += _valuenumb; } _garphics.dispose(); return _codeimage; } /// <summary> /// 显示可见条码文字 如果小于40 不显示文字 /// </summary> /// <param name="p_bitmap">图形</param> private void getviewtext(bitmap p_bitmap, string p_viewtext) { if (m_valuefont == null) return; graphics _graphics = graphics.fromimage(p_bitmap); sizef _drawsize = _graphics.measurestring(p_viewtext, m_valuefont); if (_drawsize.height > p_bitmap.height - 10 || _drawsize.width > p_bitmap.width) { _graphics.dispose(); return; } int _stary = p_bitmap.height - (int)_drawsize.height; _graphics.fillrectangle(brushes.white, new rectangle(0, _stary, p_bitmap.width, (int)_drawsize.height)); _graphics.drawstring(p_viewtext, m_valuefont, brushes.black, 0, _stary); } //12345678 //(105 + (1 * 12 + 2 * 34 + 3 * 56 + 4 *78)) % 103 = 47 //结果为starc +12 +34 +56 +78 +47 +end internal image getcodeimage(string p) { throw new notimplementedexception(); } }
这样一来,操作员手上没有多的条码,必须包装完成之后系统才会一对一的打印一份条码出来,完成一个产品的包装就贴一个条码,很大程度上面避免了条码混乱的问题.
已完成的部分功能
#1工单维护:这个一般都是由pmc完成的,pmc根据排期计划合理创建工单,如果企业上了sap系统,也可以直接链接到sap系统进行下载工单资料,这样就更方便了.
#2工单优先级:pmc在创建工单的时候会指定该信息,生产过程中系统会体现该信息,起到提示用户的目的,管理者可根据实际情况随时变更该信息。
#3工艺路线维护:工艺路线由 ie 完成,生产部根据 ie 制定的工艺路线进行生产,系统会检测每一个工序的通过情况,比如上一个工序没有做则不可以直接跳到下一个工序。
#4目检过站:操作扫描条码过站,必须按照 ie 制定的工艺路线进行,如果扫描的条码不在当前工序,则系统会提示当前条码的正确位置。
#5目检过站:系统会将不良品强制打入维修中心,在完成修理之前无法进行其它的操作。
#6组装动态装配:系统支持动态配置装配规则,不同的工单采用不同的规则进行装配,每一个装配条码可独立配置条码规则,比如长度、前缀等信息,防止用户输入错误。
#7fqc送检:系统采用 aql 标准动态抽检,打破传统的抽检模式,由系统自动计算需要抽检的产品,同时也由系统自动根据 aql 标准进行结果判定,有效帮助品质人员进行品质监控与管理。
#8fqc抽检:生产方面将产品以批次单位送检至qc,系统提示qc需要抽检的产品序列号,qc针对需要抽检的产品检测并录入抽检结果,系统根据抽检情况按照 aql 自动判定.
#9包装规则:针对每个工单配置相应的包装规则,比如卡通箱容量、箱号长度、箱号前缀等信息,并上传卡通标签模板。
#10包装:包装规则配置完成之后,即可扫描条码进行包装了。
结束包装的时候,系统自动将标签打印出来.
#11不良品维修:生产过程中的不良都会被系统强制打入维修中心,必须经过修理之后才能进行其它工序。
#12不良预警:系统会自动监控指定生产线的不良情况,当不良情况达到了红色预警值,则触发警报,系统自动锁定当前生产线,由管理者分析不良原因并改善之后进行解除预警。
#13成品发货:成品发货过程中支持上传实物图片。
#14品质异常报告:用户发起品质异常,由工程部分析原因并给出改善,由qa确认是否可行。
#15部分报表:
#16电子看板:
结尾
因为工作日需要上班,白天必须做公司的事情,所以只有每天晚上熬夜和周末来做这个项目,说真的还是有点累,如果您觉得文章过得去,还请多多支持,谢谢各位园友!!
总结
以上所述是小编给大家介绍的生产制造追溯系统之在线打印功能,希望对大家有所帮助