private void buttonBack_Click(object sender, EventArgs e) { this.hScrollBar1.Enabled = true; this.label1.Enabled = true; this.buttonRun.Enabled = true; this.textBoxCommand.Enabled = true; this.buttonInfo.Enabled = true; this.buttonBack.Enabled = false; hScrollBar1_Scroll(null, null); if (this.textBox1.ReadOnly) { this.textBox1.ReadOnly = false; } if (_infoTextIsShown) { _infoTextIsShown = false; } if (_applicationRandomSampleOfVocabularieIsRunning) { _applicationRandomSampleOfVocabularieIsRunning = false; _studyRandomSampleOfVocabularies = null; buttonPrint.Enabled = true; if (!this.buttonRun.Enabled) { this.buttonRun.Enabled = true; } } this.textBox1.Select(0, 0); }
private void buttonRun_Click(object sender, EventArgs e) { if (_applicationRandomSampleOfVocabularieIsRunning) { Command_study(); return; } string str = this.textBoxCommand.Text.Trim(); int n; if (string.IsNullOrEmpty(str)) { MessageBox.Show("A command is not given!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string[] v = str.Split(' '); string command = v[0].Trim(); switch (command) { case "f": if (v.Length != 2) { MessageBox.Show("Incorrect given parameter for command f! It should be f, one blank and then the word.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_NewWord(v[1].Trim()); } break; case "p1": if ((v.Length != 2) || (!int.TryParse(v[1].Trim(), out n))) { MessageBox.Show("Incorrect given parameter for command p1. It should be p1, one blank and then an integer giving max row length.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_p1(n); } break; case "eum": //Exempel unmasked if (v.Length != 1) { MessageBox.Show("Command \"eum\" should not have any parameters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_eum(); } break; case "em": //Exempel masked if (v.Length != 1) { MessageBox.Show("Command \"em\" should not have any parameters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_em(); } break; case "et": //Exempel translated if (v.Length != 1) { MessageBox.Show("Command \"et\" should not have any parameters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_et(); } break; case "ls": //ls (= Show location and size of of main form and textbox) if (v.Length != 1) { MessageBox.Show("Command \"ls\" should not have any parameters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_ls(); } break; case "sls": //sls (= Set location and size of of main form and textbox) if (v.Length != 9) { MessageBox.Show("Command \"sls\" should have 8 parameters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_sls(v); } break; case "we": //we (= With example, number of entries in array wordsAndExplanationArray with at least on "Exempel: " if (v.Length != 1) { MessageBox.Show("Command \"we\" should not have any parameters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_we(); } break; case "study": //study fromWord (an integer) toWord (an integer) showWordFirst (true or false) if (v.Length != 4) { MessageBox.Show("Command \"study\" should have 3 parameters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { int from, to, numberOfEntriesWithAtLeastOneExempel; bool showWordFirst; numberOfEntriesWithAtLeastOneExempel = ReturnNumberOfEntriesWithAtLeastOneExempel(); if (!int.TryParse(v[1], out from)) { MessageBox.Show("First parameter is not a valid integer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((from < 1) || (from > numberOfEntriesWithAtLeastOneExempel)) { MessageBox.Show(string.Format("First parameter must be an integer between 1 and {0}!", numberOfEntriesWithAtLeastOneExempel.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!int.TryParse(v[2], out to)) { MessageBox.Show("Second parameter is not a valid integer!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (to < from) { MessageBox.Show(string.Format("Second parameter must be less than first parameter!", numberOfEntriesWithAtLeastOneExempel.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (to > numberOfEntriesWithAtLeastOneExempel) { MessageBox.Show(string.Format("Second parameter must be less than or equal to {0}!", numberOfEntriesWithAtLeastOneExempel.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!bool.TryParse(v[3], out showWordFirst)) { MessageBox.Show(string.Format("Third parameter must be true or false!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)); return; } _studyRandomSampleOfVocabularies = new StudyRandomSampleOfVocabularies(_wordsAndExplanationArray, _wordsArray, from, to, showWordFirst); this.hScrollBar1.Enabled = false; this.label1.Enabled = false; this.textBoxCommand.Enabled = false; this.buttonInfo.Enabled = false; this.buttonBack.Enabled = true; this.buttonPrint.Enabled = false; this.textBox1.TextChanged -= new System.EventHandler(this.textBox1_TextChanged); _applicationRandomSampleOfVocabularieIsRunning = true; Command_study(); } break; case "wei": //Word Example Information (information about how many words that have and not have example) if (v.Length != 1) { MessageBox.Show("Command \"wei\" should not have any parameters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_wei(); } break; case "ps": //Show X, Y, Width and Heigh of primary screen if (v.Length != 1) { MessageBox.Show("Command \"ps\" should not have any parameters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Command_ps(); } break; default: MessageBox.Show(string.Format("The command \"{0}\" does not exist!", command), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } }