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 WKadmin_Products_DownAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("/main/error.aspx?err=非法登陆!或系统超时,请确认后重新登录");
        }
        if (!IsPostBack)
        {
            Doadmin.ddldatabind(BigProduct, "select * from DownCategory order by Sort", "BigCategory", "id");
            Doadmin.ddldatabind(smalllb, "select * from SmallDownCategory where BigCategoryId=" + BigProduct.SelectedValue.ToString().Trim(), "SmallCategory", "id");
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        string hz = this.File1.PostedFile.FileName;
        string S_hz = (hz.Substring(hz.LastIndexOf(".") + 1)).ToLower().Trim();
        string stpt = "";
        string stfilename = "";
        string picname="",filename="";
        long filesize1=0;
        if (S_hz == "jpg" || S_hz == "gif")
        {
            stfilename = DateTime.Now.ToString("yyyyMMddHHmmssffffMM");
            stpt = Server.MapPath("~/upfile/") + stfilename + "." + S_hz;
            File1.SaveAs(stpt);
            picname=stfilename + "." + S_hz;

        }
        else
        {
            Response.Write("<script language='javascript'>alert('图片上传格式有误，请确认后再上传!')</script>");
        }
        string hzf = this.File2.PostedFile.FileName;
        string U_f = (hzf.Substring(hzf.LastIndexOf(".") + 1)).ToLower().Trim();
        string stpt1 = "";
        string stfilename1 = "";
        if (U_f == "rar" || U_f=="zip" ||　U_f=="doc" || U_f=="pdf" || U_f=="psd" || U_f=="xls")
        {
            stfilename1 = DateTime.Now.ToString("yyyyMMddHHmmssffffMM");
            stpt1 = Server.MapPath("~/upfile/upload/") + stfilename1 + "." + U_f;
            File2.SaveAs(stpt1);
            filename=stfilename1 + "." + U_f;
            FileInfo fo=new FileInfo(stpt1);
            filesize1=fo.Length;
        }
        else
        {
            Response.Write("<script language='javascript'>alert('上传格式有误，请确认后再上传!')</script>");
        }
        string isfp="";
        if(this.open.Checked)
        {
        isfp="y";
        }
        else
        {
        isfp="n";
        }
        string sql = "insert into Downinfo(BigProductID,SmallProductId,Products,ProductsNo,ISPublished,Description,ThumbnailsPic,filename,filesize,Content,AddDate,Language) values";
        sql = sql + "("+this.BigProduct.SelectedValue.ToString()+","+this.smalllb.SelectedValue.ToString()+",'"+this.Products.Text.ToString()+"','"+this.ProductsNo.Text+"','"+isfp+"','"+this.Description.Text+"','"+picname+"','"+filename+"',"+filesize1+",'"+Server.HtmlEncode(this.Content.Text.ToString())+"','"+DateTime.Now.ToString()+"','"+this.lan.SelectedValue.ToString()+"')";
        if (Doadmin.Exec(sql))
        {
            Response.Write("<script language='javascript'>alert('上传成功');window.location.href='DownAdd.aspx'</script>");
        }
        else
        {
            Response.Write("<script language='javascript'>alert('添加失败');'</script>");
        }
        
    }
    protected void BigProduct_SelectedIndexChanged1(object sender, EventArgs e)
    {
        Doadmin.ddldatabind(smalllb, "select * from SmallDownCategory where BigCategoryId=" + BigProduct.SelectedValue.ToString().Trim(), "SmallCategory", "id");

    }
}
