using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

namespace JuSNS.Web.inc.Ajax.bill
{
    public partial class _class : JuSNS.UI.Page.UserPage
    {
        protected  string root = string.Empty;
        JuSNS.Home.Bill bll = new JuSNS.Home.Bill();
        protected void Page_Load(object sender, EventArgs e)
        {
            root = rooDir;
            if (Request.QueryString["a"] == "add")
            {
                string cname = Request.QueryString["cna"];
                if (string.IsNullOrEmpty(cname))
                {
                    Response.Write("error");
                    Response.End();
                }
                else
                {
                    if (bll.addbillClass(UserID, cname) > 0)
                    {
                        Response.Write("succ");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("error");
                        Response.End();
                    }
                }
            }
            else if (Request.QueryString["a"] == "edit")
            {
                string cname = Request.QueryString["cna"];
                if (string.IsNullOrEmpty(cname))
                {
                    Response.Write("error");
                    Response.End();
                }
                else
                {
                    if (bll.EditbillClass(UserID, cname, Convert.ToInt32(Request.QueryString["classid"])) > 0)
                    {
                        Response.Write("succ");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("error");
                        Response.End();
                    }
                }
            }
            else
            {
                GetClassList("0");
            }

        }


        public void GetClassList(string ID)
        {
            IDataReader dr = bll.GetClassList(UserID);
            while (dr.Read())
            {
                ListItem it = new ListItem();
                string stxt = "";
                it.Value = dr["ID"].ToString();
                it.Text = stxt + dr["className"].ToString();
                if (ID == dr["ID"].ToString())
                {
                    it.Selected = true;
                }
                this.float_bill_classID.Items.Add(it);
            }
            dr.Close();
        }

        public void GetClassListHTML()
        {
            string list = "<select id=\"classID\">";
            IDataReader dr = bll.GetClassList(UserID);
            while (dr.Read())
            {
                list += "<option value=\"" + dr["id"].ToString() + "\">" + dr["className"].ToString() + "</option>";
            }
            dr.Close();
            list += "<option value=\"0\">--ÎÒ×Ô¼º--</option>";
            list += "</select>";
            Response.Write(list);
            Response.End();
        }
    }
}
