private void StepCategory_Load(object sender, EventArgs e) { if (!DesignMode) { Localizer.TranslateControl(this); Dictionary<int, ProcessType> types = new Dictionary<int, ProcessType>(); foreach (var form in options.Processes) if (!types.ContainsKey(form.ProcessType.Id)) types.Add(form.ProcessType.Id, form.ProcessType); if (types.Count == 0) DoFinish(); foreach (var t in types.Values) { var index = tblNewUnits.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize }); var lblName = new H3bLabel { AutoSize = true, Text = t.TypeName, Margin = new Padding(0, 5, 10, 5) }; tblNewUnits.Controls.Add(lblName, 0, index); var lnk = new H3Link { Text = Translations.DownloadImportFile, Margin = new Padding(0, 5, 10, 5) }; tblNewUnits.Controls.Add(lnk, 1, index); lnk.ClickOverride += () => { List<IHaveDynamicIndicatorValues> forms = options.Processes.Where(s => s.ProcessType.Id == t.Id).Cast<IHaveDynamicIndicatorValues>().ToList(); ProcessImporter importer = new ProcessImporter(); importer.SetType(t.Id); var payload = new SplitDistro.WorkerPayload { FileName = Util.CleanFilename(t.TypeName) + "_" + options.SplitType.ToString() + DateTime.Now.ToString("yyyyMMdd") + ".xlsx", Importer = importer, Forms = forms }; SplitDistro.CreateDownload(payload); }; var lnk2 = new H3Link { Text = Translations.UploadImportFile, Margin = new Padding(0, 5, 10, 5) }; tblNewUnits.Controls.Add(lnk2, 2, index); lnk2.ClickOverride += () => { Upload(t); }; } } }
private void Upload(ProcessType type) { List<IHaveDynamicIndicatorValues> forms = new List<IHaveDynamicIndicatorValues>(); forms = options.Processes.Where(d => d.ProcessType.Id == type.Id).Cast<IHaveDynamicIndicatorValues>().ToList(); ProcessImporter importer = new ProcessImporter(); importer.SetType(type.Id); var payload = new Nada.UI.View.Wizard.SplitDistro.WorkerPayload { Importer = importer, Forms = forms, }; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = Translations.ExcelFiles + " (*.xlsx)|*.xlsx"; ofd.DefaultExt = ".xlsx"; if (ofd.ShowDialog() == DialogResult.OK) { OnSwitchStep(new WorkingStep(Translations.ImportingFile)); payload.FileName = ofd.FileName; BackgroundWorker importerWorker = new BackgroundWorker(); importerWorker.DoWork += importerWorker_DoWork; importerWorker.RunWorkerCompleted += importerWorker_RunWorkerCompleted; importerWorker.RunWorkerAsync(payload); } }