private void Scan_Click(object sender, RoutedEventArgs e) { LoadFrom loadFrom = new LoadFrom(); BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.WorkerSupportsCancellation = true; bool WaitFalg = true; string ErrMsg = ""; worker.DoWork += delegate(object s, DoWorkEventArgs args) { DateTime fileBeforeCreatedTime = WanTai.Controller.EVO.ProcessorFactory.GetDateTimeNow(); Services.DeskTopService desktopService = new Services.DeskTopService(); try { desktopService.CallScanScript(); } catch (Exception ex) { MessageBox.Show("扫描错误!", "系统提示"); return; } //get data from scan files, check plates ,and update scan volume of reagents foreach (ReagentAndSuppliesConfiguration reagent in reagentAndSupplies) { reagent.FirstAddVolume = 0; } foreach (PlateBase plate in ViewPlates) { plate.FirstAddVolume = 0; } DataTable dtScan = GetScanResult(fileBeforeCreatedTime); DataTable dtDitiScan = GetDitiScanResult(fileBeforeCreatedTime); DataTable dtHeaterScan = GetHeaterScanResult(fileBeforeCreatedTime); CheckByScanResult(dtScan); CheckDitiByScanResult(dtDitiScan); CheckHeaterScanResult(dtHeaterScan); GetDetectedLiquid(fileBeforeCreatedTime); //if any plate of a reagent is incorrect this reagent is incorrect foreach (ReagentAndSuppliesConfiguration reagent in reagentAndSupplies) { List <PlateBase> plates = ViewPlates.FindAll(P => (P.ChineseName == reagent.DisplayName && P.ItemType == reagent.ItemType)); reagent.Correct = !plates.Exists(P => !P.Correct); //只更新第一個Plate的值 if (reagent.ItemType >= 100 && reagent.ItemType < 200) { PlateBase firstPlate = ViewPlates.FirstOrDefault(P => (P.ChineseName == reagent.DisplayName && P.ItemType == reagent.ItemType)); if (firstPlate != null) { firstPlate.FirstAddVolume = reagent.FirstAddVolume; } } } worker.ReportProgress(1, ErrMsg); while (WaitFalg) { Thread.Sleep(1000); } }; worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args) { //to show the last column which contains confirm buttons foreach (DataGrid dg in dataGridDictionary.Values) { dg.Columns[5].Visibility = Visibility.Visible; } //incorrect plates and corresponding reagents will shine BindRelatedControls(); UpdatePlates(); foreach (UIElement uiElement in DeskTopWithGrid.Children) { if (uiElement is CarrierBase) { ((CarrierBase)uiElement).ShiningStop(); ((CarrierBase)uiElement).Scan(); } } loadFrom.Close(); btnSave.IsEnabled = reagentAndSupplies.FirstOrDefault(P => P.Correct == false) == null; }; worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) { }; worker.RunWorkerAsync(); loadFrom.ShowDialog(); /******************************************* * //call script and generate scan files * System.Windows.Input.Cursor currentCurson = this.Cursor; * this.Cursor = Cursors.Wait; * //call script and generate scan files * DateTime fileBeforeCreatedTime = WanTai.Controller.EVO.ProcessorFactory.GetDateTimeNow(); * Services.DeskTopService desktopService = new Services.DeskTopService(); * try * { * desktopService.CallScanScript(); * } * catch (Exception ex) * { * MessageBox.Show("扫描错误!"); * } * * //get data from scan files, check plates ,and update scan volume of reagents * foreach (ReagentAndSuppliesConfiguration reagent in reagentAndSupplies) * { * reagent.FirstAddVolume = 0; * } * foreach (PlateBase plate in ViewPlates) * { * plate.FirstAddVolume = 0; * } * DataTable dtScan = GetScanResult(fileBeforeCreatedTime); * DataTable dtDitiScan = GetDitiScanResult(fileBeforeCreatedTime); * DataTable dtHeaterScan = GetHeaterScanResult(fileBeforeCreatedTime); * * CheckByScanResult(dtScan); * CheckDitiByScanResult(dtDitiScan); * CheckHeaterScanResult(dtHeaterScan); * GetDetectedLiquid(fileBeforeCreatedTime); * * //if any plate of a reagent is incorrect this reagent is incorrect * foreach (ReagentAndSuppliesConfiguration reagent in reagentAndSupplies) * { * List<PlateBase> plates = ViewPlates.FindAll(P => (P.ChineseName == reagent.DisplayName && P.ItemType == reagent.ItemType)); * reagent.Correct = !plates.Exists(P => !P.Correct); * } * * //to show the last column which contains confirm buttons * foreach (DataGrid dg in dataGridDictionary.Values) * { * dg.Columns[5].Visibility = Visibility.Visible; * } * * //incorrect plates and corresponding reagents will shine * BindRelatedControls(); * UpdatePlates(); * foreach (UIElement uiElement in DeskTopWithGrid.Children) * { * if (uiElement is CarrierBase) * { * ((CarrierBase)uiElement).Scan(); * } * } * * Cursor = currentCurson; * btnSave.IsEnabled = reagentAndSupplies.FirstOrDefault(P => P.Correct == false) == null; ****************************************************************************************************/ }
private void WhenAdd() { //DataGrid AddColumns(dtReagent); ReagentSuppliesConfigurationController configurationController = new ReagentSuppliesConfigurationController(); List <ReagentAndSuppliesConfiguration> configurations = configurationController.GetAllActived().Where(P => P.ItemType < 100).OrderBy(P => P.ItemType).ToList(); configurationController.UpdateExperimentVolume(SessionInfo.ExperimentID, ref configurations, new short[] { ConsumptionType.consume, ConsumptionType.Add, ConsumptionType.FirstAdd }, ReagentAndSuppliesConfiguration.CurrentVolumeFieldName); //configurationController.UpdateExperimentVolume(SessionInfo.ExperimentID, ref configurations, new short[] { // ConsumptionType.Need }, ReagentAndSuppliesConfiguration.NeedVolumeFieldName); configurationController.NeededVolumeofProcessingRotations(ref configurations); List <ReagentAndSupply> reagents = new ReagentAndSuppliesController().GetAll(SessionInfo.ExperimentID); foreach (ReagentAndSuppliesConfiguration config in configurations) { if (config.ItemType >= 100) { continue; } Guid?reagentAndSuppplieID = null; config.Correct = config.Correct = config.NeedVolume == 0 ? true : config.CurrentVolume > config.NeedVolume * Common.Configuration.GetMinVolume(); ReagentAndSupply reagent = reagents.FirstOrDefault(P => P.ConfigurationItemID == config.ItemID); if (reagent != null) { reagentAndSuppplieID = reagent.ItemID; } dtReagent.Rows.Add(config.DisplayName, config.CurrentVolume, 0, config.Unit, config.Correct, config.ItemType, reagentAndSuppplieID, config.NeedVolume, config.NeedVolume * Common.Configuration.GetMinVolume(), config.ItemID); } dtReagent.DefaultView.Sort = "ItemType"; dgReagent.DataContext = dtReagent.DefaultView.FindRows(0); foreach (short dataGridKey in dataGridDictionary.Keys) { dataGridDictionary[dataGridKey].ItemsSource = dtReagent.DefaultView.FindRows(dataGridKey); } //Drawing Plates and Carriers viewPlates = new Services.DeskTopService().SetReagentPosition(configurations, new CarrierController().GetCarrier(), 0); double lengthUnit = (this.Width - 50) / 84; double cooPoint = 1.4; panelDeskTop.Width = (this.Width - 50); panelDeskTop.Height = lengthUnit * 30; View.Services.DeskTopService desktopService = new Services.DeskTopService(); carrierBases = desktopService.GetCarriers(lengthUnit, cooPoint); foreach (CarrierBase carrier in carrierBases) { carrier.UpdatePlate(viewPlates.FindAll(P => P.ContainerName == carrier.CarrierName)); panelDeskTop.Children.Add(carrier); } panelDeskTop.Children.Add(desktopService.DrawCoordinate((this.Width - 50), 69, lengthUnit)); for (int i = 0; i < dtReagent.Rows.Count; i++) { if (!(bool)dtReagent.Rows[i]["Correct"]) { this.btnSave.Visibility = System.Windows.Visibility.Visible; } } }