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.Data.SqlClient;
    
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      

    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        SqlConnection connsk = CDatabase.wtoconn();
        connsk.Open();
        if (Session["skin"] == null)
        {
            SqlCommand smdskin = new SqlCommand("select skinid from SystemBasicInformation", connsk);
            Session["skin"] = Convert.ToString(smdskin.ExecuteScalar());
        }
        this.Page.Theme = Session["skin"].ToString();
        connsk.Close();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
      string userip="0";
      if(Request.ServerVariables["HTTP_VIA"]!=null)
      {

          userip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();

　　  }
      else
      {

          userip = Request.ServerVariables["REMOTE_ADDR"].ToString();
 
　  　}
    string hzf = this.File2.PostedFile.FileName;
    string U_f = (hzf.Substring(hzf.LastIndexOf(".") + 1)).ToLower().Trim();
    string stpt1 = "";
    string filename = "";
    string stfilename1 = "";
    if (U_f == "jpg" || U_f == "bmp" || U_f == "png" || U_f == "gif")
    {
        stfilename1 = DateTime.Now.ToString("yyyyMMddHHmmssffffMM");
        stpt1 = Server.MapPath("~/upfile/") + stfilename1 + "." + U_f;
        File2.SaveAs(stpt1);
        filename = "~/upfile/"+stfilename1 + "." + U_f;
    }
    else
    {
        Response.Write("<script language='javascript'>alert('上传格式有误，请确认后再上传!')</script>");
    }

    string sqltxt = "insert into newscomm(username,tel,Content,ip,pid,pname,pic,lan,type,addtime,address,gtype,gname) values('" + this.pm.Text + "','" + this.ptel.Text + "','" + this.pco.Text + "','" + userip + "','001','" + this.gycp.Text + "','" + filename + "','china','3','" + DateTime.Now.ToString() + "','"+address.Text+"','"+gtype.Text+"','"+pn.Text+"')";
       if (Doadmin.Exec(sqltxt))
       {
           Response.Write("<script>alert('资料提交成功!感谢您的支持 ');window.location.href('/china/gysdj.aspx')</script>");
       }
       else
       {

           Response.Write(sqltxt);
           //Response.Write("<script>alert('资料提交失败；请认真填填写! ');window.location.href('/china/gysdj.aspx')</script>");

       }
    }
    
}
