private void btnSave_Click(object sender, EventArgs e) { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName, false, Encoding.UTF8)) { for (int i = 0; i < dataGridView1.RowCount - 1; i++) { string name = dataGridView1[0, i].Value.ToString(); DataGridViewComboBoxCell vcbc = (DataGridViewComboBoxCell)dataGridView1[1, i]; //int index = vcbc.Items.IndexOf(vcbc.Value); string size = (string)vcbc.Value; sw.WriteLine(name + "\t" + size); } sw.Flush(); sw.Close(); } string fname = saveFileDialog1.FileName.Split(new string[] { ".txt" }, StringSplitOptions.RemoveEmptyEntries)[0] + "_format.txt"; using (StreamWriter sw = new StreamWriter(fname, false, Encoding.UTF8)) { List <int[]> format = BarcodeCore.getFormatData(getAllBits()); foreach (int[] singleBlock in format) { foreach (int bit in singleBlock) { sw.Write(bit.ToString() + "\t"); } sw.Write("\r\n"); } sw.Flush(); sw.Close(); } } }
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 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; }
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; } } }