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 Pages_Client_Default : CRM.Common.Login
{
    protected void ClientList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string id = ClientList1.ClientID;
        ClientScript.RegisterClientScriptBlock(GetType(),"ClientInfo", "<script language=javascript>location.href='ClientInfo.aspx?ClientID=" + id + "';</script>");
    }
    protected void ClientList1_RowCommand(object sender, EventArgs e)
    {
        
        //新增客户
        if (ClientList1.CommandName == "ADD")
        {
            ClientScript.RegisterClientScriptBlock(GetType(), "ADD", "<script language=javascript>location.href='ClientInfo.aspx';</script>");
        }
        #region 删除客户 只有本人才可以删除客户资料
        if (ClientList1.CommandName == "DEL") {
            for (int i = 0; i < ((GridView)ClientList1.FindControl("GridView1")).Rows.Count; i++) {
                CheckBox cb=(CheckBox)(((GridView)ClientList1.FindControl("GridView1")).Rows[i].FindControl("CheckBox2"));
                if(cb.Checked==true){
                    string id = ((GridView)ClientList1.FindControl("GridView1")).DataKeys[i].Values["id"].ToString();
                    IList<ClientBasicInfo> clientbasicinfo = new List<ClientBasicInfo>();

                    ClientBasic clientBasic = new ClientBasic();
                    clientbasicinfo = clientBasic.GetClientBasicById(id);

                    if (clientbasicinfo.Count > 0)
                    {
                        if (clientbasicinfo[0].业务员.ToString() == Session["LoginID"].ToString())
                        {
                            //ClientBasic clientBasic = new ClientBasic();
                            clientBasic.ClientBasicDeleteById(id);
                        }                        
                    }

                }
            }
            ClientList1.Bind();

        }
        #endregion
    } 
    
}
