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 transcontent : System.Web.UI.Page
{
    public string username = string.Empty;
    public string title = string.Empty;
    public string language = string.Empty;
    public string content = string.Empty;
    public string person = string.Empty;
    public string chatstr = string.Empty;
    public string mssage = string.Empty;
    public string lg = string.Empty;
    public string fujian = string.Empty;
    public int uid = 0;
    public int cid = 0;
    public int id = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        uid = Convert.ToInt32(Request.QueryString["userid"].ToString());
        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("index.aspx");
        }
        if (!IsPostBack)
        {
            etwusername();
            BindDrpClass();
        }
       
    }

    public void etwusername()
    {
        
        etw.etw_user lead = new etw.etw_user();
        lead.userid =uid;
        lead.GetModel();
        username = lead.company;

        
        etw.etw_onlines ols = new etw.etw_onlines();
        ols.id = cid;
        ols.GetModel();
        title = ols.title;
        language = china_lang(ols.language);
        int chatuserid =ols.childuserid;

        
        etw.etw_translate etl = new etw.etw_translate();
        etl.id = id;
        etl.GetModel();
        content = etl.source_content;
        person = getusername(etl.personid);
       
        if(etl.fujian!=null && etl.fujian!="")
        {
            fujian = " <a target='_blank' href='download.aspx?fujian=" + etl.fujian + "' style='text-decoration:none; color:#004080'><img src='images/downpic.gif' border='0' />下载 附件 </a>";
        }


      
        if (chatuserid ==0)
        {
            chatstr = "来自总帐户";
        }
        else
        {
            DataSet ds3 = DbHelperSQL.Query("select realname,username from chat_user where id='" + cid + "'");
            if (ds3.Tables[0].Rows.Count > 0)
            {
                chatstr = ds3.Tables[0].Rows[0]["realname"].ToString();
                chatstr = chatstr + "--" + ds3.Tables[0].Rows[0]["username"].ToString();
            }
            chatstr = "来自子帐户:" + chatstr;
        }
      
        
    }
    private void BindDrpClass()
    {       
        DataSet ds1 = DbHelperSQL.Query("select * from etw_language order by id");
        if (ds1.Tables[0].Rows.Count > 0)
        {
            langlist.DataSource = ds1.Tables[0].DefaultView;
            langlist.DataTextField = "language";
            langlist.DataValueField = "id";
            langlist.DataBind();
        }
    }

    public string  china_lang (string lang)
    {
        string chinalang;
        if (lang == "0")
        {
			chinalang="邮件,无法识别语言";
		}
        else
        {
           if (lang == "null")
           {
			chinalang="无法识别语言";
		  }
          else
          {
              chinalang = Convert.ToString(DbHelperSQL.GetSingle("select language from etw_language where domain like '%" + lang + "%'"));
   			 
		  }	
        }
		return chinalang;
    }

    public string getusername(int personid)
    {
        string username =Convert.ToString(DbHelperSQL.GetSingle("select realname from etw_admin where id=" + personid + ""));
        return username;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        etw.etw_language lang = new etw.etw_language();
        int lid = Convert.ToInt32(langlist.SelectedValue);
        lang.id = lid;
        lang.GetModel();
        lg =Convert.ToString(lang.domain);
        HttpCookie userlang = new HttpCookie("userlg", lg);
        userlang.Values.Add("userl", lg);
        userlang.Expires = DateTime.Now.AddHours(12);
        Response.Cookies.Add(userlang);
        FormsAuthentication.SetAuthCookie(username, true);

        string lange = Convert.ToString(lang.language);
        DataSet ds4 = DbHelperSQL.Query("select * from etw_web where langId=" + lid + " and usernameid=" + uid + "");
        if (ds4.Tables[0].Rows.Count > 0)
        {

            DbHelperSQL.ExecuteSql("update etw_translate set language='" + lg + "' where id=" + id + "");
            DbHelperSQL.ExecuteSql("update etw_onlines set language='" + lg + "' where id= " + cid + "");
            Response.Write("<script  language=javascript>location.href='alluntrans.aspx';</script>");
        }
        else
        {
            this.RegisterStartupScript("a", "<script type='text/javascript'>getlan('" + lg + "','" + lange + "');</script>");
        }
      
    }
    public void cheshi()
    {
        HttpCookie GetCoolie = Request.Cookies["userlg"];
        DbHelperSQL.ExecuteSql("update etw_translate set language='" + Request.Cookies["userlg"]["userl"] + "' where id=" + id + "");
        DbHelperSQL.ExecuteSql("update etw_onlines set language='" + Request.Cookies["userlg"]["userl"] + "' where id= " + cid + "");
        Response.Write("<script  language=javascript>location.href='alluntrans.aspx';</script>");
    }


    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        DbHelperSQL.ExecuteSql("update etw_translate set isread=1,achivetime='" + Fun.GetDateTime() + "' where id=" + id + "");
        Response.Write("<script type=\"text/javascript\">window.location.href='alluntrans.aspx';</script>");
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        DbHelperSQL.ExecuteSql("update etw_translate set language='no', achivetime='" + Fun.GetDateTime() + "' where id=" + id + "");
        DbHelperSQL.ExecuteSql("update etw_onlines set language='no' where id=" + cid + "");
        Response.Write("<script type=\"text/javascript\">window.location.href='alluntrans.aspx';</script>");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        cheshi();
    }
}
