using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
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.BLL;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin.Model
{
    public partial class Model_Manage : System.Web.UI.Page
    {
        SQLModel s_model = new SQLModel();
        private bool ModelEdit = RightsCheck.HasRight("M_2");
        private bool ModelDel = RightsCheck.HasRight("M_3");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Check();
                BindList();
            }
        }

        private void Check()
        {

        }

        public void BindList()
        {
            s_model.WHERE = "Hide=0";//请自己根据实际情况动态的改变查询条件
            s_model.PageSize = 10;//每行显示 N 条
            //绑定数据的控件，分页控件，分页实体类
            new TopWinCMS.BLL.ModelManage().BindList(GV_List, PageNavigation1, s_model);
        }

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

        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string ID = GV_List.DataKeys[e.Row.RowIndex].Value.ToString();
                TableCell tc = e.Row.Cells[2];
                HyperLink lb = (HyperLink)tc.Controls[0];
                lb.Attributes.Add("onclick", string.Format("return NewTabPage('{0}_{1}','{0}','{2}');", lb.Text, ID, lb.NavigateUrl));
                lb.NavigateUrl = "#";


                LinkButton LB = e.Row.Cells[7].Controls[0] as LinkButton;

                if (LB.Text == "1")
                {
                    LB.Text = "<IMG alt=\"生成\" src=\"../Images/success-true.gif\">";
                }
                else
                {
                    LB.Text = "<IMG alt=\"不生成\" src=\"../Images/failed-false.gif\">";
                }

                if (ModelEdit == false)
                {
                    tc = e.Row.Cells[9];
                    lb = (HyperLink)tc.Controls[0];

                    lb.Attributes.Add("onclick", "alert('你没有修改权限');return false;");
                }
                else
                {
                    tc = e.Row.Cells[9];
                    lb = (HyperLink)tc.Controls[0];
                    lb.Attributes.Add("onclick", string.Format("return NewTabPage('{0}_{1}','{0}','Model/{2}');", lb.Text, ID, lb.NavigateUrl));
                    lb.NavigateUrl = "#";
                }

                if (ModelDel == false)
                {
                    tc = e.Row.Cells[10];
                    LinkButton lbDel = (LinkButton)tc.Controls[0];

                    lbDel.Attributes.Add("onclick", "alert('你没有删除权限');return false;");

                }
            }
        }

        protected void BT_Delete_Click(object sender, EventArgs e)
        {
            new TopWinCMS.BLL.ModelManage().Delete(GetSelectedRow.IDs(this.GV_List), UpdatePanel1);

            BindList();
        }

        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

            new TopWinCMS.BLL.ModelManage().Delete(GV_List.DataKeys[e.RowIndex].Value.ToString(), UpdatePanel1);

            BindList();
        }

        protected void GV_List_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "StaticChange")
            {
                int Index = Convert.ToInt32(e.CommandArgument);
                string ID = GV_List.DataKeys[Index].Value.ToString();
                new TopWinCMS.BLL.ModelManage().ChangeProperty(ID);

                BindList();
            }

        }


    }
}