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;
using System.IO;

public partial class WTOSYSadmin_Products_ProductAttribute : System.Web.UI.Page
{
    string picPath = "";
    string picServer = "/upfile";
    protected string itemID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string urlPath = "";
        //插入大类
        string BrandName = Request["BName"].ToString().Trim();
        //取图片
        string fnamepd = this.BLogoPic.FileName;
        if (fnamepd != "")
        {
            string fpathpd = this.BLogoPic.PostedFile.FileName;
            string ftypepd = this.BLogoPic.PostedFile.ContentType;
            string[] typepd = ftypepd.Split('/');
            string[] fnpd = fnamepd.Split('.');
            if (typepd[0].ToString() != "image")
            {
                Response.Write("文件格式错误！");

            }
            else
            {
                string tyy = fnamepd.Substring(fnamepd.LastIndexOf("."), 1);
                urlPath = DateTime.Now.ToString("yyyyMMssssMM") + ".jpg";
                string l11 = Server.MapPath("~/images/Brand/");
                string ptpd = l11 + urlPath;
                this.BLogoPic.SaveAs(ptpd);
                this.BLogoPic.Dispose();
            }
        }
        else
        {
            Response.Write("<script>alert('图片未添加');window.location.href='BrandAdd.aspx'</script>");
        }


        string BrandWeb = Request["BWeb"].ToString().Trim();
        //编辑器内容

        string BrandConect = Server.HtmlEncode(Binfo.Text.Replace("'", "''")).Replace("\n", "<br />");
        //加放数据库
        if (Doadmin.Exec("insert into Brand(BrandName,BrandPic,BrandWeb,BrandConect) values ('" + BrandName + "','" + urlPath + "','" + BrandWeb + "','" + BrandConect + "')"))
        {
            Response.Write("<script>alert('添加成功!')</script>");
        }
        else
        {
            Response.Write("<script>alert('记录未添加!')</script>");
        }

        
    }
    //处理更多图片上传;
    


    //#region 创建文件夹并重命名
    //private string GetExtension(string fileName)
    //{
    //    int startPos = fileName.LastIndexOf(".");
    //    string ext = fileName.Substring(startPos, fileName.Length - startPos);
    //    return ext;
    //}
    //private string GetSaveFilePath()
    //{
    //    DateTime dateTime = DateTime.Now;
    //    string yearStr = dateTime.Year.ToString(); ;
    //    string monthStr = dateTime.Month.ToString();
    //    string dayStr = dateTime.Day.ToString();
    //    string hourStr = dateTime.Hour.ToString();
    //    string minuteStr = dateTime.Minute.ToString();
    //    string dir = dateTime.ToString(@"\\yyyyMMdd");
    //    if (!Directory.Exists(picPath + dir))
    //    {
    //        Directory.CreateDirectory(picPath + dir);
    //    }
    //    return dir + dateTime.ToString("\\\\yyyyMMddhhmmssffff");
    //}
    //#endregion
}
