示例#1
0
        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));
        }