private void SingleCellOperationsToDescriptorItem(object sender, EventArgs e) { List<string> ListNamesDesc = new List<string>(); foreach (var item in cGlobalInfo.CurrentScreening.ListDescriptors) { if (item.GetDataType() != "Single") { ListNamesDesc.Add(item.GetName()); } } FormForDescOperations MainWindow = new FormForDescOperations(ListNamesDesc); if (MainWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; string NewDescName = MainWindow.textBoxNewDescName.Text; cDescriptorType DescType1 = cGlobalInfo.CurrentScreening.ListDescriptors.GetDescriptorByName(MainWindow.comboBoxDescriptor1.Text); cDescriptorType DescType2 = cGlobalInfo.CurrentScreening.ListDescriptors.GetDescriptorByName(MainWindow.comboBoxDescriptor2.Text); if ((DescType1 == null) || (DescType2 == null)) return; FormForProgress ProgressWindow = new FormForProgress(); ProgressWindow.Show(); int IdxProgress = 1; int MaxProgress = cGlobalInfo.CurrentScreening.ListPlatesAvailable.Count; ProgressWindow.progressBar.Maximum = MaxProgress; cDescriptorType NewDescType = new cDescriptorType(NewDescName, true, 256, true); cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(NewDescType); //HCSAnalyzer.Classes.General_Types.cDBConnection.cSingleCellOperations SCO = new HCSAnalyzer.Classes.General_Types.cDBConnection.cSingleCellOperations() cSingleCellOperations SingleCellOperation = new cSingleCellOperations(); if (MainWindow.tabControlMain.SelectedTab.Name == "tabPageBinary") { SingleCellOperation.ListDualOperations = new List<eBinaryOperationType>(); // eDualOperationType OperationType = eDualOperationType.ADD; switch (MainWindow.domainUpDown1.Text) { case "*": SingleCellOperation.ListDualOperations.Add(eBinaryOperationType.MULTIPLY); break; case "+": SingleCellOperation.ListDualOperations.Add(eBinaryOperationType.ADD); break; case "/": SingleCellOperation.ListDualOperations.Add(eBinaryOperationType.DIVIDE); break; case "-": SingleCellOperation.ListDualOperations.Add(eBinaryOperationType.SUBSTRACT); break; default: return; } if (MainWindow.checkBoxActivePostProcess.Checked) { SingleCellOperation.PostProcessingOperation = new List<eBinaryOperationType>(); switch (MainWindow.domainUpDownPostProcessOperator.Text) { case "*": SingleCellOperation.PostProcessingOperation.Add(eBinaryOperationType.MULTIPLY); break; case "+": SingleCellOperation.PostProcessingOperation.Add(eBinaryOperationType.ADD); break; case "/": SingleCellOperation.PostProcessingOperation.Add(eBinaryOperationType.DIVIDE); break; case "-": SingleCellOperation.PostProcessingOperation.Add(eBinaryOperationType.SUBSTRACT); break; default: return; } SingleCellOperation.PostProcessingValue = (double)MainWindow.numericUpDownPostProcessValue.Value; } foreach (cPlate CurrentPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable) { CurrentPlate.DBConnection.OpenConnection(); CurrentPlate.DBConnection.CreateNewColumn(NewDescType, DescType1, DescType2, SingleCellOperation, GlobalInfo, ref CurrentPlate.ListActiveWells); CurrentPlate.DBConnection.CloseConnection(); ProgressWindow.progressBar.Value = IdxProgress++; ProgressWindow.richTextBoxForComment.AppendText(CurrentPlate.GetShortInfo()); ProgressWindow.Refresh(); } } else { eUnaryOperationType OperationType = eUnaryOperationType.LOG; if (MainWindow.radioButtonSQRT.Checked) OperationType = eUnaryOperationType.SQRT; else if (MainWindow.radioButtonLog.Checked) OperationType = eUnaryOperationType.LOG; else if (MainWindow.radioButtonABS.Checked) OperationType = eUnaryOperationType.ABS; else if (MainWindow.radioButtonEXP.Checked) OperationType = eUnaryOperationType.EXP; foreach (cPlate CurrentPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable) { CurrentPlate.DBConnection.OpenConnection(); CurrentPlate.DBConnection.CreateNewColumn(NewDescType, DescType1, OperationType, GlobalInfo, ref CurrentPlate.ListActiveWells); CurrentPlate.DBConnection.CloseConnection(); ProgressWindow.progressBar.Value = IdxProgress++; ProgressWindow.richTextBoxForComment.AppendText(CurrentPlate.GetShortInfo()); ProgressWindow.Refresh(); } } ProgressWindow.Close(); int IdxNull = 0; foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesActive) { foreach (cWell TmpWell in TmpPlate.ListActiveWells) if (TmpWell.ListSignatures.Count != cGlobalInfo.CurrentScreening.ListDescriptors.Count) IdxNull++; } if (IdxNull > 0) System.Windows.Forms.MessageBox.Show("List signature count is different from list descriptor count", "Critical Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); cGlobalInfo.CurrentScreening.ListDescriptors.UpDateDisplay(); // CompleteScreening.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesAvailable.Count; idxP++) cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax(); StartingUpDateUI(); this.toolStripcomboBoxPlateList.Items.Clear(); for (int IdxPlate = 0; IdxPlate < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; IdxPlate++) { string Name = cGlobalInfo.CurrentScreening.ListPlatesActive.GetPlate(IdxPlate).GetName(); this.toolStripcomboBoxPlateList.Items.Add(Name); PlateListWindow.listBoxPlateNameToProcess.Items.Add(Name); PlateListWindow.listBoxAvaliableListPlates.Items.Add(Name); } cGlobalInfo.CurrentScreening.CurrentDisplayPlateIdx = 0; cGlobalInfo.CurrentScreening.SetSelectionType(comboBoxClass.SelectedIndex - 1); UpdateUIAfterLoading(); cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().DisplayDistribution(cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptor(), false); }
/// <summary> /// Create a new column in the database of the current plate /// </summary> /// <param name="ColumnName">Column name</param> /// <param name="DefaultValue">Array of values</param> /// <returns>Return the number of table (i.e. wells) processed</returns> public void CreateNewColumn(cDescriptorType NewDescType, cDescriptorType Desc0, cDescriptorType Desc1, cSingleCellOperations SingleCellOperations, cGlobalInfo GlobalInfo, ref cListWells ListWell) { string ColumnName = NewDescType.GetName(); int NumTableProcessed = 0; foreach (var item in GetListTableNames()) // loop over the wells { // compute the new values List<cDescriptorType> LDes = new List<cDescriptorType>(); LDes.Add(Desc0); LDes.Add(Desc1); cExtendedTable LValues = this.GetWellValues(item, LDes); cExtendedList ListResults = LValues[0].Operation(LValues[1], SingleCellOperations.ListDualOperations[0]); if ((SingleCellOperations.PostProcessingOperation != null) && (SingleCellOperations.PostProcessingOperation.Count > 0)) { switch (SingleCellOperations.PostProcessingOperation[0]) { case eBinaryOperationType.ADD: ListResults += SingleCellOperations.PostProcessingValue; break; case eBinaryOperationType.SUBSTRACT: ListResults -= SingleCellOperations.PostProcessingValue; break; case eBinaryOperationType.MULTIPLY: ListResults *= SingleCellOperations.PostProcessingValue; break; case eBinaryOperationType.DIVIDE: ListResults /= SingleCellOperations.PostProcessingValue; break; default: break; } } #region Update the database // create new column SQLiteCommand mycommand = new SQLiteCommand(_SQLiteConnection); String SQL = "ALTER TABLE \"" + item + "\" ADD COLUMN \"" + ColumnName + "\" REAL DEFAULT 0"; using (SQLiteCommand Command = new SQLiteCommand(SQL, _SQLiteConnection)) { Command.ExecuteNonQuery(); } // write data using (SQLiteTransaction transaction = _SQLiteConnection.BeginTransaction()) using (SQLiteDataAdapter sqliteAdapter = new SQLiteDataAdapter("SELECT * FROM \"" + item + "\"", _SQLiteConnection)) { DataSet DS = new DataSet(); sqliteAdapter.Fill(DS); using (sqliteAdapter.InsertCommand = new SQLiteCommandBuilder(sqliteAdapter).GetUpdateCommand()) { for (int i = 0; i < DS.Tables[0].Rows.Count; i++) DS.Tables[0].Rows[i][ColumnName] = ListResults[i]; sqliteAdapter.Update(DS); } transaction.Commit(); } #endregion #region Update the screening data cListSignature LDesc = new cListSignature(); cSignature NewSignature = new cSignature(ListResults, 256, NewDescType, cGlobalInfo.CurrentScreening); LDesc.Add(NewSignature); string[] Positions = item.Split('x'); cWell TmpWell = ListWell.GetFirstWell(int.Parse(Positions[1]), int.Parse(Positions[2])); if(TmpWell!=null) TmpWell.AddSignatures(LDesc); #endregion NumTableProcessed++; } }