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_menu
    {
        public etw_menu()
        {
        }
        private int etw_id;
        private string etw_menuname;
        private string etw_Url;
        private string etw_sqltext;
        private int etw_parentid;
        private float etw_orderby;
        public int id
        {
            set { etw_id = value; }
            get { return etw_id; }
        }
        public string menuname
        {
            set { etw_menuname = value; }
            get { return etw_menuname; }
        }
        public string Url
        {
            set { etw_Url = value; }
            get { return etw_Url; }
        }
        public string sqltext
        {
            set { etw_sqltext = value; }
            get { return etw_sqltext; }
        }
        public int parentid
        {
            set { etw_parentid = value; }
            get { return etw_parentid; }
        }
        public float orderby
        {
            set { etw_orderby = value; }
            get { return etw_orderby; }
        }
        public bool exists()
        {
            StringBuilder strsql = new StringBuilder();
            strsql.Append("select count(id) from etw_menu");
            strsql.Append("where id=" + id + "");
            return DbHelperSQL.Exists(strsql.ToString());

        }
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [etw_menu](");
            strSql.Append("menuname,Url,sqltext,parentid,orderby");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("N'" + menuname + "',");
            strSql.Append("N'" + Url + "',");
            strSql.Append("N'" + sqltext + "',");
            strSql.Append("" + parentid + ",");
            strSql.Append("" + orderby + "");
            strSql.Append(")");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update etw_menu set ");
            strSql.Append("menuname=N'" + menuname + "',");
            strSql.Append("Url=N'" + Url + "',");
            strSql.Append("sqltext=N'" + sqltext + "',");
            strSql.Append("orderby=" + orderby + ",");
            strSql.Append("parentid=" + parentid + "");
            strSql.Append(" where id=" + id + " ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

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

        public void GetModel()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append("[id],[menuname],[Url],[sqltext],[parentid],[orderby]");
            strSql.Append(" from etw_menu ");
            strSql.Append("where id=" + id + "");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                menuname = ds.Tables[0].Rows[0]["menuname"].ToString();
                Url = ds.Tables[0].Rows[0]["Url"].ToString();
                sqltext = ds.Tables[0].Rows[0]["sqltext"].ToString();
                parentid = Convert.ToInt32(ds.Tables[0].Rows[0]["parentid"]);
                orderby = Convert.ToSingle(ds.Tables[0].Rows[0]["orderby"].ToString());
            }
        }
        public DataSet GetList(int strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [id],[menuname],[Url],[sqltext],[parentid],[orderby]");
            strSql.Append(" FROM etw_menu ");
            if (strWhere != 0)
            {
                strSql.Append(" where  id=" + id);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetClassList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from etw_menu ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
    }
}
