public JsonResult getcompliancetypeact() { // string compliancetype = Request.QueryString["compliancetype"]; int compliancetypeid = Convert.ToInt32(Session["compliancetypeid"]); ComplianceXrefService.ComplianceXrefServiceClient client = new ComplianceXrefService.ComplianceXrefServiceClient(); //Session["compliancetypeid"] = compliancetypeid; var root = new treenode() //Create our root node and ensure it is opened { id = Guid.NewGuid().ToString(), text = "Select All", state = new Models.State(true, false, false) }; var children = new List <treenode>(); string xmldata = client.GetActs(0); DataSet ds = new DataSet(); ds.ReadXml(new StringReader(xmldata)); DataSet dsact = new DataSet(); //int compliancetypeid = 0; xmldata = client.GetXrefComplainceTypemapping(compliancetypeid, 0); dsact.ReadXml(new StringReader(xmldata)); Session["AssignedActs"] = dsact; if (ds.Tables.Count > 0) { foreach (System.Data.DataRow row in ds.Tables[0].Rows) { var list = new treenode() { id = Convert.ToString(row["Compliance_Xref_ID"]), text = Convert.ToString(row["Compliance_Title"]), children = null, categorytype = "Act", state = new Models.State(false, false, false) }; if (dsact.Tables.Count > 0) { foreach (System.Data.DataRow item in dsact.Tables[0].Rows) { if (Convert.ToString(item["Compliance_Xref_ID"]) == list.id) { list.state = new Models.State(false, false, true); } } } children.Add(list); } } root.children = children; return(Json(root, JsonRequestBehavior.AllowGet)); }
public static string part1(bool debug) { treenode root = new treenode(); var MD5istance = MD5.Create(); Queue <treenode> _toaccross = new Queue <treenode>(); while (root.x != 3 || root.y != 3) { byte[] hashbyte = MD5istance.ComputeHash(Encoding.ASCII.GetBytes(input + root.path)); if (root.y > 0 && (hashbyte[0] >> 4) > 10) { _toaccross.Enqueue(new treenode() { path = root.path + "U", x = root.x, y = root.y - 1 }); } if (root.y < 3 && (hashbyte[0] & 15) > 10) { _toaccross.Enqueue(new treenode() { path = root.path + "D", x = root.x, y = root.y + 1 }); } if (root.x > 0 && (hashbyte[1] >> 4) > 10) { _toaccross.Enqueue(new treenode() { path = root.path + "L", x = root.x - 1, y = root.y }); } if (root.x < 3 && (hashbyte[1] & 15) > 10) { _toaccross.Enqueue(new treenode() { path = root.path + "R", x = root.x + 1, y = root.y }); } root = _toaccross.Dequeue(); draw(root); Thread.Sleep(150); } return(root.path); }
static void draw(treenode nodes) { Console.CursorTop = 0; Console.CursorLeft = 0; Console.WriteLine("#########"); for (int y = 0; y < 3; y++) { Console.WriteLine("# | | | #"); Console.WriteLine("#-#-#-#-#"); } Console.WriteLine("# | | | "); Console.WriteLine("####### V"); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.SetCursorPosition(1, 1); Console.Write("0"); Console.CursorLeft--; foreach (var item in nodes.path) { switch (item) { case 'U': Console.CursorTop -= 2; break; case 'D': Console.CursorTop += 2; break; case 'L': Console.CursorLeft -= 2; break; case 'R': Console.CursorLeft += 2; break; } Console.Write("0"); Console.CursorLeft--; } Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("S"); Console.ResetColor(); Console.SetCursorPosition(1, 9); Console.Write(nodes.path.Length > 50 ? "..." + nodes.path.Substring(nodes.path.Length - 50) : nodes.path); }
private void ResolveSubTree(DataRow dr, treenode treeNode) { DataRow[] rows = dr.GetChildRows("TreeRelation"); if (rows.Length > 0) { //treeNode.Expanded = true; foreach (DataRow row in rows) { treenode node = new treenode(); node.name = dr["name"].ToString(); node.value = dr["value"].ToString(); node.pid = dr["pid"].ToString(); treeNode.list.Add(node); ResolveSubTree(row, node); } } }
protected List <treenode> tabletolist(DataTable dt) { List <treenode> list = new List <treenode>(); DataSet ds = new DataSet(); ds.Tables.Add(dt.Copy()); ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["value"], ds.Tables[0].Columns["pid"], false); foreach (DataRow dr in ds.Tables[0].Rows) { if (Convert.ToInt16(dr["pid"]) == 0) { treenode node = new treenode(); node.name = dr["name"].ToString(); node.value = dr["value"].ToString(); node.pid = dr["pid"].ToString(); list.Add(node); ResolveSubTree(dr, node); } } return(list); }
public void draw(bool[,] matrix, treenode root, ConsoleColor color, ConsoleColor haedcolor) { Console.CursorTop = 0; Console.CursorLeft = 0; for (int y = 0; y < this.height; y++) { for (int x = 0; x < this.width; x++) { if (root.y == y && root.x == x) { try { Console.SetCursorPosition(x, y); Console.ForegroundColor = haedcolor; Console.Write("O"); Console.ResetColor(); } catch (Exception) { } } else if (matrix[y, x]) { try { Console.SetCursorPosition(x, y); Console.ForegroundColor = color; Console.Write("O"); Console.ResetColor(); } catch (Exception) { } } ; } Console.WriteLine(""); } }
public static string part2() { treenode root = new treenode(); var MD5istance = MD5.Create(); string biggestSolution = ""; Queue <treenode> _toaccross = new Queue <treenode>(); do { byte[] hashbyte = MD5istance.ComputeHash(Encoding.ASCII.GetBytes(input + root.path)); if (root.y > 0 && (hashbyte[0] >> 4) > 10) { _toaccross.Enqueue(new treenode() { path = root.path + "U", x = root.x, y = root.y - 1 }); } if (root.y < 3 && (hashbyte[0] & 15) > 10) { _toaccross.Enqueue(new treenode() { path = root.path + "D", x = root.x, y = root.y + 1 }); } if (root.x > 0 && (hashbyte[1] >> 4) > 10) { _toaccross.Enqueue(new treenode() { path = root.path + "L", x = root.x - 1, y = root.y }); } if (root.x < 3 && (hashbyte[1] & 15) > 10) { _toaccross.Enqueue(new treenode() { path = root.path + "R", x = root.x + 1, y = root.y }); } if (_toaccross.Count > 0) { root = _toaccross.Dequeue(); } else { break; } if (root.x == 3 && root.y == 3) { if (biggestSolution.Length < root.path.Length) { biggestSolution = root.path; } draw(root); Console.WriteLine("\nBiggest ({1}):{0}", (biggestSolution.Length > 50) ? "..." + biggestSolution.Substring(biggestSolution.Length - 50) : biggestSolution, biggestSolution.Length); root = _toaccross.Dequeue(); } } while (true); return(root.path); }
public Dictionary <int, int> shortest(int number, treenode from, ConsoleColor color, ConsoleColor haedcolor, bool debug) { Queue <treenode> _toaccross = new Queue <treenode>(); Dictionary <int, int> retval = new Dictionary <int, int>(10); retval.Add(allNumber.Where(item => item.Value.CompareTo(from) == 0).First().Key, 0); bool[,] matrix = new bool[height, width]; treenode root = from; Stopwatch sp = new Stopwatch(); sp.Start(); while (retval.Count != allNumber.Count) { if (root.y > 0 && getNodeType(root.y - 1, root.x) != NodeType.CLOSED && !matrix[root.y - 1, root.x]) { var node = new treenode() { x = root.x, y = root.y - 1, steps = root.steps + 1 }; _toaccross.Enqueue(node); matrix[node.y, node.x] = true; } if (root.y < height && getNodeType(root.y + 1, root.x) != NodeType.CLOSED && !matrix[root.y + 1, root.x]) { var node = new treenode() { x = root.x, y = root.y + 1, steps = root.steps + 1 }; _toaccross.Enqueue(node); matrix[node.y, node.x] = true; } if (root.x > 0 && getNodeType(root.y, root.x - 1) != NodeType.CLOSED && !matrix[root.y, root.x - 1]) { var node = new treenode() { x = root.x - 1, y = root.y, steps = root.steps + 1 }; _toaccross.Enqueue(node); matrix[node.y, node.x] = true; } if (root.x < width && getNodeType(root.y, root.x + 1) != NodeType.CLOSED && !matrix[root.y, root.x + 1]) { var node = new treenode() { x = root.x + 1, y = root.y, steps = root.steps + 1 }; _toaccross.Enqueue(node); matrix[node.y, node.x] = true; } root = _toaccross.Dequeue(); if (getNodeType(root.y, root.x) == NodeType.NUMBER) { var key = allNumber.Where(item => item.Value.CompareTo(root) == 0).First().Key; if (!retval.ContainsKey(key)) { retval.Add(key, root.steps); } } if (debug) { Thread.Sleep(1); if (sp.ElapsedMilliseconds > 1500) { lock (Console.Out) { Console.CursorTop = height + 1 + number; Console.WriteLine("{0}. QUEUE Lenght:{1}", number, _toaccross.Count); draw(matrix, root, color, haedcolor); } sp.Restart(); } } } if (debug) { draw(matrix, root, color, haedcolor); } return(retval); }
public JsonResult GetJsTree3Data(string audittypeid, string acttype) { int auditid = Convert.ToInt32(audittypeid); OrgService.OrganizationServiceClient client = new OrgService.OrganizationServiceClient(); string xmldata = client.getorglocation(Convert.ToInt32(Session["Branch_Id"])); DataSet loc = new DataSet(); loc.ReadXml(new StringReader(xmldata)); int countryid = Convert.ToInt32(loc.Tables[0].Rows[0]["Country_ID"]); int stateid = 0; int cityid = 0; int flag = Convert.ToInt32(acttype); if (acttype == "1") { countryid = Convert.ToInt32(loc.Tables[0].Rows[0]["Country_ID"]); stateid = 0; cityid = 0; } else if (acttype == "2") { stateid = Convert.ToInt32(loc.Tables[0].Rows[0]["State_ID"]); cityid = 0; } else { cityid = Convert.ToInt32(loc.Tables[0].Rows[0]["City_ID"]); } var root = new treenode() //Create our root node and ensure it is opened { id = Guid.NewGuid().ToString(), text = "Select All", state = new Models.State(true, false, false) }; int orgid = Convert.ToInt32(Session["Branch_Id"]); int vendorid = Convert.ToInt32(Session["VendorId"]); //Create a basic structure of nodes var children = new List <treenode>(); ComplianceXrefService.ComplianceXrefServiceClient xrefclient = new ComplianceXrefService.ComplianceXrefServiceClient(); xmldata = xrefclient.GetcomplianceonType(auditid, countryid, stateid, cityid, flag); DataSet dscomp = new DataSet(); dscomp.ReadXml(new StringReader(xmldata)); DataTable ds = new DataTable(); DataTable dsection = new DataTable(); DataTable dsrules = new DataTable(); if (dscomp.Tables.Count > 0) { DataView dv = new DataView(dscomp.Tables[0]); dv.RowFilter = "level=1"; ds = dv.ToTable(); dv.Table = dscomp.Tables[0]; dv.RowFilter = "level=3"; dsrules = dv.ToTable(); dv.Table = dscomp.Tables[0]; dv.RowFilter = "level=2"; dsection = dv.ToTable(); } else { TempData["Error"] = "No Rules for the state level"; } xmldata = xrefclient.getRuleforBranch(orgid, vendorid); DataSet dsassigenedrule = new DataSet(); dsassigenedrule.ReadXml(new StringReader(xmldata)); treenode act = new treenode(); if (ds.Rows.Count > 0) { foreach (System.Data.DataRow row in ds.Rows) { bool isrule = false; act = new treenode { id = row["Compliance_Xref_ID"].ToString(), text = row["Compliance_Title"].ToString(), icon = "fa fa-legal", state = new Models.State(true, false, false), categorytype = "Act", children = new List <treenode>() }; if (dsection.Rows.Count > 0) { foreach (System.Data.DataRow section in dsection.Rows) { if (row["Compliance_Xref_ID"].ToString() == section["Compliance_Parent_ID"].ToString()) { isrule = false; var sec = new treenode { id = section["Compliance_Xref_ID"].ToString(), text = section["Compliance_Title"].ToString(), icon = "fa fa-book", state = new Models.State(false, false, false), categorytype = "Section", children = new List <treenode>() }; if (dsrules.Rows.Count > 0) { foreach (System.Data.DataRow rules in dsrules.Rows) { if (section["Compliance_Xref_ID"].ToString() == rules["Compliance_Parent_ID"].ToString()) { isrule = true; var rule = new treenode { id = rules["Compliance_Xref_ID"].ToString(), text = rules["Compliance_Title"].ToString(), icon = "fa fa-leanpub", state = new Models.State(false, false, false), categorytype = "Rule", children = new List <treenode>() }; if (dsassigenedrule.Tables.Count > 0) { foreach (System.Data.DataRow assignrules in dsassigenedrule.Tables[0].Rows) { if (assignrules["Compliance_Xref_ID"].ToString() == rules["Compliance_Xref_ID"].ToString()) { rule.state = new Models.State(false, false, true); break; } } } if (isrule == true) { sec.children.Add(rule); } } } } if (isrule == true) { act.children.Add(sec); } } } } if (isrule == true) { children.Add(act); } } } // Add the sturcture to the root nodes children property root.children = children; // Return the object as JSON return(Json(root, JsonRequestBehavior.AllowGet)); }