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;

public partial class admin_Advertisement_MangerEditAd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack) 
        {
            btn_confim.Attributes.Add("onclick", "return UserAd();");
            Btn_upload.Attributes.Add("onclick", "return di();");
            BindDataAd();
        }
    }

    private void BindDataAd()
    {
        string adname = Request.QueryString["adname"] as string;
        int id = Convert.ToInt32(Request.QueryString["mid"].ToString());
        string strWhere = "where M_ID="+id;
        DAL.Ad.MemberInfo mem = new DAL.Ad.MemberInfo();
        Model.Ad.AdMemberInfo adme = mem.GetModelMemberAdInfo(strWhere);
        this.TxB_Adrees.Text = adme.M_Adrees;
        this.TxB_Image.Text = adme.MImageAdrees;
        this.TxB_Day.Text = adme.MDay.ToString();
        this.TxB_word.Text = adme.MLeter;
        this.txt_edit.Text = adname;
        this.txt_AdMName.Text = adme.Ad_MemberInfo_Name.ToString();
    }
    protected void btn_confim_Click1(object sender, EventArgs e) 
    {
       int id = Convert.ToInt32(Request.QueryString["mid"].ToString());
       Model.Ad.AdMemberInfo adm = new Model.Ad.AdMemberInfo();
       adm.MLeter = this.TxB_word.Text.ToString().Trim();
       adm.MDay =Convert.ToInt32(this.TxB_Day.Text.ToString().Trim());
       adm.M_Adrees = this.TxB_Adrees.Text.ToString().Trim();
       adm.MImageAdrees = this.TxB_Image.Text.ToString().Trim();
       adm.Ad_MemberInfo_Name = this.txt_AdMName.Text.ToString().Trim();
       DAL.Ad.MemberInfo mem = new DAL.Ad.MemberInfo();
       mem.UpdateMemberAdInfo(id, adm);
       Response.Redirect("AdvertisementList.aspx");
   }
   #region 上传图片
   protected void Btn_up_Click(object sender, EventArgs e)
    {
        Base.Core.WebConfig web = new Base.Core.WebConfig();
        string imgsFolder = web.ImgFolder;
        string LoinName = Session["ManagerName"] as string;
        string datatime = System.DateTime.Now.ToString("yyyyMMddHHmmssffff");
        if (this.upfile_href.HasFile)
        {
            string fileName = this.upfile_href.FileName;
            string fileExition = System.IO.Path.GetExtension(fileName).ToLower();
            string de = "|.gif|.png|.jpeg|.jpg";
            string strDay = System.DateTime.Now.ToString("yyyyMM");
            string path = HttpContext.Current.Server.MapPath("~/img/" + strDay + "/" + imgsFolder);
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            if (fileName == "")
            {
                Response.Write("<script>alert('请选择上传的图片');</script>");
                return;
            }
            if (de.IndexOf(fileExition) > 0)
            {
                string NewFileName ="/"+datatime + fileExition;
                this.upfile_href.PostedFile.SaveAs(path + NewFileName);
                this.TxB_Image.Text = Base.BasePage.Config.WebURL + "img/" + strDay + imgsFolder + NewFileName;
            }
            else
            {
                Response.Write("<script>alert('上传图片格式错误');</script>");
            }

        }
    }
   #endregion 
}
