public Formula(string name, Topic top, Subject sub) { this.name = name; this.topic = top; this.subject = sub; }
//For calling this for a list of subjects public ListEdit(BindingList<Subject> sb, listType t) { type = t; subjects = sb; selectedSubject = null; selectedTopic = null; InitializeComponent(); }
//For calling this for a list of formulas (as they need both selected subject and topic) public ListEdit(BindingList<Subject> sb, Subject selSub, Topic selTop, listType t) { type = t; subjects = sb; selectedSubject = selSub; selectedTopic = selTop; InitializeComponent(); }
//Add or remove formulas in a new dialogue box private void formulaOptions_Click(object sender, EventArgs e) { currentSubject = (Subject)listSubject.SelectedValue; currentTopic = (Topic)listTopic.SelectedValue; if (currentSubject != null && currentTopic != null) { ListEdit ld = new ListEdit(subjects, currentSubject, currentTopic, ListEdit.listType.Formula); ld.ShowDialog(); if(ld.DialogResult == DialogResult.OK) { listFormula.DataSource = null; listFormula.DataSource = currentTopic.formulas; } } else { statusSay.Text = "Invalid Subject or Topic"; } }
//When a new item on the subject list is selected, update all other lists and show the first formula of the first topic private void listSubject_SelectedIndexChanged(object sender, EventArgs e) { currentSubject = (Subject)listSubject.SelectedValue; if (currentSubject != null) { listTopic.DisplayMember = "name"; listTopic.DataSource = currentSubject.topics; statusSay.Text = "Selected " + currentSubject.ToString(); } else if (currentSubject == null) { listTopic.DataSource = null; statusSay.Text = "No subject to be selected"; } listFormula.DataSource = null; }
//Add or remove topics in a new dialogue box private void topicOptions_Click(object sender, EventArgs e) { currentSubject = (Subject)listSubject.SelectedValue; if (currentSubject != null) { ListEdit ld = new ListEdit(subjects, currentSubject, ListEdit.listType.Topic); ld.ShowDialog(); if(ld.DialogResult == DialogResult.OK) { listTopic.DataSource = null; listTopic.DataSource = currentSubject.topics; if(currentTopic == null && currentSubject.topics.Count > 0) { currentTopic = currentSubject.topics[0]; } } } else { statusSay.Text = "Invalid Subject."; } }
public Topic(string name, Subject parent) { this.name = name; this.subject = parent; formulas = new BindingList<Formula>(); }