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_news
    {
        public etw_news()
        {
        }
        private int etw_id;
        private string etw_title;
        private string etw_content;
        private string etw_description;
        private string etw_updatetime;
        private int etw_userid;
        private int etw_lanid;
        private string etw_website;
        private string etw_picture;
        private int etw_isnewslated;

        public int id
        {
            set { etw_id = value; }
            get { return etw_id; }
        }
        public string title
        {
            set { etw_title = value; }
            get { return etw_title; }
        }
        public string content
        {
            set { etw_content = value; }
            get { return etw_content; }
        }
        public string description
        {
            set { etw_description = value; }
            get { return etw_description; }
        }
        public string updatetime
        {
            set { etw_updatetime = value; }
            get { return etw_updatetime; }
        }
        public int userid
        {
            set { etw_userid = value; }
            get { return etw_userid; }
        }
        public int lanid
        {
            set { etw_lanid = value; }
            get { return etw_lanid; }
        }
        public string website
        {
            set { etw_website = value; }
            get { return etw_website; }
        }
        public string picture
        {
            set { etw_picture = value; }
            get { return etw_picture; }
        }
        public int isnewslated
        {
            set { etw_isnewslated = value; }
            get { return etw_isnewslated; }
        }
        public bool exists()
        {
            StringBuilder strsql = new StringBuilder();
            strsql.Append("select count(id) from etw_news");
            strsql.Append("where id=" + id + "");
            return DbHelperSQL.Exists(strsql.ToString());

        }
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [etw_news](");
            strSql.Append("title,content,description,updatetime,userid,lanid,website,picture,isnewslated");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("N'" + title + "',");
            strSql.Append("N'" + content + "',");
            strSql.Append("N'" + description + "',");
            strSql.Append("N'" + updatetime + "',");
            strSql.Append("" + userid + ",");
            strSql.Append("" + lanid + ",");
            strSql.Append("N'" + website + "',");
            strSql.Append("N'" + picture + "',");
            strSql.Append("" + isnewslated + "");
            strSql.Append(")");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update etw_news set ");
            strSql.Append("website=N'" + website + "',");
            strSql.Append("title=N'" + title + "',");
            strSql.Append("content=N'" + content + "',");
            strSql.Append("description=N'" + description + "',");
            strSql.Append("updatetime=N'" + updatetime + "',");
            strSql.Append("picture=N'" + picture + "',");
            strSql.Append("isnewslated=0");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }
        public void Updatepic()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update etw_news set ");
            strSql.Append("picture=N'" + picture + "'");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }
        public void Delete()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from etw_news ");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void GetModel()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append("[id],[title],[content],[description],[updatetime],[userid],[lanid],[website],[picture],[isnewslated]");
            strSql.Append(" from etw_news ");
            strSql.Append("where id=" + id + "");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                title = ds.Tables[0].Rows[0]["title"].ToString();
                content = ds.Tables[0].Rows[0]["content"].ToString();
                description = ds.Tables[0].Rows[0]["description"].ToString();
                updatetime = ds.Tables[0].Rows[0]["updatetime"].ToString();
                userid = Convert.ToInt32(ds.Tables[0].Rows[0]["userid"]);
                lanid = Convert.ToInt32(ds.Tables[0].Rows[0]["lanid"]);
                website = ds.Tables[0].Rows[0]["website"].ToString();
                picture = ds.Tables[0].Rows[0]["picture"].ToString();
                isnewslated = Convert.ToInt32(ds.Tables[0].Rows[0]["isnewslated"]);

            }
        }
        public DataSet GetList(int strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [id],[title],[content],[description],[updatetime],[userid],[lanid],[website],[picture],[isnewslated]");
            strSql.Append(" FROM etw_news ");
            if (strWhere != 0)
            {
                strSql.Append(" where  id=" + id);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }


    }
}
