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;

public partial class etwuser_Websitechanges : System.Web.UI.Page
{
    public string edittime=string.Empty;
    public int userid=0;
    public string msg = string.Empty;
    public string filename2 = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
          HttpCookie GetCookie = Request.Cookies["cookEtwuser"];
        if (Request.Cookies["cookEtwuser"] == null)
        {
            Response.Redirect("../index.aspx");
        }
        edittime = DateTime.Now.ToString();
        DataSet ds1 = DbHelperSQL.Query("select userid from etw_user where username='" + GetCookie["username"].ToString() + "'");
        if (ds1.Tables[0].Rows.Count > 0)
        {
            userid = Convert.ToInt32(ds1.Tables[0].Rows[0]["userid"]);
            Fun.Funrecord(Request.Url.AbsoluteUri,Page.Request.UserHostAddress, userid.ToString());
        }
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        Savecaption();
        etw.etw_productupd lead = new etw.etw_productupd();
        lead.userid = userid;
        lead.url = "网站修改:" + Fun.Encode(titletxt.Text.Trim());
        lead.content = Fun.Encode(contenttxt.Text.Trim());
        lead.edittime = edittime;
        lead.isread = 0;
        lead.fujian = filename2;
        lead.Add();
        Fun.JsAlerT("添加成功！", "Websitechanges.aspx"); 
    }
    private void Savecaption()
    {

        try
        {
            string extension = System.IO.Path.GetExtension(File1.PostedFile.FileName);  //判断用户上传文件扩展名
            if (extension != "")
            {
                if (File1.PostedFile.FileName == "")
                {
                    msg = "请选择要上传的附件";
                }

                else if (extension == ".exe" && extension == ".EXE")
                {
                    msg = "禁止上传此类文件";
                }
                else
                {
                    string filepath = File1.PostedFile.FileName;
                    int i = filepath.LastIndexOf(".");
                    //取得文件扩展名
                    string newext2 = filepath.Substring(i);
                    string newname1 = DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss");
                    string newname2 = userid+"-"+newname1.Replace("-", "").Replace("/", "");
                    filename2 = newname2 + newext2;
                    string serverpath = Server.MapPath("../etw_c_m/fujian/") + filename2;
                    if (!Directory.Exists(serverpath))
                    {
                        Directory.CreateDirectory(Server.MapPath("../etw_c_m/fujian/"));
                    }
                    File1.PostedFile.SaveAs(serverpath);
                }
            }
            else
            {
                filename2 = "";
            }
        }
        catch (Exception ex)
        {
            msg = "上传错误";
        }
    }
}
