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();
}