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;
using System.Data.SqlClient;
using System.Xml;
using System.IO;

public partial class WTOSYSadmin_Products_AJAXddl : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        string isdo = Request.QueryString["isdo"].Trim();
        //string isdo = "xl";
        string str = "";
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        switch (isdo)
        { 
            case "sel"://取出所属的下拉列表
                string msg = Request.QueryString["ddlFl"].Trim();
               
                SqlCommand smd = new SqlCommand("select * from SmallProductAttribute where BigAttributeId=" + msg + " and attvalue='novalue'", conn);
                SqlDataReader sdr = smd.ExecuteReader();
                string xmlstr = "";
                string bigname="";
                while (sdr.Read())
                {
                    xmlstr += sdr.GetString(1).Trim() + "|";
                    bigname =Convert.ToString(sdr.GetInt32(2));
                }

                sdr.Close();
                string[] sArray = xmlstr.Split('|');
                string xmlstr2 = "";

                for (int i = 0; i < sArray.Length - 1; i++)
                {
                    SqlCommand smd2 = new SqlCommand("select * from SmallProductAttribute where SmallAttribute='" + sArray[i].ToString() + "' and  attvalue<>'novalue'", conn);
                    SqlDataReader sdr2 = smd2.ExecuteReader();

                    xmlstr2 += sArray[i].ToString() + "|";

                    while (sdr2.Read())
                    {
                        xmlstr2 += sdr2.GetString(6).ToString() + ";";

                    }
                    xmlstr2 += "$";
                    smd2.Dispose();
                    sdr2.Dispose();

                }


                Response.Write(bigname+"$"+xmlstr2);
                Response.End();
                break;

            case "xl":
                string va = Request.QueryString["va"].Trim();
                string FL = Request.QueryString["ddlFl"].Trim();
                //string va ="1";
                //string FL = "白色";
                SqlCommand sqlcomm = new SqlCommand("select * from SmallProductAttribute where attvalue='"+FL+"'", conn);
                SqlDataReader sdrr = sqlcomm.ExecuteReader();
                sdrr.Read();
                
                if (sdrr.GetInt32(4) == 1)
                {
                    str += sdrr.GetString(1) + ";" + sdrr.GetString(6) + "$" + "1";
                }
                else
                {
                    str += sdrr.GetString(1)+";"+sdrr.GetString(6)+";"+sdrr.GetInt32(7)+";"+sdrr.GetDecimal(8)+"$"+"2";
                }
                Response.Write(str+ "|" +va);
                sdrr.Close();
                sdrr.Dispose();
                conn.Close();
                Response.End();
                break;
            case "er":
                string ddlbig= Request.QueryString["ddlFl"].ToString().Trim();
                SqlCommand smdB = new SqlCommand("select * from SmallProductCategory where BigCategoryId=" + ddlbig, conn);
                SqlDataReader sdrB = smdB.ExecuteReader();
                string strBl = "";
                while (sdrB.Read())
                {
                    strBl += sdrB.GetInt32(0).ToString().Trim() + "+" + sdrB.GetString(2).Trim() + "-";
                }
                conn.Close();
                Response.Write(strBl);
                break;

        }
        
            //XmlDocument xmldoc = new XmlDocument(); //创建空的XML文档
            //xmldoc.LoadXml(xmlstr2);
            //string picPath = Server.MapPath("..\\Products\\XMLp\\");
            //string filed = "bookstore.xml";
            //string strNewPath = GetSaveFilePath(picPath) + GetExtension(filed);
            //xmldoc.Save(picPath + strNewPath); //保存
            //Response.Write(strNewPath);
       

      }
   

    //#region 创建文件夹并重命名
    //private string GetExtension(string fileName)
    //{
    //    int startPos = fileName.LastIndexOf(".");
    //    string ext = fileName.Substring(startPos, fileName.Length - startPos);
    //    return ext;
    //}
    //private string GetSaveFilePath(string picname)
    //{
    //    DateTime dateTime = DateTime.Now;
    //    string yearStr = dateTime.Year.ToString(); ;
    //    string monthStr = dateTime.Month.ToString();
    //    string dayStr = dateTime.Day.ToString();
    //    string hourStr = dateTime.Hour.ToString();
    //    string minuteStr = dateTime.Minute.ToString();
    //    string dir = dateTime.ToString("\\yyyyMMdd");
    //    if (!Directory.Exists(picname + dir))
    //    {
    //        Directory.CreateDirectory(picname + dir);
    //    }
    //    return dir + dateTime.ToString("\\\\yyyyMMddhhmmssffff");
    //}
    //#endregion
  
}
     
