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_baohu
    {
        public etw_baohu()
        {
        }
        private int etw_id;
        private int etw_userid;
        private int etw_questionid;
        private string etw_answer;
        private string etw_definequestion;
        private string etw_defineanswer;
        private string etw_email;

        public int id
        {
            set { etw_id = value; }
            get { return etw_id; }
        }
        public int userid
        {
            set { etw_userid = value; }
            get { return etw_userid; }
        }
        public int questionid
        {
            set { etw_questionid = value; }
            get { return etw_questionid; }
        }
        public string answer
        {
            set { etw_answer = value; }
            get { return etw_answer; }
        }
        public string definequestion
        {
            set { etw_definequestion = value; }
            get { return etw_definequestion; }
        }
        public string defineanswer
        {
            set { etw_defineanswer = value; }
            get { return etw_defineanswer; }
        }
        public string email
        {
            set { etw_email = value; }
            get { return etw_email; }
        }
        public bool exists()
        {
            StringBuilder strsql = new StringBuilder();
            strsql.Append("select count(id) from etw_baohu");
            strsql.Append("where id=" + id + "");
            return DbHelperSQL.Exists(strsql.ToString());

        }
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [etw_baohu](");
            strSql.Append("userid,questionid,answer,definequestion,defineanswer,email");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("" + userid + ",");
            strSql.Append("" + questionid + ",");
            strSql.Append("N'" + answer + "',");
            strSql.Append("N'" + definequestion + "',");
            strSql.Append("N'" + defineanswer + "',");
            strSql.Append("N'" + email + "'");
            strSql.Append(")");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update etw_baohu set ");
            strSql.Append("userid=" + userid + ",");
            strSql.Append("questionid=" + questionid + ",");
            strSql.Append("answer=N'" + answer + "',");
            strSql.Append("definequestion=N'" + definequestion + "',");
            strSql.Append("defineanswer=N'" + defineanswer + "',");
            strSql.Append("email=N'" + email + "'");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

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

        public void GetModel()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append("[id],[userid],[questionid],[answer],[definequestion],[defineanswer],[email]");
            strSql.Append(" from etw_baohu ");
            strSql.Append("where id=" + id + "");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                userid = Convert.ToInt32(ds.Tables[0].Rows[0]["userid"]);
                questionid = Convert.ToInt32(ds.Tables[0].Rows[0]["questionid"]);
                answer = ds.Tables[0].Rows[0]["answer"].ToString();
                definequestion = ds.Tables[0].Rows[0]["definequestion"].ToString();
                defineanswer = ds.Tables[0].Rows[0]["defineanswer"].ToString();
                email = ds.Tables[0].Rows[0]["email"].ToString();

            }
        }
        public DataSet GetList(int strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [id],[userid],[questionid],[answer],[definequestion],[defineanswer],[email]");
            strSql.Append(" FROM etw_baohu ");
            if (strWhere != 0)
            {
                strSql.Append(" where  id=" + id);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        public DataSet check_baohu(int strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [id],[userid],[questionid],[answer],[definequestion],[defineanswer],[email]");
            strSql.Append(" FROM etw_baohu ");
            if (strWhere != 0)
            {
                strSql.Append(" where  userid=" + userid);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

    }
}
