<%@ Page Language="C#" ContentType="text/html" Inherits="Ycbw.Data.OleDbClient" %>

<%@ Register TagPrefix="Rajah" TagName="Head" src="../ctrls/head.ascx" %>
<%@ Register TagPrefix="Rajah" TagName="Foot" src="../ctrls/foot.ascx" %>

<script language="c#" runat="server">
private void Page_Load(object sender, EventArgs e)
{
	if( !Page.IsPostBack )
	{
		this.Initialize();
		
		this.p_width.Text = "600";
		this.p_height.Text = "400";
	
		if( Request.QueryString["id"] != null && Request.QueryString["id"] != "" )
		{
			this.Fill("Select top 1 * from [b_articles] where id = " + Convert.ToInt32(Request.QueryString["id"]), "data_article");
	
			System.Data.DataRow dr = this.Data.Tables["data_article"].Rows[0];
	
			this.cid.Text 		= dr["cid"].ToString();
			this.title.Text     = dr["title"].ToString();
			this.forecolor.Text = dr["forecolor"].ToString();
			this.tags.Text      = dr["tags"].ToString();
			this.link.Text      = dr["link"].ToString();
			this.picture.Text   = dr["picture"].ToString();
			this.source.Text    = dr["source"].ToString();
			this.addtime.Text   = dr["addtime"].ToString();
			this.content.Text   = dr["content"].ToString();
			this.state.Text     = dr["state"].ToString();
		}
	}
}

private void Initialize()
{
	this.BindDropDownList("select name,id,depth from [b_article_categories] order by lft", "categories", cid);
	
	this.referer.Text = Request.ServerVariables["HTTP_REFERER"];
}

private void button_submit_click(object sender, EventArgs e)
{
	this.Fill("Select top 1 * from [b_articles] where id = " + Convert.ToInt32(Request.QueryString["id"]), "data_article" );

	System.Data.DataRow dr = this.Data.Tables[0].Rows[0];

	dr["cid"]       = this.cid.Text;
	dr["title"]     = this.title.Text;
	dr["forecolor"] = this.forecolor.Text;
	dr["tags"]      = this.tags.Text;
	dr["link"]      = this.link.Text;
	dr["source"]    = this.source.Text;
	dr["picture"]   = this.picture.Text;
	dr["addtime"]   = this.addtime.Text;
	dr["content"]   = new Common().GetText(this.content.Text);
	dr["state"]		= ( this.state.Text == "" ) ? "0" : this.state.Text;

	//上传图片
	HttpPostedFile inputFile = Request.Files[0]; 
	
	if( inputFile.FileName != "" )
	{
		string fileExt  = inputFile.FileName.Substring( inputFile.FileName.LastIndexOf(".") );
		string filename = DateTime.Now.ToString("yyMMddhhmmss") + this.CreateRandomCode(2).ToString() + fileExt;
		
		if( compress.Checked )
			this.Upload( inputFile, "/uploadfiles", filename, Convert.ToInt32(p_width.Text), Convert.ToInt32(p_height.Text) );
		else
			this.Upload( inputFile, "/uploadfiles", filename );

		dr["picture"] = "/uploadfiles/" + filename;
	}
	else
	{
		if( dr["picture"].ToString() == "" && Regex.IsMatch(dr["content"].ToString(), "src=\"[/]?uploadfiles/\\S*\"", RegexOptions.IgnoreCase) )
		{
			dr["picture"] = Regex.Match(dr["content"].ToString(), "src=\"([/]?uploadfiles/\\S*)\"", RegexOptions.IgnoreCase).Groups[1].ToString();
		}
	}

	this.Update("data_article");
	
	this.JWrite( "alert('修改成功');window.location.href = '"+ referer.Text +"';" );
}
</script>

