private (Position Above, Position Near) GetAboveAndNearPositions(string diskName) { try { Position posAbove = null; Position posNear = null; using (var r = new RegataContext()) { posAbove = r.Positions.AsNoTracking().Where(p => p.Detector == PairedDetector && p.SerialNumber == p.SerialNumber && p.Name == $"AboveCell{diskName}Disk").First(); posNear = r.Positions.AsNoTracking().Where(p => p.Detector == PairedDetector && p.SerialNumber == p.SerialNumber && p.Name == $"NearAndAbove{diskName}Disk").First(); if (posAbove == null || posNear == null || !posAbove.C.HasValue) { Report.Notify(new Message(Codes.ERR_XM_WRONG_POS)); return(null, null); } return(posAbove, posNear); } } catch (Exception ex) { Report.Notify(new Message(Codes.ERR_XM_GET_PIN_POS_UNREG) { DetailedText = ex.Message }); return(null, null); } }
private void FillDefaultElements() { MessageDefault md = null; try { using (var rdbc = new RegataContext()) { md = rdbc.MessageDefaults.Where(m => m.Language == GlobalSettings.CurrentLanguage.ToString()).FirstOrDefault(); } } //FIXME: I would like to use it in Login Form, but I have to remove dependency from DB here. catch { } if (md == null) { md = new MessageDefault() { FooterText = "Show details", ExpandButtonText = "Show details", HideButtonText = "Hide details" }; } _tdf = new TaskDialogFootnote(md.FooterText); _tde = new TaskDialogExpander(); _tde.CollapsedButtonText = md.ExpandButtonText; _tde.ExpandedButtonText = md.HideButtonText; _tde.Position = TaskDialogExpanderPosition.AfterFootnote; }
public ContainersToDetectorsForm(string[] dets, int loadNumber) { InitializeComponent(); _loadNumber = loadNumber; _assignedContainers = new Dictionary <int, bool>(); using (var rc = new RegataContext()) { MaxContNumber = rc.Irradiations.Where(ir => ir.LoadNumber == _loadNumber).Select(ir => ir.Container).Max(); } if (!MaxContNumber.HasValue) { throw new ArgumentNullException($"Irradiation register with loadNumber = {loadNumber} has samples with empty container record."); } foreach (var ic in Enumerable.Range(1, MaxContNumber.Value)) { _assignedContainers.Add(ic, false); } FillDetectorsRow(dets); FillButtonsRow(); ResumeLayouts(); Labels.SetControlsLabels(this); }
public void ReportInfoTest() { var msg = new Message(0) { Caption = "", Head = "", Code = 0, Status = Status.Error, Text = "", DetailedText = "", Sender = "ReportTest" //BaseBody = "TestInform BaseBody", //Level = Status.Error, //Place = "InformLevelTest", //Sender = "ReportTest", //Title = "InformLevelTest", //User = "******", //TechBody = "TestInform TechBody" }; Report.Notify(new Message(0), WriteToLog: true); using (var lc = new RegataContext()) { var last_log = lc.Logs.OrderBy(l => l.DateTime).Last(); Assert.AreEqual(msg.Status.ToString().ToUpper(), last_log.Level); Assert.IsTrue(10 > (DateTime.Now.AddHours(-2) - last_log.DateTime).TotalSeconds); Assert.AreEqual("bdrum", last_log.Assistant); Assert.AreEqual(msg.Sender, last_log.Frominstance); Assert.AreEqual(msg.Code, last_log.Code); } }
public static User GetUserByLogin(string log) { using (var rc = new RegataContext()) { return(rc.Users.Where(u => u.Login == log).FirstOrDefault()); } }
private async Task UpdateCurrentReigster() { try { using (var r = new RegataContext()) { var ir = r.Irradiations.Where(ir => ir.Id == mainForm.MainRDGV.CurrentDbSet.Local.Select(m => m.IrradiationId).Min()).FirstOrDefault(); CurrentMeasurementsRegister.IrradiationDate = ir.DateTimeStart.Value.Date; CurrentMeasurementsRegister.Name = ir.DateTimeStart.Value.Date.ToShortDateString(); CurrentMeasurementsRegister.LoadNumber = ir.LoadNumber; CurrentMeasurementsRegister.DateTimeStart = mainForm.MainRDGV.CurrentDbSet.Local.Select(m => m.DateTimeStart).Min(); CurrentMeasurementsRegister.DateTimeFinish = mainForm.MainRDGV.CurrentDbSet.Local.Select(m => m.DateTimeFinish).Max(); CurrentMeasurementsRegister.SamplesCnt = mainForm.MainRDGV.CurrentDbSet.Local.Where(m => m.FileSpectra != null).Count(); CurrentMeasurementsRegister.Detectors = string.Join(',', mainForm.MainRDGV.CurrentDbSet.Local.Select(m => m.Detector).Distinct().ToArray()); // TODO: https://github.com/regata-jinr/Measurements.Desktop/issues/46 //CurrentMeasurementsRegister.Assistant = GlobalSettings.User; r.MeasurementsRegisters.Update(CurrentMeasurementsRegister); await r.SaveChangesAsync(); } } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_UPD_CUR_MEAS_REG) { DetailedText = ex.ToString() }); } }
private void CreateNewMeasurementsRegister() { try { using (var r = new RegataContext()) { // We can not have Measurement register with duplicate name and type. In case of unhandled stop of app it is possible to // Dispose method of the from will not be run. In this case current register will remain in DB with null value of Name and -1 for type // Here we catch it and remove. var null_register = r.MeasurementsRegisters.Where(m => m.IrradiationDate == null).FirstOrDefault(); if (null_register != null) { r.MeasurementsRegisters.Remove(null_register); } r.MeasurementsRegisters.Add(CurrentMeasurementsRegister); r.SaveChanges(); } } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_CRT_MEAS_REG) { DetailedText = ex.ToString() }); } }
private async Task FillAdditionalTable <T>(DataGridView dgv2, IQueryable <T> query2, bool[] predicatesArray, IEnumerable <string> columnNames) { try { if (predicatesArray[0]) { return; } var _chosenEntities = new List <T>(); _chosenEntities.Clear(); _chosenEntities.Capacity = 499; dgv2.DataSource = null; using (var r = new RegataContext()) { _chosenEntities.AddRange(await query2.ToArrayAsync()); }; _chosenEntities.TrimExcess(); dgv2.DataSource = _chosenEntities; HideTable2RedundantColumns(columnNames); Labels.SetControlsLabels(this); } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_SEL_TBLS_UNREG) { DetailedText = ex.ToString() }); } }
private async Task FillMeasurementsRegisters() { try { using (var r = new RegataContext()) { mainForm.TabsPane[1, 0].DataSource = await r.MeasurementsRegisters .AsNoTracking() .Where(m => m.Type == (int)MeasurementsTypeItems.CheckedItem && m.DateTimeStart.HasValue) .Select(m => new { m.Id, m.LoadNumber, m.IrradiationDate }) .Distinct() .OrderByDescending(m => m.Id) .Take(mainForm.TabsPane[1, 0].RowCount + 20) .ToArrayAsync(); } mainForm.TabsPane[1, 0].FirstDisplayedScrollingRowIndex = mainForm.TabsPane[1, 0].RowCount - 20;; //mainForm.TabsPane[1, 0].Columns[0].Visible = false; } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_MEAS_REGS) { DetailedText = ex.ToString() }); } }
private async Task FillIrradiationRegisters() { try { var type = MeasurementsTypeItems.CheckedItem switch { MeasurementsType.sli => 0, MeasurementsType.bckg => 3, _ => 1 }; using (var r = new RegataContext()) { mainForm.TabsPane[0, 0].DataSource = await r.Irradiations .AsNoTracking() .Where(ir => ir.Type == type && ir.DateTimeStart != null) .Select(ir => new { ir.LoadNumber, ir.DateTimeStart.Value.Date }) .Distinct() .OrderByDescending(i => i.Date) .Take(mainForm.TabsPane[0, 0].RowCount + 20) .ToArrayAsync(); } mainForm.TabsPane[0, 0].FirstDisplayedScrollingRowIndex = mainForm.TabsPane[0, 0].RowCount - 20; } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_IRR_REGS) { DetailedText = ex.ToString() }); } }
private async Task FillSelectedStandards() { try { if (mainForm.TabsPane[1, 0].SelectedCells.Count <= 0) { mainForm.TabsPane[1, 1].DataSource = null; return; } mainForm.TabsPane[1, 1].DataSource = null; _chosenStandards.Clear(); _chosenStandards.Capacity = 199; var set = mainForm.TabsPane[1, 0].SelectedCells[0].Value as string; var set_num = mainForm.TabsPane[1, 0].SelectedCells[1].Value as string; using (var r = new RegataContext()) { _chosenStandards.AddRange(await r.Standards.AsNoTracking() .Where(s => s.SetName == set && s.SetNumber == set_num) .OrderBy(s => s.Number) .ToArrayAsync()); } _chosenStandards.TrimExcess(); if (_displaySetsParam.Checked) { foreach (var ir in mainForm.MainRDGV.CurrentDbSet.Local) { var c = _chosenStandards.Where(cs => ir.Year == "s" && ir.SetNumber == cs.SetName && ir.SetIndex == cs.SetNumber && ir.SampleNumber == cs.Number).FirstOrDefault(); if (c != null) { _chosenStandards.Remove(c); } } } mainForm.TabsPane[1, 1].DataSource = _chosenStandards; HideColumns(mainForm.TabsPane[1, 1], new string[] { "SetName", "SetNumber" }); Labels.SetControlsLabels(mainForm); } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_SEL_STD_UNREG) { DetailedText = ex.ToString() }); } }
private void SetView() { using (var r = new RegataContext()) { var roles = r.UserRoles(); if (!roles.Contains("operator") && !roles.Contains("rehandler") && !roles.Contains("db_owner")) { mainForm.BottomLayoutPanel.Visible = false; } } }
private void InitIrradiationsRegisters() { try { mainForm.TabsPane[0, 0].SuspendLayout(); mainForm.TabsPane[0, 0].MultiSelect = false; mainForm.TabsPane[0, 0].SelectionChanged += async(e, s) => { await FillSelectedIrradiations(); if (mainForm.TabsPane[0, 0].SelectedRows.Count > 0) { CurrentMeasurementsRegister.IrradiationDate = (DateTime)mainForm.TabsPane[0, 0].SelectedRows[0].Cells[1].Value; } }; mainForm.TabsPane[0, 0].Scroll += async(s, e) => { var type = MeasurementsTypeItems.CheckedItem switch { MeasurementsType.sli => 0, MeasurementsType.bckg => 3, _ => 1 }; using (var r = new RegataContext()) { if (mainForm.TabsPane[0, 0].RowCount == await r.Irradiations.AsNoTracking() .Where(ir => ir.Type == type && ir.DateTimeStart != null) .Distinct().CountAsync()) { return; } } if (RowIsVisible(mainForm.TabsPane[0, 0].Rows[mainForm.TabsPane[0, 0].RowCount - 1])) { await FillIrradiationRegisters(); } }; mainForm.TabsPane[0, 0].ResumeLayout(false); } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_INI_IRR_REGS) { DetailedText = ex.ToString() }); } }
private void _goToLLI2_Click(object sender, EventArgs e) { using (var r = new RegataContext()) { if (!r.MeasurementsRegisters.Where(mr => mr.IrradiationDate == _irrDate && mr.Type == 2).Any()) { return; } } var f = new MeasurementsRegisterForm(_irrDate, DataBase.Models.MeasurementsType.lli2); f.mainForm.Show(); }
private async void _downloadpectraMenuItem_Click(object sender, EventArgs e) { try { if (mainForm.MainRDGV == null || mainForm.MainRDGV.SelectedCells.Count <= 0) { return; } if (_folderDialog.ShowDialog() != DialogResult.OK) { return; } var _cts = new CancellationTokenSource(TimeSpan.FromMinutes(2)); mainForm.ProgressBar.Value = 0; mainForm.ProgressBar.Maximum = mainForm.MainRDGV.SelectedCells.OfType <DataGridViewCell>().Select(c => c.RowIndex).Where(c => c >= 0).Distinct().Count(); foreach (var i in mainForm.MainRDGV.SelectedCells.OfType <DataGridViewCell>().Select(c => c.RowIndex).Where(c => c >= 0).Distinct()) { var fileS = mainForm.MainRDGV.Rows[i].Cells["FileSpectra"].Value.ToString(); if (string.IsNullOrEmpty(fileS)) { continue; } using (var rc = new RegataContext()) { var sharedSpectra = rc.SharedSpectra.Where(ss => ss.fileS == fileS).FirstOrDefault(); if (sharedSpectra == null) { continue; } await WebDavClientApi.DownloadFileAsync(sharedSpectra.token, Path.Combine(_folderDialog.SelectedPath, MeasurementsTypeItems.CheckedItem.ToString(), $"{fileS}.cnf"), _cts.Token); mainForm.ProgressBar.Value++; } } } catch (TaskCanceledException) { } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_WF_IRR_REG_DWNL_SPECTRA_UNREG) { DetailedText = ex.ToString() }); } }
public static async Task <List <SpectrumSLI> > GetSLISpectraForSampleSetAsync(string SetKey, CancellationToken ct) { var sks = SetKey.Split('-'); using (var ssc = new RegataContext()) { return(await ssc.SLISpectra.FromSqlRaw("exec FormSLIFilesList @countryCode, @clientid, @year, @setnum, @setind", new SqlParameter("countrycode", sks[0]), new SqlParameter("clientid", sks[1]), new SqlParameter("year", sks[2]), new SqlParameter("setnum", sks[3]), new SqlParameter("setind", sks[4])).ToListAsync(ct)); } }
private void AddAllIrradiationsAndAssignDiskPosition(int loadNumber, Dictionary <string, int[]> det_cont) { using (var r = new RegataContext()) { foreach (var d in det_cont) { int currPosition = 0; foreach (var ir in r.Irradiations.AsNoTracking().Where(ir => ir.LoadNumber == loadNumber && d.Value.ToList().Contains(ir.Container.Value)).OrderBy(ir => ir.Container).ThenBy(ir => ir.Position)) { AddRecord(ir.Id, d.Key, ++currPosition); } } } }
private async Task FillSelectedMeasurements() { try { if (mainForm.TabsPane[1, 0].SelectedCells.Count <= 0) { return; } var mRegId = mainForm.TabsPane[1, 0].SelectedCells[0].Value as int?; if (!mRegId.HasValue) { return; } using (var r = new RegataContext()) { CurrentMeasurementsRegister.IrradiationDate = r.MeasurementsRegisters.AsNoTracking().Where(m => m.Id == mRegId.Value).Select(m => m.IrradiationDate).FirstOrDefault(); var tmp = await r.Measurements .AsNoTracking() .Where( m => m.Type == (int)MeasurementsTypeItems.CheckedItem && m.RegId == mRegId.Value ) .OrderBy(m => m.Detector) .ThenBy(m => m.DiskPosition) .ToArrayAsync(); _chosenMeasurements.AddRange(tmp); }; _chosenMeasurements.TrimExcess(); mainForm.TabsPane[1, 1].DataSource = _chosenMeasurements; HideMeasurementsRedundantColumns(); _SLIShowAlreadyAdded_CheckedChanged(null, null); Labels.SetControlsLabels(mainForm); } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_SEL_MEAS) { DetailedText = ex.ToString() }); } }
public async Task PutSampleAboveDetectorWithHeightAsync(Heights h, CancellationToken ct) { try { var hstr = h switch { Heights.h2p5 => "H2p5", Heights.h5 => "H5", Heights.h10 => "H10", Heights.h20 => "H20", _ => "H2p5" // ? }; Position posAbove = null; using (var r = new RegataContext()) { posAbove = r.Positions.AsNoTracking().Where(p => p.Detector == PairedDetector && p.SerialNumber == p.SerialNumber && p.Name == $"AboveDetector{hstr}").First(); if (posAbove == null) { Report.Notify(new Message(Codes.ERR_XM_WRONG_POS)); return; } } MoveToY(MaxY); await MoveToPositionAsync(posAbove, Axes.X, ct).ConfigureAwait(false); PinnedPosition = h switch { Heights.h2p5 => PinnedPositions.AboveDet2p5, Heights.h5 => PinnedPositions.AboveDet5, Heights.h10 => PinnedPositions.AboveDet10, Heights.h20 => PinnedPositions.AboveDet20 }; } catch (Exception ex) { Report.Notify(new Message(Codes.ERR_XM_PUT_ABV_DET_ASYNC_UNREG) { DetailedText = ex.Message }); } }
private async void MainForm_Load(object sender, EventArgs e) { await FillSamplesRegisters(); await FillStandardsRegisters(); await FillMonitorsRegisters(); mainForm.buttonAddAllSamples.Enabled = true; mainForm.buttonAddSelectedSamplesToReg.Enabled = true; mainForm.buttonRemoveSelectedSamples.Enabled = true; mainForm.MainRDGV.HideColumns(); //mainForm.MainRDGV.SetUpReadOnlyColumns(); mainForm.MainRDGV.SetUpWritableColumns(); if (_irrType == IrradiationType.sli) { mainForm.MainRDGV.Columns["DateTimeStart"].DefaultCellStyle.Format = "dd.MM.yyyy HH:mm:ss"; mainForm.MainRDGV.Columns["DateTimeFinish"].Visible = false; mainForm.MainRDGV.Columns["Container"].Visible = false; mainForm.MainRDGV.Columns["Position"].Visible = false; CheckedContainerArrayControl.Visible = false; controlsMovingInContainer.Visible = false; controlsRepack.Visible = false; _selRowRepackers.Visible = false; } // FIXME: doesn't work properly ColorizeDGV(mainForm.MainRDGV); //_logId[] using (var rc = new RegataContext()) { var repackers = await rc.Users.AsNoTracking().Where(u => u.Role.Contains("rehandler")).ToArrayAsync(); foreach (var u in repackers) { _comboBoxRepackers.Items.Add(u.Login); _logId[u.Login] = u.Id; } } _comboBoxRepackers.SelectedItem = null; _comboBoxRepackers.SelectedText = "Assing repacker to selected samples"; Labels.SetControlsLabels(mainForm); #if !DEBUG SetView(); #endif }
public Message(int code) { Code = code; Status = code == 0 ? Status.Error : (Status)(code / 1000); using (var rdbc = new RegataContext()) { _mb = rdbc.MessageBases.Where(m => m.Code == Code && m.Language == GlobalSettings.CurrentLanguage.ToString()).FirstOrDefault(); } if (_mb == null) { _mb = new MessageBase(); } Head = _mb.Head; Text = _mb.Text; }
private void InitMeasurementsRegisters() { try { mainForm.TabsPane[1, 0].SuspendLayout(); mainForm.TabsPane[1, 0].MultiSelect = false; mainForm.TabsPane[1, 0].SelectionChanged += async(e, s) => { _chosenMeasurements.Clear(); _chosenMeasurements.Capacity = 499; mainForm.TabsPane[1, 1].DataSource = null; await FillSelectedMeasurements(); }; mainForm.TabsPane[1, 0].Scroll += async(s, e) => { using (var r = new RegataContext()) { if (mainForm.TabsPane[1, 0].RowCount == await r.Irradiations.AsNoTracking() .Where(m => m.Type == (int)MeasurementsTypeItems.CheckedItem && m.DateTimeStart.HasValue) .Distinct().CountAsync()) { return; } } if (RowIsVisible(mainForm.TabsPane[1, 0].Rows[mainForm.TabsPane[1, 0].RowCount - 1])) { await FillMeasurementsRegisters(); } }; mainForm.TabsPane[1, 0].ResumeLayout(false); } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_INI_MEAS_REGS) { DetailedText = ex.ToString() }); } }
private async Task MStartAsync(Detector d) { try { var m = GetFirstNotMeasuredForDetector(d.Name); if (m == null) { //Report.Notify(new RCM.Message(Codes.WARN_UI_WF_ACQ_START_ALL_MEAS)); return; } Irradiation i = null; using (var r = new RegataContext()) { i = r.Irradiations.Where(ir => ir.Id == m.IrradiationId).FirstOrDefault(); if (i == null) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_ACQ_START_IRR_NF)); return; } } await RunSampleChangerCycle(d); d.LoadMeasurementInfoToDevice(m, i); await RunSampleChangerCycle(d); d.Start(); Report.Notify(new RCM.Message(Codes.SUCC_UI_WF_ACQ_START) { Head = $"{d.Name} complete acq for {d.CurrentMeasurement}" }); } catch (Exception ex) { Det_HardwareError(d); Report.Notify(new RCM.Message(Codes.ERR_UI_WF_ACQ_START) { DetailedText = ex.ToString() }); } }
public static async IAsyncEnumerable <SpectrumSLI> GetSLISpectraForSampleSetAsync(string SetKey, CancellationToken ct) { var sks = SetKey.Split('-'); using (var ssc = new RegataContext()) { var sliSpectras = ssc.SLISpectra.FromSqlRaw("exec FormSLIFilesList @countryCode, @clientid, @year, @setnum, @setind", new SqlParameter("countrycode", sks[0]), new SqlParameter("clientid", sks[1]), new SqlParameter("year", sks[2]), new SqlParameter("setnum", sks[3]), new SqlParameter("setind", sks[4])).AsAsyncEnumerable().WithCancellation(ct); await foreach (var spectraInfo in sliSpectras) { yield return(spectraInfo); } } }
private void InitMonitorsRegisters() { try { mainForm.TabsPane[2, 0].SuspendLayout(); mainForm.TabsPane[2, 0].MultiSelect = false; mainForm.TabsPane[2, 0].SelectionChanged += async(e, s) => { _chosenMonitors.Clear(); _chosenMonitors.Capacity = 499; mainForm.TabsPane[2, 1].DataSource = null; await FillSelectedMonitors(); }; mainForm.TabsPane[2, 0].Scroll += async(s, e) => { using (var r = new RegataContext()) { if (mainForm.TabsPane[2, 0].RowCount == await r.MonitorSets.AsNoTracking().CountAsync()) { return; } } if (RowIsVisible(mainForm.TabsPane[2, 0].Rows[mainForm.TabsPane[2, 0].RowCount - 1])) { await FillMonitorsRegisters(); } }; mainForm.TabsPane[2, 0].ResumeLayout(false); } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_INI_MON_REGS_UNREG) { DetailedText = ex.ToString() }); } }
private RegisterForm <Irradiation> Create_Form(string name) { var f = new RegisterForm <Irradiation>(); f.LangItem.CheckItem(Settings <LabelsSettings> .CurrentSettings.CurrentLanguage); f.LangItem.CheckedChanged += () => { Settings <LabelsSettings> .CurrentSettings.CurrentLanguage = f.LangItem.CheckedItem; Labels.SetControlsLabels(f); }; f.Name = name; var btn = new Button(); f.BottomLayoutPanel.Controls.Add(btn, 1, 0); using (var r = new RegataContext()) { f.TabsPane[0, 0].DataSource = r.Irradiations.Where(ir => ir.Type == 1 && ir.DateTimeStart != null).Select(ir => new { ir.LoadNumber, ir.DateTimeStart.Value.Date }).Distinct().Take(10).ToArray(); f.TabsPane[1, 0].DataSource = r.Irradiations.Where(ir => ir.Type == 0 && ir.DateTimeStart != null).Select(ir => new { ir.DateTimeStart.Value.Date }).Distinct().Take(10).ToArray(); } Labels.SetControlsLabels(f); return(f); }
private async Task FillMainTable <T1>(DataGridView dgv1, IQueryable <T1> query1) { try { using (var r = new RegataContext()) { dgv1.DataSource = await query1.ToArrayAsync(); } dgv1.FirstDisplayedScrollingRowIndex = dgv1.RowCount - 20;; } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_TBL1_UNREG) { DetailedText = ex.ToString() }); } }
private static T GetWeightedSample <T>(ISample sample) where T : class, ISample { if (sample == null) { return(null); } using (var r = new RegataContext()) { return(r.Set <T>().Where(s => s.CountryCode == sample.CountryCode && s.ClientNumber == sample.ClientNumber && s.Year == sample.Year && s.SetNumber == sample.SetNumber && s.SetIndex == sample.SetIndex && s.SampleNumber == sample.SampleNumber) .FirstOrDefault()); } }
private async Task FillSamplesRegisters() { try { using (var r = new RegataContext()) { if (!_displaySetsParam.Checked || !mainForm.MainRDGV.CurrentDbSet.Local.Any()) { mainForm.TabsPane[0, 0].DataSource = await r.SamplesSets .AsNoTracking() .Select(ss => new { ss.CountryCode, ss.ClientNumber, ss.Year, ss.SetNumber, ss.SetIndex }) .Distinct() .OrderByDescending(ss => ss.Year) .ThenByDescending(ss => ss.SetNumber) .ThenByDescending(ss => ss.SetIndex) .Take(mainForm.TabsPane[0, 0].RowCount + 20) .ToArrayAsync(); mainForm.TabsPane[0, 0].FirstDisplayedScrollingRowIndex = mainForm.TabsPane[0, 0].RowCount - 20; } else { mainForm.TabsPane[0, 0].DataSource = mainForm.MainRDGV.CurrentDbSet.Local .Where(ss => ss.Year != "s" && ss.Year != "m") .Select(ss => new { ss.CountryCode, ss.ClientNumber, ss.Year, ss.SetNumber, ss.SetIndex }) .Distinct() .OrderByDescending(ss => ss.Year) .ThenByDescending(ss => ss.SetNumber) .ThenByDescending(ss => ss.SetIndex) .ToArray(); } } } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_FILL_SMP_REGS_UNREG) { DetailedText = ex.ToString() }); } }
public static T GetSrmOrMonitor <T>(string SrmOrMonitorStringId) where T : class, ISrmAndMonitor { try { if (string.IsNullOrEmpty(SrmOrMonitorStringId)) { return(null); } if (!SrmOrMonitorStringId.Contains("s-") && !SrmOrMonitorStringId.Contains("m-")) { return(null); } var ssid_arr = SrmOrMonitorStringId.Split('-'); if (ssid_arr.Length != 5) { return(null); } using (var r = new RegataContext()) { return(r.Set <T>().Where(s => s.SetName == ssid_arr[1] && s.SetNumber == ssid_arr[2] && s.Number == ssid_arr[3]) .FirstOrDefault()); } } catch (Exception ex) { Report.Notify(new Message(Codes.ERR_DATA_GET_SRMSID) { DetailedText = string.Join(Environment.NewLine, SrmOrMonitorStringId, ex.Message) }); return(null); } }