using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
 
using TopWinCMS.BLL;
using TopWinCMS.Common;
using TopWinCMS.Model;
namespace TopWinCMS.WebUI.Admin
{
    /// <summary>
    /// Admin_Friend_Link 的摘要说明。
    /// </summary>
    public partial class Friend_Link : System.Web.UI.Page
    {

        FriendLinkManage MyClassBLL = new FriendLinkManage();
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {


                RightsCheck.CheckWorkPower("F_1");
                

                string Action = Request["Action"];
                if (Action == "Edit")
                {
                    GV_List.Visible = false;
                    Panel1.Visible = true;

                    FriendLinkInfo model = MyClassBLL.EditLoad(Request["ID"]);

                    TB_Title.Text = model.FL_Title;
                    TB_Logo.Text = model.FL_Logo;
                    Img_Logo.ImageUrl = model.FL_Logo;
                    TB_URL.Text = model.FL_URL;
                    CB_Pass.Checked = model.Pass == 1 ? true : false;
                }
                else if (Action == "Add")
                {
                    GV_List.Visible = false;
                    Panel1.Visible = true;

                }
                else
                {
                    GV_List.Visible = true;
                    Panel1.Visible = false;

                    GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);

                    MyClassBLL.BindList(GV_List);
                }
            }
        }
 

        protected void BT_OK_Click(object sender, EventArgs e)
        {
            FriendLinkInfo model = new FriendLinkInfo();
            if (Request["ID"] == null)
            {
                model.ID = "0";
            }
            else
            {
                model.ID = Request["ID"];
            }
            model.FL_Title = TB_Title.Text;
            model.FL_Logo = TB_Logo.Text;
            model.FL_URL = TB_URL.Text;
            model.Pass = CB_Pass.Checked == true ? 1 : 0;

            MyClassBLL.Add(model, UpdatePanel1);
        }

 

        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.DataRow)
            {
                return;
            }

            TableCell myTableCell = e.Row.Cells[8];

            string strTemp = myTableCell.Text.Trim();
            if (MyValidate.IsNumeric(strTemp) == true)
            {
                int I = Convert.ToInt16(strTemp);
                if (I == 1)
                {
                    myTableCell.Text = "已审核";
                }
                else
                {
                    myTableCell.Text = "未审核";
                }
            }
            else
            {
                bool b = Convert.ToBoolean(strTemp);
                if (b)
                {
                    myTableCell.Text = "已审核";
                }
                else
                {
                    myTableCell.Text = "未审核";
                }
            }
        }

        protected void GV_List_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string ID = GV_List.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString();

            if (e.CommandName.ToLower() == "up")
            {
                MyClassBLL.UpDown(ID, "up");
            }
            if (e.CommandName.ToLower() == "down")
            {
                MyClassBLL.UpDown(ID, "down");
            }

            MyClassBLL.BindList(GV_List);
        }

        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string ID = GV_List.DataKeys[e.RowIndex].ToString();

            MyClassBLL.Delete(ID, UpdatePanel1);

            MyClassBLL.BindList(GV_List);
        }

      
    }
}