/// <summary> /// 取数字和最后一位的校验码 /// </summary> /// <param name="code"></param> /// <returns></returns> public static string ModCheckCode(BarCode code) { string codeStr = code.prefix + code.sn + code.suffix; int num = 0; foreach (char c in codeStr) { if (char.IsNumber(c)) { num += int.Parse(c.ToString()); } } return(num.ToString().Substring(num.ToString().Length - 1)); }
public BarCode GetCodeByRule() { BarCode bc = new BarCode(); int snIdx = this.RuleStr.IndexOf("[SN:"); int pfx; //前缀开始的下标 int sfxIdx = -1; //后缀开始的下标 if (snIdx > -1) //如果有流水号 { //=================前缀========================= if (snIdx == 0) //如果SN的开头是第一个字符 { pfx = -1; //没有前缀 } else { pfx = 0; //有前缀 } //===================后缀========================== for (int i = snIdx + 1; i < RuleStr.Length; i++) { if (RuleStr[i] == ']') { if (i == RuleStr.Length - 1) //如果SN的结尾是最后一个字符 { sfxIdx = -1; //没有后缀 } else { sfxIdx = i + 1; } break; //只要找到]就结束 } } } else //如果没有流水号 { //则只有前缀,没有后缀 pfx = 0; sfxIdx = -1; } if (pfx > -1) { int idx = snIdx; if (snIdx == -1) //如果有前缀没SN,前缀就是这个字符串的全部内容 { idx = RuleStr.Length; } string buffs = ""; //常量的缓存 string buffd = ""; //带规则的缓存 for (int i = pfx; i < idx; i++) { if (buffd != "") //如果当前是在处理规则 { if (RuleStr[i] == ']') { string s = GetStrByDateRule(buffd + "]"); buffs += s; buffd = ""; } else { buffd += RuleStr[i].ToString(); } } else { if (RuleStr[i] == '[') { buffd += "["; } else { buffs += RuleStr[i].ToString(); } } } bc.prefix = buffs; //得到条码的前缀; } if (snIdx != -1) { int endidx = 0; for (int j = snIdx + 4; j < RuleStr.Length; j++) { if (RuleStr[j] == ']') { endidx = j; break; } } //[sn:01] bc.sn = RuleStr.Substring(snIdx + 4, endidx - snIdx - 4); foreach (char c in bc.sn) { bc.snStr += "*"; } } if (sfxIdx > -1) { string bfs = ""; //常量的缓存 string bfd = ""; //带规则的缓存 for (int i = sfxIdx; i < RuleStr.Length; i++) { if (bfd != "") //如果当前是在处理规则 { if (RuleStr[i] == ']') { string s = GetStrByDateRule(bfd + "]"); bfs += s; bfd = ""; } else { bfd += RuleStr[i].ToString(); } } else { if (RuleStr[i] == '[') { bfd += "["; } else { bfs += RuleStr[i].ToString(); } } } bc.suffix = bfs; //得到条码的前缀; } return(bc); }
public static void Print(string variable, string Main_order, Form fm, List <P_SSW_TemplateList> list, string clas) { string var = variable; string Main_Od = Main_order; Form form = fm; List <P_SSW_TemplateList> proc1 = list; KryptonComboBox com = new KryptonComboBox(); com = (KryptonComboBox)form.Controls.Find("kryptonComboBox1", true)[0]; KryptonTextBox tb = new KryptonTextBox(); tb = (KryptonTextBox)form.Controls.Find("ktb_orderNO", true)[0]; TextBox tb_1 = new TextBox(); tb_1 = (TextBox)form.Controls.Find("tb_1", true)[0]; TextBox tb_2 = new TextBox(); tb_2 = (TextBox)form.Controls.Find("tb_2", true)[0]; KryptonLabel lb = new KryptonLabel(); lb = (KryptonLabel)form.Controls.Find("klb_barcode", true)[0]; pn = NVBarcode.PrintEngine6.GetPrintEngine(proc1[0].TemplatePath); string Mid = proc1[0].RuleStr.ToString(); if (Mid.IndexOf("(") > -1) { PrintVari pv = new PrintVari(Mid, "", ""); pv.ShowDialog(); Mid = pv.result; } NVBarcode.CodeRule coderule = NV_SNP.Objs.SpecialRule.TransformRuleStr(Mid); //将特殊规则转成一般规则 barcode = coderule.GetCodeByRule(); lb.Text = barcode.prefix + barcode.snStr + barcode.suffix; if (com.SelectedIndex > 0) //如果打印进制不是10进制 { string entName = com.SelectedValue.ToString(); sm = GetSM(entName); //获取一个序列号管理对象 } for (int it = int.Parse(tb_1.Text); it <= int.Parse(tb_2.Text); it++) { string sn = NVBarcode.CodeRule.GetCompleteSN(GetSNByEnter(sm, it), barcode.snStr.Length); //获取完整的SN string suffix = ""; if (proc1[0].checkCode == 1) { barcode.sn = GetSNByEnter(sm, it); suffix = barcode.suffix + NVBarcode.CheckCode.ModCheckCode(barcode); } else { suffix = barcode.suffix; } pn.printDocument(sn, 1, barcode.prefix, suffix, 1, 1, int.Parse(proc1[0].faxType.ToString())); string order_No = tb.Text.ToString(); string workinfo = NV_SNP.Toos.ServiceReferenceManager.GetClient().RunServerAPI("BLL.SSW", "GetWorder", order_No); List <P_WorkOrder> proc2 = JsonConvert.DeserializeObject <List <P_WorkOrder> >(workinfo); //补打是重复的条码不重复插入清单 string product_code = proc2[0].product_code; string ProductCode = NV_SNP.Toos.ServiceReferenceManager.GetClient().RunServerAPI("BLL.SSW", "GetProduct", product_code); List <B_Product> ProductCodeList = JsonConvert.DeserializeObject <List <B_Product> >(ProductCode); if (ProductCodeList[0].print_bind == 1) { string Bar = barcode.prefix + sn + suffix; string BarCode = NV_SNP.Toos.ServiceReferenceManager.GetClient().RunServerAPI("BLL.SSW", "GetBarCode", Bar); List <P_WorkOrder> BarCodeList = JsonConvert.DeserializeObject <List <P_WorkOrder> >(BarCode); if (BarCodeList == null) { //打印一个条码,在条码绑定表插入一条数据 P_BarCodeBing P_barcode = new P_BarCodeBing() { order = order_No, parent_order = proc2[0].parent_order, main_order = proc2[0].main_order, state = 0, barcode = Bar, product_code = proc2[0].product_code, InputTime = DateTime.Now }; string strJson = JsonToolsNet.ObjectToJson(P_barcode); NV_SNP.Toos.ServiceReferenceManager.GetClient().RunServerAPI("BLL.SSW", "InsertBarCode", strJson); } } //string MID=proc1[0].Template_id; //if (Convert.ToInt32(tb_2.Text) > proc1[0].currentSN) //{ // int CSN = Convert.ToInt32(tb_2.Text); // NV_SNP.Toos.ServiceReferenceManager.GetClient().RunServerAPI("BLL.SSW", "UpdateTemplateByMid", MID + "|" + CSN); //} } }