protected void buttonAccountRegisterE_OnClick(object sender, EventArgs e) { if (ddUsers.SelectedValue == Guid.Empty.ToString()) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Du må velge en konto først"); return; } try { Database.Interface.open(); Database.Ringtest ringtest = new Database.Ringtest(); if (ringtest.select_all_where_year(DateTime.Now.Year)) { if (ringtest.Finished) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Ringtesten for " + DateTime.Now.Year.ToString() + " er avsluttet"); return; } } Database.Account account = new Database.Account(); account.select_all_where_ID(new Guid(ddUsers.SelectedValue)); if (account.update_Int_by_ID("intLastRegistrationYear", DateTime.Now.Year)) { Utils.displayStatus(ref labelStatusEdit, Color.SeaGreen, "Konto '" + account.Name + "' etter-registrert"); tbLastRegistrationE.Text = DateTime.Now.Year.ToString(); } else { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Etter-registrering av konto feilet"); } } catch (Exception ex) { Utils.displayStatus(ref labelStatusEdit, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void buttonAccountUnregisterE_OnClick(object sender, EventArgs e) { if (ddUsers.SelectedValue == Guid.Empty.ToString()) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Du må velge en konto først"); return; } try { Database.Interface.open(); Database.Account account = new Database.Account(); account.select_all_where_ID(new Guid(ddUsers.SelectedValue)); Database.Ringtest ringtest = new Database.Ringtest(); if (ringtest.select_all_where_year(DateTime.Now.Year)) { Database.RingtestReport.delete_where_AccountID_and_Year(account.ID, ringtest.ID); } account.RingtestBoxID = Guid.Empty; account.select_LastYear_from_RingtestReport(); if (!account.update_all_by_ID()) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "buttonAccountUnregisterE_OnClick: Oppdatering av konto feilet"); return; } tbLastRegistrationE.Text = account.LastRegistrationYear.ToString(); Utils.displayStatus(ref labelStatusEdit, Color.SeaGreen, "Konto '" + account.Name + "' avregistrert fra årets ringtest"); } catch (Exception ex) { Utils.displayStatus(ref labelStatusEdit, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void initializePage() { bool ringtestExists = false; bool hasStarted = false; try { Database.Interface.open(); Database.Configuration configuration = new Database.Configuration(); if (!configuration.select_all_where_name("Default")) { Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: Configuration not found"); return; } Database.Ringtest ringtest = new Database.Ringtest(); if (ringtest.select_all_where_year(DateTime.Now.Year)) { ringtestExists = true; if (DateTime.Now >= ringtest.StartDate) { hasStarted = true; } if (hasStarted && ringtest.Finished) { multiViewRingtest.SetActiveView(viewFinished); return; } } Database.Account account = new Database.Account(); if (!account.select_all_where_ID(new Guid(hiddenAccountID.Value))) { Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: Account not found"); return; } if (account.LastRegistrationYear != DateTime.Now.Year) { if (hasStarted) { // send info to admin multiViewRingtest.SetActiveView(viewSendMessage); labelSendMessage.Text = Lang.RingtestAlreadyStarted; } else { multiViewRingtest.SetActiveView(viewRegister); labelRegister.Text = Lang.RingtestAccountNotRegistered; } return; } if (hasStarted) { hiddenRingtestID.Value = ringtest.ID.ToString(); } else { multiViewRingtest.SetActiveView(viewNoInit); if (ringtestExists) { labelInit.Text = Lang.RingtestNotStarted + " " + ringtest.StartDate.ToShortDateString(); } else { labelInit.Text = Lang.RingtestDateNotDetermined; } return; } if (account.RingtestBoxID == Guid.Empty) { multiViewRingtest.SetActiveView(viewSendMessage); labelSendMessage.Text = Lang.RingtestAccountBoxNotAssigned; return; } hiddenRingtestBoxID.Value = account.RingtestBoxID.ToString(); Database.DeviceCategory category = new Database.DeviceCategory(); if (!category.select_all_where_name("Detektor")) { multiViewRingtest.SetActiveView(viewNoInit); labelInit.Text = Lang.DatabaseError; Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: Category 'Detektor' not found"); return; } List <Database.Identifiers> idList = new List <Database.Identifiers>(); if (!Database.Device.select_identifiers_where_accountID_categoryID_status(account.ID, category.ID, "Ok", ref idList)) { multiViewRingtest.SetActiveView(viewNoInit); labelInit.Text = Lang.RingtestNoDetectors1 + " " + account.Name + Lang.RingtestNoDetectors2 + " " + configuration.RingtestAdminEmail + " " + Lang.RingtestNoDetectors3; return; } ddDetector.Items.Add(new ListItem("---", Guid.Empty.ToString())); foreach (Database.Identifiers ids in idList) { ddDetector.Items.Add(new ListItem(ids.Name, ids.ID.ToString())); } } catch (Exception ex) { Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: " + ex.Message); } finally { Database.Interface.close(); } multiViewRingtest.SetActiveView(viewSelectDetector); }
protected void buttonUpdateED_OnClick(object sender, EventArgs e) { if (ddCategoriesED.SelectedValue == Guid.Empty.ToString() || ddTypesED.SelectedValue == Guid.Empty.ToString() || String.IsNullOrEmpty(ddStatusED.Text) || ddOwnershipED.SelectedValue == Guid.Empty.ToString()) { Utils.displayStatus(ref labelStatusCreate, Color.Red, "Mangler informasjon"); return; } try { Database.Interface.open(); Database.Device device = new Database.Device(); device.select_all_where_ID((Guid)gridDevicesED.SelectedDataKey.Value); if (device.AccountID.ToString() != ddAccountED.SelectedValue) { Database.Ringtest ringtest = new Database.Ringtest(); if (ringtest.select_all_where_year(DateTime.Now.Year)) { Database.RingtestReport report = new Database.RingtestReport(); if (report.select_all_where_ringtestID_AccountID_DetectorID_approved(ringtest.ID, device.AccountID, device.ID, false)) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Oppdatering avbrutt. Kan ikke oppdatere innehaver fordi enheten har en aktiv ringtestrapport"); return; } } } device.DeviceCategoryID = new Guid(ddCategoriesEdit.SelectedValue); device.DeviceTypeID = new Guid(ddTypesEdit.SelectedValue); device.AccountID = new Guid(ddAccountED.SelectedValue); device.SerialNumber = tbSerialnumberED.Text; device.Status = ddStatusED.SelectedValue; device.Ownership = ddOwnershipED.SelectedValue; device.Comment = tbCommentED.Text; device.ReceivedNew = String.IsNullOrEmpty(tbReceivedNewED.Text) ? DateTime.MinValue : DateTime.Parse(tbReceivedNewED.Text); if (device.update_by_ID()) { Utils.displayStatus(ref labelStatusEdit, Color.SeaGreen, "Enhet oppdatert"); } else { Utils.displayStatus(ref labelStatusEdit, Color.SeaGreen, "Oppdatering av enhet feilet"); } gridDevicesED.SelectedIndex = -1; gridDevicesED.DataBind(); gridDevicesAllED.DataBind(); panelDeviceED.Visible = false; } catch (Exception ex) { Utils.displayStatus(ref labelStatusEdit, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void buttonDetectorContinue_OnClick(object sender, EventArgs e) { if (ddDetector.SelectedValue == Guid.Empty.ToString()) { Utils.displayStatus(ref labelStatusSelectDetector, Color.Red, Lang.NoDetectorSelected); return; } try { Database.Ringtest ringtest = new Database.Ringtest(); Database.RingtestReport report = new Database.RingtestReport(); Database.RingtestBox box = new Database.RingtestBox(); Database.Interface.open(); if (!ringtest.select_all_where_year(DateTime.Now.Year)) { Utils.reportStatus(ref labelStatusSelectDetector, Color.Red, "Ringtest.buttonDetectorContinue_OnClick: No ringtest found for year " + DateTime.Now.Year.ToString()); return; } if (!report.select_all_where_accountID_detectorID_ringtestID( new Guid(hiddenAccountID.Value), new Guid(ddDetector.SelectedValue), ringtest.ID)) { report.AccountID = new Guid(hiddenAccountID.Value); report.DetectorID = new Guid(ddDetector.SelectedValue); report.RingtestID = ringtest.ID; report.RingtestBoxID = new Guid(hiddenRingtestBoxID.Value); report.AnswerByEmail = false; report.MeasureDate = SqlDateTime.MinValue.Value; report.RefDate = SqlDateTime.MinValue.Value; if (!report.insert_with_ID(Guid.NewGuid())) { Utils.reportStatus(ref labelStatusSelectDetector, Color.Red, "Ringtest.buttonDetectorContinue_OnClick: Insert new report failed"); return; } } if (!box.select_all_where_ID(report.RingtestBoxID)) { Utils.reportStatus(ref labelStatusSelectDetector, Color.Red, "Ringtest.buttonDetectorContinue_OnClick: Ringtestbox not found"); return; } hiddenRingtestReportID.Value = report.ID.ToString(); multiViewRingtest.SetActiveView(viewRingtestReport); Database.Device detector = new Database.Device(); if (!detector.select_all_where_ID(report.DetectorID)) { Utils.reportStatus(ref labelStatusReport, Color.Red, "Ringtest.buttonDetectorContinue_OnClick: Detector not found"); return; } labelReportDetector.Text = detector.SerialNumber; if (report.ContactID == Guid.Empty) { ddCurrentActor.SelectedIndex = -1; } else { ddCurrentActor.SelectedValue = report.ContactID.ToString(); } ddMCAType.SelectedValue = report.MCAType; labelBoxWeight.Text = Utils.roundOff(box.Weight, 1) + "g (" + box.KNumber + ")"; //calMeasureDate.SelectedDate = report.MeasureDate; tbBackground.Text = Utils.roundOff(report.Background, 2); tbIntegralBackground.Text = Utils.intToString(report.IntegralBackground); tbCountingBackground.Text = Utils.intToString(report.CountingBackground); tbGeometryFactor.Text = Utils.roundOff(report.GeometryFactor, 2); tbActivity.Text = Utils.roundOff(report.Activity, 1); tbActivityRef.Text = Utils.roundOff(report.ActivityRef, 1); tbUncertainty.Text = Utils.roundOff(report.Uncertainty, 1); tbAvgIntegralSample.Text = Utils.roundOff(report.AvgIntegralSample, 1); tbAvgLivetimeSample.Text = Utils.roundOff(report.AvgLivetimeSample, 1); //calRefDate.SelectedDate = report.RefDate; cbWantEvaluation.Checked = report.WantEvaluation; cbAnswerByEmail.Checked = report.AnswerByEmail; cbEvaluated.Checked = report.Evaluated; cbApproved.Checked = report.Approved; gridComments.DataSource = Database.RingtestReport.get_comments(report.ID); gridComments.DataBind(); if (report.MeasureDate != SqlDateTime.MinValue.Value) { calMeasureDate.SelectedDate = report.MeasureDate; } if (report.RefDate != SqlDateTime.MinValue.Value) { calRefDate.SelectedDate = report.RefDate; } if (report.Approved) { ddCurrentActor.Enabled = false; ddMCAType.Enabled = false; tbMeasureDate.Enabled = false; tbBackground.ReadOnly = true; tbIntegralBackground.ReadOnly = true; tbCountingBackground.ReadOnly = true; tbGeometryFactor.ReadOnly = true; tbActivity.ReadOnly = true; tbActivityRef.ReadOnly = true; tbUncertainty.ReadOnly = true; tbAvgIntegralSample.ReadOnly = true; tbAvgLivetimeSample.ReadOnly = true; tbRefDate.Enabled = false; cbWantEvaluation.Enabled = false; cbAnswerByEmail.Enabled = false; buttonRingtestReportUpdate.Enabled = false; } else { ddCurrentActor.Enabled = true; ddMCAType.Enabled = true; tbMeasureDate.Enabled = true; tbBackground.ReadOnly = false; tbIntegralBackground.ReadOnly = false; tbCountingBackground.ReadOnly = false; tbGeometryFactor.ReadOnly = false; tbActivity.ReadOnly = false; tbActivityRef.ReadOnly = false; tbUncertainty.ReadOnly = false; tbAvgIntegralSample.ReadOnly = false; tbAvgLivetimeSample.ReadOnly = false; tbRefDate.Enabled = true; cbWantEvaluation.Enabled = true; cbAnswerByEmail.Enabled = true; buttonRingtestReportUpdate.Enabled = true; } if (ddMCAType.SelectedValue == "Inspector1000") { tbIntegralBackground.Visible = false; labelIntegralBackground.Visible = false; tbCountingBackground.Visible = false; labelCountingBackground.Visible = false; tbBackground.Visible = false; labelBackground.Visible = false; tbAvgIntegralSample.Visible = false; labelAvgIntegralSample.Visible = false; tbActivity.Visible = false; labelActivity.Visible = false; labelGeometryFactor.Text = Lang.Efficiency; labelUncertainty.Text = Lang.Uncertainty_insp1000; } else { tbIntegralBackground.Visible = true; labelIntegralBackground.Visible = true; tbCountingBackground.Visible = true; labelCountingBackground.Visible = true; tbBackground.Visible = true; labelBackground.Visible = true; tbAvgIntegralSample.Visible = true; labelAvgIntegralSample.Visible = true; tbActivity.Visible = true; labelActivity.Visible = true; labelGeometryFactor.Text = Lang.GeometryFactor; labelUncertainty.Text = Lang.Uncertainty_serie10; } } catch (Exception ex) { Utils.displayStatus(ref labelStatusSelectDetector, Color.Red, "Ringtest.buttonDetectorContinue_OnClick: " + ex.Message); Utils.displayStatus(ref labelStatusReport, Color.Red, "Ringtest.buttonDetectorContinue_OnClick: " + ex.Message); } finally { Database.Interface.close(); } }