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_childaccount : System.Web.UI.Page
{
    public string msg = string.Empty;
    public int userid = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie GetCookie = Request.Cookies["cookEtwuser"];
        if (Request.Cookies["cookEtwuser"] == null)
        {
            Response.Redirect("../index.aspx");
        }
        regtimetxt.Text = DateTime.Now.ToString();
        DataSet ds1 = DbHelperSQL.Query("select userid,company from etw_user where username='" + GetCookie["username"].ToString() + "'");
        if (ds1.Tables[0].Rows.Count>0)
        {
            companytxt.Text = ds1.Tables[0].Rows[0]["company"].ToString();
            userid = Convert.ToInt32(ds1.Tables[0].Rows[0]["userid"]);
            Fun.Funrecord(Request.Url.AbsoluteUri,Page.Request.UserHostAddress, userid.ToString());
        }
        if (!IsPostBack)
        {
            Databind();
        }
    }
    public void Databind()
    {
        DataSet ds = DbHelperSQL.Query("select id,username,password,realname,companyname,regtime from chat_user where userid=" + userid + " order by id desc");
        if (ds.Tables[0].Rows.Count > 0)
        {
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (passwordtxt.Text.Trim() != repasswordtxt.Text.Trim())
        {
            msg = "\"密码\"和\"确认密码\"输入不一致";
        }
        else
      {
        etw.chat_user lead = new etw.chat_user();
        lead.userid = userid;
        lead.companyname = companytxt.Text.Trim();
        lead.username = usernametxt.Text.Trim();
        lead.password = passwordtxt.Text.Trim();
        lead.realname = realnametxt.Text.Trim();
        lead.regtime = regtimetxt.Text.Trim();
        lead.userstate = 0;
        lead.Add();
        Fun.JsAlerT("子帐户添加成功！", "childaccount.aspx"); 
      }
        
    }
    public string Cutyidu(string namestr)
    {
        string countstr = string.Empty;
        DataSet ds = DbHelperSQL.Query("select id from chat_user where username='" + namestr + "' and userid=" + userid + "");
        if (ds.Tables[0].Rows.Count > 0)
        {
            string  sqlcount = "select count(id) from etw_onlines where  childreaded=1 and isdelete=0  and yid!=-1  and  childuserid=" + ds.Tables[0].Rows[0]["id"] + " and id not in(select onlines_id from etw_repeat where usernameid=" + userid + ")";
            countstr = DbHelperSQL.GetSingle(sqlcount).ToString();
        }
        return countstr;
    }
    public string Cutweidu(string namestr)
    {
        string countstr = string.Empty;
        DataSet ds = DbHelperSQL.Query("select id from chat_user where username='" + namestr + "' and userid=" + userid + "");
        if (ds.Tables[0].Rows.Count > 0)
        {
            string sqlcount = "select count(id) from etw_onlines where  childreaded=0 and isdelete=0  and translate=0  and yid!=-1  and  childuserid=" + ds.Tables[0].Rows[0]["id"] + " and id not in(select onlines_id from etw_repeat where usernameid=" + userid + ")";
            countstr = DbHelperSQL.GetSingle(sqlcount).ToString();
        }
        return countstr;
    }
}
