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 void RemoveCurrentRegisterIfEmpty() { try { // running creates measurement register. // in case of after disposing the form there are not measurements records for register the last one will be deleted using (var r = new RegataContext()) { if (CurrentMeasurementsRegister.SamplesCnt == 0) { r.MeasurementsRegisters.Remove(CurrentMeasurementsRegister); } r.Measurements.RemoveRange(r.Measurements.Where(m => m.RegId == CurrentMeasurementsRegister.Id && m.FileSpectra == null).ToArray()); r.SaveChanges(); } } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_UI_WF_MAIN_FORM_DISP) { DetailedText = ex.ToString() }); } }