using System;
using System.Web;
using System.Web.UI;
using Models;
using System.Linq;



    public partial class ADAdd : AdminBase
    {
        private int _Id=0;


        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "no-cache";

            if (!string.IsNullOrEmpty(Request.Params["ID"]))
            {
                _Id = int.Parse(HttpContext.Current.Request.QueryString["ID"]);

            }

            if (!Page.IsPostBack)
            {


                if (_Id != 0)
                {
                    ShowInfo(_Id);
                }

              //  chkLoginLevel("editArticle");
                //绑定类别
              //  ChannelTreeBind(0, "请选择所属类别...", (int)Channel.Article, this.ddlClassId);
  
            }
               
           
        }

        //保存
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Entities mydb = new Entities();
            {
                L_AD _news = new L_AD();

                if (_Id != 0)
                    _news = mydb.L_AD.First(p => p.NID == _Id);
               

                _news.Title = txtTitle.Text.Trim();

                _news.Url = txtUrl.Text.Trim();

                //自动提取关健字
                if (txtKeyword.Text.Trim() != string.Empty)
                {
                    _news.Tag = txtKeyword.Text.Trim();
                }
                else
                {
                    _news.Tag = txtTitle.Text.Trim();
                }
                //自动提取摘要
        
                    _news.ZhaiYao = Utils.DropHTML(txtZhaiyao.Text, 250);
    
                //自动提取导读

             
                _news.Img = txtImgUrl.Text.Trim();
                _news.Img2 = txtImgUrl2.Text.Trim();
            
                _news.Click = txtClick.Text.Trim();
         
                _news.IsTop = false;
                _news.IsRed = false;
                _news.IsHot = false;
                _news.IsSlide = false;
                _news.IsLock = false;

         
                    _news.IsLock = true;
               
                    _news.IsTop = true;
              
                    _news.IsRed = true;
              
                    _news.IsHot = true;
               
                    _news.IsSlide = true;
              
                    _news.Time = DateTime.Parse(txtRQ.Text.ToString());
                
              
                    _news.Time = DateTime.Now;
                

                if (_Id == 0)
                {

                    mydb.L_AD.Add(_news);
                    mydb.SaveChanges();
                    JscriptPrint("广告发布成功啦！", "list.aspx", "Success");
                }
                else
                {
                  
                    mydb.SaveChanges();
                    JscriptPrint("广告修改成功啦！", "list.aspx", "Success");
                }

            }

            // bll.Add(model);
            //保存日志
            //SaveLogs("[资讯模块]添加文章：" + model.Title);
          
        }

        private void ShowInfo(int _id)
        {

            Entities mydb = new Entities();
            {

             L_AD _news = mydb.L_AD.First(p => p.NID == _id);
            
            txtTitle.Text = _news.Title;
           
            txtKeyword.Text = _news.Tag;
            txtZhaiyao.Text = _news.ZhaiYao;
        
            txtImgUrl.Text = _news.Img;
            txtImgUrl2.Text = _news.Img2;
           
            txtUrl.Text = _news.Url;

            if (_news.Click != null)
                txtClick.Text = _news.Click.ToString();

         
            txtRQ.Text = _news.Time.ToString();
          }
        }


 


    }


