using MgTestAdmin.Model; using SqliteDotNet; using System; using System.Windows.Forms; namespace MgTestAdmin { public partial class TestManagerControl : UserControl { public TestManagerControl() { InitializeComponent(); } private SqliteDb _db; public void Setup(SqliteDb db) { _db = db; lstTests.DataSource = _db.GetTests(); //If we have any tests in the list select the first one by default if (lstTests.Items.Count > 0) { lstTests.SelectedIndex = 0; } tbDeleteTest.Enabled = lstTests.SelectedIndex >= 0; } private void ClearMainPanel() { foreach (Control c in splitContainer1.Panel2.Controls) { c.Dispose(); } splitContainer1.Panel2.Controls.Clear(); } private void LoadMainPanel(Control c) { this.ClearMainPanel(); c.Dock = DockStyle.Fill; splitContainer1.Panel2.Controls.Add(c); } private void lstTests_SelectedIndexChanged(object sender, EventArgs e) { tbDeleteTest.Enabled = lstTests.SelectedIndex >= 0; if (lstTests.SelectedItem != null) { var tc = (TestCaseInfo)lstTests.SelectedItem; var test = _db.GetTest(tc.TestName); if (test != null) { this.LoadMainPanel(new TestCaseControl().Attach(test, _db)); } } } private void tbDeleteTest_Click(object sender, EventArgs e) { if (lstTests.SelectedItem != null) { var tc = (TestCaseInfo)lstTests.SelectedItem; MessageBox.Show("TODO: Delete " + tc.TestName); } } private void tbAddTest_Click(object sender, EventArgs e) { lstTests.ClearSelected(); var newTest = new TestCase { }; this.LoadMainPanel(new TestCaseControl().Attach(newTest, _db)); } } }