BackTerminal.frmCatMan.btnEditCategory_Click C# (CSharp) Méthode

btnEditCategory_Click() private méthode

private btnEditCategory_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
Résultat void
        private void btnEditCategory_Click(object sender, EventArgs e)
        {
            if (!TreeViewSelected()) return;
            string title = tvCategory.SelectedNode.Text;

            // 不能编辑“全部分类”
            if (title == root)
            {
                MessageBox.Show("不能编辑“全部分类”。请重新选择一个分类!",
                    "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }

            frmCatEdit form = new frmCatEdit(title);
            form.ShowDialog();
            string newTitle = form.newTitle;

            if (newTitle == null) return;

            string str =
                "UPDATE dbo.category SET title='" + newTitle +
                "' WHERE title='" + title + "';";
            Console.Out.WriteLine(str);

            SqlConnection connection = Library.Connection.Instance();
            SqlCommand command = new SqlCommand(str, connection);
            command.ExecuteNonQuery();
            command.Dispose();

            tvCategory.Nodes.Clear();
            InitializeTreeViewCategory();
        }