动态生成JS做为数据源提高性能

 private void WriteAutoCompleteDS()
        {
            WriteDataSourceToJS("Skill", "Category");
            WriteDataSourceToJS("Certification", "CertificationCategory");
            this.Page.ClientScript.RegisterClientScriptInclude("AllSkill", UIUtilities.ApplicationPath + "JS/SkillDataSource" + LanString + ".js");
            this.Page.ClientScript.RegisterClientScriptInclude("AllCertification", UIUtilities.ApplicationPath + "JS/CertificationDataSource" + LanString + ".js");
        }

        private void WriteDataSourceToJS(string tableName, string codeType)
        {
            string fileFullName = Server.MapPath("~") + "//JS//" + tableName + "DataSource" + LanString + ".js";
            if (File.Exists(fileFullName) && File.GetCreationTime(fileFullName).AddHours(1) > DateTime.Now)
            {
                return;
            }
            List<DCAvoCode> allCodes = UICacheManager.GetAvoCodeByType(codeType);
            List<DCAvoCode> childCodes = (from o in allCodes where !string.IsNullOrEmpty(o.ParentAvoCodeCode) select o).ToList();
            StringBuilder sb = new StringBuilder();
            sb.Append("var All" + tableName + "Array = [");
            foreach (DCAvoCode da in childCodes)
            {
                //Text
                sb.Append("['" + UICacheManager.CodeLanDescription(codeType, da.CodeName) + "',");
                //Value
                sb.Append("'" + da.ParentAvoCodeCode + ((char)18).ToString() + da.CodeName + "',");
                //Category
                sb.Append("'" + UICacheManager.CodeLanDescription(codeType, da.ParentAvoCodeCode) + "'],");
            }
            string sqlString = "SELECT DISTINCT OtherName" + LanString + " FROM " + tableName + " T WHERE T.Category='Others'";
            DataTable dtOtherNames = DBManager.GetIDBHelper.ExecQuery(sqlString, null).Tables[0];
            if (dtOtherNames.Rows.Count > 0)
            {
                foreach (DataRow dr in dtOtherNames.Rows)
                {
                    sb.Append("['" + dr[0] + "',");
                    sb.Append("'Others" + ((char)18).ToString() + dr[0] + "',");
                    sb.Append("'" + UICacheManager.CodeLanDescription("Category", "Others") + "'],");
                }
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("];/r/n");
            StreamWriter sw = new StreamWriter(fileFullName, false);
            sw.Write(sb.ToString());
            sw.Close();
            sw.Dispose();
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值