Exemplo n.º 1
0
        public void FillData(string _fileName)
        {
            if (File.Exists(_fileName))
            {
                Input = null;
                ListSsCc.Clear();
                IsFillData = false;

                var file = File.ReadAllLines(_fileName);
                if (this.listSsCc == null)
                {
                    this.ListSsCc = new ObservableCollection <SimpleScan.Model.Row>();
                }

                SimpleScan.Model.Row addRow = null;
                foreach (var row in file)
                {
                    string[] r = row.Split('\t');

                    addRow = new SimpleScan.Model.Row()
                    {
                        Id     = int.Parse(r[0]),
                        Pallet = r[1],
                        Carton = r[2],
                        SsCc   = r[3],
                        Date   = DateTime.ParseExact(r[4], LocalDateTimeFormat, System.Globalization.CultureInfo.InvariantCulture)
                    };
                    this.ListSsCc.Add(addRow);
                }
                LastId           = this.listSsCc.OrderBy(i => i.Id).Select(i => i.Id).Last();
                this.SelectedRow = addRow;
            }
            else
            {
                throw new Exception("Текущий файл отсутствует.\nНачинайте просто сканировать");
            }
        }
Exemplo n.º 2
0
 string RowToString(SimpleScan.Model.Row _row)
 {
     return($"{_row.Id}\t{_row.Pallet}\t{_row.Carton}\t{_row.SsCc}\t{_row.Date.ToString(LocalDateTimeFormat)}");
 }
Exemplo n.º 3
0
        public void Add(string input)
        {
            if (!Directory.Exists(DirCurrentFile))
            {
                Directory.CreateDirectory(DirCurrentFile);
            }
            if (!string.IsNullOrWhiteSpace(input))
            {
                try
                {
                    if (input.Length < minLenght)
                    {
                        throw new Exception($"Минимальная длинна шк: {minLenght}");
                    }
                    if (isUniqueSsCc && this.ListSsCc != null)
                    {
                        var find = this.ListSsCc.FirstOrDefault(s => s.SsCc == input);
                        if (find != null)
                        {
                            throw new Exception($"Контроль шникальности, уже отсканирован шк: {input}");
                        }
                    }

                    Regex           regex   = new Regex(regexFindErrorChars);
                    MatchCollection matches = regex.Matches(input);
                    if (matches.Count > 0)
                    {
                        throw new Exception($"Недопустимые символы: {RegexFindErrorChars}");
                    }

                    Validate_FirstScan(CurrentFileName);

                    if (this.listSsCc == null)
                    {
                        this.ListSsCc = new ObservableCollection <SimpleScan.Model.Row>();
                    }

                    //---------------------------------------------------
                    SimpleScan.Model.Row addRow = new SimpleScan.Model.Row()
                    {
                        Id     = LastId + 1,
                        Pallet = Pallet,
                        Carton = Carton,
                        SsCc   = input,
                        Date   = DateTime.Now
                    };
                    this.ListSsCc.Add(addRow);
                    this.SelectedRow = addRow;
                    this.LastInput   = input;

                    string record = RowToString(addRow);
                    File.AppendAllLines(CurrentFileName, new List <string>()
                    {
                        record
                    });
                    IsFillData = true;

                    this.Input = string.Empty;
                    LastId++;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                finally
                {
                    this.Input = string.Empty;
                }
            }
        }