using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Text;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TopWinCMS.Common;
using TopWinCMS.BLL;
namespace TopWinCMS.WebUI.Admin.UDT
{
    public partial class UDT_Manage : System.Web.UI.Page
    {
        SQLModel s_model = new SQLModel();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Check();
                BindList();
            }
        }

        private void Check()
        {
            BT_DelSeletedID.Enabled = RightsCheck.HasRight("L_2");

            BT_Stop.Enabled = BT_UnStop.Enabled = RightsCheck.HasRight("L_3");
        }

        #region 网页属性

        /// <summary>
        /// 是否处于搜索状态
        /// </summary>
        private bool IsSearch
        {
            get
            {
                if (ViewState["IsSearch"] != null)
                {
                    return Convert.ToBoolean(ViewState["IsSearch"]);
                }
                else
                {
                    return false;
                }
            }
            set
            {
                ViewState["IsSearch"] = value;
            }
        }
        #endregion

        public void BindList()
        {
            GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);

            string strPath = "<a href='UDT_Manage.aspx'>标签管理</a>";


            if (this.IsSearch == true)
            {
                string strKeyWord = TB_KeyWord.Text.Trim();
                strKeyWord = MyString.SQL_ESC(strKeyWord);

                s_model.WHERE = DDL_Sort.SelectedValue + " like '%" + strKeyWord + "%'";

                strPath += string.Format(" → 搜索“{0}”", TB_KeyWord.Text.Trim());
            }
            else
            {

                
            }


            s_model.PageSize = 10;//每行显示 N 条
            //绑定数据的控件，分页控件，分页实体类
            new TopWinCMS.BLL.UDTManage().BindList(GV_List, PageNavigation1, s_model);

            LB_Path.Text = strPath;
            MyJavascript.RegJS(UpdatePanel1, "attachMouseEvent('" + GV_List.ClientID + "');");
        }

        protected void PageNavigation1_PageChanging(object src, TopWinCMS.WebControls.PageChangingEventArgs e)
        {
            s_model.PageNo = e.NewPageIndex;
            BindList();
        }

        protected void BT_DelSeletedID_Click(object sender, EventArgs e)
        {
            new UDTManage().Delete(GetSelectedRow.IDs(GV_List), UpdatePanel1);
            s_model.PageNo = 1;
            BindList();
        }

        protected void BT_Stop_Click(object sender, EventArgs e)
        {
            new UDTManage().Stop(GetSelectedRow.IDs(GV_List), UpdatePanel1);
            s_model.PageNo = PageNavigation1.PageNo;
            BindList();
        }

        protected void BT_UnStop_Click(object sender, EventArgs e)
        {
            new UDTManage().UnStop(GetSelectedRow.IDs(GV_List), UpdatePanel1);
            s_model.PageNo = PageNavigation1.PageNo;
            BindList();

        }

        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCell tc = e.Row.Cells[3];

                switch (tc.Text)
                {
                    case "0":
                        tc.Text = "SqlServer版主数据库";
                        break;
                    case "1":
                        tc.Text = "Access版主数据库";
                        break;
                    case "2":
                        tc.Text = "外部SqlServer";
                        break;
                    case "3":
                        tc.Text = "外部Access";
                        break;
                }
                tc = e.Row.Cells[4];

                switch (tc.Text)
                {
                    case "0":
                        tc.Text = "普通";
                        break;
                    case "1":
                        tc.Text = "Ajax";
                        break;
                    case "2":
                        tc.Text = "数据调用JS";
                        break;
                    case "3":
                        tc.Text = "静态JS";
                        break;
                }
            }
        }

        protected void BT_Search_Click(object sender, EventArgs e)
        {
            if (TB_KeyWord.Text.Length == 0)
            {
                Response.Redirect("UDT_Manage.aspx");
            }
            else
            {
                this.IsSearch = true;
                BindList();
            }
        }

        #region 动态修改链接
        /// <summary>
        /// 动态修改链接
        /// </summary>
        /// <param name="ContentTitle"></param>
        /// <param name="intLong"></param>
        /// <param name="ID"></param>
        /// <param name="Hits"></param>
        /// <returns></returns>
        protected string MyLink(object Name, object ID)
        {
            StringBuilder winner = new StringBuilder();
            winner.Append(" <a href=\"#\"  onclick=\"");
            winner.Append("return NewTabPage('修改" + Name + "_" + ID + "','修改" + Name + "','UDT/UDT_Add.aspx?ID=" + ID + "');\">");
            winner.Append(Name);
            winner.Append("</a>");

            return winner.ToString();
        }
        #endregion
    }
}