public static String GetSerialNumberFromBarcode(String ProductNo, String BarcodeText) { if (BarcodeText.Length == 13) { try { Double buff = Convert.ToDouble(BarcodeText); return(BarcodeText.Substring(8)); } catch { return(BarcodeText); } } ProductBarcode PB = new ProductBarcode(); PB.LoadProductsConfig(); if (BarcodeText.Length < 5) { BarcodeText = PB.FormatSerialNumber(BarcodeText); return(BarcodeText); } if (BarcodeText.Length == 13) { Int32 n_CheckVar = 0; try { n_CheckVar = Convert.ToInt32(BarcodeText); BarcodeText = BarcodeText.Substring(8); return(BarcodeText); } catch { } } if (BarcodeText.Substring(0, 1) == "#") { BarcodeText = BarcodeText.Substring(9, 5); return(BarcodeText); } if (BarcodeText.IndexOf(';') > -1) { switch (BarcodeText.Length - BarcodeText.Replace(";", "").Length) { case 1: case 2: case 3: PB.ErrorMessageBoxShow("Nespravny format barcodu. Prilis malo znakov ';'"); return(BarcodeText); case 4: return(BarcodeText.Substring(BarcodeText.LastIndexOf(';') + 1)); default: Int32 n_startPosition = BarcodeText.IndexOf(';') + 1; n_startPosition = BarcodeText.IndexOf(';', n_startPosition) + 1; n_startPosition = BarcodeText.IndexOf(';', n_startPosition) + 1; n_startPosition = BarcodeText.IndexOf(';', n_startPosition) + 1; return(BarcodeText.Substring(n_startPosition, BarcodeText.IndexOf(';', n_startPosition) - n_startPosition)); } } XmlNode node_actProdNoNode = PB.GetProductNode(ProductNo); if (node_actProdNoNode.SelectSingleNode("./BarcodeLength") != null) { if (BarcodeText.Length < Convert.ToInt32(node_actProdNoNode.SelectSingleNode("./BarcodeLength").InnerText)) { return(""); } } XmlNode actBarcodeIdentifierNode = node_actProdNoNode.SelectSingleNode("./BarcodeSettings"); if (actBarcodeIdentifierNode == null) { XmlNode actFamilyNode = PB.GetFamilyNode(ProductNo); if (actFamilyNode != null) { if (BarcodeText.Length < Convert.ToInt32(actFamilyNode.SelectSingleNode("./BarcodeLength").InnerText)) { return(PB.FormatSerialNumber(BarcodeText)); } XmlNode actSerialNumberNode = actFamilyNode.SelectSingleNode("./BarcodeSettings/SerialNumber"); if (actSerialNumberNode == null) { PB.ErrorMessageBoxShow(String.Concat("V konfiguracnom subore chyba info \"BarcodeSettings/SerialNumber\" pre vyrobok ", ProductNo, "\n Zavolajte testovacieho inziniera!")); return(""); } else { try { Int16 n_StartIndex = Convert.ToInt16(actSerialNumberNode.SelectSingleNode("./StartIndex").InnerText); Int16 n_Length = Convert.ToInt16(actSerialNumberNode.SelectSingleNode("./Length").InnerText); return(PB.FormatSerialNumber(BarcodeText.Substring(n_StartIndex, n_Length))); } catch (Exception ex) { PB.ErrorMessageBoxShow(ex.Message); return(""); } } } } else { XmlNode actSerialNumberNode = actBarcodeIdentifierNode.SelectSingleNode("./SerialNumber"); if (actSerialNumberNode == null) { PB.ErrorMessageBoxShow(String.Concat("V konfiguracnom subore chyba info \"BarcodeSettings/SerialNumber\" pre vyrobok ", ProductNo, "\n Zavolajte testovacieho inziniera!")); return(""); } else { try { Int16 n_StartIndex = Convert.ToInt16(actSerialNumberNode.SelectSingleNode("./StartIndex").InnerText); Int16 n_Length = Convert.ToInt16(actSerialNumberNode.SelectSingleNode("./Length").InnerText); return(PB.FormatSerialNumber(BarcodeText.Substring(n_StartIndex, n_Length))); } catch (Exception ex) { PB.ErrorMessageBoxShow(ex.Message); return(""); } } } return(PB.FormatSerialNumber(BarcodeText)); }
public static String GetJobIdFromBarcode(String ProductNo, String BarcodeText) { if (BarcodeText.Length == 13) { try { double buf = Convert.ToDouble(BarcodeText); return(BarcodeText.Substring(0, 8)); } catch { } } if ((BarcodeText.IndexOf(';') > -1) || (BarcodeText.Length == 14)) { if (BarcodeText[0] != '#') { //SPDCSCO-30G;16;02433956;AD;00226;341-0435-01 A0;PSK2016W06N;A9K-750W-DC V03;IPUPAH9AAA;191688 String retVal = BarcodeText.Substring(BarcodeText.IndexOf(';') + 1); retVal = retVal.Substring(retVal.IndexOf(';') + 1); retVal = retVal.Substring(0, retVal.IndexOf(';')); return(retVal); } else { //#0245594100002;350DNC40-24-8G;AA;1614;16;;350DNC40-24-8G;;1834103-RG;12KG return(BarcodeText.Substring(1, 8)); } } try { Convert.ToDouble(BarcodeText); return(BarcodeText); } catch { } ProductBarcode PB = new ProductBarcode(); PB.LoadProductsConfig(); XmlNode node_actProdNoNode = PB.GetProductNode(ProductNo); if (node_actProdNoNode == null) { return(null); } if (node_actProdNoNode.SelectSingleNode("./BarcodeLength") != null) { if (BarcodeText.Length < Convert.ToInt32(node_actProdNoNode.SelectSingleNode("./BarcodeLength").InnerText)) { if ((BarcodeText.Length == 7) || (BarcodeText.Length == 8)) { return(BarcodeText); } return(""); } } XmlNode actBarcodeIdentifierNode = node_actProdNoNode.SelectSingleNode("./BarcodeSettings"); if (actBarcodeIdentifierNode == null) { XmlNode actFamilyNode = PB.GetFamilyNode(ProductNo); if (actFamilyNode != null) { if (BarcodeText.Length < Convert.ToInt32(actFamilyNode.SelectSingleNode("./BarcodeLength").InnerText)) { return(BarcodeText); } XmlNode actJobIDNode = actFamilyNode.SelectSingleNode("./BarcodeSettings/JobID"); if (actJobIDNode == null) { PB.ErrorMessageBoxShow(String.Concat("V konfiguracnom subore chyba info \"BarcodeSettings/JobID\" pre vyrobok ", ProductNo, "\n Zavolajte testovacieho inziniera!")); return(""); } else { try { Int16 n_StartIndex = Convert.ToInt16(actJobIDNode.SelectSingleNode("./StartIndex").InnerText); Int16 n_Length = Convert.ToInt16(actJobIDNode.SelectSingleNode("./Length").InnerText); if (n_StartIndex < 0) { return(""); } else { return(BarcodeText.Substring(n_StartIndex, n_Length)); } } catch (Exception ex) { PB.ErrorMessageBoxShow(ex.Message); return(""); } } } } else { XmlNode actJobIDNode = actBarcodeIdentifierNode.SelectSingleNode("./JobID"); if (actJobIDNode == null) { PB.ErrorMessageBoxShow(String.Concat("V konfiguracnom subore chyba info \"BarcodeSettings/JobID\" pre vyrobok ", ProductNo, "\n Zavolajte testovacieho inziniera!")); return(""); } else { try { Int16 n_StartIndex = Convert.ToInt16(actJobIDNode.SelectSingleNode("./StartIndex").InnerText); Int16 n_Length = Convert.ToInt16(actJobIDNode.SelectSingleNode("./Length").InnerText); if (n_StartIndex < 0) { return(""); } else { return(BarcodeText.Substring(n_StartIndex, n_Length)); } } catch (Exception ex) { PB.ErrorMessageBoxShow(ex.Message); return(""); } } } return(BarcodeText); }