using System;
using System.IO;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;

using TopWinCMS.BLL;
using TopWinCMS.Common;
using TopWinCMS.Model;
namespace TopWinCMS.WebUI.Admin.Common
{
    /// <summary>
    ///  Special 的摘要说明。
    /// </summary>
    public partial class Special : System.Web.UI.Page
    {

        SpecialManage MySpecialBLL = new SpecialManage();
        #region 权限变量
        private bool ContenDel = RightsCheck.HasRight("ContenDel", true);
        private bool SpecialAdd = RightsCheck.HasRight("SpecialAdd", true);
        private bool SpecialDel = RightsCheck.HasRight("SpecialDel", true);
        private bool SpecialEdit = RightsCheck.HasRight("SpecialEdit", true);
        #endregion
        protected void Page_Load(object sender, System.EventArgs e)
        {


            if (!IsPostBack)
            {
                ManageUI();
            }
        }

        private void ManageUI()
        {
            GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);

            MySpecialBLL.BindList(GV_List, Request["ModelID"]);


            MyJavascript.RegJS(UpdatePanel1, "attachMouseEvent('" + GV_List.ClientID + "');");
        }

        #region 改变专题显示样式
        /// <summary>
        /// 改变专题显示样式
        /// </summary>
        /// <param name="strPath"></param>
        /// <param name="strSpecialName"></param>
        /// <param name="iHaveBaby"></param>
        /// <returns></returns>
        protected string changstyle(string strPath, string strSpecialName, int iHaveBaby)
        {
            string[] arrstr = strPath.Split('|');

            if (arrstr.Length == 2 && iHaveBaby == 0)
            {
                return "<img align=\"absmiddle\" src=\"../images/tree/minusmiddle.gif\"/><img align=\"absmiddle\" src=\"../images/tree/folder.gif\"/>" + strSpecialName + "  <font color=\"#0066FF\">(" + iHaveBaby + ")</font>";
            }
            else if (arrstr.Length == 2 && iHaveBaby > 0)
            {
                return "<img align=\"absmiddle\" src=\"../images/tree/plusmiddle.gif\"/><img align=\"absmiddle\" src=\"../images/tree/folder.gif\"/>" + strSpecialName + "  <font color=\"#0066FF\">(" + iHaveBaby + ")</font>";
            }
            else if (arrstr.Length >= 3)
            {
                string empty = new string('　', (arrstr.Length - 2) * 2);

                if (iHaveBaby == 0)
                {

                    return "<img align=\"absmiddle\" src=\"../images/tree/line.gif\"/>" + empty + "<img align=\"absmiddle\" src=\"../images/tree/minusmiddle.gif\"/><img align=\"absmiddle\" src=\"../images/tree/folder.gif\"/>" + strSpecialName + " <font color=\"#0066FF\">(" + iHaveBaby + ")</font>";
                }
                else
                {
                    return "<img align=\"absmiddle\" src=\"../images/tree/line.gif\"/>" + empty + "<img align=\"absmiddle\" src=\"../images/tree/plusmiddle.gif\"/><img align=\"absmiddle\" src=\"../images/tree/folder.gif\"/>" + strSpecialName + " <font color=\"#0066FF\">(" + iHaveBaby + ")</font>";
                }

            }
            else
            {
                return strSpecialName + iHaveBaby;
            }
        }
        #endregion

        protected string LinkURL(object URL)
        {
            if (URL.ToString().Length > 0)
            {
                return string.Format("<a href=\"{0}\" target=_blank><font color=#0066FF>[外部链接]</font></a>", URL);

            }
            else
            {
                return "";
            }
        }

        protected void GV_List_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string SpecialID = GV_List.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();
            if (e.CommandName == "down")
            {
                MySpecialBLL.OrderByMove(SpecialID, "down");
            }
            if (e.CommandName == "up")
            {
                MySpecialBLL.OrderByMove(SpecialID, "up");
            }

            if (e.CommandName == "Clear")
            {
                MySpecialBLL.Clear(SpecialID, int.Parse(Request["ModelID"]), UpdatePanel1);
            }
            if (e.CommandName == "DelSpecial")
            {
                MySpecialBLL.Del(SpecialID, int.Parse(Request["ModelID"]), UpdatePanel1);
            }
            ManageUI();
        }


        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[4].Attributes.Add("style", "display:none");
                e.Row.Cells[5].Attributes.Add("style", "display:none");
                e.Row.Cells[6].Attributes.Add("style", "display:none");
                e.Row.Cells[7].ColumnSpan = 4;
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCell myTableCell;
                //TableCell myTableCell = e.Row.Cells[6];
                //LinkButton btnDel = (LinkButton)myTableCell.Controls[0];
                //btnDel.Attributes.Add("onclick", "return confirm('确定要删除这个专题及其子专题吗？');");

                //TableCell myTableCell1 = e.Row.Cells[7];
                //LinkButton btnClear = (LinkButton)myTableCell1.Controls[0];
                //btnClear.Attributes.Add("onclick", "return confirm('确定要清空该专题及其子专题的数据吗？');");


                #region 权限

                if (SpecialAdd == false)
                {
                    myTableCell = e.Row.Cells[4];
                    LinkButton btnAdd = (LinkButton)myTableCell.Controls[0];
                    btnAdd.Attributes.Add("onclick", "alert('您没有添加权限！');return false;");
                }
                if (SpecialEdit == false)
                {
                    myTableCell = e.Row.Cells[2];//向上
                    LinkButton btnEdit = (LinkButton)myTableCell.Controls[0];
                    btnEdit.Attributes.Add("onclick", "alert('该功能需要修改权限！');return false;");

                    myTableCell = e.Row.Cells[3];//向下
                    btnEdit = (LinkButton)myTableCell.Controls[0];
                    btnEdit.Attributes.Add("onclick", "alert('该功能需要修改权限！');return false;");

                    myTableCell = e.Row.Cells[5];
                    btnEdit = (LinkButton)myTableCell.Controls[0];
                    btnEdit.Attributes.Add("onclick", "alert('您没有修改权限！');return false;");
                }
                if (SpecialDel == false)
                {
                    myTableCell = e.Row.Cells[6];
                    LinkButton btnDel = (LinkButton)myTableCell.Controls[0];
                    btnDel.Attributes.Add("onclick", "alert('您没有删除权限！');return false;");
                }
                else
                {
                    myTableCell = e.Row.Cells[6];
                    LinkButton btnDel = (LinkButton)myTableCell.Controls[0];
                    btnDel.Attributes.Add("onclick", "return confirm('确定要删除这个专题及其子专题吗？');");
                }

                if (SpecialDel == ContenDel == false)
                {
                    myTableCell = e.Row.Cells[7];
                    LinkButton btnClear = (LinkButton)myTableCell.Controls[0];
                    btnClear.Attributes.Add("onclick", "alert('该功能需要删除专题权限和删除内容的权限！');return false;");
                }
                else
                {
                    TableCell myTableCell1 = e.Row.Cells[7];
                    LinkButton btnClear = (LinkButton)myTableCell1.Controls[0];
                    btnClear.Attributes.Add("onclick", "return confirm('确定要清空该专题及其子专题的数据吗？');");
                }
                #endregion
            }
        }





    }
}