public void bindandsavesubject() { string subjectno = ""; string parentcode = ""; string unitname = ""; string topicno = ""; string description = ""; string noofhrs = ""; string bookref = ""; string steachaid = ""; string bookdetails = ""; string methogology = ""; string instruction = ""; int count = 0; int firsttopicnumber = 0; int inctopicnum = 0; string bindparentcode = ""; string bindtempparentcode = ""; string bindpreviouspcode = ""; ArrayList alunitname = new ArrayList(); DataSet dsvalue = new DataSet(); DataView dvvalue = new DataView(); if (ddlsubject.SelectedValue != toddlsubject.SelectedValue) { lblerrormsg.Text = ""; lblerrormsg.Visible = false; string query = "select * from sub_unit_details where subject_no='" + ddlsubject.SelectedValue + "'"; dsvalue = d2.select_method_wo_parameter(query, "n"); string dt_topics = ""; string dt_topics1 = ""; string subjectsno = toddlsubject.SelectedValue.ToString(); subjectno = ddlsubject.SelectedValue.ToString(); if (!string.IsNullOrEmpty(subjectsno)) { con.Close(); con.Open(); //this.TreeView1.Nodes.Clear(); HierarchyTrees hierarchyTrees = new HierarchyTrees(); HierarchyTrees.HTree objHTree = null; // TreeView2.Nodes.Clear(); //start=======common tree load using (SqlCommand command = new SqlCommand("select topic_no,parent_code,unit_name from sub_unit_details where subject_no='" + subjectno + "' order by parent_code,topic_no ", con)) { //this.TreeView1.Nodes.Clear(); hierarchyTrees.Clear(); SqlDataReader reader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection); while (reader.Read()) { objHTree = new HierarchyTrees.HTree(); objHTree.topic_no = int.Parse(reader["Topic_no"].ToString()); objHTree.parent_code = int.Parse(reader["parent_code"].ToString()); objHTree.unit_name = reader["unit_name"].ToString(); hierarchyTrees.Add(objHTree); } } int i = 0; foreach (HierarchyTrees.HTree hTree in hierarchyTrees) { HierarchyTrees.HTree parentNode = hierarchyTrees.Find(delegate(HierarchyTrees.HTree emp) { return(emp.topic_no == hTree.parent_code); }); if (parentNode != null) { foreach (TreeNode tn in TreeView2.Nodes) { if (tn.Value == parentNode.topic_no.ToString()) { //tn.ChildNodes.Add(new TreeNode(hTree.unit_name.ToString(), hTree.topic_no.ToString())); //Session["session_tnValue"] = tn; } if (tn.ChildNodes.Count > 0) { foreach (TreeNode ctn in tn.ChildNodes) { string checkunitname = parentNode.unit_name.ToString(); if (alunitname.Contains(hTree.unit_name) == false) { alunitname.Add(hTree.unit_name); dsvalue.Tables[0].DefaultView.RowFilter = "unit_name='" + hTree.unit_name + "'"; dvvalue = dsvalue.Tables[0].DefaultView; if (dvvalue.Count > 0) { description = Convert.ToString(dvvalue[0]["description"]); } string parentsNode = parentNode.topic_no.ToString(); string bindpparentcode = "select topic_no from sub_unit_details where subject_no='" + subjectsno + "' and unit_name='" + checkunitname + "' "; con.Close(); con.Open(); SqlCommand findparentcmd = new SqlCommand(bindpparentcode, con); string preparentcode = Convert.ToString(findparentcmd.ExecuteScalar()); unitname = hTree.unit_name; //=================Modified by Venkat======================= //string insertvalue = "insert into sub_unit_details(subject_no,Parent_code,unit_name)values('" + subjectsno + "','" + preparentcode + "','" + unitname + "')"; //con.Close(); //con.Open(); //SqlCommand sqlcmd = new SqlCommand(insertvalue, con); //count = sqlcmd.ExecuteNonQuery(); string insertvalue = "insert into sub_unit_details(subject_no,Parent_code,unit_name)values('" + subjectsno + "','" + preparentcode + "','" + unitname + "')"; int a = dal.update_method_wo_parameter(insertvalue, "Text"); } // tn.ChildNodes.Remove(new TreeNode(hTree.unit_name.ToString(), hTree.topic_no.ToString())); } } } } else { // TreeView1.Nodes.Add(new TreeNode(hTree.unit_name, hTree.topic_no.ToString())); unitname = hTree.unit_name; string pparentNode = "0"; //=================Modified by Venkat======================= //string insertvalue = "insert into sub_unit_details(subject_no,Parent_code,unit_name)values('" + subjectsno + "','" + pparentNode + "','" + unitname + "')"; //con.Close(); //con.Open(); //SqlCommand sqlcmd = new SqlCommand(insertvalue, con); //count = sqlcmd.ExecuteNonQuery(); string insertvalue = "insert into sub_unit_details(subject_no,Parent_code,unit_name)values('" + subjectsno + "','" + pparentNode + "','" + unitname + "')"; count = dal.update_method_wo_parameter(insertvalue, "Text"); } } if (count != 0) { ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "alert('Syllabus copied Successfully')", true); clear(); } } } else { lblerrormsg.Text = "Kindly Select Different Subject"; lblerrormsg.Visible = true; } }
private void toPopulateTreeview() { string dt_topics = ""; string dt_topics1 = ""; string subjectno = ddlsubject.SelectedValue.ToString(); if (!string.IsNullOrEmpty(subjectno)) { con.Close(); con.Open(); //this.TreeView1.Nodes.Clear(); HierarchyTrees hierarchyTrees = new HierarchyTrees(); HierarchyTrees.HTree objHTree = null; //start=======common tree load using (SqlCommand command = new SqlCommand("select topic_no,parent_code,unit_name from sub_unit_details where subject_no='" + subjectno + "' order by parent_code,topic_no ", con)) { //this.TreeView1.Nodes.Clear(); hierarchyTrees.Clear(); SqlDataReader reader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection); while (reader.Read()) { objHTree = new HierarchyTrees.HTree(); objHTree.topic_no = int.Parse(reader["Topic_no"].ToString()); objHTree.parent_code = int.Parse(reader["parent_code"].ToString()); objHTree.unit_name = reader["unit_name"].ToString(); hierarchyTrees.Add(objHTree); } } foreach (HierarchyTrees.HTree hTree in hierarchyTrees) { HierarchyTrees.HTree parentNode = hierarchyTrees.Find(delegate(HierarchyTrees.HTree emp) { return(emp.topic_no == hTree.parent_code); } ); if (parentNode != null) { foreach (TreeNode tn in TreeView2.Nodes) { if (tn.Value == parentNode.topic_no.ToString()) { tn.ChildNodes.Add(new TreeNode(hTree.unit_name.ToString(), hTree.topic_no.ToString())); //Session["session_tnValue"] = tn; } if (tn.ChildNodes.Count > 0) { foreach (TreeNode ctn in tn.ChildNodes) { RecursiveChild(ctn, parentNode.topic_no.ToString(), hTree); } } } } else { TreeView2.Nodes.Add(new TreeNode(hTree.unit_name, hTree.topic_no.ToString())); } TreeView2.ExpandAll(); } TreeView2.ExpandAll(); if (TreeView2.Nodes.Count < 1) { } else { TreeView2.Visible = true; btnsave.Visible = true; } } }