private void OpenSavedGrid(string strFilename) { Reset(); bool bXML = (Path.GetExtension(strFilename).ToLower() == ".xml"); if (bXML) { DiscourseChartDataClass file = new DiscourseChartDataClass(); file.ReadXml(strFilename); // get the font colors if (file.VernacularFont.Count > 0) { DiscourseChartDataClass.VernacularFontRow aVFRow = file.VernacularFont[0]; m_fontVernacular = new Font(aVFRow.FontName, aVFRow.FontSize); m_colorVernacular = Color.FromName(aVFRow.FontColor); SetVernacularFontColor(); } if (file.GlossFont.Count > 0) { DiscourseChartDataClass.GlossFontRow aGFRow = file.GlossFont[0]; m_fontGloss = new Font(aGFRow.FontName, aGFRow.FontSize); m_colorGloss = Color.FromName(aGFRow.FontColor); } if (file.TransliterationFont.Count > 0) { DiscourseChartDataClass.TransliterationFontRow aTFRow = file.TransliterationFont[0]; m_fontTransliteration = new Font(aTFRow.FontName, aTFRow.FontSize); m_colorTransliteration = Color.FromName(aTFRow.FontColor); } foreach (DiscourseChartDataClass.DiscourseClauseRow aClause in file.DiscourseClause) { Debug.Assert(aClause.GetVernacularRows().Length > 0); DiscourseChartDataClass.VernacularRow aVernRow = aClause.GetVernacularRows()[0]; int nIndex = dataGridViewChart.Rows.Add(); DataGridViewRow aRow = dataGridViewChart.Rows[nIndex]; aRow.Height = m_fontVernacular.Height + CnExtraHeight; aRow.HeaderCell.ToolTipText = "Right-click to add/edit a free translation"; aRow.Cells[0].Value = aClause.Ref; aRow.Cells[1].Value = (aVernRow.IsPreSNull()) ? null : aVernRow.PreS; aRow.Cells[2].Value = (aVernRow.IsSubjectNull()) ? null : aVernRow.Subject; aRow.Cells[3].Value = (aVernRow.IsX1Null()) ? null : aVernRow.X1; aRow.Cells[4].Value = (aVernRow.IsX2Null()) ? null : aVernRow.X2; aRow.Cells[5].Value = (aVernRow.IsVerbNull()) ? null : aVernRow.Verb; aRow.Cells[6].Value = (aVernRow.IsPostSNull()) ? null : aVernRow.PostS; GlossTranslations gts = new GlossTranslations { Reference = aClause.Ref, FreeTranslation = (!aClause.IsFreeTranslationNull()) ? aClause.FreeTranslation : null }; aRow.Tag = gts; DiscourseChartDataClass.GlossRow[] aGRs = aClause.GetGlossRows(); if (aGRs.Length > 0) { DiscourseChartDataClass.GlossRow aGlossRow = aGRs[0]; gts.GlossInfo = new GlossTranslationInfo { PreS = (aGlossRow.IsPreSNull()) ? null : aGlossRow.PreS, Subject = (aGlossRow.IsSubjectNull()) ? null : aGlossRow.Subject, X1 = (aGlossRow.IsX1Null()) ? null : aGlossRow.X1, X2 = (aGlossRow.IsX2Null()) ? null : aGlossRow.X2, Verb = (aGlossRow.IsVerbNull()) ? null : aGlossRow.Verb, PostS = (aGlossRow.IsPostSNull()) ? null : aGlossRow.PostS }; } DiscourseChartDataClass.TransliterationRow[] theTRs = aClause.GetTransliterationRows(); if (theTRs.Length > 0) { DiscourseChartDataClass.TransliterationRow aTransliterationRow = theTRs[0]; gts.TransInfo = new GlossTranslationInfo { PreS = (aTransliterationRow.IsPreSNull()) ? null : aTransliterationRow.PreS, Subject = (aTransliterationRow.IsSubjectNull()) ? null : aTransliterationRow.Subject, X1 = (aTransliterationRow.IsX1Null()) ? null : aTransliterationRow.X1, X2 = (aTransliterationRow.IsX2Null()) ? null : aTransliterationRow.X2, Verb = (aTransliterationRow.IsVerbNull()) ? null : aTransliterationRow.Verb, PostS = (aTransliterationRow.IsPostSNull()) ? null : aTransliterationRow.PostS }; } } // adjust the column indices if (file.DiscourseChartData.Count > 0) { DiscourseChartDataClass.DiscourseChartDataRow aDCDRow = file.DiscourseChartData[0]; dataGridViewChart.Columns[6].DisplayIndex = aDCDRow.DisplayIndexPostS; dataGridViewChart.Columns[5].DisplayIndex = aDCDRow.DisplayIndexVerb; dataGridViewChart.Columns[4].DisplayIndex = aDCDRow.DisplayIndexX2; dataGridViewChart.Columns[3].DisplayIndex = aDCDRow.DisplayIndexX1; dataGridViewChart.Columns[2].DisplayIndex = aDCDRow.DisplayIndexSubject; dataGridViewChart.Columns[1].DisplayIndex = aDCDRow.DisplayIndexPreS; dataGridViewChart.Columns[0].DisplayIndex = aDCDRow.DisplayIndexRef; } saveFileDialog.FileName = strFilename; // so we know what file to save later } else { Debug.Assert(false); string[] astrLines = File.ReadAllLines(strFilename, Encoding.UTF8); if (astrLines[0] != cstrHeader) { MessageBox.Show("This doesn't look like a file that I've written!", cstrCaption); } else { for (int i = 1; i < astrLines.Length; i++) { string strLine = astrLines[i]; string[] astrWords = strLine.Split(new char[] { ',' }); int nIndex = dataGridViewChart.Rows.Add(); DataGridViewRow aRow = dataGridViewChart.Rows[nIndex]; aRow.Height = m_fontVernacular.Height + CnExtraHeight; for (int j = 0, k = 0; j < astrWords.Length; j++, k++ ) { string strWord = astrWords[j]; if ((strWord != null) && (strWord.Length > 1)) { while(strWord[strWord.Length - 1] != cDelim) // this means that this word had a comma in it // (which mistakenly was tokenized away), so add the // next word as well. (probably should count "s to make // sure they're even strWord += ',' + astrWords[++j]; // then strip off the delimiters Debug.Assert(strWord.Length > 2); strWord = strWord.Substring(1, strWord.Length - 2); // remove the extra double-quote(s) added int nQuoteIndex = 0; while ((nQuoteIndex = strWord.IndexOf('"', nQuoteIndex)) != -1) strWord = strWord.Remove(++nQuoteIndex, 1); } aRow.Cells[k].Value = strWord; } } } } AddFilenameToTitle(strFilename); m_bModified = false; }
private object[] GetGlossData(GlossTranslations gts, DataGridViewRow theVernRow) { if (gts.GlossInfo == null) { // otherwise, grab the value out of the main (upper) chart, and transliterate it. gts.Reference = (string)theVernRow.Cells[0].Value; gts.GlossInfo = new GlossTranslationInfo { PreS = GlossCell(theVernRow, 1), Subject = GlossCell(theVernRow, 2), X1 = GlossCell(theVernRow, 3), X2 = GlossCell(theVernRow, 4), Verb = GlossCell(theVernRow, 5), PostS = GlossCell(theVernRow, 6) }; } object[] aoGlossValues = new object[] { gts.Reference, gts.GlossInfo.PreS, gts.GlossInfo.Subject, gts.GlossInfo.X1, gts.GlossInfo.X2, gts.GlossInfo.Verb, gts.GlossInfo.PostS }; return aoGlossValues; }