public void saveOutput(string fileName) { HeaderRecgonition hRec = new HeaderRecgonition(); bool headersFormatedCorrectly = true; foreach (DataGridViewCell dCell in dataViewer.Rows[0].Cells) { if (hRec.isHeaderInStandardFormat(dCell.Value.ToString()) != true) { headersFormatedCorrectly = false; } } if (headersFormatedCorrectly) { switch (comboFileExtension.Text) { case (".wtr"): saveWater(fileName); break; case (".wnd"): saveWind(fileName); break; case (".sal"): saveSalinity(fileName); break; case(".csv"): saveCSV(fileName); break; default: saveStandard(fileName); break; } } else { DialogResult result = MessageBox.Show("Some of your headers appear to be incorrectly formatted.\n\rDo you wish to save anyway?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { switch (comboFileExtension.Text) { case (".wtr"): saveWater(fileName); break; case (".wnd"): saveWind(fileName); break; case (".sal"): saveSalinity(fileName); break; case (".csv"): saveCSV(fileName); break; default: saveStandard(fileName); break; } } } }
private void setBoxesFromGLEONCoding(int index, string input) { HeaderRecgonition hRec = new HeaderRecgonition(); if(hRec.isHeaderInStandardVariableFormat(input)) { string comboMainName = index + "ComboMain"; Control comboMaintemp = panelVariableControls.Controls[comboMainName]; ComboBox comboMain = comboMaintemp as ComboBox; string combo2Name = index + "Combo2"; Control combo2temp = panelVariableControls.Controls[combo2Name]; ComboBox combo2 = combo2temp as ComboBox; string combo3Name = index + "Combo3"; Control combo3temp = panelVariableControls.Controls[combo3Name]; ComboBox combo3 = combo3temp as ComboBox; string combo4Name = index + "Combo4"; Control combo4temp = panelVariableControls.Controls[combo4Name]; ComboBox combo4 = combo4temp as ComboBox; string Text1Name = index + "Text1"; Control Text1temp = panelVariableControls.Controls[Text1Name]; TextBox Text1 = Text1temp as TextBox; string temp = ""; comboMain.Text = "Variable"; foreach(testTypeUnits tTU in GLEONCodeData) { if(tTU.testCode == input.Substring(0,input.IndexOf("_"))) { combo2.Text = tTU.testName; } } combo3.Text = input.Substring(input.IndexOf("(") + 1, (input.IndexOf(")") - (input.IndexOf("(") + 1))); foreach (string displacement in combo4.Items) { if (input.Substring(input.IndexOf("_") + 1, 1) == displacement.Substring(0,1)) { combo4.Text = displacement; temp = input.Substring(input.IndexOf("_") + 1, 1); if (hRec.getHeaderType(input) == "dhem") { Text1.Text = input.Substring(input.IndexOf(temp) + 1, input.IndexOf("(") - input.IndexOf(temp) + 1); } if(hRec.getHeaderType(input) == "i") { Text1.Text = input.Substring(input.IndexOf(temp) + 1, input.IndexOf("-") - input.IndexOf(temp) + 1); } } } } }
private void HeaderGuess() { List<string> unRecHeaders = new List<string>(); HeaderRecgonition Hrec = new HeaderRecgonition(); foreach (DataGridViewCell dCell in dataViewer.Rows[0].Cells) { if (Hrec.isHeaderInStandardFormat(dCell.Value.ToString()) == false) { string guess = Hrec.RoughGuess(dCell.Value.ToString()); if (guess != dCell.Value.ToString()) { if (guess != "") { DialogResult result = MessageBox.Show("Header '"+ dCell.Value.ToString()+"' was recognized as \"" + guess + "\"\n\rUse the recognized header?\n\r(If you click \"No\" the old header will be retained.", "Recognition made", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { InputTable.Rows[dCell.RowIndex][dCell.ColumnIndex] = guess; } } else { unRecHeaders.Add(dCell.ColumnIndex.ToString()); } } } } if (unRecHeaders.Count != 0) { string unRecWarning = ""; unRecWarning = "Some columns have unrecognized headers\n\r"; foreach (string colNum in unRecHeaders) { unRecWarning += colNum + " "; } MessageBox.Show(unRecWarning, "Invalid Column Headers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } for (int i = 1; i < dataViewer.Columns.Count; i++) { setBoxesFromGLEONCoding(i, dataViewer.Rows[0].Cells[i].Value.ToString()); } }
//Only scans the first 30 rows for strings the fit the header pattern. private void headerRowDetection() { int currentHeaderRowGuess = -1; int currentHeaderFreq = 0; int acceptedHeaderFreq = 0; HeaderRecgonition hRec = new HeaderRecgonition(); for (int index = 0; index <= 30 && index < dataViewer.Rows.Count; index++) { DataGridViewRow dRow = dataViewer.Rows[index]; acceptedHeaderFreq = 0; foreach (DataGridViewCell dCell in dRow.Cells) { if (Regex.IsMatch(dCell.Value.ToString(), @"([a-z]|[A-Z]){2,6}_[d,h,e,m]([0-9]|[.])+([^),^(]*)") || Regex.IsMatch(dCell.Value.ToString(), @"([a-z]|[A-Z]){2,6}_i([0-9]|[.])+\-([0-9]|[.])+([^),^(]*)") || Regex.IsMatch(dCell.Value.ToString(), @"([a-z]|[A-Z]){2,6}_[v,n]([^),^(]*)") || Regex.IsMatch(dCell.Value.ToString(), @"DateTime[A-Z]{3}\+[0-9]{1,2}") || hRec.checkforHeaderWords(dCell.Value.ToString())) { acceptedHeaderFreq++; } } if (acceptedHeaderFreq > currentHeaderFreq) { currentHeaderFreq = acceptedHeaderFreq; currentHeaderRowGuess = dRow.Index; } } if (currentHeaderFreq != 0) { DataRow dRow = InputTable.NewRow(); dRow.ItemArray = InputTable.Rows[currentHeaderRowGuess].ItemArray; InputTable.Rows.RemoveAt(currentHeaderRowGuess); InputTable.Rows.InsertAt(dRow, 0); } foreach (DataGridViewCell dCell in dataViewer.Rows[0].Cells) { dCell.Style.BackColor = Color.LightYellow; } HeaderSelected = true; }
private void autoDetectHeadersForPanel() { HeaderRecgonition hRec = new HeaderRecgonition(); foreach(DataGridCell header in dataViewer.Rows[0].Cells) { int index = Convert.ToInt16(header.ColumnNumber); string comboMainName = index + "ComboMain"; Control comboMaintemp = panelVariableControls.Controls[comboMainName]; ComboBox comboMain = comboMaintemp as ComboBox; string combo2Name = index + "Combo2"; Control combo2temp = panelVariableControls.Controls[combo2Name]; ComboBox combo2 = combo2temp as ComboBox; string combo3Name = index + "Combo3"; Control combo3temp = panelVariableControls.Controls[combo3Name]; ComboBox combo3 = combo3temp as ComboBox; string combo4Name = index + "Combo4"; Control combo4temp = panelVariableControls.Controls[combo4Name]; ComboBox combo4 = combo4temp as ComboBox; string Text1Name = index + "Text1"; Control Text1temp = panelVariableControls.Controls[Text1Name]; TextBox Text1 = Text1temp as TextBox; if(hRec.getHeaderType(header.ToString()) == "DateTime") { comboMain.Text = "DateTime"; } else if(hRec.getHeaderType(header.ToString()) == "dhem" || hRec.getHeaderType(header.ToString()) == "i" || hRec.getHeaderType(header.ToString()) == "vn") { comboMain.Text = "Variable"; } } }