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 etwuser_Noticelist : System.Web.UI.Page
{
    public int page = 1;
    public string sqlstr = string.Empty;
    public string sqlcount = string.Empty;
    public int mun = 1;
    public string Cutpage = string.Empty;
    public string Cutpage1 = string.Empty;
    public int pagecount = 1;
    public int PageSize = 20;
    public string username = string.Empty;
    public string usernameid = string.Empty;
    public string company = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie ChatCookie = Request.Cookies["cookChatuser"];
        HttpCookie GetCookie = Request.Cookies["cookEtwuser"];
        if (Request.Cookies["cookChatuser"] == null)
        {
            if (Request.Cookies["cookEtwuser"] == null)
            {
                Response.Redirect("../index.aspx");
            }
            else
            {
                username = GetCookie["username"];
                DataSet ds = DbHelperSQL.Query("select userid,company from etw_user where username='" + username + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    usernameid = ds.Tables[0].Rows[0]["userid"].ToString();
                    company = ds.Tables[0].Rows[0]["company"].ToString();
                }
            }
        }
        else
        {
            username = ChatCookie["username"];
            DataSet ds1 = DbHelperSQL.Query("select id,userid,companyname from chat_user where username='" + username + "'");
            if (ds1.Tables[0].Rows.Count > 0)
            {
                usernameid = ds1.Tables[0].Rows[0]["userid"].ToString();
                company = ds1.Tables[0].Rows[0]["companyname"].ToString();
            }
        }
        if (Request.QueryString["page"] != null)
        {
            page = Convert.ToInt32(Request.QueryString["page"].ToString());
        }
        if (!IsPostBack)
        {
            DataUser();
            Fun.Funrecord(Request.Url.AbsoluteUri, Page.Request.UserHostAddress, usernameid);
        }
    }
    public void DataUser()
    {
        mun = (page - 1) * PageSize;
        sqlstr = "select top " + PageSize + " * from etw_gonggao where  id not in(select  top " + mun + " id  from etw_gonggao order by id desc) order by id desc";
        sqlcount = "select count(id) from etw_gonggao ";

        if (!IsPostBack)
        {
            int totalOrders = (int)DbHelperSQL.GetSingle(sqlcount);
            if (totalOrders > PageSize)
            {
                if (totalOrders % PageSize == 0)
                {
                    pagecount = totalOrders / PageSize;
                }
                else
                {
                    pagecount = (totalOrders / PageSize) + 1;
                }
            }
            if (pagecount > 1)
            {
                if (page == 1)
                {
                    Cutpage = "<a class=\"txt-disabd\">首页</a><a  class=\"txt-disabd\">上一页</a><a  href=\"Noticelist.aspx?page=" + Convert.ToString(page + 1) + "\">下一页</a><a href=\"Noticelist.aspx?page=" + pagecount + "\">末页</a>";
                    Cutpage1 = Cutpage;
                }
                else if (page == pagecount)
                {
                    Cutpage = "<a href=\"Noticelist.aspx?page=1\">首页</a><a href=\"Noticelist.aspx?page=" + Convert.ToString(page - 1) + "\">上一页</a><a  class=\"txt-disabd\">下一页</a><a class=\"txt-disabd\">末页</a>";
                    Cutpage1 = Cutpage;
                }
                else
                {
                    Cutpage = "<a href=\"Noticelist.aspx?page=1\">首页</a><a href=\"Noticelist.aspx?page=" + Convert.ToString(page - 1) + "\">上一页</a><a href=\"Noticelist.aspx?page=" + Convert.ToString(page + 1) + "\">下一页</a><a href=\"Noticelist.aspx?page=" + pagecount + "\">末页</a>";
                    Cutpage1 = Cutpage;
                }
            }
        }
        DataSet dss = DbHelperSQL.Query(sqlstr);
        if (dss.Tables[0].Rows.Count > 0)
        {
            Repeater1.DataSource = dss.Tables[0].DefaultView;
            Repeater1.DataBind();
        }
    }
}
