public void AddData(OrderParser parser, List <OrderData> orderData) { var recordCounter = 0; var newEmployeesName = new List <string>(); var payment = parser.GetPayment(); foreach (var data in orderData) { var id = $"{data.FullName}, {data.Office}"; if (!TryGetAllDetalizations(data.WorkDates, payment, data.ID, out var fullDayDetalizations)) { MessageBox.Show(@"Файл не удалось распознать", @"Ошибка при чтении файла", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } recordCounter += fullDayDetalizations.Count; if (repository.GetEmployeeById(id) == null) { newEmployeesName.Add(data.FullName); var newEmployee = new Employee { FullName = data.FullName, Office = data.Office, FullDayDetalizations = fullDayDetalizations, PartialDayDetalization = new List <PartialDayDetalization>(), Fired = false, HoursFullDays = fullDayDetalizations.Sum(d => d.WorkHours) }; repository.SaveEmployee(id, newEmployee); Log.AppendLine( $"Добавлен: {newEmployee.FullName}, {newEmployee.Office}"); continue; } foreach (var d in fullDayDetalizations) { repository.TryAddFullDayDetalization(id, d); } } foreach (var data in orderData) { repository.SaveOrderData(Guid.NewGuid().ToString(), data); } var loadInfo = $@"Загружено {recordCounter} записей Из них новых сотрудников {newEmployeesName.Count}: Посмотреть их можно в файле: {$"{Path.GetDirectoryName(Application.ExecutablePath)}\\Logs"}"; MessageBox.Show(loadInfo, @"Импорт приказа", MessageBoxButtons.OK, MessageBoxIcon.Information); Log.AppendLine(loadInfo); SaveLog(); }
public bool Import() { var parser = new OrderParser(repository); string orderPath = null; using (var openFileDialog = new OpenFileDialog()) { openFileDialog.Filter = @"doc files (*.doc;*.docx)|*.doc;*docx"; if (openFileDialog.ShowDialog() == DialogResult.OK) { orderPath = openFileDialog.FileName; } } if (orderPath != null && parser.TryParse(orderPath, out var orderData)) { AddData(parser, orderData); return(true); } return(false); }