private void convertAllDataToLong() { data = new long[blockSize]; byte[] dataBytes = new byte[4]; // 0: [Version, Concentration Unit, null, T Band Appears] dataBytes[0] = 0; dataBytes[1] = (byte)CBConcUnit.SelectedIndex; dataBytes[3] = (byte)lTBandAppear; data[0] = dataBytes2Long(dataBytes); // 1 - 5: Product ID string[] prodID = splitString4char(txProdId.Text, 5); for (int i = 0; i < 5; i++) { data[i + 1] = BarcodeCore.Text256ToLong(prodID[i]); } // 6 - 8: Product Lot string[] prodLot = splitString4char(txProdLot.Text, 3); for (int i = 0; i < 3; i++) { data[i + 6] = BarcodeCore.Text256ToLong(prodLot[i]); } // 9: Expiration Date DateTime dateTime = dateTimePicker1.Value; dataBytes = new byte[4]; dataBytes[0] = (byte)dateTime.Day; dataBytes[1] = (byte)dateTime.Month; byte[] expYear = BitConverter.GetBytes(dateTime.Year); dataBytes[2] = expYear[0]; dataBytes[3] = expYear[1]; data[9] = dataBytes2Long(dataBytes); // 10: [Left Bound, Top Bound, Target Width, Target Height] dataBytes = new byte[4]; dataBytes[0] = (byte)mLb; dataBytes[1] = (byte)mTb; dataBytes[2] = (byte)mTw; dataBytes[3] = (byte)mTh; data[10] = dataBytes2Long(dataBytes); // 11: [Right Bound, Target C-T Interval, Target T-T Interval, Invalid Threshold (C Cutoff)] dataBytes = new byte[4]; dataBytes[0] = (byte)mRb; dataBytes[1] = (byte)mTi; dataBytes[2] = (byte)mTi; dataBytes[3] = (byte)mCco; data[11] = dataBytes2Long(dataBytes); // 12: [Rows, Lines, T1 Cutoff RLU, T2 Cutoff RLU] dataBytes = new byte[4]; dataBytes[0] = (byte)mRows; dataBytes[1] = (byte)mLines; dataBytes[2] = (byte)mTco; data[12] = dataBytes2Long(dataBytes); // 13: T1 Cutoff Concentration data[13] = BarcodeCore.FloatToLong(mTCoC); // 14: T1 Name data[14] = BarcodeCore.Text256ToLong(mTn); // 15 - 19: T1 RLU-Concentration Pairs x 5 for (int i = 0; i < fRLUs.Length; i++) { dataBytes = new byte[4]; byte[] tmpRLU = BarcodeCore.float16ToBytes(fRLUs[i]); byte[] tmpConc = BarcodeCore.float16ToBytes(fConcs[i]); dataBytes[0] = tmpRLU[0]; dataBytes[1] = tmpRLU[1]; dataBytes[2] = tmpConc[0]; dataBytes[3] = tmpConc[1]; data[i + 15] = dataBytes2Long(dataBytes); } }
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; }