public override void OnBarcode(string Barcode) { textBoxControl.Hide(); string prefix = "SB_NAC."; int asterixIndex = Barcode.IndexOf("*"); string barcodePrefix = ""; BarcodeValue barcodeValue = new BarcodeValue(); if (Barcode.Length > 7) { barcodePrefix = Barcode.Substring(0, 7); barcodeValue.Value = Barcode.Substring(7); } if (barcodePrefix == prefix && barcodeValue.Value != "") { #region Обработка штрих-кода номенклатуры if (currentBarcodeValue.IsEquals(barcodeValue)) { ShowMessage("Вы отсканировали текущий тип работ."); return; } string name = GetNomenclatureDescr(barcodeValue.NomenclatureID); if (name == null) { if (ShowQuery("Данная номенклатура не найдена. Необходимо обновить базу на устройстве и повторить сканирование.\r\nОбновить базу на устройстве?")) { UpdateRules(); } return; } ShowRules(barcodeValue); currentBarcodeValue.Value = barcodeValue.Value; Nomenclature = name; #endregion } else if (Barcode.Length == 13 && Number.IsNumber(Barcode)) { // Обработка штрих-кода паллеты if (currentBarcodeValue.Value == "") { // Еще не был отсканирован тип работы ShowMessage("Начните со сканирования штрих-кода типа работы"); return; } AddPalletNumber(Barcode.Substring(1, 11)); } else { ShowMessage("Ожидается штрих-код паллеты или типа работы!"); } }
public int CompareTo(Barcode other) { int compare = 0; if (BarcodeType != other.BarcodeType) { return(BarcodeType.CompareTo(other.BarcodeType)); } if (BarcodeValue != other.BarcodeValue) { return(BarcodeValue.CompareTo(other.BarcodeValue)); } return(compare); }
public bool IsEquals(BarcodeValue b) { return(nomID == b.nomID && depID == b.depID); }
private bool ShowRules(BarcodeValue barcodeVal) { if (currentBarcodeValue.Value != "") { WriteMarks(); } ParentCriterions = new Dictionary <long, ParentCriterionData>(); bool isExistResult = false; table.DT.Rows.Clear(); using (SqlCeConnection dBConnection = new SqlCeConnection(DBEngine.LocalConnectionString)) { dBConnection.Open(); using (SqlCeCommand SQLCommand = dBConnection.CreateCommand()) { SQLCommand.CommandText = "select \r\n" + "c.Id,\r\n" + "c.Descr,\r\n" + "c.HaveSubCriterion,\r\n" + "c.ParentCriterionId,\r\n" + "c.LineNumber,\r\n" + "m.Mark\r\n" + "from Criterions c\r\n" + "join NomenclatureCriterions r\r\n" + "on c.Id = r.CriterionsId \r\n" + "or c.ParentCriterionId = r.CriterionsId\r\n" + "left join Marks m\r\n" + "on c.Id = m.CriterionsId\r\n" + "and r.NomenclatureId = m.NomenclatureId\r\n" + "and c.ParentCriterionId = m.ParentCriterionId\r\n" + "and m.DepartmentId = @DepartmentId\r\n" + "where r.NomenclatureId = @NomenclatureId\r\n" + "order by r.Number, c.LineNumber"; SQLCommand.Parameters.AddWithValue("@NomenclatureId", barcodeVal.NomenclatureID); SQLCommand.Parameters.AddWithValue("@DepartmentId", barcodeVal.DepartmentID); using (SqlCeDataReader result = SQLCommand.ExecuteReader()) { while (result.Read()) { object obj = result["Mark"]; if (obj == DBNull.Value) { obj = 0; } long criterionsId = (long)result["Id"]; bool haveSubCriterion = (bool)result["HaveSubCriterion"]; long parentCriterionId = (long)result["ParentCriterionId"]; DataRow row = table.AddRow(((int)result["LineNumber"] > 0 ? (" " + result["LineNumber"].ToString() + ". ") : "") + ((string)result["Descr"]).Trim(), criterionsId, obj, haveSubCriterion, parentCriterionId); isExistResult = true; if (haveSubCriterion) { if (!ParentCriterions.ContainsKey(criterionsId)) { ParentCriterions.Add(criterionsId, new ParentCriterionData(row)); } else { ParentCriterions[criterionsId].SetRow(row); } } if (parentCriterionId > 0) { if (!ParentCriterions.ContainsKey(parentCriterionId)) { ParentCriterions.Add(parentCriterionId, new ParentCriterionData()); ParentCriterions[parentCriterionId].SubCriterionsId.Add(criterionsId, (int)obj); } else { ParentCriterions[parentCriterionId].SubCriterionsId.Add(criterionsId, (int)obj); } } } } } } foreach (ParentCriterionData pcd in ParentCriterions.Values) { long sum = 0; foreach (long val in pcd.SubCriterionsId.Values) { sum = sum + val; } pcd.Row["Mark"] = 100 - sum; } return(isExistResult); }
public bool IsEquals(BarcodeValue b) { return nomID == b.nomID && depID == b.depID; }
private bool ShowRules(BarcodeValue barcodeVal) { if (currentBarcodeValue.Value != "") { WriteMarks(); } ParentCriterions = new Dictionary<long, ParentCriterionData>(); bool isExistResult = false; table.DT.Rows.Clear(); using (SqlCeConnection dBConnection = new SqlCeConnection(DBEngine.LocalConnectionString)) { dBConnection.Open(); using (SqlCeCommand SQLCommand = dBConnection.CreateCommand()) { SQLCommand.CommandText = "select \r\n" + "c.Id,\r\n" + "c.Descr,\r\n" + "c.HaveSubCriterion,\r\n" + "c.ParentCriterionId,\r\n" + "c.LineNumber,\r\n" + "m.Mark\r\n" + "from Criterions c\r\n" + "join NomenclatureCriterions r\r\n" + "on c.Id = r.CriterionsId \r\n" + "or c.ParentCriterionId = r.CriterionsId\r\n" + "left join Marks m\r\n" + "on c.Id = m.CriterionsId\r\n" + "and r.NomenclatureId = m.NomenclatureId\r\n" + "and c.ParentCriterionId = m.ParentCriterionId\r\n" + "and m.DepartmentId = @DepartmentId\r\n" + "where r.NomenclatureId = @NomenclatureId\r\n" + "order by r.Number, c.LineNumber"; SQLCommand.Parameters.AddWithValue("@NomenclatureId", barcodeVal.NomenclatureID); SQLCommand.Parameters.AddWithValue("@DepartmentId", barcodeVal.DepartmentID); using (SqlCeDataReader result = SQLCommand.ExecuteReader()) { while (result.Read()) { object obj = result["Mark"]; if (obj == DBNull.Value) obj = 0; long criterionsId = (long)result["Id"]; bool haveSubCriterion = (bool)result["HaveSubCriterion"]; long parentCriterionId = (long)result["ParentCriterionId"]; DataRow row = table.AddRow(((int)result["LineNumber"] > 0 ? (" " + result["LineNumber"].ToString() + ". ") : "") + ((string)result["Descr"]).Trim(), criterionsId, obj, haveSubCriterion, parentCriterionId); isExistResult = true; if (haveSubCriterion) { if (!ParentCriterions.ContainsKey(criterionsId)) { ParentCriterions.Add(criterionsId, new ParentCriterionData(row)); } else { ParentCriterions[criterionsId].SetRow(row); } } if (parentCriterionId > 0) { if (!ParentCriterions.ContainsKey(parentCriterionId)) { ParentCriterions.Add(parentCriterionId, new ParentCriterionData()); ParentCriterions[parentCriterionId].SubCriterionsId.Add(criterionsId, (int)obj); } else { ParentCriterions[parentCriterionId].SubCriterionsId.Add(criterionsId, (int)obj); } } } } } } foreach (ParentCriterionData pcd in ParentCriterions.Values) { long sum = 0; foreach (long val in pcd.SubCriterionsId.Values) { sum = sum + val; } pcd.Row["Mark"] = 100 - sum; } return isExistResult; }
private void Receiver(object sender, SerialDataReceivedEventArgs e) { Console.WriteLine(Environment.NewLine + nameBarDec + "Получение данных | {0}", DateTime.Now.ToLocalTime().ToString()); if (e.EventType != SerialData.Eof) { IsBarcodeDecode = false; byte[] buf = null; foreach (SerialPort port in _port) { if (port.BytesToRead != 0) { Console.WriteLine(nameBarDec + "Данные c {0}:", port.PortName); try { int bytesToRead = port.BytesToRead; buf = new byte[bytesToRead]; port.Read(buf, 0, bytesToRead); validBarcode = BarcodeVersions.IsValidBarcode(buf); BarcodeVersion barcodeVersion = BarcodeVersions.GetBarcodeVersion(buf); if (validBarcode) { #region Декодирование int offset = 0; object[] values = new object[7] { GetObject(buf, _cnvs[typeof(NumberConverter)], typeof(byte), ref offset), GetObject(buf, _cnvs[typeof(NumberConverter)], typeof(ulong), ref offset), GetObject(buf, _cnvs[typeof(OMS62EncodingStringConverter)], typeof(string), ref offset, 51), GetObject(buf, _cnvs[typeof(NumberConverter)], typeof(byte), ref offset), GetObject(buf, _cnvs[typeof(ShortBirthDateConverter)], typeof(DateTime), ref offset), GetObject(buf, _cnvs[typeof(ShortBirthDateConverter)], typeof(DateTime), ref offset), ((IEnumerable <byte>)buf).ToList <byte>().GetRange(offset, barcodeVersion.Length - offset).ToArray() // электронная подпись }; #endregion string[] fullname = values[2].ToString().Split('|'); BarcodeData = new BarcodeValue { code_type_Barcode = Convert.ToInt32(values[0]), number_Policy = Convert.ToInt64(values[1]), FullName = String.Format("{0} {1} {2}", fullname[0], fullname[1], fullname[2]), Surname = fullname[0], Name = fullname[1], Middle_Name = fullname[2], Gender = Convert.ToInt32(values[3]), Date_of_Birth = Convert.ToDateTime(values[4]).ToShortDateString(), _Date = Convert.ToDateTime(values[5]).ToShortDateString(), Bytecode = (byte[])values[6] }; Console.WriteLine(nameBarDec + "code_type_Barcode: " + BarcodeData.code_type_Barcode); Console.WriteLine(nameBarDec + "number_Policy: " + BarcodeData.number_Policy); Console.WriteLine(nameBarDec + "FullName: " + BarcodeData.FullName); Console.WriteLine(nameBarDec + "Gender: " + BarcodeData.Gender); Console.WriteLine(nameBarDec + "Date_of_Birth: " + BarcodeData.Date_of_Birth); Console.WriteLine(nameBarDec + "_Date: " + BarcodeData._Date); Console.WriteLine(nameBarDec + "Bytecode: " + BitConverter.ToString(BarcodeData.Bytecode)); try { onBarcodeDecode(this, BarcodeData); } catch (NullReferenceException ex) { Console.WriteLine(nameBarDec + ex.Message); } IsBarcodeDecode = true; port.DiscardInBuffer(); } } catch (Exception ex) { Console.WriteLine(nameBarDec + "Ошибка во время декодирования: " + ex.Message); } } } } else { Console.WriteLine(nameBarDec + "Нет, это не данные!"); } }