using System;
using System.Data;
using System.Configuration;
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 System.Data.SqlClient;
using System.Text;

namespace etw
{
    public class chat_user
    {
        public chat_user()
        {
        }
        private int etw_id;
        private string etw_username;
        private string etw_password;
        private string etw_realname;
        private string etw_companyname;
        private int etw_userid;
        private string etw_regtime;
        private string etw_url;
        private int etw_userstate;
        private int etw_changepwd;
        public int id
        {
            set { etw_id = value; }
            get { return etw_id; }
        }
        public string username
        {
            set { etw_username = value; }
            get { return etw_username; }
        }
        public string password
        {
            set { etw_password = value; }
            get { return etw_password; }
        }
        public string realname
        {
            set { etw_realname = value; }
            get { return etw_realname; }
        }
        public string companyname
        {
            set { etw_companyname = value; }
            get { return etw_companyname; }
        }
        public int userid
        {
            set { etw_userid = value; }
            get { return etw_userid; }
        }
        public string regtime
        {
            set { etw_regtime = value; }
            get { return etw_regtime; }
        }
        public string url
        {
            set { etw_url = value; }
            get { return etw_url; }
        }
        public int userstate
        {
            set { etw_userstate = value; }
            get { return etw_userstate; }
        }
        public int changepwd
        {
            set { etw_changepwd = value; }
            get { return etw_changepwd; }
        }
        public bool exists()
        {
            StringBuilder strsql = new StringBuilder();
            strsql.Append("select count(id) from chat_user");
            strsql.Append("where id=" + id + "");
            return DbHelperSQL.Exists(strsql.ToString());

        }
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [chat_user](");
            strSql.Append("username,password,realname,companyname,userid,regtime,url,userstate");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("N'" + username + "',");
            strSql.Append("N'" + password + "',");
            strSql.Append("N'" + realname + "',");
            strSql.Append("N'" + companyname + "',");
            strSql.Append("" + userid + ",");
            strSql.Append("N'" + regtime + "',");
            strSql.Append("N'" + url + "',");
            strSql.Append("" + userstate + "");
            strSql.Append(")");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update chat_user set ");
            strSql.Append("password=N'" + password + "',");
            strSql.Append("realname=N'" + realname + "',");
            strSql.Append("companyname=N'" + companyname + "',");
            strSql.Append("regtime=N'" + regtime + "'");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }
        public void Updatepassword()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update chat_user set ");
            strSql.Append("password=N'" + password + "'");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }
        public void Updatechangepwd()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update chat_user set ");
            strSql.Append("changepwd=1");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }
        public void Delete()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from chat_user ");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }
        public void GetModel()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append("[id],[username],[password],[realname],[companyname],[userid],[regtime],[url],[userstate]");
            strSql.Append(" from chat_user ");
            strSql.Append("where id=" + id + "");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                username = ds.Tables[0].Rows[0]["username"].ToString();
                password = ds.Tables[0].Rows[0]["password"].ToString();
                realname = ds.Tables[0].Rows[0]["realname"].ToString();
                companyname = ds.Tables[0].Rows[0]["companyname"].ToString();
                userid = Convert.ToInt32(ds.Tables[0].Rows[0]["userid"]);
                regtime = ds.Tables[0].Rows[0]["regtime"].ToString();
                url = ds.Tables[0].Rows[0]["url"].ToString();
                userstate = Convert.ToInt32(ds.Tables[0].Rows[0]["userstate"]);
            }
        }
        public DataSet GetList(int strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [id],[username],[password],[realname],[companyname],[userid],[regtime],[url],[userstate]");
            strSql.Append(" FROM chat_user ");
            if (strWhere != 0)
            {
                strSql.Append(" where  id=" + id);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

    }
}
