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 family : 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.addbillfamily(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("名称不能为空！");
                    Response.End();
                }
                else
                {
                    if (bll.EditbillFamily(UserID, cname, Convert.ToInt32(Request.QueryString["fid"])) > 0)
                    {
                        Response.Write("succ");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("找不到记录!");
                        Response.End();
                    }
                }
            }
            else
            {
                GetFamilyList("0");
            }

        }

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