public static TreeNode AppendChilds(TreeNode node) { Subject subject = (Subject)node.Tag; SqlConnection con = new SqlConnection(ConnectionString); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tbl_BookCommentSubject WHERE BookCommentSubjectParentId=" + subject.Id, con); DataSet ds = new DataSet(); da.Fill(ds); foreach (DataRow row in ds.Tables[0].Rows) { TreeNode child = new TreeNode(); Subject childTag = new Subject(); childTag.ParentId = -1; childTag.Id = Convert.ToInt32(row["BookCommentSubjectId"]); childTag.Title = row["BookCommentSubjectTitle"].ToString(); child.Tag = childTag; child.Text = childTag.Title; child = AppendChilds(child); node.Nodes.Add(child); } return node; }
private void افزودنToolStripMenuItem_Click(object sender, EventArgs e) { if (tree.SelectedNode == null) return; string title = "موضوع جدید"; if (title.Equals("")) { MessageBox.Show("اطلاعات وارد نشده است"); return; } Subject parent = (Subject)tree.SelectedNode.Tag; int parentId = parent.Id; int id = DatabaseAccess.AddSubject(title, parentId); Subject subject = new Subject(); subject.Title = title; subject.Id = id; subject.ParentId = parentId; TreeNode node = new TreeNode(); node.Tag = subject; node.Text = title; tree.SelectedNode.Nodes.Add(node); tree.Refresh(); tree.ExpandAll(); }
private void افزودنریشهToolStripMenuItem_Click(object sender, EventArgs e) { string title = "موضوع جدید"; if (title.Equals("")) { MessageBox.Show("اطلاعات وارد نشده است"); return; } int id = DatabaseAccess.AddSubject(title, -1); Subject subject = new Subject(); subject.Title = title; subject.Id = id; subject.ParentId = -1; TreeNode node = new TreeNode(); node.Tag = subject; node.Text = title; tree.Nodes.Add(node); tree.Refresh(); node.BeginEdit(); }
public static List<TreeNode> GetRoots() { SqlConnection con = new SqlConnection(ConnectionString); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tbl_BookCommentSubject WHERE BookCommentSubjectParentId IS NULL", con); DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count == 0) return null; List<TreeNode> roots = new List<TreeNode>(); foreach (DataRow row in ds.Tables[0].Rows) { TreeNode node = new TreeNode(); Subject subject = new Subject(); subject.ParentId = -1; subject.Id = Convert.ToInt32(row["BookCommentSubjectId"]); subject.Title = row["BookCommentSubjectTitle"].ToString(); node.Tag = subject; node.Text = subject.Title; node = AppendChilds(node); roots.Add(node); } return roots; }
public static Subject GetSubject(int id) { SqlConnection con = new SqlConnection(ConnectionString); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tbl_BookCommentSubject WHERE BookCommentSubjectId=" + id, con); DataSet ds = new DataSet(); da.Fill(ds); Subject subject = new Subject(); subject.Id = Convert.ToInt32(ds.Tables[0].Rows[0]["BookCommentSubjectId"]); subject.ParentId = Convert.ToInt32(ds.Tables[0].Rows[0]["BookCommentSubjectParentId"]); subject.Title = ds.Tables[0].Rows[0]["BookCommentSubjectTitle"].ToString(); return subject; }