private void comboBox1_SelectedValueChanged(object sender, EventArgs e) { SGTIN sGTIN = new SGTIN(); try { _numberOfSGTINBits = sGTIN.GetSGTINNumberOfBits(((ComboBox)sender).SelectedItem.ToString()); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
private void Serach_Click(object sender, EventArgs e) { listView1.Items.Clear(); if (_FiePath == null || _FiePath == "") { MessageBox.Show("Please choose SGTN EPC file"); return; } SGTIN sgtin = new SGTIN(); System.IO.StreamReader file = new System.IO.StreamReader(_FiePath); string line = ""; while ((line = file.ReadLine()) != null) { if (line[0] != '3' || line[1] != '0') { _invalidSGTIN96_EPC += 1; continue; } try { //Call method and remove Header string binary = sgtin.ConvertHexToListOfInts(line.Remove(0, 2).ToCharArray(), _numberOfSGTINBits); //Remove Filter binary = binary.Remove(0, 3); //Get partition and remove it int partition = Convert.ToInt32(binary.Substring(0, 3), 2); binary = binary.Remove(0, 3); //Get number of digits for Company Prefix, get Company Prefix and remove digits from list int companyPrefixBits = sgtin.GetNumberOfBitsForCompanyPrefix(partition); long companyPrefix = Convert.ToInt64(binary.Substring(0, companyPrefixBits), 2); binary = binary.Remove(0, companyPrefixBits); //Get number of digits for Item Reference, get Item Reference and remove digits from list int itemReferenceBits = sgtin.GetNumberOfBitsForItemReference(partition); long itemReference = Convert.ToInt64(binary.Substring(0, itemReferenceBits), 2); binary = binary.Remove(0, itemReferenceBits); //Compare Item Reference and add to listView if (itemReference.ToString() == _Product.ItemReference) { int serialNumber = Convert.ToInt32(binary, 2); ListViewItem listItem = new ListViewItem(_Product.CompanyName); listItem.SubItems.Add(_Product.ItemName); listItem.SubItems.Add(serialNumber.ToString()); listView1.Items.Add(listItem); listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); _numberOfSearchedItema += 1; } } catch (FormatException formatException) { if (formatException.Message == "Could not find any recognizable digits.") { _invalidSGTIN96_EPC += 1; } } } numberOfInvalidSGTIN96_EPCs.Text = _invalidSGTIN96_EPC.ToString(); numberOfSearchedItems_Label.Text = _numberOfSearchedItema.ToString(); _invalidSGTIN96_EPC = 0; _numberOfSearchedItema = 0; }