private void loadDBToolStripMenuItem_Click(object sender, EventArgs e) { if (CompleteScreening != null) CompleteScreening.Close3DView(); FolderBrowserDialog OpenFolderDialog = new FolderBrowserDialog(); if (OpenFolderDialog.ShowDialog() != DialogResult.OK) return; string Path = OpenFolderDialog.SelectedPath; FormForPlateDimensions PlateDim = new FormForPlateDimensions(); PlateDim.checkBoxAddCellNumber.Visible = true; PlateDim.checkBoxIsOmitFirstColumn.Visible = true; PlateDim.labelHisto.Visible = true; PlateDim.numericUpDownHistoSize.Visible = true; if (PlateDim.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; LoadCellByCellDB(PlateDim, Path); }
public void LoadDB(string DefaultPath, bool IsDisplayPlateSelection) { if (!Directory.Exists(DefaultPath)) DefaultPath = ""; string SelectedPath = DefaultPath; if (DefaultPath == "") { var dlg1 = new Ionic.Utils.FolderBrowserDialogEx(); dlg1.Description = "Select the folder containing your databases."; dlg1.ShowNewFolderButton = true; dlg1.ShowEditBox = true; if (DefaultPath != "") dlg1.SelectedPath = DefaultPath; //dlg1.NewStyle = false; //dlg1.SelectedPath = txtExtractDirectory.Text; dlg1.ShowFullPathInEditBox = true; dlg1.RootFolder = System.Environment.SpecialFolder.Desktop; // Show the FolderBrowserDialog. DialogResult result = dlg1.ShowDialog(); if (result != DialogResult.OK) return; SelectedPath = dlg1.SelectedPath; } if (Directory.Exists(SelectedPath) == false) return; FormForPlateDimensions PlateDim = new FormForPlateDimensions(); PlateDim.checkBoxAddCellNumber.Checked = false; PlateDim.checkBoxAddCellNumber.Visible = true; PlateDim.checkBoxIsOmitFirstColumn.Visible = true; PlateDim.labelHisto.Visible = true; PlateDim.numericUpDownHistoSize.Visible = true; if (PlateDim.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; LoadCellByCellDB(PlateDim, SelectedPath, IsDisplayPlateSelection); }
private void generateDBFromCSVToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog CurrOpenFileDialog = new OpenFileDialog(); CurrOpenFileDialog.Filter = "csv files (*.csv)|*.csv";//|db files (*.db)|*.db|nc files (*.nc)|*.nc CurrOpenFileDialog.Multiselect = false; DialogResult Res = CurrOpenFileDialog.ShowDialog(); if (Res != DialogResult.OK) return; FormForImportExcel CSVWindow = CellByCellFromCSV(CurrOpenFileDialog.FileNames[0]); if (CSVWindow == null) return; if (CSVWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; if (CompleteScreening != null) CompleteScreening.Close3DView(); FolderBrowserDialog WorkingFolderDialog = new FolderBrowserDialog(); WorkingFolderDialog.ShowNewFolderButton = true; WorkingFolderDialog.Description = "Select the working directory"; if (WorkingFolderDialog.ShowDialog() != DialogResult.OK) return; //if (IsFileUsed(CurrOpenFileDialog.FileNames[0])) //{ // MessageBox.Show("File currently used by another application.\n", "Loading error !", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} //Microsoft.Research.Science.Data.DataSet Datacsv = Microsoft.Research.Science.Data.CSV.CsvDataSet.Open(CurrOpenFileDialog.FileNames[0]); //int NumDesc = Datacsv.Variables.Count; //for (int IdxDesc = 0; IdxDesc < NumDesc; IdxDesc++) //{ // var DescInfo = Datacsv.Variables[IdxDesc]; // string NameDesc = DescInfo.Name; // var TypeData = DescInfo.TypeOfData; // string DataName = TypeData.Name; //} int NumPlateName = 0; int NumRow = 0; int NumCol = 0; int NumWellPos = 0; // int NumLocusID = 0; // int NumConcentration = 0; // int NumName = 0; // int NumInfo = 0; // int NumClass = 0; int numDescritpor = 0; for (int i = 0; i < CSVWindow.dataGridViewForImport.Rows.Count; i++) { string CurrentVal = CSVWindow.dataGridViewForImport.Rows[i].Cells[2].Value.ToString(); if ((CurrentVal == "Plate name") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value)) NumPlateName++; if ((CurrentVal == "Row") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value)) NumRow++; if ((CurrentVal == "Column") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value)) NumCol++; if ((CurrentVal == "Well position") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value)) NumWellPos++; if ((CurrentVal == "Descriptor") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value)) numDescritpor++; } if (NumPlateName != 1) { MessageBox.Show("One and only one \"Plate Name\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((NumRow != 1) && (GlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked == true)) { MessageBox.Show("One and only one \"Row\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((NumCol != 1) && (GlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked == true)) { MessageBox.Show("One and only one \"Column\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((NumWellPos != 1) && (GlobalInfo.OptionsWindow.radioButtonWellPosModeSingle.Checked == true)) { MessageBox.Show("One and only one \"Well position\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((numDescritpor < 1) && (CSVWindow.IsImportCSV)) { MessageBox.Show("You need to select at least one \"Descriptor\" !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int Mode = 2; if (GlobalInfo.OptionsWindow.radioButtonWellPosModeSingle.Checked) Mode = 1; CsvFileReader CSVsr = new CsvFileReader(CurrOpenFileDialog.FileNames[0]); CsvRow OriginalNames = new CsvRow(); if (!CSVsr.ReadRow(OriginalNames)) { CSVsr.Close(); return; } int ColPlateName = GetColIdxFor("Plate name", CSVWindow); int ColCol = GetColIdxFor("Column", CSVWindow); int ColRow = GetColIdxFor("Row", CSVWindow); int ColWellPos = GetColIdxFor("Well position", CSVWindow); int[] ColsForDescriptors = GetColsIdxFor("Descriptor", CSVWindow); int WellLoaded = 0; int FailToLoad = 0; // CompleteScreening.Columns = (int)CSVWindow.numericUpDownColumns.Value; // CompleteScreening.Rows = (int)CSVWindow.numericUpDownRows.Value; // CompleteScreening.ListDescriptors.Clean(); FormForProgress ProgressWindow = new FormForProgress(); ProgressWindow.Show(); CsvRow CurrentDesc = new CsvRow(); if (CSVsr.ReadRow(CurrentDesc) == false) return; do { string OriginalPlatePlateName = CurrentDesc[ColPlateName]; string CurrentPlateName = CurrentDesc[ColPlateName]; string ConvertedName = ""; foreach (var c in System.IO.Path.GetInvalidFileNameChars()) { ConvertedName = OriginalPlatePlateName.Replace(c, '-'); } List<string> ListNameSignature = new List<string>(); for (int idxDesc = Mode + 1; idxDesc < ColsForDescriptors.Length + Mode + 1; idxDesc++) ListNameSignature.Add(OriginalNames[idxDesc]); cSQLiteDatabase SQDB = new cSQLiteDatabase(WorkingFolderDialog.SelectedPath + "\\" + ConvertedName, ListNameSignature, true); do { string OriginalWellPos = CurrentDesc[ColWellPos]; string CurrentWellPos = OriginalWellPos; int[] Pos = new int[2]; if (Mode == 1) { Pos = ConvertPosition(CurrentDesc[ColWellPos]); if (Pos == null) { if (MessageBox.Show("Error in converting the current well position.\nGo to Edit->Options->Import-Export->Well Position Mode to fix this.\nDo you want continue ?", "Loading error !", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.No) { CSVsr.Close(); return; } //else // goto NEXTLOOP; } } else { //if (int.TryParse(CurrentDesc[ColCol], out Pos[0]) == false) // // goto NEXTLOOP; //if (int.TryParse(CurrentDesc[ColRow], out Pos[1]) == false) // goto NEXTLOOP; } cWellForDatabase WellForDB = new cWellForDatabase(OriginalPlatePlateName, Pos[0], Pos[1]); List<List<double>> ListData = new List<List<double>>(); // for (int idxDesc = 0; idxDesc < ColsForDescriptors.Length; idxDesc++) // ListData[idxDesc] = new List<double>(); ProgressWindow.label.Text = OriginalWellPos; ProgressWindow.label.Refresh(); do { // CurrentWellPos = CurrentDesc[ColWellPos]; List<double> Signature = new List<double>(); for (int idxDesc = 0; idxDesc < ColsForDescriptors.Length; idxDesc++) { double Value; if ((double.TryParse(CurrentDesc[ColsForDescriptors[idxDesc]], out Value)) && (!double.IsNaN(Value))) { //cDescriptor CurrentDescriptor = new cDescriptor(Value, CompleteScreening.ListDescriptors[idxDesc/* + ShiftIdx*/], CompleteScreening); Signature.Add(Value); } /*else { FailToLoad++; goto NEXTLOOP; }*/ } ListData.Add(Signature); // WellForDB.AddSignature(Signature); if (CSVsr.ReadRow(CurrentDesc) == false) { WellForDB.AddListSignatures(ListData); SQDB.AddNewWell(WellForDB); SQDB.CloseConnection(); goto NEXTLOOP; } CurrentPlateName = CurrentDesc[ColPlateName]; CurrentWellPos = CurrentDesc[ColWellPos]; } while (CurrentWellPos == OriginalWellPos); WellForDB.AddListSignatures(ListData); SQDB.AddNewWell(WellForDB); } while (OriginalPlatePlateName == CurrentPlateName); SQDB.CloseConnection(); } while (true); NEXTLOOP: ; ProgressWindow.Close(); FormForPlateDimensions PlateDim = new FormForPlateDimensions(); PlateDim.Text = "Load generated screening"; PlateDim.checkBoxAddCellNumber.Visible = true; PlateDim.checkBoxIsOmitFirstColumn.Visible = true; PlateDim.labelHisto.Visible = true; PlateDim.numericUpDownHistoSize.Visible = true; if (PlateDim.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; LoadCellByCellDB(PlateDim, WorkingFolderDialog.SelectedPath); }