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 etwuser_Common : System.Web.UI.Page
{
    public string id = string.Empty;
    public string username = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie ChatCookie = Request.Cookies["cookChatuser"];
        HttpCookie GetCookie = Request.Cookies["cookEtwuser"];
        if (Request.Cookies["cookChatuser"] == null)
        {
            if (Request.Cookies["cookEtwuser"] == null)
            {
                Response.Redirect("../index.aspx");
            }
            else
            {
                username = GetCookie["username"];
            }
        }
        else
        {
            username = ChatCookie["username"];
        }
        id = Request.Params["id"];
        DataSet dss = DbHelperSQL.Query("select * from etw_user where username='" + username + "'");
        if (dss.Tables[0].Rows.Count > 0)
        {
            data(dss.Tables[0].Rows[0]["userid"].ToString());
        }
        else
        {
            dss = DbHelperSQL.Query("select * from chat_user where username='" + username + "'");
            if (dss.Tables[0].Rows.Count > 0)
            {
                data(dss.Tables[0].Rows[0]["userid"].ToString());
            }
        }
    }
    public void data(string userid)
    {
        Fun.Funrecord(Request.Url.AbsoluteUri,Page.Request.UserHostAddress, userid.ToString());
        string[] strid = id.Split(new char[] { ',' });
        etw.etw_communication lead = new etw.etw_communication();
        for (int i = 0; i < strid.Length; i++)
        {
            if (strid[i] != "")
            {
                DataSet ds = DbHelperSQL.Query("select id from etw_communication where onlines_id=" + strid[i] + "");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DbHelperSQL.ExecuteSql("update etw_communication set cid=1 where onlines_id=" + strid[i] + "");
                }
                else
                {
                    lead.onlines_id = Convert.ToInt32(strid[i]);
                    lead.cid = 1;
                    lead.usernameid = Convert.ToInt32(userid);
                    lead.Add();
                }
            }
        }
    }
}
