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 System.Data.SqlClient;

public partial class etw_c_m_test : System.Web.UI.Page
{
    public int page = 1;
    public string where = string.Empty;
    SqlConnection conn;
    public string strsql = "", searchstr = "";
    public int totalOrders;
    protected void Page_Load(object sender, EventArgs e)
    {
       
        Cache["totalproduct"] = totalOrders;
        if (!IsPostBack)
        {
            if (search.Text.Trim() != "" && langlist.SelectedItem.Text == "语言")
            {
                DataUser1();
            }
            else
            {
                DataUser();
            }
            BindDrpClass();
        }
    }
    private void BindDrpClass()
    {
        langlist.Items.Add(new ListItem("语言", "0"));
        DataSet ds3 = DbHelperSQL.Query("select * from etw_language order by id");
        for (int i = 0; i < ds3.Tables[0].Rows.Count; i++)
        {
            langlist.Items.Add(new ListItem(ds3.Tables[0].Rows[i]["language"].ToString(), ds3.Tables[0].Rows[i]["domain"].ToString()));
        }
        langlist.DataBind();
    }
    public void DataUser()
    {
        searchstr = "select count(*) from etw_translate where achivetime!=0 and trans_content is not null";
        strsql = "select t.id,t.type,t.target,t.userid,t.receivetime,t.achivetime,t.chatid,u.company,l.language  from etw_translate t left join etw_user u  on t.userid=u.userid left join etw_language l on t.language =l.domain where achivetime!=0 and trans_content is not null order by receivetime desc";
        totalOrders = (int)DbHelperSQL.GetSingle(searchstr);
        conn = new SqlConnection(DbHelperSQL.connectionString);
        SqlDataAdapter cmd = new SqlDataAdapter(strsql, conn);
        DataSet ds = new DataSet();
        cmd.Fill(ds, Pager1.StartRecordIndex - 1, Pager1.PageSize, "ds");
        Pager1.RecordCount = totalOrders;
        Repeater1.DataSource = ds.Tables[0].DefaultView;
        Repeater1.DataBind();
    }
    public void DataUser1()
    {
        searchstr = "select count(t.id) from etw_translate t left join etw_user u  on t.userid=u.userid left join etw_language l on t.language =l.domain where achivetime!=0 and trans_content is not null and u.company like '%" + search.Text.Trim() + "%' ";
        strsql = "select t.id,t.type,t.target,t.userid,t.receivetime,t.achivetime,t.chatid,u.company,l.language  from etw_translate t left join etw_user u  on t.userid=u.userid left join etw_language l on t.language =l.domain where achivetime!=0 and trans_content is not null and u.company like '%" + search.Text.Trim() + "%'  order by receivetime desc";
        totalOrders = (int)DbHelperSQL.GetSingle(searchstr);
        conn = new SqlConnection(DbHelperSQL.connectionString);
        SqlDataAdapter cmd = new SqlDataAdapter(strsql, conn);
        DataSet ds = new DataSet();
        cmd.Fill(ds, Pager1.StartRecordIndex - 1, Pager1.PageSize, "ds");
        Pager1.RecordCount = totalOrders;
        Repeater1.DataSource = ds.Tables[0].DefaultView;
        Repeater1.DataBind();
    }
    public string trans_type(string type)
    {
        string str = string.Empty;
        if (type == "1")
        {
            str = "询盘";
        }
        if (type == "2")
        {
            str = "回复";
        }
        return str;
    }
    protected void Pager1_PageChanging1(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        Pager1.CurrentPageIndex = e.NewPageIndex;
        page = Pager1.CurrentPageIndex;
        if (search.Text.Trim() != "" && langlist.SelectedItem.Text == "语言")
        {
            DataUser1();
        }
        else
        {
            DataUser();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
         if (search.Text.Trim() != "" && langlist.SelectedItem.Text == "语言")
        {
            DataUser1();
        }
        else if (search.Text.Trim() == "" && langlist.SelectedItem.Text != "语言")
        {

        }
        else if (search.Text.Trim() != "" && langlist.SelectedItem.Text != "语言")
        {
        }
        else
        {
            searchstr = "select count(*) from etw_translate where achivetime!=0 and trans_content is not null";
            strsql = "select t.id,t.type,t.target,t.userid,t.receivetime,t.achivetime,t.chatid,u.company,l.language  from etw_translate t left join etw_user u  on t.userid=u.userid left join etw_language l on t.language =l.domain where achivetime!=0 and trans_content is not null order by receivetime desc";
        }
    }
}
