/// <summary>
/// 生成JS按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LBCreateAdFile_Click(object sender, EventArgs e)
{
string sMapPath = Server.MapPath("/Js/Date/HomeAd.js");
string sTxt = string.Empty;
string sql = " where State = 1 order by HomeAdvertisingId desc";
IList<HomeAdvertisingInfo> hailists = HomeAdvertisingBLL.GetHomeAdvertisingByStr(sql);
if (hailists.Count > 0)
{
sTxt = "var HomeAdObj = [";
for (int i = 0; i < hailists.Count; i++)
{
sTxt += "{\"Label\":" + "\"" + hailists[i].Label + "\"" + ",\"ImgUrl\":" + "\"" + hailists[i].ImgUrl + "\"" + ",\"BackgroundColor\":" + "\"" + hailists[i].BackgroundColor + "\"" + ",\"Link\":" + "\"" + hailists[i].Link + "\"" + ",\"State\":" + "\"" + hailists[i].State + "\"" + ",\"Sort\":" + "\"" + hailists[i].Sort + "\"" + "}";
if (hailists.Count > 1 && i < hailists.Count - 1)
{
sTxt += ",";
}
}
sTxt += "];";
File.WriteAllText(sMapPath, sTxt);
MessageBox.Show(this.Page, "生成文件成功");
}
else
{
MessageBox.Show(this.Page, "暂无数据");
}
BindData();
}