private void btnAddCategory_Click(object sender, EventArgs e) { if (!TreeViewSelected()) return; frmCatNew form = new frmCatNew(); form.ShowDialog(); string title = form.result; if (title == null) return; string parentTitle = tvCategory.SelectedNode.Text; string str; Console.Out.Write(parentTitle); if (parentTitle == root) { str = "INSERT INTO dbo.category (title, parent_id) VALUES('" + title + "',NULL);"; } else { int id = GetIdByTitle(parentTitle); str = "INSERT INTO dbo.category (title, parent_id) VALUES('" + title + "'," + id + ");"; } SqlConnection connection = Library.Connection.Instance(); SqlCommand command = new SqlCommand(str, connection); command.ExecuteNonQuery(); MessageBox.Show("添加成功", "添加分类"); tvCategory.Nodes.Clear(); InitializeTreeViewCategory(); }
private void btnAddCategory_Click(object sender, EventArgs e) { if (!TreeViewSelected()) { return; } frmCatNew form = new frmCatNew(); form.ShowDialog(); string title = form.result; if (title == null) { return; } string parentTitle = tvCategory.SelectedNode.Text; string str; Console.Out.Write(parentTitle); if (parentTitle == root) { str = "INSERT INTO dbo.category (title, parent_id) VALUES('" + title + "',NULL);"; } else { int id = GetIdByTitle(parentTitle); str = "INSERT INTO dbo.category (title, parent_id) VALUES('" + title + "'," + id + ");"; } SqlConnection connection = Library.Connection.Instance(); SqlCommand command = new SqlCommand(str, connection); command.ExecuteNonQuery(); MessageBox.Show("添加成功", "添加分类"); tvCategory.Nodes.Clear(); InitializeTreeViewCategory(); }