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_record
    {
        public etw_record()
        {
        }
        private int etw_id;
        private int etw_usernameid;
        private string etw_pagename;
        private string etw_datatime;
        private string etw_ip;
        public int id
        {
            set { etw_id = value; }
            get { return etw_id; }
        }
        public int usernameid
        {
            set { etw_usernameid = value; }
            get { return etw_usernameid; }
        }
        public string pagename
        {
            set { etw_pagename = value; }
            get { return etw_pagename; }
        }
        public string datatime
        {
            set { etw_datatime = value; }
            get { return etw_datatime; }
        }
        public string ip
        {
            set { etw_ip = value; }
            get { return etw_ip; }
        }
        public bool exists()
        {
            StringBuilder strsql = new StringBuilder();
            strsql.Append("select count(id) from etw_record");
            strsql.Append("where id=" + id + "");
            return DbHelperSQL.Exists(strsql.ToString());

        }
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [etw_record](");
            strSql.Append("usernameid,pagename,ip,datatime");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("" + usernameid + ",");
            strSql.Append("N'" + pagename + "',");
            strSql.Append("N'" + ip + "',");
            strSql.Append("N'" + datatime + "'");
            strSql.Append(")");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update etw_record set ");
            strSql.Append("usernameid=" + usernameid + ",");
            strSql.Append("pagename=N'" + pagename + "',");
            strSql.Append("ip=N'" + ip + "',");
            strSql.Append("datatime=N'" + datatime + "'");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

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

        public void GetModel()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append("[id],[usernameid],[pagename],[datatime],[ip]");
            strSql.Append(" from etw_record ");
            strSql.Append("where id=" + id + "");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                usernameid = Convert.ToInt32(ds.Tables[0].Rows[0]["usernameid"].ToString());
                pagename = ds.Tables[0].Rows[0]["pagename"].ToString();
                datatime = ds.Tables[0].Rows[0]["datatime"].ToString();
                ip = ds.Tables[0].Rows[0]["ip"].ToString();
            }
        }
        public DataSet GetList(int strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [id],[usernameid],[pagename],[datatime],[ip]");
            strSql.Append(" FROM etw_record ");
            if (strWhere != 0)
            {
                strSql.Append(" where  id=" + id);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

    }
}
