using ESoft.Script;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESToolkit;
using System.Data;
using ESToolkit.Helper;
using ESoft.Public.Struct;
using ESoft.Public.Enum;
using System.Collections.Specialized;
using System.IO;

namespace ESoft.Web
{
    public class test : WebScript
    {
        public override void Run() {
			string qryFilter = "a.PState=0 and a.Num>0";
            int count = Toolkit.ToInt(GET["count"]);
            count = count == 0 ? 30 : count;
            int param = Toolkit.ToInt(GET["param"]);
            qryFilter += " and "+DB.Field("b.Param",param);
            DataTable dt = DB.ExecuteDataTable("select top "+ count + " b.Code as ItemCode,b.Name as ItemName,b.Spc as ItemSpc,b.Pic as ItemPic,b.Unit as ItemUnit,Num =sum(a.Num),MinSafeStore=max(d.MinSafeStore),MaxSafeStore=max(d.MaxSafeStore),MinWareDay =datediff(d,max(a.LastInDate),getdate()),MaxWareDay = datediff(d,Min(a.LastInDate),getdate()) from CK_WareStockTB a inner join BS_ItemTB b on a.ItemID=b.ID left join BS_WareListTB c on a.WareID=c.ID and b.WareID=c.ID left join BS_ItemSafeTB d on a.ItemID=d.ItemID where " + qryFilter + " group by b.Code,b.Name,b.Spc,b.Pic,b.Unit");
			string str="<ul style=\"position: absolute;\">";
			int i=0;
			foreach(DataRow dr in dt.Rows){
				str+="  <li "+(i%2==1?"class=\"even\"":"")+">";
                str+="    <div>"+dr["ItemName"]+"</div>";
				if(param==1)
					str+="    <div>"+dr["ItemSpc"]+"</div>";
				else
					str+="    <div>"+dr["ItemPic"]+"</div>";
                str+="    <div class=\"green\">"+Toolkit.ToInt(dr["Num"])+"</div>";
                str+="    <div>"+ Toolkit.ToInt(dr["MinSafeStore"])+"</div>";
                str+="    <div>"+Toolkit.ToInt(dr["MaxSafeStore"])+"</div>";
                str+="    <div>"+Toolkit.ToInt(dr["MinWareDay"])+"天</div>";
                str+="  </li>";
				i++;
			}
			str+="</ul>";
            byte[] bs = Encoding.UTF8.GetBytes(str);
            ListenerContext.Response.OutputStream.Write(bs,0,bs.Length);

        }
    }
    
}
