private void OkPB_Click(object sender, RoutedEventArgs e) { MaskContainer mc = new MaskContainer(); mc.MaskID = m_mask.Mask.MaskID; mc.Angle = m_mask.Mask.Angle; mc.Cols = m_mask.Mask.Cols; mc.Description = m_mask.Mask.Description; mc.IsDefault = m_mask.Mask.IsDefault; mc.PlateTypeID = m_mask.Mask.PlateTypeID; mc.ReferenceImageID = m_mask.Mask.ReferenceImageID; mc.Rows = m_mask.Mask.Rows; mc.Shape = m_mask.Mask.Shape; mc.XOffset = m_mask.Mask.XOffset; mc.XSize = m_mask.Mask.XSize; mc.XStep = m_mask.Mask.XStep; mc.YOffset = m_mask.Mask.YOffset; mc.YSize = m_mask.Mask.YSize; mc.YStep = m_mask.Mask.YStep; if (wgDB == null) { wgDB = new WaveguideDB(); } bool success = wgDB.UpdateMask(mc); if (!success) { MessageBox.Show(wgDB.GetLastErrorMsg(), "Database Error: Failed to Update Mask", MessageBoxButton.OK, MessageBoxImage.Error); } Close(); }
void SetMaskIsDefault(MaskContainer mask, bool isDefault) { bool success; if (wgDB == null) { wgDB = new WaveguideDB(); } if (isDefault) // if setting to true, set any others are true to false (to make sure we don't have multiple defaults) { PlateTypeItem ptItem = null; // find parent PlateTypeItem foreach (PlateTypeItem pti in VM.PlateTypeList) { if (mask.PlateTypeID == pti.PlateType.PlateTypeID) { ptItem = pti; break; } } if (ptItem != null) { foreach (MaskContainer mc in ptItem.MaskList) { if (mc.IsDefault) { mc.IsDefault = false; success = wgDB.UpdateMask(mc); } } } } mask.IsDefault = isDefault; success = wgDB.UpdateMask(mask); if (!success) { MessageBox.Show("Failed to Update Mask", wgDB.GetLastErrorMsg(), MessageBoxButton.OK, MessageBoxImage.Error); } }
private void SavePB_Click(object sender, RoutedEventArgs e) { WaveguideDB wgDB = new WaveguideDB(); bool success = wgDB.GetAllFilters(); if (success) { bool goodData = true; string errStr = "No Error"; // check to make sure that the FilterChanger/FilterPosition combination is not already occupied for (int i = 0; i < wgDB.m_filterList.Count(); i++) { if (FilterVM.Filter.FilterChanger == wgDB.m_filterList[i].FilterChanger && FilterVM.Filter.PositionNumber == wgDB.m_filterList[i].PositionNumber) { goodData = false; errStr = ((FilterPositionEnum)FilterVM.Filter.PositionNumber).ToString() + " already taken in " + ((FilterChangerEnum)FilterVM.Filter.FilterChanger).ToString() + " Filter Changer"; } } if (goodData) { if (m_addingNew) { // adding new filter, so call insert FilterContainer fc = FilterVM.Filter; success = wgDB.InsertFilter(ref fc); } else { // updating existing filter, so call update FilterContainer fc = FilterVM.Filter; success = wgDB.UpdateFilter(fc); } if (success) { m_OK = true; Close(); } else { errStr = wgDB.GetLastErrorMsg(); MessageBox.Show(errStr, "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); } } if (!goodData) { MessageBox.Show(errStr, "Error in Filter Data", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void btnLogin_Click(object sender, RoutedEventArgs e) { string username = txtUserName.Text; string password = txtPassword.Password; UserContainer user; bool success = wgDB.IsServerConnected(); if (success) { success = wgDB.GetUserByUsername(username, out user); if (success) { if (user != null) { if (user.Password == password) { GlobalVars.Instance.UserID = user.UserID; GlobalVars.Instance.UserDisplayName = user.Firstname + " " + user.Lastname; GlobalVars.Instance.UserRole = user.Role; ExperimentParams expParams = ExperimentParams.GetExperimentParams; expParams.user = user; LoginSuccess = true; Close(); } else { // password not correct MessageBoxResult result = MessageBox.Show("Incorrect Password", "Login Failure", MessageBoxButton.OK, MessageBoxImage.Error); } } else { // username not found MessageBoxResult result = MessageBox.Show("Username: '******' not found", "Login Failure", MessageBoxButton.OK, MessageBoxImage.Error); } } else { // database query issue MessageBoxResult result = MessageBox.Show("Database query failure!", "Database Failure", MessageBoxButton.OK, MessageBoxImage.Error); } } else { // database connection issue string errMsg = wgDB.GetLastErrorMsg(); MessageBoxResult result = MessageBox.Show(errMsg, "Database Connection Failure", MessageBoxButton.OK, MessageBoxImage.Error); } }
public CameraSettingsContainer AddNew(string description) { CameraSettingsContainer cs = new CameraSettingsContainer(); cs.Description = description; cs.ExposureLimit = CurrentCameraSettings.ExposureLimit; cs.HighPixelThresholdPercent = CurrentCameraSettings.HighPixelThresholdPercent; cs.HSSIndex = CurrentCameraSettings.HSSIndex; cs.IncreasingSignal = CurrentCameraSettings.IncreasingSignal; cs.IsDefault = false; cs.LowPixelThresholdPercent = CurrentCameraSettings.LowPixelThresholdPercent; cs.MaxPercentPixelsAboveHighThreshold = CurrentCameraSettings.MaxPercentPixelsAboveHighThreshold; cs.MinPercentPixelsAboveLowThreshold = CurrentCameraSettings.MinPercentPixelsAboveLowThreshold; cs.StartingExposure = CurrentCameraSettings.StartingExposure; cs.UseEMAmp = CurrentCameraSettings.UseEMAmp; cs.UseFrameTransfer = CurrentCameraSettings.UseFrameTransfer; cs.VertClockAmpIndex = CurrentCameraSettings.VertClockAmpIndex; cs.VSSIndex = CurrentCameraSettings.VSSIndex; cs.EMGainLimit = CurrentCameraSettings.EMGainLimit; cs.StartingBinning = CurrentCameraSettings.StartingBinning; bool success = myWgDB.InsertCameraSettings(ref cs); if (success) { CameraSettingsList.Add(cs); CurrentCameraSettings = cs; } else { string errMsg = myWgDB.GetLastErrorMsg(); MessageBox.Show("Failed to Add new Camera Settings record to database: " + errMsg, "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); cs = null; } return(cs); }
private void DeleteExperimentsBeforeDateTimePB_Click(object sender, RoutedEventArgs e) { ObservableCollection <ExperimentContainer> experiments; bool success = m_db.GetAllExperimentsBeforeDateTime(m_vm.datetime1, out experiments); MessageBoxResult result = MessageBox.Show("Delete " + experiments.Count.ToString() + " Experiments?", "Delete Experiments", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { success = m_db.DeleteAllExperimentsBefore(m_vm.datetime1); if (!success) { string errMsg = m_db.GetLastErrorMsg(); MessageBox.Show("Failed to Delete Experiments: " + errMsg); } } }
public bool WriteExperimentFile_WaveGuide(string filename, List <AnalysisContainer> analysisList) { bool success = true; if (File.Exists(filename)) { MessageBoxResult result = MessageBox.Show("File: " + filename + " already exists! Do you want to over write it?", "File Already Exists", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); switch (result) { case MessageBoxResult.Yes: File.Delete(filename); break; case MessageBoxResult.No: success = false; m_lastErrorString = "File already exists"; break; } } if (success) { try { string delimiter = "\t"; // \t = tab FileStream fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write); using (StreamWriter sw = new StreamWriter(fs)) { // Start writing HEADER sw.WriteLine("<HEADER>"); DateTime dt = m_experiment.TimeStamp; sw.WriteLine("Date" + delimiter + dt.Year.ToString() + "-" + dt.Month.ToString() + "-" + dt.Day.ToString()); sw.WriteLine("Time" + delimiter + dt.Hour.ToString() + ":" + dt.Minute.ToString() + ":" + dt.Second.ToString()); sw.WriteLine("Instrument" + delimiter + "Panoptic"); sw.WriteLine("ProtocolName" + delimiter + m_method.Description); sw.WriteLine("AssayPlateBarcode" + delimiter + m_plate.Barcode); success = m_wgDB.GetAllExperimentCompoundPlatesForExperiment(m_experiment.ExperimentID); if (success) { foreach (ExperimentCompoundPlateContainer ecPlate in m_wgDB.m_experimentCompoundPlateList) { sw.WriteLine("AddPlateBarcode" + delimiter + ecPlate.Barcode); } } ObservableCollection <ExperimentIndicatorContainer> expIndicatorList = new ObservableCollection <ExperimentIndicatorContainer>(); foreach (AnalysisContainer ac in analysisList) { ExperimentIndicatorContainer expIndicator; success = m_wgDB.GetExperimentIndicator(ac.ExperimentIndicatorID, out expIndicator); if (success && expIndicator != null) { // make sure this experiment indicator isn't already in the list bool alreadyInList = false; foreach (ExperimentIndicatorContainer expCont in expIndicatorList) { if (expIndicator.ExperimentIndicatorID == expCont.ExperimentIndicatorID) { alreadyInList = true; break; } } if (!alreadyInList) { sw.WriteLine("Indicator" + delimiter + expIndicator.Description + delimiter + expIndicator.ExcitationFilterDesc + delimiter + expIndicator.EmissionFilterDesc + delimiter + expIndicator.Exposure.ToString() + delimiter + expIndicator.Gain.ToString()); expIndicatorList.Add(expIndicator); } } } success = m_wgDB.GetAllExperimentIndicatorsForExperiment(m_experiment.ExperimentID, out expIndicatorList); if (success) { foreach (ExperimentIndicatorContainer expIndicator in expIndicatorList) { } } sw.WriteLine("NumRows" + delimiter + m_plateType.Rows.ToString()); sw.WriteLine("NumCols" + delimiter + m_plateType.Cols.ToString()); List <EventMarkerContainer> eventMarkerList; success = m_wgDB.GetAllEventMarkersForExperiment(m_experiment.ExperimentID, out eventMarkerList); if (success) { foreach (EventMarkerContainer eventMarker in eventMarkerList) { string timeString = String.Format("{0:0.000}", (float)eventMarker.SequenceNumber / 1000); sw.WriteLine("Event" + delimiter + eventMarker.Name + delimiter + eventMarker.Description + delimiter + timeString); } } sw.WriteLine("Operator" + delimiter + m_user.Username + delimiter + m_user.Lastname + delimiter + m_user.Firstname); sw.WriteLine("Project" + delimiter + m_project.Description); sw.WriteLine("</HEADER>"); // END writing HEADER if (success) { foreach (AnalysisContainer analysis in analysisList) { ExperimentIndicatorContainer expIndicator; success = m_wgDB.GetExperimentIndicator(analysis.ExperimentIndicatorID, out expIndicator); sw.WriteLine("<INDICATOR_DATA" + delimiter + expIndicator.Description + delimiter + ">"); // START write column headers sw.Write("Time" + delimiter); StringBuilder builder = new StringBuilder(); for (int r = 0; r < m_plateType.Rows; r++) { for (int c = 0; c < m_plateType.Cols; c++) { builder.Append((char)(65 + r)).Append(c + 1).Append(delimiter); } } builder.Remove(builder.Length - delimiter.Length, delimiter.Length); // remove last delimiter sw.WriteLine(builder.ToString()); // END write column headers // START writing data frames success = m_wgDB.GetAllAnalysisFramesForAnalysis(analysis.AnalysisID); if (success) { foreach (AnalysisFrameContainer aFrame in m_wgDB.m_analysisFrameList) { string timeString = String.Format("{0:0.000}", (float)aFrame.SequenceNumber / 1000); sw.Write(timeString + delimiter); string[] values = aFrame.ValueString.Split(','); foreach (string val in values) { sw.Write(val + delimiter); } sw.WriteLine(""); } } // END writing data frames sw.WriteLine("</INDICATOR_DATA>"); } } } if (!success) { m_lastErrorString = m_wgDB.GetLastErrorMsg(); } } // end try catch (Exception e) { success = false; m_lastErrorString = e.Message; } } return(success); } // end function
private void SavePB_Click(object sender, RoutedEventArgs e) { bool goodData = true; string errStr = "No Error"; WaveguideDB wgDB = new WaveguideDB(); bool success = wgDB.GetAllProjects(true); bool ProjectNameUnique = true; // if creating a new project, make sure project name isn't already used in database if (m_addingNew) { for (int i = 0; i < wgDB.m_projectList.Count(); i++) { if (wgDB.m_projectList[i].Description.Equals(ProjectVM.ProjectDescription, StringComparison.OrdinalIgnoreCase)) { ProjectNameUnique = false; break; } } } if (ProjectVM.ProjectDescription.Length < 1) { goodData = false; errStr = "Project must have a Name"; } else if (!ProjectNameUnique) { goodData = false; errStr = "Project Name: " + ProjectVM.ProjectDescription + " is already in use by another project (Includes Archived Projects)."; } if (goodData) { ProjectContainer pc = new ProjectContainer(); if (m_addingNew) // creating a new project { pc.Description = ProjectVM.ProjectDescription; pc.Archived = ProjectVM.Archived; pc.TimeStamp = ProjectVM.TimeStamp; success = wgDB.InsertProject(ref pc); } else // updating current project instead of creating a new one { pc.Description = ProjectVM.ProjectDescription; pc.ProjectID = ProjectVM.ProjectID; pc.Archived = ProjectVM.Archived; pc.TimeStamp = ProjectVM.TimeStamp; success = wgDB.UpdateProject(pc); } if (success) { ProjectVM.ProjectDescription = pc.Description; ProjectVM.ProjectID = pc.ProjectID; ProjectVM.Archived = pc.Archived; ProjectVM.TimeStamp = pc.TimeStamp; // delete all current UserProject records for this Project success = wgDB.RemoveProjectFromUserProjectTable(pc.ProjectID); if (success) { // add UserProject records as designed by ProjectVM.Users list for (int i = 0; i < ProjectVM.Users.Count(); i++) { if (ProjectVM.Users[i].AssignedToProject) { success = wgDB.AddUserToProject(ProjectVM.Users[i].UserID, ProjectVM.ProjectID); if (!success) { errStr = wgDB.GetLastErrorMsg(); MessageBox.Show(errStr, "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); break; } } } } } if (success) { m_OK = true; Close(); } } if (!goodData) { MessageBox.Show(errStr, "Error in Project Data", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void SavePB_Click(object sender, RoutedEventArgs e) { if (VM.SaveAsFile) { if (VM.Filename.Length == 0) { System.Windows.MessageBox.Show("Filename cannot be empty.", "Enter a Filename", MessageBoxButton.OK, MessageBoxImage.Warning); return; } string path = VM.Location + "\\" + VM.Filename + ".png"; if (File.Exists(path)) { MessageBoxResult result = System.Windows.MessageBox.Show("File already exists. Do you want to OverWrite it?", "File Already Exists", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { return; } } using (FileStream stream = new FileStream(path, FileMode.Create)) { PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(m_bitmap.Clone())); encoder.Save(stream); stream.Close(); } } else { if (VM.Description.Length == 0) { System.Windows.MessageBox.Show("Description cannot be empty for the Reference Image.", "Enter a Description", MessageBoxButton.OK, MessageBoxImage.Warning); return; } // save as reference image in database WaveguideDB wgDB = new WaveguideDB(); ReferenceImageContainer refCont = new ReferenceImageContainer(); refCont.CompressionAlgorithm = GlobalVars.CompressionAlgorithm; refCont.Depth = 2; refCont.Height = m_height; refCont.Width = m_width; refCont.ImageData = m_imageData; refCont.MaxPixelValue = GlobalVars.MaxPixelValue; refCont.NumBytes = m_imageData.Length * 2; refCont.TimeStamp = DateTime.Now; refCont.Description = VM.Description; refCont.Type = VM.Type; bool alreadyExists; bool success = wgDB.ReferenceImageTypeAlreadyExists(VM.Type, out alreadyExists); if (success) { if (!alreadyExists) { success = wgDB.InsertReferenceImage(ref refCont); if (!success) { System.Windows.MessageBox.Show("Failed to insert Reference Image: " + wgDB.GetLastErrorMsg(), "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } else { string sMessageBoxText = "This reference already exists for: " + VM.Type.ToString() + ". Do you want to replace it?"; string sCaption = "Reference Image Already Exists For This Type"; MessageBoxButton btnMessageBox = MessageBoxButton.YesNo; MessageBoxImage icnMessageBox = MessageBoxImage.Warning; MessageBoxResult rsltMessageBox = System.Windows.MessageBox.Show(sMessageBoxText, sCaption, btnMessageBox, icnMessageBox); switch (rsltMessageBox) { case MessageBoxResult.Yes: // delete the existing reference image success = wgDB.ClearReferenceImageType(VM.Type); if (success) { // insert the new reference image success = wgDB.InsertReferenceImage(ref refCont); if (!success) { System.Windows.MessageBox.Show("Failed to insert Reference Image: " + wgDB.GetLastErrorMsg(), "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { System.Windows.MessageBox.Show("Failed to clear Reference Image: " + wgDB.GetLastErrorMsg(), "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); } break; case MessageBoxResult.No: // do nothing return; } } } } Close(); }
void m_vworks_PostVWorksCommandEvent(object sender, WaveGuideEvents.VWorksCommandEventArgs e) { VWORKS_COMMAND command = e.Command; int param1 = e.Param1; string name = e.Name; string desc = e.Description; int sequenceNumber = m_imager.GetSequenceCount(); bool success; EventMarkerContainer eventMarker; switch (command) { case VWORKS_COMMAND.Protocol_Aborted: PostMessage("VWorks - Protocol Aborted"); m_dispatcher.Invoke((Action)(() => { m_timer.Stop(); VM.DelayText = ""; m_tokenSource.Cancel(); // stops the imaging task VM.RunState = RunExperiment_ViewModel.RUN_STATE.ABORTED; SetButton(VM.RunState); })); break; case VWORKS_COMMAND.Protocol_Resumed: PostMessage("VWorks - Protocol Resumed"); m_dispatcher.Invoke((Action)(() => { m_timer.Stop(); VM.DelayText = ""; VM.DelayHeaderVisible = false; })); break; case VWORKS_COMMAND.Protocol_Complete: PostMessage("VWorks - Protocol Complete"); m_dispatcher.Invoke((Action)(() => { m_timer.Stop(); VM.DelayText = ""; VM.DelayHeaderVisible = false; m_tokenSource.Cancel(); // make sure the imaging task stops VM.RunState = RunExperiment_ViewModel.RUN_STATE.FINISHED; SetButton(VM.RunState); ReportDialog dlg = new ReportDialog(m_project, m_experiment, m_indicatorList); dlg.ShowDialog(); })); break; case VWORKS_COMMAND.Protocol_Paused: PostMessage("VWorks - Protocol Paused"); m_dispatcher.Invoke((Action)(() => { m_delayTime = param1; VM.DelayHeaderVisible = true; m_timer.Start(); })); break; case VWORKS_COMMAND.Event_Marker: PostMessage("VWorks - Event Marker"); m_dispatcher.Invoke((Action)(() => { ChartArray.AddEventMarker(sequenceNumber, desc); eventMarker = new EventMarkerContainer(); eventMarker.Description = desc; eventMarker.ExperimentID = m_experiment.ExperimentID; eventMarker.Name = name; eventMarker.SequenceNumber = sequenceNumber; eventMarker.TimeStamp = DateTime.Now; success = m_wgDB.InsertEventMarker(ref eventMarker); if (!success) { PostMessage("Database Error in InsertEventMarker: " + m_wgDB.GetLastErrorMsg()); } })); break; case VWORKS_COMMAND.Initialization_Complete: PostMessage("VWorks Initialization Complete"); m_dispatcher.Invoke((Action)(() => { BringWindowToFront(); })); break; case VWORKS_COMMAND.Pause_Until: //PostMessage("VWorks - Pause Until"); m_dispatcher.Invoke((Action)(() => { m_delayTime = param1; VM.DelayHeaderVisible = true; VM.DelayText = ((int)(m_delayTime / 1000)).ToString(); m_timer.Start(); })); break; case VWORKS_COMMAND.Set_Time_Marker: //PostMessage("VWorks - Set Time Marker"); break; case VWORKS_COMMAND.Start_Imaging: PostMessage("VWorks - Start Imaging"); ///////////////////////////////////////////////////////////////////////////////// /// Start Imaging Task m_dispatcher.Invoke((Action)(() => { BringWindowToFront(); })); StartImaging_2(10000); //////////////////////////////////////////////////////////////////////////////// break; case VWORKS_COMMAND.Stop_Imaging: PostMessage("VWorks - Stop Imaging"); m_dispatcher.Invoke((Action)(() => { StopImaging(); })); break; case VWORKS_COMMAND.Unrecoverable_Error: PostMessage("VWorks - Unrecoverable Error" + ", " + name + ", " + desc); m_dispatcher.Invoke((Action)(() => { m_timer.Stop(); VM.DelayText = ""; m_tokenSource.Cancel(); // stops the imaging task VM.RunState = RunExperiment_ViewModel.RUN_STATE.ERROR; SetButton(VM.RunState); })); break; case VWORKS_COMMAND.Error: PostMessage("VWorks - Error" + ", " + name + ", " + desc); m_dispatcher.Invoke((Action)(() => { m_timer.Stop(); VM.DelayText = ""; VM.DelayHeaderVisible = false; m_tokenSource.Cancel(); // stops the imaging task VM.RunState = RunExperiment_ViewModel.RUN_STATE.ERROR; SetButton(VM.RunState); })); break; case VWORKS_COMMAND.Message: PostMessage("VWorks - Message, " + name + ", " + desc); break; default: break; } }
private void SavePB_Click(object sender, RoutedEventArgs e) { if (VM.SaveAsFile) { if (VM.Filename.Length == 0) { System.Windows.MessageBox.Show("Filename cannot be empty.", "Enter a Filename", MessageBoxButton.OK, MessageBoxImage.Warning); return; } string path = VM.Location + "\\" + VM.Filename + ".png"; if (File.Exists(path)) { MessageBoxResult result = System.Windows.MessageBox.Show("File already exists. Do you want to OverWrite it?", "File Already Exists", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { return; } } using (FileStream stream = new FileStream(path, FileMode.Create)) { PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(m_bitmap.Clone())); encoder.Save(stream); stream.Close(); } } else { if (VM.Description.Length == 0) { System.Windows.MessageBox.Show("Description cannot be empty for the Reference Image.", "Enter a Description", MessageBoxButton.OK, MessageBoxImage.Warning); return; } // save as reference image in database WaveguideDB wgDB = new WaveguideDB(); ReferenceImageContainer refCont = new ReferenceImageContainer(); refCont.CompressionAlgorithm = GlobalVars.CompressionAlgorithm; refCont.Depth = 2; refCont.Height = m_height; refCont.Width = m_width; refCont.ImageData = m_imageData; refCont.MaxPixelValue = GlobalVars.MaxPixelValue; refCont.NumBytes = m_imageData.Length * 2; refCont.TimeStamp = DateTime.Now; refCont.Description = VM.Description; bool success = wgDB.InsertReferenceImage(ref refCont); if (!success) { System.Windows.MessageBox.Show("Failed to insert Reference Image: " + wgDB.GetLastErrorMsg(), "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); } } Close(); }