private async void ButtonSaveToDB_Click(object sender, EventArgs e) { FooterStatusProgressBar.Value = 0; var _cancellationTokenSource = new CancellationTokenSource(); _cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(TimeOutSeconds)); try { ButtonSaveToDB.Enabled = false; FooterStatusLabel.Text = _labels.GetLabel("InitSavingToDb"); await _ic.SaveChangesAsync(_cancellationTokenSource.Token); FooterStatusLabel.Text = _labels.GetLabel("SavedToDbSuccessfuly"); FooterStatusProgressBar.Value = FooterStatusProgressBar.Maximum; } catch (OperationCanceledException) { FooterStatusLabel.Text = _labels.GetLabel("ExportCancelledByTimeout"); } catch (DbUpdateException tie) { MessageBoxTemplates.WrapExceptionToMessageBox(new ExceptionEventsArgs() { exception = tie.InnerException, Level = ExceptionLevel.Warn }); } finally { ButtonSaveToDB.Enabled = true; _cancellationTokenSource.Dispose(); } }
private async void ButtonDeleteRow_Click(object sender, EventArgs e) { try { if (DataGridView.SelectedCells.Count == 0) { MessageBoxTemplates.InfoSync(_labels.GetLabel("SelectBeforeRemove")); return; } var res = MessageBox.Show(_labels.GetLabel("WarningBeforeRemove"), "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (res == DialogResult.Cancel) { return; } foreach (DataGridViewCell selCell in DataGridView.SelectedCells) { _ic.Samples.Remove(Data.Where(s => s.ToString() == SetKey && s.A_Sample_ID == selCell.OwningRow.Cells["A_Sample_ID"].Value.ToString()).FirstOrDefault()); DataGridView.Rows.Remove(selCell.OwningRow); } await _ic.SaveChangesAsync(); } catch (Exception ex) { MessageBoxTemplates.ErrorSync(ex.Message); } }
private void DataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= DataGridView.Rows.Count) { return; } if (e.RowIndex == -1) { return; } if (DataGridView.Rows[e.RowIndex].IsNewRow) { return; } ButtonSaveToDB.Enabled = true; var cell = DataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; var column = DataGridView.Columns[e.ColumnIndex]; if (column.Name == "A_Longitude" || column.Name == "A_Latitude") { if (cell.Value == null) { MessageBoxTemplates.InfoSync($"Value of {column.Name} is empty and doesn't match with template: <->00.00000<0>"); return; } if (cell.Value.ToString().Length > 9) { MessageBoxTemplates.InfoSync($"Value of {column.Name} is to long for db {cell.Value.ToString().Length}. Should be 9."); return; } var reg = new System.Text.RegularExpressions.Regex(@"[-]{0,1}\d{1,2}.\d{1,6}"); if (!reg.IsMatch(cell.Value.ToString())) { MessageBoxTemplates.InfoSync($"Format of {column.Name} doesn't match with template: <->00.00000<0>"); return; } if (!double.TryParse(cell.Value.ToString(), out _)) { MessageBoxTemplates.InfoSync($"Format of {column.Name} doesn't match with template: <->00.00000<0>"); return; } } }
private async void MenuItemMenuSpectraAll_Click(object sender, EventArgs e) { if (_folderDialog.ShowDialog() != DialogResult.OK) { return; } _cts = new CancellationTokenSource(); FooterStatusLabel.Text = $"{_labels.GetLabel("InitAllSpectraDownloading")}"; FooterStatusProgressBar.Value = 0; ButtonCancel.Enabled = true; try { _cts = new CancellationTokenSource(); var sliSpectras = SpectraTools.SLISetSpectrasAsync(SetKey, _cts.Token).WithCancellation(_cts.Token); var lli1Spectras = SpectraTools.LLISetSpectrasAsync(SetKey, IrradiationType.LLI1, _cts.Token).WithCancellation(_cts.Token); var lli2Spectras = SpectraTools.LLISetSpectrasAsync(SetKey, IrradiationType.LLI2, _cts.Token).WithCancellation(_cts.Token); var taskSli = Task.Run(async() => { await foreach (var ssi in sliSpectras.WithCancellation(_cts.Token)) { if (_cts == null) { _cts = new CancellationTokenSource(); } await WebDavClientApi.DownloadFile(ssi.token, Path.Combine(_folderDialog.SelectedPath, SetKey, "SLI", ssi.SampleType, $"{ssi.SampleSpectra}.cnf"), _cts.Token); } }); var taskLLI1 = Task.Run(async() => { await foreach (var ssi in lli1Spectras.WithCancellation(_cts.Token)) { if (_cts == null) { _cts = new CancellationTokenSource(); } await WebDavClientApi.DownloadFile(ssi.token, Path.Combine(_folderDialog.SelectedPath, SetKey, SpectraTools.IrradiationTypeMap[IrradiationType.LLI1], ssi.LoadNumber.ToString(), $"c-{ssi.Container}", ssi.SampleType, $"{ssi.SampleSpectra}.cnf"), _cts.Token); } }); var taskLLI2 = Task.Run(async() => { await foreach (var ssi in lli2Spectras.WithCancellation(_cts.Token)) { if (_cts == null) { _cts = new CancellationTokenSource(); } await WebDavClientApi.DownloadFile(ssi.token, Path.Combine(_folderDialog.SelectedPath, SetKey, SpectraTools.IrradiationTypeMap[IrradiationType.LLI2], ssi.LoadNumber.ToString(), $"c-{ssi.Container}", ssi.SampleType, $"{ssi.SampleSpectra}.cnf"), _cts.Token); } }); await Task.WhenAll(taskSli, taskLLI1, taskLLI2); FooterStatusLabel.Text = $"{_labels.GetLabel("AllSpectraDownldCompl")}"; FooterStatusProgressBar.Value = FooterStatusProgressBar.Maximum; } catch (IndexOutOfRangeException) { MessageBox.Show(_labels.GetLabel("SpectraNotFound"), Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (OperationCanceledException ose) { FooterStatusProgressBar.Value = 0; FooterStatusLabel.Text = _labels.GetLabel("CancelOperation"); } catch (AggregateException ae) { foreach (var ie in ae.InnerExceptions) { MessageBoxTemplates.WrapExceptionToMessageBox(new ExceptionEventsArgs() { exception = ie, Level = ExceptionLevel.Error }); } } finally { ButtonCancel.Enabled = false; _cts.Dispose(); _cts = null; } }
private async void MenuItemMenuSpectraLLI_Click(object sender, EventArgs e) { if (_folderDialog.ShowDialog() != DialogResult.OK) { return; } var objName = (sender as ToolStripMenuItem)?.Name; var type = objName.Contains("LLI1") ? IrradiationType.LLI1 : IrradiationType.LLI2; _cts = new CancellationTokenSource(); ButtonCancel.Enabled = true; try { FooterStatusProgressBar.Value = 0; FooterStatusProgressBar.Maximum = 1; var i = 0; await foreach (var ssi in SpectraTools.LLISetSpectrasAsync(SetKey, type, _cts.Token).WithCancellation(_cts.Token)) { if (_cts == null) { _cts = new CancellationTokenSource(); } i++; if (i % 2 == 0) { FooterStatusProgressBar.Value = 0; } FooterStatusLabel.Text = $"{_labels.GetLabel("DownloadingFile")}{ssi.SampleSpectra}"; await WebDavClientApi.DownloadFile(ssi.token, Path.Combine(_folderDialog.SelectedPath, SetKey, SpectraTools.IrradiationTypeMap[type], ssi.LoadNumber.ToString(), $"c-{ssi.Container}", ssi.SampleType, $"{ssi.SampleSpectra}.cnf"), _cts.Token); FooterStatusProgressBar.Value = 1; } if (i == 0) { throw new IndexOutOfRangeException(); } FooterStatusLabel.Text = $"{_labels.GetLabel("DownloadingHasDone")}{i}"; } catch (IndexOutOfRangeException) { MessageBox.Show(_labels.GetLabel("SpectraNotFound"), Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (OperationCanceledException ose) { try { FooterStatusProgressBar.Value = 0; FooterStatusLabel.Text = _labels.GetLabel("CancelOperation"); } catch (NullReferenceException) { } } catch (AggregateException ae) { foreach (var ie in ae.InnerExceptions) { MessageBoxTemplates.WrapExceptionToMessageBox(new ExceptionEventsArgs() { exception = ie, Level = ExceptionLevel.Error }); } } finally { ButtonCancel.Enabled = false; _cts?.Dispose(); _cts = null; } }
private async void ExportFromGoogleButton_Click(object sender, EventArgs e) { FooterStatusProgressBar.Value = 0; FooterStatusLabel.Text = _labels.GetLabel("InitialExport"); if (Data.Any()) { var res = MessageBox.Show(_labels.GetLabel("DeleteFromDB"), _labels.GetLabel("HelpCaptionPromt"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (res == DialogResult.No) { return; } _ic.Samples.RemoveRange(Data); } Data.Clear(); var result = ""; using (Prompt prompt = new Prompt(_labels.GetLabel("HelpMessagePromt"), _labels.GetLabel("HelpCaptionPromt"))) { result = prompt.Result; } if (string.IsNullOrEmpty(result)) { FooterStatusLabel.Text = ""; return; } var _cancellationTokenSource = new CancellationTokenSource(); _cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(TimeOutSeconds)); try { var samples = await ExportData.FromGoogleSheet <Sample>(result, _cancellationTokenSource.Token); FooterStatusProgressBar.Maximum = samples.Length; foreach (var l in samples) { if (string.IsNullOrEmpty(l.A_Client_Sample_ID)) { break; } l.F_Country_Code = SetKey.Split('-')[0]; l.F_Client_Id = SetKey.Split('-')[1]; l.F_Year = SetKey.Split('-')[2]; l.F_Sample_Set_Id = SetKey.Split('-')[3]; l.F_Sample_Set_Index = SetKey.Split('-')[4]; l.A_Sample_ID = (Array.IndexOf(samples, l) + 1).ToString("d2"); Data.Add(l); FooterStatusProgressBar.Value++; } FooterStatusProgressBar.Value = FooterStatusProgressBar.Maximum; FooterStatusLabel.Text = _labels.GetLabel("SuccessExport"); await _ic.Samples.AddRangeAsync(Data); //await _ic.SaveChangesAsync(); } catch (NullReferenceException nre) { MessageBoxTemplates.WrapExceptionToMessageBox(new ExceptionEventsArgs() { exception = nre, Level = ExceptionLevel.Error }); } catch (OperationCanceledException) { FooterStatusLabel.Text = _labels.GetLabel("ExportCancelledByTimeout"); } catch (AggregateException ae) { foreach (var ie in ae.InnerExceptions) { MessageBoxTemplates.WrapExceptionToMessageBox(new ExceptionEventsArgs() { exception = ie, Level = ExceptionLevel.Error }); } } catch (Exception ex) { MessageBoxTemplates.WrapExceptionToMessageBox(new ExceptionEventsArgs() { exception = ex, Level = ExceptionLevel.Error }); } finally { _cancellationTokenSource.Dispose(); } }
private async void ExportFromExcelButton_Click(object sender, EventArgs e) { MessageBoxTemplates.InfoSync("Functional would soon be added"); }