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_etwview : System.Web.UI.Page
{
 
    public string title = string.Empty;
    public string language = string.Empty;
    public string username = string.Empty;
    public string domain = string.Empty;
    public string url = string.Empty;
    public string address = string.Empty;
    public string kehuname = string.Empty;
    public string fanyi_content = string.Empty;
    public int untranssum = 0;
    public int langid = 0;
    public int translatesum = 0;
    public int lanid = 0;
    public int cid = 0;
    public int id = 0;
    public int userid = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        cid = Convert.ToInt32(Request.QueryString["chatid"].ToString());
        id = Convert.ToInt32(Request.QueryString["id"].ToString());
        HttpCookie GetCookie = Request.Cookies["cook_admin"];
        if (Request.Cookies["cook_admin"] == null)
        {
            Response.Redirect("../etw_c_m/index.aspx");
        }

        if (!IsPostBack)
        {
            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 + "' )");
            etwusername();
            translate();
        }
    }

    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;
    }
    public void etwusername()
    {
        etw.etw_onlines ols = new etw.etw_onlines();
        ols.id = cid;
        ols.GetModel();
        title = ols.title;
        int chatuserid = ols.childuserid;
        address = ols.address;
        url = ols.url;
        if (url!= null && url!="")
        {
        if (ols.url.Contains("http:") == true)
        {
            url = "<a target='_blank' href='" + url + "'>" + url + "</a>";
        }
        else
        {
            url = "<a target='_blank' href='http://www." + url + "'>http://www." + url + "</a>";
        }
        }
        userid = ols.usernameid;
        kehuname = Convert.ToString(DbHelperSQL.GetSingle("select company from etw_user where userid=" + userid + ""));

        etw.etw_translate tlt = new etw.etw_translate();
        tlt.id = id;
        tlt.GetModel();
        fanyi_content = tlt.source_content;
 
    }
   

    protected void translate()
    {
        DataSet ds5 = DbHelperSQL.Query("select t.id,t.achivetime,a.realname,t.trans_content,t.source_content,t.fujian,t.trans_fujian from etw_translate t left join etw_admin a on t.personid=a.id  where chatid=" + cid + " and achivetime!=0 order by receivetime asc");
        if (ds5.Tables[0].Rows.Count > 0)
        {
            Repeater1.DataSource = ds5.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        
    }

    public string trans_fujian(string trnsfujian)
    {
        if (trnsfujian != null && trnsfujian != "")
        {
            trnsfujian = " <a target='_blank' href='download.aspx?fujian=" + trnsfujian + "' style='text-decoration:none; color:#004080'><img src='../images/downpic.gif' border='0' />下载 附件 </a>";
        }
        return trnsfujian;
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Cookies["cook_admin"].Expires = DateTime.Now.AddDays(-5);
        Response.Write("<script type=text/javascript>parent.location.reload();</script>");
    }
}
