private void actualLoad(object sender, EventArgs e, String fullFileName) { int recNo, idx, noOfLines; ulong recordCount; Char[] charArray; String keyWord, fileBuffer; String[] recordFields; Char[] splitParams = { '\u2063' }; StreamReader srOpen; WordStore currentEntry; btnClearAll_Click(sender, e); // Load the data and store in the classes srOpen = new StreamReader(fullFileName); fileBuffer = srOpen.ReadLine(); while (fileBuffer != null) { recordFields = fileBuffer.Split(splitParams); keyWord = recordFields[0]; noOfLines = Convert.ToInt32(recordFields[1]); recordCount = Convert.ToUInt64(recordFields[2]); charArray = new Char[recordCount]; srOpen.ReadBlock(charArray, 0, (int)recordCount); fileBuffer = new String(charArray); recordFields = fileBuffer.Split(splitParams); currentEntry = new WordStore(); currentEntry.Keyword = keyWord; recNo = 0; for (idx = 0; idx < noOfLines; idx++) { currentEntry.addEntry(recordFields[recNo++], recordFields[recNo++], recordFields[recNo++]); } lexicon.Add(keyWord, currentEntry); cbEntries.Items.Add(keyWord); fileBuffer = srOpen.ReadLine(); } srOpen.Close(); srOpen.Dispose(); cbEntries.SelectedIndex = 0; btnDisplay_Click(sender, e); }
private void btnStore_Click(object sender, EventArgs e) { /************************************************************************************************* * * * btnStore_Click: Store the current Entry * * ======================================= * * * * Adds the current entry to the store but does not remove it from presentation. * * * *************************************************************************************************/ bool isEditMode = false; int idx; String keyWord = "", keyPstn, sourceText, englishText, exampleText; DataGridViewCell cell1, cell2, cell3, cell4; WordStore currentWordStore = null; DialogResult dlgResult; for (idx = 0; idx < dgvMain.RowCount; idx++) { cell1 = dgvMain.Rows[idx].Cells[0]; cell2 = dgvMain.Rows[idx].Cells[1]; cell3 = dgvMain.Rows[idx].Cells[2]; cell4 = dgvMain.Rows[idx].Cells[3]; if ((cell1.Value == null) && (cell2.Value == null) && (cell3.Value == null) && (cell4.Value == null)) { continue; // Nothing to save } if (cell1.Value == null) { keyPstn = ""; } else { keyPstn = cell1.Value.ToString(); } if (cell2.Value == null) { sourceText = ""; } else { sourceText = cell2.Value.ToString(); } if (cell3.Value == null) { englishText = ""; } else { englishText = cell3.Value.ToString(); } if (cell4.Value == null) { exampleText = ""; } else { exampleText = cell4.Value.ToString(); } if (idx == 0) { if (keyPstn.Length == 0) { MessageBox.Show("You must provide a keyword for the entry", "Keyword error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } keyWord = keyPstn; if (lexicon.ContainsKey(keyWord)) { dlgResult = MessageBox.Show("Replace any changed values (Yes) or abort (No)", "The keyword " + keyWord + " has already been used", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dlgResult == DialogResult.Yes) { isEditMode = true; } else { return; } } if (isEditMode) { lexicon.TryGetValue(keyWord, out currentWordStore); } else { currentWordStore = new WordStore(); lexicon.Add(keyWord, currentWordStore); currentWordStore.Keyword = keyWord; } } currentWordStore.addEntry(sourceText, englishText, exampleText); } if (!isEditMode) { cbEntries.Items.Add(keyWord); } isModified = true; }