Beispiel #1
0
        /// <summary>
        /// 递归加载分类
        /// </summary>
        /// <param name="dt">dt</param>
        /// <param name="code">code</param>
        /// <returns></returns>
        private static JArray GetTreeChild(DataTable dt, string code)
        {
            JArray childobjArray = new JArray();

            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow[] dr = null;
                if (string.IsNullOrEmpty(code))
                {
                    dr = dt.Select("SUBSTRING(BIOLOGICALTYPECODE,11,2) <> '00' AND SUBSTRING(BIOLOGICALTYPECODE,13,2)='00'");
                }
                else
                {
                    string str = "";
                    if (PublicCls.BioCodeIsKe(code))
                    {
                        str = PublicCls.GetKeBioCode(code);
                        dr  = dt.Select("SUBSTRING(BIOLOGICALTYPECODE,1,10) = '" + str + "' AND SUBSTRING(BIOLOGICALTYPECODE,11,2)<>'00' AND SUBSTRING(BIOLOGICALTYPECODE,13,2)='00'");
                    }
                    else if (PublicCls.BioCodeIsShu(code))
                    {
                        str = PublicCls.GetShuBioCode(code);
                        dr  = dt.Select("SUBSTRING(BIOLOGICALTYPECODE,1,12) = '" + str + "' AND SUBSTRING(BIOLOGICALTYPECODE,13,2)<>'00'");
                    }
                    else
                    {
                        str = PublicCls.GetZhongBioCode(code);
                        dr  = dt.Select("SUBSTRING(BIOLOGICALTYPECODE,1,14) = '" + str + "' AND LEN(BIOLOGICALTYPECODE)>'" + code.Length + "'");
                    }
                }
                if (dr != null && dr.Count() > 0)
                {
                    for (int i = 0; i < dr.Count(); i++)
                    {
                        code = dr[i]["BIOLOGICALTYPECODE"].ToString();
                        JObject root = new JObject
                        {
                            { "id", dr[i]["BIOLOGICALTYPECODE"].ToString() },
                            { "text", dr[i]["BIOLOGICALTYPECODENAME"].ToString() },
                            { "state", "closed" }
                        };
                        root.Add("children", GetTreeChild(dt, code));
                        childobjArray.Add(root);
                    }
                }
            }
            return(childobjArray);
        }