private void btnGen_Click(object sender, EventArgs e) { List <long> data = new List <long>(); List <int> size = new List <int>(); for (int i = 0; i < dataGridView1.RowCount - 1; i++) { //DataGridViewComboBoxCell vcbc = (DataGridViewComboBoxCell)dataGridView1[1, i]; //int index = vcbc.Items.IndexOf(vcbc.Value); string text, value; try { text = dataGridView1[1, i].Value.ToString(); value = dataGridView1[2, i].Value.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); txInfo.Text = null; return; } long v = 0; int index; if (!sizeTable.TryGetValue(text, out index)) { goto Exit; } else { size.Add(index); switch (index) { case 24: data.Add(BarcodeCore.TextToLong(value)); break; case 28: data.Add(BarcodeCore.Text128ToLong(value)); break; case 32: float f1; if (!float.TryParse(value, out f1)) { goto Exit; } data.Add(BarcodeCore.FloatToLong(f1)); break; default: ushort ushortV; if (UInt16.TryParse(value, out ushortV)) { v = (long)ushortV; data.Add(v); } else { goto Exit; } break; } } } List <int[]> format; List <string> barcodes; BarcodeCore.BarcodeEncoder(size.ToArray(), data.ToArray(), out format, out barcodes); if (format == null) { goto Exit; } string mBarcodes = ""; foreach (string barcode in barcodes) { mBarcodes += barcode; } Image image = Code128Rendering.MakeBarcodeImage(mBarcodes, 5, true); (new BarcodeWindow(image)).Show(); int[] deValues, deFormat; BarcodeCore.BarcodeDecoder(barcodes, format, out deValues, out deFormat); if (deValues == null) { goto Exit; } string decodeValue = "Barcodes:\r\n"; foreach (string barcode in barcodes) { decodeValue += barcode + "\r\n"; } decodeValue += "\r\nDecode Data:\r\n"; for (int i = 0; i < deValues.Length; i++) { switch (deFormat[i]) { case 24: decodeValue += BarcodeCore.IntToText(deValues[i]) + "\r\n"; break; case 28: decodeValue += BarcodeCore.IntToText128(deValues[i]) + "\r\n"; break; case 32: decodeValue += BarcodeCore.IntToFloat(deValues[i]).ToString() + "\r\n"; break; default: decodeValue += deValues[i].ToString() + "\r\n"; break; } } txInfo.Text = decodeValue; return; Exit: MessageBox.Show("Error"); txInfo.Text = null; return; }
private void generateBarcodeImage(object sender, EventArgs e) { if (gatherAllData()) { convertAllDataToLong(); List <string> barcodes = BarcodeCore.BarcodeEncoder(bits, data); string BC = ""; if (barcodes != null) { byte[] bcBytes = new byte[barcodes.Count * 4]; for (int i = 0; i < barcodes.Count; i++) { BC += barcodes[i]; long code = long.Parse(barcodes[i]); byte[] codeBytes = BitConverter.GetBytes(code); bcBytes[i * 4] = codeBytes[0]; bcBytes[i * 4 + 1] = codeBytes[1]; bcBytes[i * 4 + 2] = codeBytes[2]; bcBytes[i * 4 + 3] = codeBytes[3]; } mQRCodeImage = KwQRCodeWriter.textToQRImage(BC, QR_CORRECT_LEV.L); #if DEBUG int[] retData = BarcodeCore.BarcodeDecoder(BC, bits); byte[] dataBytes; // 0: [Version, Concentration Unit, RLU-Conc Points, T Band Appears] dataBytes = int2DataBytes(retData[0]); int dVersion = dataBytes[0]; int dConcUnit = dataBytes[1]; //int dRLUConcPts = dataBytes[2]; int dTband = dataBytes[3]; // 1 - 5: Product ID string dProdID = ""; for (int i = 1; i < 6; i++) { dProdID += BarcodeCore.IntToText256(retData[i]); } // 6 - 8: Product Lot string dProdLot = ""; for (int i = 6; i < 9; i++) { dProdLot += BarcodeCore.IntToText256(retData[i]); } // 9: Expiration Date dataBytes = int2DataBytes(retData[9]); int dDay = dataBytes[0]; int dMonth = dataBytes[1]; int dYear = BitConverter.ToUInt16(dataBytes, 2); // 10: [Left Bound, Top Bound, Target Width, Target Height] dataBytes = int2DataBytes(retData[10]); int dLb = dataBytes[0]; int dTb = dataBytes[1]; int dTw = dataBytes[2]; int dTh = dataBytes[3]; // 11: [Right Bound, Target C-T Interval, Target T-T Interval, Invalid Threshold (C Cutoff)] dataBytes = int2DataBytes(retData[11]); int dRb = dataBytes[0]; int dTCTi = dataBytes[1]; int dTTTi = dataBytes[2]; int dCco = dataBytes[3]; // 12: [Rows, Lines, T1 Cutoff RLU, T2 Cutoff RLU] dataBytes = int2DataBytes(retData[12]); int dRows = dataBytes[0]; int dLines = dataBytes[1]; int dTco = dataBytes[2]; // 13: T1 Cutoff Concentration float dTcoConc = BarcodeCore.IntToFloat(retData[13]); // 14: T1 Name string dTName = BarcodeCore.IntToText256(retData[14]); // 15 - 19: T1 RLU-Concentration Pairs x 4 double[] dRLU = new double[5]; double[] dConc = new double[5]; for (int i = 0; i < 5; i++) { dataBytes = int2DataBytes(retData[15 + i]); dRLU[i] = BarcodeCore.DecodeFloat16(BitConverter.ToUInt16(dataBytes, 0)); dConc[i] = BarcodeCore.DecodeFloat16(BitConverter.ToUInt16(dataBytes, 2)); Console.WriteLine(dRLU[i].ToString() + "\t" + dConc[i].ToString()); } Console.WriteLine("Check Complete!"); #endif } else { mQRCodeImage = null; } } else { mQRCodeImage = null; } pictureBox3.Image = mQRCodeImage; }
private void btnDecode_Click(object sender, EventArgs e) { string barcodes = txBarcode.Text; if (barcodes.Length % 10 != 0) { MessageBox.Show("Error"); return; } List <string> bc = new List <string>(); for (int i = 0; i < barcodes.Length / 10; i++) { bc.Add(barcodes.Substring(i * 10, 10)); } txBarcode.Text = null; if (openFileDialog1.ShowDialog() == DialogResult.OK) { using (StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.UTF8)) { List <int> singleBlock = new List <int>(); List <int[]> dataFormat = new List <int[]>(); while (!sr.EndOfStream) { string text = sr.ReadLine(); string[] format = text.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); foreach (string bit in format) { singleBlock.Add(int.Parse(bit)); } dataFormat.Add(singleBlock.ToArray()); singleBlock.Clear(); } int[] deValues, deFormat; BarcodeCore.BarcodeDecoder(bc, dataFormat, out deValues, out deFormat); if (deValues == null) { MessageBox.Show("Error"); return; } string decodeValue = "Barcodes:\r\n"; foreach (string barcode in bc) { decodeValue += barcode + "\r\n"; } decodeValue += "\r\nDecode Data:\r\n"; for (int i = 0; i < deValues.Length; i++) { if (deFormat[i] == 24) { string word = ""; int mask = 0x3F; for (int j = 0; j < 4; j++) { int idx = (deValues[i] >> 6 * j) & mask; word += BarcodeCore.numberText[idx]; } decodeValue += word + "\r\n"; } else if (deFormat[i] == 32) { byte[] iByte = BitConverter.GetBytes(deValues[i]); float f2 = BitConverter.ToSingle(iByte, 0); decodeValue += f2.ToString() + "\r\n"; } else { decodeValue += deValues[i].ToString() + "\r\n"; } } txInfo.Text = decodeValue; } } }