private void terminalControl1_Command(object sender, TerminalControl.CommandEventArgs e) { List <Column> independSet, dependSet; List <string> independStr, dependStr; var msgBuilder = new StringBuilder(); switch (e.Command) { case "help": e.Message = @" You can use the following commands: 1- analyze : to start the functional analysis process. 2- show_depen : to show the current stored functional dependencies. 3- add : adds a new functional dependency. Command Syntax: add {a,b}->{c,d} | or | add a->{c,d} | or | add a->b. 4- rem : remove a current stored function depen. Command Syntax: rem {a,b}->{c,d} | or | rem a->{c,d} | or | rem a->b. 5- tbchng : changes the current active table of function dependency editing. Command Syntaax: tbchng [NAME OF TABLE]. 6- exit : terminates the application with saving option enabled. 7- help : show this help menu. 8- cls : Clear the messages window and log. 9- save : saves the current project state, log and function dependency. "; break; case "analyze": AnalyzeDatabase(null, null); BHasChanges = true; break; case "show_depen": foreach (var table in Program.LoadedProject.Tables) { msgBuilder.AppendLine("Table " + table.Name + " functional dependency:"); foreach (var dependency in table.TableDependency.DependencyList) { independSet = table.ColumnSet(dependency.Item1); dependSet = table.ColumnSet(dependency.Item2); msgBuilder.Append("{"); for (var i = 0; i < independSet.Count; i++) { msgBuilder.Append(independSet[i].Name); msgBuilder.Append(i + 1 == independSet.Count ? "}" : ","); } msgBuilder.Append("->{"); for (var i = 0; i < dependSet.Count; i++) { msgBuilder.Append(dependSet[i].Name); msgBuilder.Append(i + 1 == dependSet.Count ? "}" : ","); } msgBuilder.AppendLine(); } } e.Message = msgBuilder.ToString(); break; case "add": if (CurrentTable == null) { e.Message = "Select table first!"; break; } if (e.Parameters.Length != 3) { e.Message = "Error parsing command!"; break; } independStr = e.Parameters[1].Split(',', '{', '}').Where(t => !string.IsNullOrWhiteSpace(t)).ToList(); dependStr = e.Parameters[2].Split(',', '{', '}').Where(t => !string.IsNullOrWhiteSpace(t)).ToList(); independSet = CurrentTable.ColumnSet(independStr); dependSet = CurrentTable.ColumnSet(dependStr); if (independSet.Count != independStr.Count || dependSet.Count != dependStr.Count) { e.Message = "Error parsing command! No such columns!"; break; } CurrentTable.TableDependency.AddDependency(CurrentTable.ColumnSet(independSet), CurrentTable.ColumnSet(dependSet)); e.Message = "Command executed successfully! Mbrouk!"; LogText($"Added functional dependency in table : {CurrentTable.Name}"); BHasChanges = true; break; case "rem": if (CurrentTable == null) { e.Message = "Select table first!"; break; } if (e.Parameters.Length != 3) { e.Message = "Error parsing command!"; break; } independStr = e.Parameters[1].Split(',', '{', '}').Where(t => !string.IsNullOrWhiteSpace(t)).ToList(); dependStr = e.Parameters[2].Split(',', '{', '}').Where(t => !string.IsNullOrWhiteSpace(t)).ToList(); independSet = CurrentTable.ColumnSet(independStr); dependSet = CurrentTable.ColumnSet(dependStr); if (independSet.Count != independStr.Count || dependSet.Count != dependStr.Count) { e.Message = "Error parsing command! No such columns!"; break; } try { CurrentTable.TableDependency.RemoveDependency(CurrentTable.ColumnSet(independSet), CurrentTable.ColumnSet(dependSet)); e.Message = "Command executed successfully! Mbrouk!"; BHasChanges = true; LogText($"Removed functional dependency in table : {CurrentTable.Name}"); } catch (ArgumentOutOfRangeException) { e.Message = "No such dependency exist!"; } break; case "exit": ShowExitMessage(); break; case "tbchng": if (e.Parameters[1] == null) { terminalControl1.AddMessage("Syntax error."); return; } for (var i = 0; i < Program.LoadedProject.Tables.Count; i++) { if (Program.LoadedProject.Tables[i].Name == e.Parameters[1]) { tablesListBox.SetSelected(i, true); } } UpdatePromptString(); BHasChanges = true; break; case "cls": terminalControl1.ClearMessages(); logTextBox.Clear(); ResetLog(); Program.LoadedProject.Log = logTextBox.Text; break; case "set_primary_key": if (CurrentTable == null) { e.Message = "Select table first!"; break; } if (e.Parameters.Length < 1) { break; } independStr = e.Parameters[1].Split(',', '{', '}').Where(t => !string.IsNullOrWhiteSpace(t)).ToList(); try { CurrentTable.SetPrimaryKey(independStr, true); e.Message = "Mbrouk!"; LogText($"Set primary key in table : {CurrentTable.Name}"); } catch (ArgumentException) { e.Message = "Can't find some keys!"; } BHasChanges = true; break; case "show_primary_key": if (CurrentTable == null) { e.Message = "Select table first!"; break; } if (CurrentTable.PrimaryKey.Count == 0) { e.Message = "{}"; break; } msgBuilder.Append("{"); for (var i = 0; i < CurrentTable.PrimaryKey.Count; i++) { msgBuilder.Append(CurrentTable.PrimaryKey[i].Name); msgBuilder.Append(i + 1 == CurrentTable.PrimaryKey.Count ? "}" : ","); } e.Message = msgBuilder.ToString(); break; case "save": PerformSaveActions(false, false); /// Silent Save e.Message = "Saved"; LogText("Saved."); break; } }