using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.OleDb;

public partial class BackCenter_Class_SetType : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 过期和权限

        PageFunc.IfLogin(this.Page);
        //PubPageFunc.PageHavePurview(this.Page, "2001");

        #endregion

        if (!IsPostBack)
        {
            BindData();
        }
    }

    //绑定
    public void BindData()
    {

        //查询语句的头部
        string sql_SelectFirst = "select ";
        sql_SelectFirst += " [ID],[ClassId],[TypeName],[OrderNum]";
        sql_SelectFirst += " from NT_ClassType";
        sql_SelectFirst += " where ClassId=" + Request["ClassId"] + "";

        //排序
        string sql_SelectLast = " order by OrderNum asc,Id desc";


        //查询条件
        string sql_Conditions = string.Empty;



        //查询语句
        string str_Select = sql_SelectFirst + sql_Conditions + sql_SelectLast;


        DataSet sda = DbHelperOleDb.ExecuteDataSet(CommandType.Text, str_Select, null);
        GridView1.DataSource = sda.Tables[0];
        GridView1.DataBind();
        GridView1.Dispose();
    }

    //删除
    protected void btnDelete_Command(object sender, CommandEventArgs e)
    {

        StringBuilder strSql = new StringBuilder();
        strSql.Append("delete from NT_ClassType ");
        strSql.Append(" where Id=@Id");
        OleDbParameter[] parameters = {
					new OleDbParameter("@ID",e.CommandArgument.ToString())
			};


        int rows = DbHelperOleDb.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);

        BindData();
    }

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string str_ClassId = Request["ClassId"];
        string str_TypeName = this.txt_TypeName.Text;
        string str_OrderNum = this.txt_OrderNum.Text;
        #region 操作数据库

        //执行语句

        StringBuilder strSql = new StringBuilder();
        strSql.Append("insert into NT_ClassType(");
        strSql.Append("[ClassId],[TypeName],[OrderNum])");
        strSql.Append(" values (");
        strSql.Append("@ClassId,@TypeName,@OrderNum)");
        OleDbParameter[] parameters = {
					new OleDbParameter("@PropertyNameId", OleDbType.Integer),
					new OleDbParameter("@Name", OleDbType.VarChar),
					new OleDbParameter("@OrderNum", OleDbType.Integer)};
        parameters[0].Value = str_ClassId;
        parameters[1].Value = str_TypeName;
        parameters[2].Value = str_OrderNum;
        DbHelperOleDb.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);

        this.txt_TypeName.Text = "";
        this.txt_OrderNum.Text = "";
        JavaScriptFunc.Alert(this.Page, "添加成功");
        #endregion
        BindData();

    }

}
