using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TopWinCMS.BLL;
using TopWinCMS.Common;
using TopWinCMS.Model;
namespace TopWinCMS.WebUI.Admin
{
    public partial class UC_AdminSelect : System.Web.UI.UserControl
    {
        AdminManage MyClassBLL = new AdminManage();
        AdminInfo model = new AdminInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //BindGrid();

            }
        }
        private void BindGrid()
        {
            MyClassBLL.BindList(GridView1, null);
            if (LB_Selected.Text.Length > 0)
            {
                string[] strArr = LB_Selected.Text.Split('|');

                foreach (GridViewRow GVR in GridView1.Rows)
                {
                    foreach (string str in strArr)
                    {
                        if (str.Length == 0)
                        {
                            continue;
                        }
                        if (GVR.Cells[2].Text == str)
                        {
                            CheckBox CB = GVR.Cells[0].FindControl("CB_SelectID") as CheckBox;
                            CB.Checked = true;
                        }
                    }
                }
            }
        }

        protected void BT_OK_Click(object sender, EventArgs e)
        {
            MyStringBuilder winner = new MyStringBuilder();
            winner.Append("|");
            foreach (GridViewRow GVR in GridView1.Rows)
            {
                CheckBox CB = GVR.Cells[0].FindControl("CB_SelectID") as CheckBox;
                if (CB.Checked == true)
                {
                    winner.Append(GVR.Cells[2].Text);
                    winner.Append("|");
                }

            }
            if (winner.ToString() == "|")
            {
                LB_Selected.Text = "";
            }
            else
            {
                LB_Selected.Text = winner.ToString();
            }

            this.GridView1.Visible = false;
            BT_OK.Visible = false;
            BT_Cancel.Visible = false;
        }

        protected void BT_SelectAdmin_Click(object sender, EventArgs e)
        {
            BindGrid();
            this.GridView1.Visible = true;
            BT_OK.Visible = true;
            BT_Cancel.Visible = true;
        }

        protected void BT_Cancel_Click(object sender, EventArgs e)
        {
            this.GridView1.Visible = false;
            BT_OK.Visible = false;
            BT_Cancel.Visible = false;
        }
    }

}