public TestForm() { InitializeComponent(); serviceProvider = new ActivatorServiceProvider(); cbScenarios.DisplayMember = nameof(ScenarioBase.ScenarioName); var scenarios = ScenarioResolver.GetScenariosFromAssembly(this.GetType().Assembly, serviceProvider); cbScenarios.Items.AddRange(scenarios); int prevIndex = 0; cbScenarios.SelectedIndexChanged += (s, e) => { if (prevIndex != cbScenarios.SelectedIndex) { scenarios[prevIndex].Clear(); } viewport.Controls.Clear(); var control = scenarios[cbScenarios.SelectedIndex].Initialize(); control.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left; control.Size = viewport.Size; viewport.Controls.Add(control); prevIndex = cbScenarios.SelectedIndex; }; cbScenarios.SelectedIndex = 0; }
public List <FundResponse.UploadReportData> UploadFundResponse(User user, string zipPath, bool runScenario) { List <FundResponse.UploadReportData> report = new List <FundResponse.UploadReportData>(); string zipDirectoryName = Path.Combine(ConfiguraionProvider.FileStorageFolder, Path.GetFileNameWithoutExtension(zipPath)); ZipHelper.UnZipFiles(zipPath, zipDirectoryName); FundResponseCreateDataBuilder builder = new FundResponseCreateDataBuilder(); var responsesToCreate = GetResponsesFromArchive(builder, zipDirectoryName); var responsesByclientVisitId = GroupByClientVisitId(report, responsesToCreate); DateTime date = DateTime.Now; foreach (var pack in responsesByclientVisitId) { long clientVisitId = pack.Key; ClientVisit clientVisit = ClientDao.Instance.ClientVisit_Get(clientVisitId); if (clientVisit == null) { foreach (var response in pack.Value) { report.Add(new FundResponse.UploadReportData() { Recid = response.Recid, ClientVisitId = clientVisitId, ResponseTypeName = response.GetResponseTypeName(), UploadResult = "Не найдена соответствующая заявка" }); } continue; } ClientVisit lastClientVisitInGroup = ClientDao.Instance.ClientVisit_GetLastClientVisitInGroup(clientVisit.VisitGroupId); ReferenceItem lastCurrentStatus = clientVisit.Status; DateTime lastClientStatusDate = clientVisit.StatusDate; long? lastClientVisitId = null; if (lastClientVisitInGroup.Status.Id == ClientVisitStatuses.FundError.Id || lastClientVisitInGroup.Status.Id == ClientVisitStatuses.AnswerPending.Id || lastClientVisitInGroup.Status.Id == ClientVisitStatuses.Processed.Id) { clientBusinessLogic.ClientVisit_SetStatus(user, lastClientVisitInGroup.Id, ClientVisitStatuses.Reconciliation.Id, true); lastCurrentStatus = ClientVisitStatuses.Reconciliation; lastClientStatusDate = date; } if (lastClientVisitInGroup.Status.Id == ClientVisitStatuses.SubmitPending.Id) { ClientVisit.SaveData newClientVisitData = new ClientVisit.SaveData(lastClientVisitInGroup); newClientVisitData.Status = ClientVisitStatuses.Reconciliation.Id; lastCurrentStatus = ClientVisitStatuses.Reconciliation; newClientVisitData.StatusDate = date; lastClientStatusDate = date; newClientVisitData.IsActual = true; var saveResult = clientBusinessLogic.ClientVisit_Save(user, newClientVisitData, date); lastClientVisitId = saveResult.ClientVisitID; } foreach (var response in pack.Value) { FundProcessingDao.Instance.FundResponse_Create(response, date); report.Add(AddReportItem(clientVisit, response, lastClientVisitId, lastCurrentStatus, lastClientStatusDate)); } if (runScenario) { clientVisit = ClientDao.Instance.ClientVisit_GetLastClientVisitInGroup(clientVisit.VisitGroupId); ScenarioResolver resolver = new ScenarioResolver(clientVisit, pack.Value.OfType <ReconciliationFundResponse.CreateData>().ToList()); ReferenceItem resolvedScenario = resolver.GetResolvedScenario(); ClientVisit.SaveData data = ClientVisit.SaveData.BuildSaveData(clientVisit); if (resolvedScenario != null) { data.ScenarioId = resolvedScenario.Id; data.FundResponseApplyingMessage = string.Format("Сценарий изменён с {0} на {1}", clientVisit.Scenario != null ? clientVisit.Scenario.Code : string.Empty, resolvedScenario.Code); data.IsReadyToFundSubmitRequest = true; ClientVisitOldDataBuilder oldDataBuilder = new ClientVisitOldDataBuilder(data, pack.Value.OfType <IReconciliationFundResponse>().ToList()); ClientVisit firstClientVisit = clientBusinessLogic.ClientVisit_GetFirstClientVisitInGroup(clientVisit.VisitGroupId); ClientVisitNewDataBuilder newDataBuilder = new ClientVisitNewDataBuilder(data, firstClientVisit, pack.Value.OfType <IReconciliationFundResponse>().ToList()); data = oldDataBuilder.Process(); data = newDataBuilder.Process(); } clientBusinessLogic.ClientVisit_Save(user, data); } } return(report); }