添加静态页面
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Net;
public partial class manager_CMSadmin_news_add : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitPage();
}
}
private void InitPage()
{
BindLabelCode("sy");
BindGardenCode();
}
private void BindLabelCode(String strTypeCode)
{
CNNet.BLL.advadmin.PLabelBLL bll = new CNNet.BLL.advadmin.PLabelBLL();
DataSet ds = bll.GetList(" TypeCode = '" + strTypeCode + "' ");
this.drl_LabelCode.DataSource = ds;
this.drl_LabelCode.DataBind();
}
private void BindGardenCode()
{
CNNet.BLL.RejoiceGarden bll = new CNNet.BLL.RejoiceGarden();
DataSet ds = bll.GetAllList();
this.drl_GardenCode.DataSource = ds;
this.drl_GardenCode.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
//string URL = "http://" + Request.Url.Authority+createNews();
string URL = createNews();
CNNet.Model.admin.COMwNewsMODEL model = new CNNet.Model.admin.COMwNewsMODEL();
model.sTitle = this.ctb_sTitle.Text;
model.TypeCode = this.drl_TypeCode.SelectedValue;
model.LabelCode = this.drl_LabelCode.SelectedValue;
model.sAuthor = this.ctb_sAuthor.Text;
model.sSummary = this.ctb_sSummary.Text;
model.tContent = this.ctb_tContent.Text;
model.PageUrl = URL.Replace("//","/").ToString();
model.IsFPage = (this.rbl_IsFPage.SelectedValue == "1");
model.dtPublicDate = DateTime.Parse(this.txt_dtPublicDate.Value);
model.GardenCode = "0";// this.drl_GardenCode.SelectedValue;
model.cEnable = "0";
model.CreateDate = DateTime.Now;
model.UpdateDate = DateTime.Now;
CNNet.BLL.Company.COMwNewsTBL bll = new CNNet.BLL.Company.COMwNewsTBL();
bll.Add(model);
Response.Redirect("news_manage.aspx");
}
protected void drl_TypeCode_SelectedIndexChanged(object sender, EventArgs e)
{
BindLabelCode(this.drl_TypeCode.SelectedValue);
}
protected String createNews()
{
string[] arr = new string[] { "<!--XINWENTI-->", "<!--RIQI-->", "<!--LAIYUAN-->", "<!--LEIRONG-->" };
StringWriter sww = new StringWriter();
string Url = "http://" + Request.Url.Authority + this.ResolveUrl("~");
System.Text.StringBuilder HTML = new StringBuilder();
HTML.Append(getHtml(Url + "MS/CMSadmin/newsDemo/listinfo-1.html"));
for (int i = 0; i < arr.Length; i++)
{
switch (arr[i].ToString())
{
case "<!--XINWENTI-->": HTML.Replace(arr[i].ToString(), this.ctb_sTitle.Text.Trim());
break;
case "<!--RIQI-->": HTML.Replace(arr[i].ToString(), DateTime.Now.ToString());
break;
case "<!--LAIYUAN-->": HTML.Replace(arr[i].ToString(), this.ctb_sSummary.Text.Trim());
break;
case "<!--LEIRONG-->": HTML.Replace(arr[i].ToString(), this.ctb_tContent.Text.Trim());
break;
default: break;
}
}
return CNNet.CommonBLL.UpdateImage.returnCreateNews(HTML.ToString(), CNNet.CommonBLL.UpdateImage.EN_GlobalImageType.CMS_new, "html");
}
protected string getHtml(string url)
{
string html = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Accept = "*/*";
HttpWebResponse response = null;
Stream stream = null;
StreamReader reader = null;
try
{
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
reader = new StreamReader(stream, Encoding.UTF8);
html = reader.ReadToEnd().Replace("\r\n", ""); //我知道这里会改变html代码,但和这里没关系
}/*
catch (Exception excpt)
{
Console.WriteLine(excpt);
Console.Write("\n【注意】出现异常,输入任意字符和回车继续:");
Console.ReadLine();
}*/
finally
{
if (reader != null)
{
reader.Close();
reader.Dispose();
}
if (stream != null)
{
stream.Close();
stream.Dispose();
}
if (response != null)
{
response.Close();
}
}
return html;
}
}