using System;
using System.Collections;
using System.Collections.Generic;

namespace Stat.web.v
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Website1 : System.Web.UI.Page
    {
        Stat.Security.ISecurity security = Stat.Security.DataFatory.CreateSecurity();
        Stat.Cache.IRemoveCache removeCache = Stat.Cache.CacheFatory.CreateRemoveCache();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = Plugin.Common.Rq_Int("wid");
            if (id > 0)
            {//修改

                if (!IsPostBack)
                {
                    EditBox(id);
                }
            }
            else
            {//添加
                this.ltrPowerList.Text = security.GetWebsitePowerList("");
            }
          //  this.ltrShowTypeList.Text += Html.Systems.GetShowStype();
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="id"></param>
        private void EditBox(int id)
        {
            IList<Stat.Model.WebSites> list = Stat.BLL.WebSites.GetWebSiteInfo(id);
            if (list.Count > 0)
            {
                this.txtWebname.Text = list[0].WebName;
                this.txtWebUrl.Text = list[0].WebUrl;
                this.hdfWebid.Value = list[0].WebId.ToString();
                this.ltrPowerList.Text = security.GetWebsitePowerList(list[0].OpenItem);
               // this.rBtnIsRefresh.SelectedIndex = -1;
              //  this.rBtnIsRefresh.Items.FindByValue(list[0].IsReFresh ? "1" : "0").Selected = true;
              //  this.rBtnCodeLock.SelectedIndex = -1;
             //   this.rBtnCodeLock.Items.FindByValue(list[0].IsCodeLock ? "1" : "0").Selected = true;
             //   this.ltrShowTypeList.Text += " <input name=\"hdfShowStype\" type=\"hidden\" id=\"hdfShowStype\" value=\"" + list[0].ShowStype + "\" />";
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSaveWebsite2_Click(object sender, EventArgs e)
        {
            Stat.Model.WebSites model = new Stat.Model.WebSites();

            model.WebId = int.Parse("0" + this.hdfWebid.Value);
            model.WebName = Plugin.Common.SafeRequest(this.txtWebname.Text.ToString());
            model.WebUrl = this.txtWebUrl.Text.ToString();
            model.UserId = Convert.ToInt32(security.GetCurrentUserID());
            model.OpenItem = Plugin.Common.Rq("website_power");
         //   model.IsReFresh = this.rBtnIsRefresh.SelectedValue == "1" ? true : false;
         //   model.IsCodeLock = this.rBtnCodeLock.SelectedValue == "1" ? true : false;
            model.ShowStype = Plugin.Common.Rq("ShowStype");
            if (model.WebId > 0)
            {
                if (Stat.BLL.WebSites.Edit(model))
                {
                    removeCache.RemoveWebsiteCache(model.WebId);
                    Plugin.Common.Alert("修改成功！", "WebsiteList.aspx");
                }
                else
                {
                    Plugin.Common.Alert("操作失败！");
                }

            }
            else
            {

                if (Stat.BLL.WebSites.Add(model))
                {
                    Plugin.Common.Alert("添加成功！");
                    security.ReloadCurrentUser();
                    Response.Redirect("WebsiteList.aspx", true);
                }
                else
                {
                    Plugin.Common.Alert("操作失败！");
                }
            }
        }
    }
}
