private void btnOk_Click(object sender, EventArgs e) { if (!editing) { Guid nuclideId = mNuclides[cboxNuclides.Text]; if (!Utils.IsValidGuid(nuclideId)) { MessageBox.Show("The nuclide field is mandatory"); return; } } if (String.IsNullOrEmpty(tbActivity.Text.Trim())) { MessageBox.Show("The activity field is mandatory"); return; } if (String.IsNullOrEmpty(tbUncertainty.Text.Trim())) { MessageBox.Show("The uncertainty field is mandatory"); return; } if ((double)cboxSigmaActivity.SelectedValue == 0d) { MessageBox.Show("Sigma uncertainty is mandatory"); return; } if ((double)cboxSigmaMDA.SelectedValue == 0d) { MessageBox.Show("Sigma MDA is mandatory"); return; } bool approved = cbActivityApproved.Checked || cbDetectionLimitApproved.Checked; if (approved) { using (SqlConnection conn = DB.OpenConnection()) { if (!DB.CanUserApproveAnalysis(conn, null, Common.UserId, mAnalysis.AnalysisMethodId)) { MessageBox.Show("You are not allowed to approve results for this analysis method"); return; } } } if (!approved && (cbAccredited.Checked || cbReportable.Checked)) { MessageBox.Show("Activity or MDA must be approved before setting accredited and reportable"); return; } double act; if (!Double.TryParse(tbActivity.Text.Trim(), out act)) { MessageBox.Show("Invalid number format on activity"); return; } if (act < 0d) { MessageBox.Show("Activity can not be negative"); return; } if (act == 0 && cbActivityApproved.Checked) { MessageBox.Show("Can not approve an activity of zero"); return; } double unc; if (!Double.TryParse(tbUncertainty.Text.Trim(), out unc)) { MessageBox.Show("Invalid number format on uncertainty"); return; } if (unc < 0d) { MessageBox.Show("Uncertainty can not be negative"); return; } if (!cbUncertaintyAbs.Checked) { if (unc < 0d || unc > 100d) { MessageBox.Show("Activity uncertianty is out of percent range [0, 100]"); return; } unc = act * (unc / 100d); } double sigmaAct = Convert.ToDouble(cboxSigmaActivity.SelectedValue); unc /= sigmaAct; unc *= 2d; double detlim; if (!Double.TryParse(tbDetectionLimit.Text.Trim(), out detlim)) { MessageBox.Show("Invalid number format on detection limit"); return; } if (detlim < 0d) { MessageBox.Show("Detection limit can not be negative"); return; } if (detlim == 0 && cbDetectionLimitApproved.Checked) { MessageBox.Show("Can not approve a MDA of zero"); return; } double sigmaMDA = Convert.ToDouble(cboxSigmaMDA.SelectedValue); detlim /= sigmaMDA; detlim *= 1.645d; mResult.Activity = act; mResult.ActivityUncertaintyABS = unc; mResult.DetectionLimit = detlim; mResult.ActivityApproved = cbActivityApproved.Checked; mResult.DetectionLimitApproved = cbDetectionLimitApproved.Checked; mResult.Accredited = cbAccredited.Checked; mResult.Reportable = cbReportable.Checked; if (!editing) { mResult.AnalysisId = mAnalysis.Id; mResult.NuclideName = cboxNuclides.Text; mResult.NuclideId = mNuclides[mResult.NuclideName]; mAnalysis.Results.Add(mResult); } mResult.Dirty = true; DialogResult = DialogResult.OK; Close(); }