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 Base;
using Corporation.Link;

public partial class Member_Link_LinkList : BasePage
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();

        }
    }

    private void Bind()
    {
        string strWhere = "U_UserLink.UserID=" + GetCookie("UserID");
        string TitleName = txtKeyWord.Text.Trim();
        string CompanyName = txtCompany.Text.Trim();
        if (TitleName != "")
            strWhere += " and Name like '%" + TitleName + "%'";
        if (CompanyName != "")
            strWhere += " and CompanyName like '%" + CompanyName + "%'";
        string strURl = Request.RawUrl;
        strURl = strURl.Substring(0, strURl.IndexOf(".aspx")) + ".aspx";
        PageNo1.Strurl = strURl;
        if (Request.QueryString["page"] != null)
        {
            PageNo1.Pageindex = Convert.ToInt32(Request.QueryString["page"].ToString());
            PageNo1.PageSize = 12;
            if (Session["strWhere"] != null)
            {
                PageNo1.Where = Session["strWhere"].ToString();
            }
            else
            {
                PageNo1.Where = strWhere;
            }
            PageNo1.Table = "U_UserInfo INNER JOIN U_UserLink  ON U_UserInfo.UserID = U_UserLink.UserID";
            PageNo1.FldName = "AddDate";
            PageNo1.StrGetFields = "U_UserInfo.CompanyName,U_UserLink.*";
            DataTable table = PageNo1.BindView();
            grdUserLink.DataSource = table.DefaultView;
            grdUserLink.DataBind();
        }
        else
        {
            PageNo1.Pageindex = 1;
            PageNo1.PageSize = 12;
            PageNo1.Where = strWhere;
            PageNo1.Table = "U_UserInfo INNER JOIN U_UserLink  ON U_UserInfo.UserID = U_UserLink.UserID";
            PageNo1.FldName = "AddDate";
            PageNo1.StrGetFields = "U_UserInfo.CompanyName,U_UserLink.*";
            DataTable table = PageNo1.BindView();
            grdUserLink.DataSource = table.DefaultView;
            grdUserLink.DataBind();
        }
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < grdUserLink.Rows.Count; i++)
        {
            CheckBox cbox = (CheckBox)grdUserLink.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {
                int id = Convert.ToInt32(grdUserLink.DataKeys[i].Value);
                ILink RLink = new RLink();
                RLink.Delete(id);
            }
        }
        Bind();
    }


    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        string strWhere = "U_UserLink.UserID=" + GetCookie("UserID");
        string TitleName = txtKeyWord.Text.Trim();
        string CompanyName = txtCompany.Text.Trim();
        if (TitleName != "")
            strWhere += " and Name like '%" + TitleName + "%'";
        if (CompanyName != "")
            strWhere += " and CompanyName like '%" + CompanyName + "%'";
        Session["strWhere"] = strWhere;
        string strURl = Request.RawUrl;
        strURl = strURl.Substring(0, strURl.IndexOf(".aspx")) + ".aspx?page=1";
        Response.Redirect(strURl);
        Response.End();
    }
}
