using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using TopWinCMS.BLL;
using TopWinCMS.Model;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin
{
    /// <summary>
    /// Admin_Ads_Add 的摘要说明。
    /// </summary>
    public partial class Admin_Ads_Add : System.Web.UI.Page
    {

        protected void Page_Load(object sender, System.EventArgs e)
        {
            

            if (!IsPostBack)
            {
                if (Request["ID"] != null)//修改界面
                {
                    RightsCheck.CheckWorkPower("A_2");
                    Edit_Load();
                }
                else//添加界面
                {
                    RightsCheck.CheckWorkPower("A_1");
                    CD_MaxDateTime.Value = DateTime.Now.AddMonths(1).ToString();
                }
            }
        }



        private void Edit_Load()
        {
            TopWinCMS.Model.AdListInfo model = new AdsManage().EditLoad(Request["ID"]);

            TTB_SiteName.Text = model.SiteName;
            TTB_UserName.Text = model.UserName;
            TTB_Contact.Text = model.Contact;
            TTB_Ad_Url.Text = model.Ad_Url;
            TTB_Url.Text = model.Url;
            NTB_Width.Text = model.Width.ToString();
            NTB_Height.Text = model.Height.ToString();
            DDL_Target.SelectedValue = model.Target;
            TTB_MaxShowTime.Text = model.MaxShowTime.ToString();
            TTB_MaxClick.Text = model.MaxClick.ToString();
            CD_MaxDateTime.Value = model.MaxDateTime.ToString();

            DDL_ShowType.SelectedValue = model.ShowType.ToString();
            TTB_Remark.Text = model.Remark;

            TTB_Note.Text = model.Note;

        }
        protected void BT_OK_Click(object sender, System.EventArgs e)
        {
            AdListInfo model = new AdListInfo();
            if (Request["ID"] == null)
            {
                model.ID = "0";
            }
            else
            {
                model.ID = Request["ID"];
            }
            model.SiteName = TTB_SiteName.Text;
            model.UserName = TTB_UserName.Text;
            model.Contact = TTB_Contact.Text;
            model.Ad_Url = TTB_Ad_Url.Text;
            model.Url = TTB_Url.Text;
            model.Width = NTB_Width.Text;
            model.Height = NTB_Height.Text;
            model.Target = DDL_Target.SelectedValue;
            model.MaxShowTime = TTB_MaxShowTime.Text;
            model.MaxClick = TTB_MaxClick.Text;
            model.MaxDateTime = CD_MaxDateTime.Value;

            model.ShowType = DDL_ShowType.SelectedValue;
            model.Remark = TTB_Remark.Text;
            model.Note = TTB_Note.Text;

            new AdsManage().Add(model);

        }



        protected void BT_UpLoad_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
                try
                {
                    FileUpload1.SaveAs(Server.MapPath(Config.UP + "adFile/") + FileUpload1.FileName);
                    TTB_Ad_Url.Text = Config.UP + "adFile/" + FileUpload1.FileName;
                    TTB_Ad_Url.Text = TTB_Ad_Url.Text.Replace(@"\", "/");
                }
                catch (Exception ex)
                {
                    MsgBox.Alert(ex.Message);
                }
            else
            {
                MsgBox.Alert("请选择文件！");
            }

        }
    }
}