using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using CRM.BLL;
using CRM.Model;
using CRM.Common;

public partial class Controls_Company_EmployeesListControl : System.Web.UI.UserControl
{
    private void Bind()
    {
        Employees employees = new Employees();

        GridView1.DataSource = employees.GetEmployeesByCid(Session["CID"].ToString());
        GridView1.DataKeyNames = new string[] { "eid", "boss" };
        GridView1.DataBind();

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        //int index = e.NewSelectedIndex;


        //IList<EmployeesInfo> employeesinfo = new List<EmployeesInfo>();

        //Employees employees = new Employees();
        //employeesinfo = employees.GetEmployeesById(GridView1.DataKeys[index].Values["eid"].ToString());

        //if (employeesinfo.Count > 0)
        //{
        //    txtEmployeesLoginName.Text = employeesinfo[0].登录名;
        //    txtEmployeesName.Text = employeesinfo[0].姓名;
        //    txtEmployeesPWD.Text = employeesinfo[0].密码;
        //    txtEmployeesPWD.Attributes.Add("Value", employeesinfo[0].密码);
        //    ddlDepartment.SelectedValue = employeesinfo[0].部门.ToString();
        //    ddlRole.SelectedValue = employeesinfo[0].角色.ToString();
        //    txtMobile.Text = employeesinfo[0].手机;
        //    txtTel.Text = employeesinfo[0].住宅电话;
        //    ddlRight.SelectedValue = employeesinfo[0].所属权限组.ToString();
        //    ddlStatus.SelectedValue = employeesinfo[0].用户状态.ToString();
        //    txtBz.Text = employeesinfo[0].备注;
        //}
        //Lable1.Text = "";

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int index = e.RowIndex;
        Employees employees = new Employees();
        employees.EmployeesDeleteById(GridView1.DataKeys[index].Values["eid"].ToString());

        Bind();

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int index = e.Row.RowIndex;
        if (index != -1)
        {
            if (GridView1.DataKeys[index]["boss"].ToString() == "1")
                ((ImageButton)e.Row.Cells[10].Controls[0]).Visible = false;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Bind();

    }
}
