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 etw_user
    {
        public etw_user()
        {
        }
        private int etw_userid;
        private string etw_username;
        private string etw_password;
        private string etw_company;
        private string etw_edittime;
        private string etw_mail;
        private string etw_tel;
        private string etw_industry;
        private string etw_mainproduct;
        private int etw_ischat;
        private string etw_beizhu;
        private string etw_webcontract;
        private string etw_t_emails;
        private int etw_record;
        private int etw_istrade;
        private string etw_sendmail;
        private int etw_material;
        private int etw_id;
        private int etw_isnews;
        private int etw_changepwd;

        public int userid
        {
            set { etw_userid = value; }
            get { return etw_userid; }
        }

        public string username
        {
            set { etw_username = value; }
            get { return etw_username; }
        }
        public string password
        {
            set { etw_password = value; }
            get { return etw_password; }
        }
        public string company
        {
            set { etw_company = value; }
            get { return etw_company; }
        }
        public string edittime
        {
            set { etw_edittime = value; }
            get { return etw_edittime; }
        }
        public string mail
        {
            set { etw_mail = value; }
            get { return etw_mail; }
        }
        public string tel
        {
            set { etw_tel = value; }
            get { return etw_tel; }
        }
        public string industry
        {
            set { etw_industry = value; }
            get { return etw_industry; }
        }
        public string mainproduct
        {
            set { etw_mainproduct = value; }
            get { return etw_mainproduct; }
        }
        public int ischat
        {
            set { etw_ischat = value; }
            get { return etw_ischat; }
        }
        public string beizhu
        {
            set { etw_beizhu = value; }
            get { return etw_beizhu; }
        }
        public string webcontract
        {
            set { etw_webcontract = value; }
            get { return etw_webcontract; }
        }
        public string t_emails
        {
            set { etw_t_emails = value; }
            get { return etw_t_emails; }
        }
        public int record
        {
            set { etw_record = value; }
            get { return etw_record; }
        }
        public int istrade
        {
            set { etw_istrade = value; }
            get { return etw_istrade; }
        }
        public string sendmail
        {
            set { etw_sendmail = value; }
            get { return etw_sendmail; }
        }
        public int material
        {
            set { etw_material = value; }
            get { return etw_material; }
        }
        public int id
        {
            set { etw_id = value; }
            get { return etw_id; }
        }
        public int isnews
        {
            set { etw_isnews = value; }
            get { return etw_isnews; }
        }
        public int changepwd
        {
            set { etw_changepwd = value; }
            get { return etw_changepwd; }
        }
        public bool exists()
        {
            StringBuilder strsql = new StringBuilder();
            strsql.Append("select count(id) from etw_user");
            strsql.Append("where userid=" + userid + "");
            return DbHelperSQL.Exists(strsql.ToString());

        }
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [etw_user](");
            strSql.Append("userid,username,password,company,edittime,mail,tel,material");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("" + userid + ",");
            strSql.Append("N'" + username + "',");
            strSql.Append("N'" + password + "',");
            strSql.Append("N'" + company + "',");
            strSql.Append("N'" + edittime + "',");
            strSql.Append("N'" + mail + "',");
            strSql.Append("N'" + tel + "',");
            strSql.Append("" + material + "");
            strSql.Append(")");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update etw_user set ");
            strSql.Append("company=N'" + company + "',");
            strSql.Append("mail=N'" + mail + "',");
            strSql.Append("tel=N'" + tel + "',");
            strSql.Append("industry=N'" + industry + "',");
            strSql.Append("mainproduct=N'" + mainproduct + "',");
            strSql.Append("ischat=" + ischat + ",");
            strSql.Append("beizhu=N'" + beizhu + "',");
            strSql.Append("webcontract=N'" + webcontract + "',");
            strSql.Append("t_emails=N'" + t_emails + "',");
            strSql.Append("record=" + record + ",");
            strSql.Append("istrade=" + istrade + ",");
            strSql.Append("sendmail=N'" + sendmail + "',");
            strSql.Append("material=" + material + ",");
            strSql.Append("isnews=" + isnews + "");
            strSql.Append(" where userid=" + userid + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void Updatepassword()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update etw_user set ");
            strSql.Append("password=N'" + password + "'");
            strSql.Append(" where userid=" + userid + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }
        public void Updatechangepwd()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update etw_user set ");
            strSql.Append("changepwd=1");
            strSql.Append(" where userid=" + userid + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void Delete()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from etw_user ");
            strSql.Append(" where userid=" + userid + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void GetModel()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select");
            strSql.Append("[userid],[username],[password],[company],[edittime],[mail],[tel],[industry],[mainproduct],[ischat],[beizhu],[webcontract],[t_emails],[record],[istrade],[sendmail],[material],[id],[isnews]");
            strSql.Append(" from etw_user");
            strSql.Append(" where userid=" + userid + "");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                userid = Convert.ToInt32(ds.Tables[0].Rows[0]["userid"]);
                username = ds.Tables[0].Rows[0]["username"].ToString();
                password = ds.Tables[0].Rows[0]["password"].ToString();
                company = ds.Tables[0].Rows[0]["company"].ToString();
                edittime = ds.Tables[0].Rows[0]["edittime"].ToString();
                mail = ds.Tables[0].Rows[0]["mail"].ToString();
                tel = ds.Tables[0].Rows[0]["tel"].ToString();
                industry = ds.Tables[0].Rows[0]["industry"].ToString();
                mainproduct = ds.Tables[0].Rows[0]["mainproduct"].ToString();
                ischat = Convert.ToInt32(ds.Tables[0].Rows[0]["ischat"]);
                beizhu = ds.Tables[0].Rows[0]["beizhu"].ToString();
                webcontract = ds.Tables[0].Rows[0]["webcontract"].ToString();
                t_emails = ds.Tables[0].Rows[0]["t_emails"].ToString();
                record = Convert.ToInt32(ds.Tables[0].Rows[0]["record"]);
                istrade = Convert.ToInt32(ds.Tables[0].Rows[0]["istrade"]);
                sendmail = ds.Tables[0].Rows[0]["sendmail"].ToString();
                material = Convert.ToInt32(ds.Tables[0].Rows[0]["material"]);
                id = Convert.ToInt32(ds.Tables[0].Rows[0]["id"]);
                isnews = Convert.ToInt32(ds.Tables[0].Rows[0]["isnews"]);

            }
        }
        public DataSet GetList(int strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("[userid],[username],[password],[company],[edittime],[mail],[tel],[industry],[mainproduct],[ischat],[beizhu],[webcontract],[t_emails],[record],[istrade],[sendmail],[material],[id],[isnews]");
            strSql.Append(" FROM etw_user ");
            if (strWhere != 0)
            {
                strSql.Append(" where  userid=" + userid);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

    }
}
