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;

public partial class Admin_index_center : Base.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["ManagerName"] != null && Session["ManagerName"].ToString() !="")
        {
            if (!IsPostBack)
            {
                bind();
                bindManager();
            }
        }
        else
        {
            HandleErr("0", "../login.aspx");
        }
    }


    /// <summary>
    /// 绑定管理员信息
    /// </summary>
    private void bindManager()
    {
        AdminRights.IManagerCount im = new AdminRights.RManagerCount();
        AdminRights.TManagerCount tm = im.GateItem(" where ManagerName='" + Session["ManagerName"] + "'");
        this.lblManager.Text = tm.ManagerName;
        if(tm.IP!=null&&tm.IP!="")
            this.lblIP.Text = tm.IP.ToString();
        this.lblCount.Text = Convert.ToString(tm.DefeatCount + tm.SuccessCount);
        this.lblDate.Text = tm.LastDate.ToString();
        AdminRights.IRole ir = new AdminRights.RRole();
        AdminRights.TRole tr = ir.GetItem(int.Parse(Session["RoleID"].ToString()));
        this.lblRole.Text = tr.RoleName.ToString();
    }


    /// <summary>
    /// 绑定信息统计
    /// </summary>
    private void bind()
    {

        DataTable dt = Solely.Other.GetCount();
        if (dt.Rows.Count > 0)
        {
            createth();
            for (int i = 0; i <3; i++)
            {
                TableRow tr = new TableRow();
                this.handle.Rows.Add(tr);
                TableCell td = new TableCell();
                if (i == 0)
                {
                    td.Text = "供应信息";
                    tr.Cells.Add(td);
                    TableCell su = new TableCell();
                    su.Text = dt.Rows[i]["t1"].ToString();
                    tr.Cells.Add(su);

                    TableCell pu = new TableCell();
                    pu.Text = dt.Rows[i]["t2"].ToString();
                    tr.Cells.Add(pu);

                    TableCell si = new TableCell();
                    si.Text = dt.Rows[i]["t3"].ToString();
                    tr.Cells.Add(si);

                    TableCell wi = new TableCell();
                    wi.Text = dt.Rows[i]["t4"].ToString();
                    tr.Cells.Add(wi);

                    LinkButton lb = new LinkButton();
                    lb.ID = "su";
                    lb.Text = "查看";
                    lb.PostBackUrl = "trade/SupplyManage.aspx";

                    TableCell see = new TableCell();
                    see.Text = "查看";
                    see.Controls.Add(lb);
                    tr.Cells.Add(see);
                }
                else if (i == 1)
                {
                    td.Text = "求购信息";
                    tr.Cells.Add(td);
                    TableCell su = new TableCell();
                    su.Text = dt.Rows[i]["t1"].ToString();
                    tr.Cells.Add(su);

                    TableCell pu = new TableCell();
                    pu.Text = dt.Rows[i]["t2"].ToString();
                    tr.Cells.Add(pu);

                    TableCell si = new TableCell();
                    si.Text = dt.Rows[i]["t3"].ToString();
                    tr.Cells.Add(si);

                    TableCell wi = new TableCell();
                    wi.Text = dt.Rows[i]["t4"].ToString();
                    tr.Cells.Add(wi);

                    LinkButton lb = new LinkButton();
                    lb.Text = "查看";
                    lb.ID = "pu";
                    lb.PostBackUrl = "trade/PurchaseManage.aspx";

                    TableCell see = new TableCell();
                    see.Text = "查看";
                    see.Controls.Add(lb);
                    tr.Cells.Add(see);
                }
                else
                {
                    td.Text = "公司信息";
                    tr.Cells.Add(td);
                    TableCell su = new TableCell();
                    su.Text = dt.Rows[i]["t1"].ToString();
                    tr.Cells.Add(su);

                    TableCell pu = new TableCell();
                    pu.Text = dt.Rows[i]["t2"].ToString();
                    tr.Cells.Add(pu);

                    TableCell si = new TableCell();
                    si.Text = dt.Rows[i]["t3"].ToString();
                    tr.Cells.Add(si);

                    TableCell wi = new TableCell();
                    wi.Text = dt.Rows[i]["t4"].ToString();
                    tr.Cells.Add(wi);

                    LinkButton lb = new LinkButton();
                    lb.Text = "查看";
                    lb.ID = "us";
                    lb.PostBackUrl = "Corp/UserInfo/UserInfo.aspx";

                    TableCell see = new TableCell();
                    see.Text = "查看";
                    see.Controls.Add(lb);
                    tr.Cells.Add(see);
                }
            }

        }
    }

    /// <summary>
    /// 创建Table表头
    /// </summary>
    private void createth()
    {
        
        TableFooterRow tr = new TableFooterRow();
        this.handle.Rows.Add(tr);
        TableHeaderCell td = new TableHeaderCell();
        td.Text = "统计";
        tr.Cells.Add(td);
        TableHeaderCell su = new TableHeaderCell();
        su.Text = "总数";
        tr.Cells.Add(su);
        TableHeaderCell pu = new TableHeaderCell();
        pu.Text = "已审";
        tr.Cells.Add(pu);
        TableHeaderCell si = new TableHeaderCell();
        si.Text = "未审";
        tr.Cells.Add(si);
        TableHeaderCell wi = new TableHeaderCell();
        wi.Text = "推荐";
        tr.Cells.Add(wi);
        TableHeaderCell see = new TableHeaderCell();
        see.Text = "查看";
        tr.Cells.Add(see);
    }
}