<Rajah:Head ID="Head" Level="0" Runat="Server" />
<form runat="server">
<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="title3"><div style="float:left">修改内容</div>
      <div style="float:right"></div></td>
  </tr>
  <tr>
    <td style="padding:8px"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td class="table3">
		  <table width="100%" border="0" cellspacing="0" cellpadding="0">
			  <tr>
				<td height="25"><asp:Button Text=" 提交 " OnClick="button_submit_click" runat="server" /></td>
				<td align="right">
				</td>
			  </tr>
			</table>

		  </td>
        </tr>
        <tr>
          <td bgcolor="#EFF5FB">
		  <table width="100%" border="0" cellspacing="8" cellpadding="0">
              <tr>
                <td width="60" align="right">分类</td>
                <td><asp:DropDownList ID="cid" runat="server" /></td>
                <td align="right">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right">标题</td>
                <td><asp:TextBox ID="title" CssClass="text2" runat="server" Width="400" />
                  <asp:DropDownList ID="forecolor" runat="server">
                    <asp:ListItem Value="" Text="颜色" />
                    <asp:ListItem Value="#000000" style="background-color:#000000" />
                    <asp:ListItem Value="#FFFFFF" style="background-color:#FFFFFF" />
                    <asp:ListItem Value="#008000" style="background-color:#008000" />
                    <asp:ListItem Value="#800000" style="background-color:#800000" />
                    <asp:ListItem Value="#808000" style="background-color:#808000" />
                    <asp:ListItem Value="#000080" style="background-color:#000080" />
                    <asp:ListItem Value="#800080" style="background-color:#800080" />
                    <asp:ListItem Value="#808080" style="background-color:#808080" />
                    <asp:ListItem Value="#FFFF00" style="background-color:#FFFF00" />
                    <asp:ListItem Value="#00FF00" style="background-color:#00FF00" />
                    <asp:ListItem Value="#00FFFF" style="background-color:#00FFFF" />
                    <asp:ListItem Value="#FF00FF" style="background-color:#FF00FF" />
                    <asp:ListItem Value="#FF0000" style="background-color:#FF0000" />
                    <asp:ListItem Value="#0000FF" style="background-color:#0000FF" />
                  <asp:ListItem Value="#008080" style="background-color:#008080" />                  </asp:DropDownList></td>
                <td width="10%" align="right">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right">关键字</td>
                <td colspan="3"><asp:TextBox ID="tags" CssClass="text2" runat="server" Width="400" /></td>
              </tr>
              <tr>
                <td align="right">图片</td>
                <td colspan="3"><asp:TextBox ID="picture" CssClass="text2" Width="150" runat="server" />
				<input name="file" type="file" class="text2" runat="server" style="width:200px" />&nbsp;<asp:CheckBox ID="compress" Text="自动压缩" Checked="true" runat="server" /> <asp:TextBox ID="p_width" Text="200" CssClass="text2" Width="50" runat="server" /> <asp:TextBox ID="p_height" Text="150" CssClass="text2" Width="50" runat="server" /></td>
              </tr>
              <tr>
                <td align="right">来源</td>
                <td><asp:TextBox ID="source" CssClass="text2" runat="server" Width="120" /></td>
                <td align="right">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right">时间</td>
                <td><asp:TextBox ID="addtime" CssClass="text2" runat="server" Width="120" />
                  <asp:DropDownList ID="state" runat="server">
                    <asp:ListItem Value="" Text="状态" />                  
                    <asp:ListItem Value="0" Text="普通" />                  
                    <asp:ListItem Value="1" Text="热" />                  
                    <asp:ListItem Value="2" Text="推荐" />                  
                  <asp:ListItem Value="3" Text="置顶" /></asp:DropDownList></td>
                <td align="right">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right">外部连接</td>
                <td colspan="3"><asp:TextBox ID="link" CssClass="text2" runat="server" Width="400" /></td>
              </tr>
              <tr>
                <td align="right" valign="top" style="padding-top:29px;">正文</td>
                <td colspan="3">
					<asp:TextBox ID="content" runat="server" style="display:none;"></asp:TextBox>
					<iframe src='../editbox/ewebeditor.htm?id=content&style=coolblue' frameborder='0' scrolling='no' width='100%' height='310'></iframe>				</td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td class="table3"><input type="button" onclick="history.go(-1);" value=" 返回 ">
            <asp:Button Text=" 提交 " OnClick="button_submit_click" runat="server" /></td>
        </tr>
      </table></td>
  </tr>
</table>
<asp:Label ID="referer" Visible="false" runat="server" />
</form>
<Rajah:Foot ID="Foot" Runat="Server" />
