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 Base;

public partial class M_AddAdInfo : nspBase.MemberBasePge
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!CheckCookies())
        {
            Response.Redirect("../ErrorPage.aspx?Err=0");
            return;
        }
        else
        {
            if (!this.IsPostBack)
            {
                btn_confim.Attributes.Add("onclick", "return UserAd();");
                Btn_upload.Attributes.Add("onclick", "return di();");
            }
        }
    }
    protected void btn_confim_Click1(object sender, EventArgs e)
    {
        string isum = "会员";
        string LoinName = BasePage.GetCookie("LoginName").ToString();
        int userid = Convert.ToInt32(BasePage.GetCookie("UserID").ToString());
        string tid = Session["t_id"] as string;
        int Tid = Convert.ToInt32(tid);
        Model.Ad.AdMemberInfo adm = new Model.Ad.AdMemberInfo();
        adm.MImageAdrees = this.TxB_Image.Text.ToString().Trim();
        adm.M_Adrees = this.TxB_Adrees.Text.ToString().Trim();
        adm.MDay = Convert.ToInt32(this.TxB_Day.Text.ToString().Trim());
        adm.MLeter = this.TxB_word.Text.ToString().Trim();
        adm.Ad_MemberInfo_Name = this.txt_AdMName.Text.ToString().Trim();
        DAL.Ad.MemberInfo md = new DAL.Ad.MemberInfo();
        md.AddMemberAdInfo(Tid, userid, isum, LoinName, adm);
        ShowMessage("添加成功", "Advertisement/M_SelectAd.aspx");
    }
    #region 上传图片
    protected void Btn_up_Click(object sender, EventArgs e)
    {
        Base.Core.WebConfig web = new Base.Core.WebConfig();
        string imgsFolder = web.ImgFolder;
        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 path = HttpContext.Current.Server.MapPath("~/" + 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 + imgsFolder + NewFileName;
            }
            else
            {
                Response.Write("<script>alert('上传图片格式错误');</script>");
            }

        }
    }
    #endregion
}
