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 Telerik.WebControls;
using System.IO;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Net.Mail;

public partial class etw_c_m_kefutranslate : System.Web.UI.Page
{
    public string username = string.Empty;
    public string title = string.Empty;
    public string content = string.Empty;
    public string fujian = string.Empty;
    public int id = 0;
    public string videotxt = string.Empty;
    public string filename = string.Empty;
    public int userid = 0;
    public int chatid = 0;
    public string t_emails = string.Empty;
    public string ischild = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        id = Convert.ToInt32(Request.QueryString["id"].ToString());
        HttpCookie GetCookie = Request.Cookies["cook_admin"];
        if (Request.Cookies["cook_admin"] == null)
        {
            Response.Redirect("index.aspx");
        }
        DataSet dsuser = DbHelperSQL.Query("select id from etw_admin where etwadminname='" + GetCookie ["username"]+ "'");
        userid =Convert.ToInt32(dsuser.Tables[0].Rows[0]["id"]);
        if (!IsPostBack)
        {
           
        }
        translate();
    }

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


        etw.etw_user use = new etw.etw_user();
        use.userid = usernameid;
        use.GetModel();
        username = use.company;
        t_emails = use.t_emails;

        etw.etw_onlines ols = new etw.etw_onlines();
        ols.id = chatid;
        ols.GetModel();
        title = ols.title;
        ischild =Convert.ToString(ols.childuserid);
    
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        DbHelperSQL.ExecuteSql("delete from etw_translate where id=" + id + "");
        Response.Write("<script type='text/javascript'>alert('删除成功');location.href='alluntrans.aspx';</script>");
    }

    private void Savefujian()
    {
        HttpFileCollection files = HttpContext.Current.Request.Files;
        try
        {
            string extension = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();  //判断用户上传文件扩展名
            if (extension != "")
            {
                string filepath = FileUpload1.PostedFile.FileName;
                int i = filepath.LastIndexOf(".");
                string newext = filepath.Substring(i);
                string newtime = DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss");
                newtime = newtime.Replace("-", "").Replace("/", "");
                filename = newtime + newext;
                string serverpath = Server.MapPath("fujian/") + filename;
                FileUpload1.PostedFile.SaveAs(serverpath);
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {       
        Savefujian();
        if (Request.Form["trans_content"] == "" || Request.Form["trans_content"] == null)
        {
            Response.Write("<script type='text/javascript'>alert('内容不能为空');history.back();</script>");
        }
        else
        {        
            string trans_content = Fun.Encode(Fun.NoHTML(Request.Form["trans_content"]));
            DbHelperSQL.ExecuteSql("update etw_translate set trans_content='"+trans_content+"' , personid="+userid+", achivetime='"+Fun.GetDateTime()+"', trans_fujian='"+filename+"' where id="+id+"");
            string emailstr = "你好，你收到一封ETW翻译的询盘，请<a href='http://www.etwservice.com'>登陆查收</a>";
            string[] email = t_emails.Split(new string[] { ",", ";" }, System.StringSplitOptions.RemoveEmptyEntries);
            string title = "翻译提醒";
            if (t_emails != "" && t_emails!=null)
            {
            if (ischild == "" || ischild == null || ischild=="0")
            {
              Fun.sendmail(email[0],title,emailstr);
              DbHelperSQL.ExecuteSql("update etw_onlines set readed='0' where id=" + chatid + "");
               
            }
            else
            {
                for (int i = 0; i < email.Length; i++)
                {
                    if (email[i] == ischild)
                    {
                        etw.chat_user ctu = new etw.chat_user();
                        ctu.id =Convert.ToInt32(ischild);
                        ctu.GetModel();
                        string receiver = ctu.username;
                        Fun.sendmail(receiver, title, emailstr);
                        DbHelperSQL.ExecuteSql("update etw_onlines set childreaded='0' where id=" + chatid + "");
                    }
                   
                }
            }
        }
            Response.Write("<script type=\"text/javascript\">location.href='alluntrans.aspx';</script>");
        }
    }
}
