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 othertrans : System.Web.UI.Page
{

    public int page = 1;
    public string where = string.Empty;
    public string seach = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {

        HttpCookie GetCookie = Request.Cookies["cook_admin"];
        if (Request.Cookies["cook_admin"] == null)
        {
            Response.Redirect("index.aspx");
        }
        if (!IsPostBack)
        {
            BindDrpClass();
            ViewState["whe"] = where;

        }
        DataUser(where);

    }
    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 string china_lang(string lang, string target)
    {
        string chinalang = string.Empty;
        if (lang != "" && lang != null)
        {
            chinalang = Convert.ToString(DbHelperSQL.GetSingle("select language from etw_language where domain like '%" + lang + "%'"));
        }
        else
        {
            chinalang = Convert.ToString(DbHelperSQL.GetSingle("select language from etw_language where domain like '%" + target + "%'"));
        }
        return chinalang;
    }

    public void DataUser(string where)
    {

        if (where == "" || where == null)
        {
            seach = ViewState["whe"].ToString();
        }
        else
        {
            seach = where;
        }

        int curpage = Convert.ToInt32(this.labPage.Text);
        PagedDataSource ps = new PagedDataSource();
        DataSet ds1 = DbHelperSQL.Query("select etw_translate.id,case etw_translate.type when '1' then '询盘' when '2' then '回复' else '' end as type,etw_translate.userid,etw_translate.receivetime,etw_translate.chatid,etw_translate.achivetime,etw_user.company,etw_translate.language,etw_translate.target from etw_translate inner join etw_user on etw_translate.userid=etw_user.userid  where " + seach + " achivetime!=0 and trans_content is null order by achivetime desc");
        ps.DataSource = ds1.Tables[0].DefaultView;
        ps.AllowPaging = true; //是否可以分页
        ps.PageSize = 20; //显示的数量
        ps.CurrentPageIndex = curpage - 1; //取得当前页的页码
        this.lnkbtnUp.Enabled = true;
        this.lnkbtnNext.Enabled = true;
        this.lnkbtnBack.Enabled = true;
        this.lnkbtnOne.Enabled = true;
        if (curpage == 1)
        {
            this.lnkbtnOne.Enabled = false;//不显示第一页按钮
            this.lnkbtnUp.Enabled = false;//不显示上一页按钮
        }
        if (curpage == ps.PageCount)
        {
            this.lnkbtnNext.Enabled = false;//不显示下一页
            this.lnkbtnBack.Enabled = false;//不显示最后一页
        }
        this.labBackPage.Text = Convert.ToString(ps.PageCount);
        this.Repeater1.DataSource = ps;
        this.Repeater1.DataBind();
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        string lang = langlist.SelectedItem.Value.ToString();
        if (search.Text.ToString() != "" && lang != "0")
        {
            //where = "language='" + lang + "' and ( userid in(select userid from etw_user where company like N'%" + search.Text.ToString() + "%') or DATE_FORMAT(FROM_UNIXTIME(achivetime),'%Y-%m-%d') ='" + search.Text.ToString() + "' ) and ";
            where = "language='" + lang + "' and ( etw_translate.userid in(select userid from etw_user where company like N'%" + search.Text.ToString() + "%')) and ";
            DataUser(where);
            ViewState["whe"] = where;
        }
        else
        {
            if (search.Text.ToString() != "")
            {
                // where = "( userid in(select userid from etw_user where company like N'%" + search.Text.ToString() + "%') or DATE_FORMAT(FROM_UNIXTIME(achivetime),'%Y-%m-%d') ='" + search.Text.ToString() + "' ) and ";
                where = " (etw_translate.userid in(select userid from etw_user where company like N'%" + search.Text.ToString() + "%') ) and ";
                DataUser(where);
                ViewState["whe"] = where;
            }
            else
            {
                DataUser(where);
                ViewState["whe"] = where;
            }

            if (lang != "0")
            {
                where = " language='" + lang + "' and ";
                DataUser(where);
                ViewState["whe"] = where;
            }
            else
            {
                DataUser(where);
                ViewState["whe"] = where;
            }
        }
       
    }
    protected void lnkbtnOne_Click(object sender, EventArgs e)
    {
        this.labPage.Text = "1";
        this.DataUser(seach);
    }
    protected void lnkbtnUp_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) - 1);
        this.DataUser(seach);
    }
    protected void lnkbtnNext_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) + 1);
        this.DataUser(seach);
    }
    protected void lnkbtnBack_Click(object sender, EventArgs e)
    {
        this.labPage.Text = this.labBackPage.Text;
        this.DataUser(seach);
    }

    public string time(string timeStamp)
    {
        DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
        long lTime = long.Parse(timeStamp + "0000000");
        TimeSpan toNow = new TimeSpan(lTime);
        DateTime dtResult = dtStart.Add(toNow);
        return dtResult.ToString("yy-MM-dd HH:mm");
    }
}
