private void MainForm_Activated(object sender, EventArgs e) { if (InputBarcodeBox.Visible) { InputBarcodeBox.Focus(); } }
private async Task ProcessProductImage() { var newFilePath = string.Empty; try { if (_foundImagesEnumerator == null || string.IsNullOrWhiteSpace(InputBarcodeBox.Text)) { return; } newFilePath = await new TaskFactory().StartNew(() => _copyFileService.CopyFile(_foundImagesEnumerator.Current.Path)); _copiedImages.Insert(0, new ProductImage(_foundImagesEnumerator.Current.Id, newFilePath)); ProductImagesList.Items.Insert(0, new ListViewItem(new[] { _foundImagesEnumerator.Current.Id, "" })); } catch (ArgumentException a) { throw new ArgumentException(a.Message); } catch (FileNotFoundException fnf) { _copiedImages.Remove(_copiedImages.FirstOrDefault(img => img.Id == _foundImagesEnumerator.Current.Id)); ProductImagesList.Items.Find(_foundImagesEnumerator.Current.Id, false).FirstOrDefault()?.Remove(); throw new FileNotFoundException("Не удалось скопировать файл в целевую папку\n" + fnf.Message); } catch (IOException io) { ResetSourcePath(io); } catch (Exception ex) { try { if (!string.IsNullOrWhiteSpace(_foundImagesEnumerator.Current.Id)) { if (!_copiedImages.Any(img => img.Id == _foundImagesEnumerator.Current.Id) && !string.IsNullOrWhiteSpace(newFilePath)) { _copiedImages.Insert(0, new ProductImage(_foundImagesEnumerator.Current.Id, newFilePath)); } if (!ProductImagesList.Items.Find(_foundImagesEnumerator.Current.Id, false).Any()) { ProductImagesList.Items.Insert(0, new ListViewItem(new[] { _foundImagesEnumerator.Current.Id, "" })); } } else { throw new ApplicationException(); } } catch { throw new Exception("Неизвестная ошибка в работе приложения\n" + ex.Message); } } finally { InputBarcodeBox.Clear(); } }
private void ResetSourcePath(Exception ex) { _copyFileService.SetSourceDirectory(null); _settings.SourcePath = string.Empty; SaveSettings(); SourceBox.Clear(); SourceBox.BackColor = SystemColors.Control; InputBarcodeBox.Clear(); if (MessageBox.Show(ex.Message + "\nВыбрать заново где находятся файлы?", "Ошибка при поиске файлов изображений", MessageBoxButtons.YesNo) == DialogResult.Yes) { SourceBtn.PerformClick(); } else { InputBarcodeBox.Visible = false; } }
private void NextPicBtn_Click(object sender, EventArgs e) { try { if (!_foundImagesEnumerator.MoveNext()) { _foundImagesEnumerator.Reset(); _foundImagesEnumerator.MoveNext(); } PictureBox.ImageLocation = _foundImagesEnumerator.Current.Path; PictureBox.LoadAsync(); BarcodeLabel.Text = _foundImagesEnumerator.Current.Id; InputBarcodeBox.Focus(); } catch { PictureBox.Image = null; PictureBox.ImageLocation = _foundImagesEnumerator.Current.Path; PictureBox.LoadAsync(); BarcodeLabel.Text = _foundImagesEnumerator.Current.Id; InputBarcodeBox.Focus(); } }