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 etw_f_m_translated : System.Web.UI.Page
{
    public string language = string.Empty;
    public string username = string.Empty;
    public string domain = string.Empty;
    public int untranssum = 0;
    public int translatesum = 0;
    public int langid = 0;
    public int id = 0;
    public int chatid = 0;
    public string seach = string.Empty;
    public int page = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie GetCookie = Request.Cookies["cook_admin"];
        if (Request.Cookies["cook_admin"] == null)
        {
            Response.Redirect("../etw_c_m/index.aspx");
        }
        etwadmin();
        untranssum = (int)DbHelperSQL.GetSingle("select count(id) from etw_translate where achivetime=0 and trans_content is null and  (language ='" + domain + "' or target ='" + domain + "' )");
        translatesum = (int)DbHelperSQL.GetSingle("select count(id) from etw_translate where achivetime!=0 and trans_content is not null and (language ='" + domain + "' or target ='" + domain + "' )");
        if(!IsPostBack)
        {

            ViewState["whe"] = seach;
            transplate(seach);
        }
  
     
       }
    public void etwadmin()
    {
        DataSet ds = DbHelperSQL.Query("select * from etw_admin where etwadminname='" + Request.Cookies["cook_admin"]["username"] + "'");
        if (ds.Tables[0].Rows.Count > 0)
        {
            username = ds.Tables[0].Rows[0]["realname"].ToString();
            langid = Convert.ToInt32(ds.Tables[0].Rows[0]["transid"].ToString());
        }

        etw.etw_language lag = new etw.etw_language();
        lag.id = langid;
        lag.GetModel();
        language = lag.language;
        domain = lag.domain;
    }
    
    protected void Button1_Click1(object sender, EventArgs e)
    {
        string search = search1.Text.ToString();
        if (search != "" && search != null)
        {
            string where = "and etw_user.company like N'%" + search + "%'";
            transplate(where);
            ViewState["whe"] = where;
        }
        else
        {
            ViewState["whe"] = seach;
            transplate(seach);
        }
    }

    public void transplate(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 from etw_translate inner join etw_user on etw_translate.userid=etw_user.userid  where etw_translate.id in (select max(id) as id from etw_translate  group by chatid)and achivetime!=0 and trans_content is not null and (language ='" + domain + "' or target ='" + domain + "' ) " + seach + "  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 lnkbtnOne_Click(object sender, EventArgs e)
    {
        this.labPage.Text = "1";
        this.transplate(seach);
    }
    protected void lnkbtnUp_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) - 1);
        this.transplate(seach);
    }
    protected void lnkbtnNext_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) + 1);
        this.transplate(seach);
    }
    protected void lnkbtnBack_Click(object sender, EventArgs e)
    {
        this.labPage.Text = this.labBackPage.Text;
        this.transplate(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");
    }
}
