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=非法登陆!或系统超时，请刷新后重新登录");
        }
        if (!IsPostBack)
        {
            string Bid = Request.QueryString["id"].ToString().Trim();
            string isdo = Request.QueryString["do"].ToString().Trim();
            switch (isdo)
            {
                case "Del":
                    Doadmin.Execsql("delete from Brand where id=" + Bid);

                    Response.Redirect("BrandMag.aspx");
                    break;
                case "Edit":
                    this.Label1.Text = "品牌修改";
                    SqlConnection connB = CDatabase.wtoconn();
                    connB.Open();
                    SqlCommand smd = new SqlCommand("select * from Brand where id=" + Bid, connB);
                    SqlDataReader sdr = smd.ExecuteReader();
                    sdr.Read();
                    this.BName.Text = sdr.GetString(1).ToString().Trim();
                    this.BLogo.Text = sdr.GetString(2).ToString().Trim();
                    this.BWeb.Text = sdr.GetString(3).ToString().Trim();

                    string binfo2 = sdr.GetString(4).ToString().Trim();
                    this.Binfo.Text = Server.HtmlDecode(binfo2);

                    break;

            }
        }
        
    }
    public void databind()
    { 
    
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
         //插入大类
        string urlPath="";
        string idd=Request.QueryString["id"].ToString().Trim();
        string BrandName = Request["BName"].ToString().Trim();
        //取图片  

         //图1上传
         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);
                 Response.Write("<script>alert('" + tyy + "')</script>");
                 urlPath = DateTime.Now.ToString("yyyyMMssssMM") + ".jpg";
                 string l11 = Server.MapPath("~/images/Brand/");
                 string ptpd = l11 + urlPath;
                 this.BLogoPic.SaveAs(ptpd);
                 this.BLogoPic.Dispose();
             }
         }
         else
         {
             urlPath = this.BLogo.Text;
         }
        
         string BrandWeb = Request["BWeb"].ToString().Trim();
         //编辑器内容
         string BrandConect = Server.HtmlEncode(Binfo.Text.Replace("'", "''")).Replace("\n", "<br />");
         //加放数据库
        if (Doadmin.Exec("update Brand set BrandName='" + BrandName + "',BrandPic='" + urlPath + "',BrandWeb='" + BrandWeb + "',BrandConect='" + BrandConect + "' where id=" + idd + ""))
        {
            Response.Write("<script>alert('修改成功!');window.location.href='BrandMag.aspx'</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
    

}
