private bool TryDecode(string full_bin_list) { BinaryBox1.Clear(); BinaryBox2.Clear(); PatterBox.Clear(); number_type[] n_type_array = new number_type[12]; for (int i = 0; i < 12; i++) { if (!encoding_table.TryGetValue(full_bin_list.Substring(i * 7, 7), out n_type_array[i])) { label1.Text = "Error. There is no such bit patter in encoding table"; return(false); } if (i < 6) { BinaryBox1.Text += full_bin_list.Substring(i * 7, 7) + " "; } else { BinaryBox2.Text += full_bin_list.Substring(i * 7, 7) + " "; } } string encoded_type_str = ""; for (int i = 0; i < 6; i++) { encoded_type_str += n_type_array[i].type.ToString(); } for (int i = 0; i < 12; i++) { PatterBox.Text += n_type_array[i].type.ToString(); } int first_number = -1; for (int i = 0; i < 10; i++) { if (first_number_code[i] == encoded_type_str) { first_number = i; break; } } if (first_number == -1) { label1.Text = "Error. First number wasn't recognized"; return(false); } string fullEAN = first_number.ToString(); for (int i = 0; i < 12; i++) { fullEAN += n_type_array[i].number.ToString(); } DigitBox.Text = fullEAN; if (get_control_sum(fullEAN) != int.Parse(fullEAN[12].ToString())) { label1.Text = "Error. Checksum is wrong"; return(false); } return(true); }
private bool TryDecode(string full_bin_list, number_type[] n_type_array) { BinaryBox.Clear(); PatterBox.Clear(); for (int i = 0; i < 12; i++) { if (!encoding_table.TryGetValue(full_bin_list.Substring(i * 7, 7), out n_type_array[i])) { label1.Text = "Error. There is no such bit patter in encoding table"; return(false); } BinaryBox.Text += full_bin_list.Substring(i * 7, 7) + " "; } string encoded_type_str = ""; for (int i = 0; i < 6; i++) { encoded_type_str += n_type_array[i].type.ToString(); } for (int i = 0; i < 12; i++) { PatterBox.Text += n_type_array[i].type.ToString(); } int first_number = -1; for (int i = 0; i < 10; i++) { if (first_number_code[i] == encoded_type_str) { first_number = i; break; } } if (first_number == -1) { label1.Text = "Error. First number wasn't recognized"; return(false); } string fullEAN = first_number.ToString(); for (int i = 0; i < 12; i++) { fullEAN += n_type_array[i].number.ToString(); } DigitBox.Text = fullEAN; int[] fullIntEAN = new int[13]; fullIntEAN[0] = first_number; for (int i = 0; i < 12; i++) { fullIntEAN[i + 1] = n_type_array[i].number; } if (!checkCode(fullIntEAN)) { label1.Text = "Error. Checksum is wrong"; return(false); } return(true); }