無限類別,無限子類,無限選單,無限規則, _層的的下屬計算
阿新 • • 發佈:2019-02-12
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { string sql=""; Inc inc=new Inc(); if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem) { ((Label)e.Item.FindControl("numbers")).Text=this.number.ToString(); this.number+=1; e.Item.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'"); e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=c"); int classID=Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,"id"));//本類ID int layer=Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,"layer"));//本類層 int parent=Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,"parent"));//本類的父類 ((HyperLink)e.Item.FindControl("hlGo")).NavigateUrl="admin_Addproduct.aspx?classid="+classID.ToString()+"&layer="+Convert.ToString(layer+1)+"&parent="+parent.ToString(); //計算本類下商品數量 int theClassProCount=0;//本類下商品數量,不包含子類商品 sql="select count(*) from product where proClassID="+classID; theClassProCount=Convert.ToInt32(inc.getItem(sql)); //計算本類下所有商品數量 int theClassProCountAll=theClassProCount;// int theClassLayer=0;//類表中層數量 sql="select top 1 layer from proclass order by layer desc"; theClassLayer=Convert.ToInt32(inc.getItem(sql)); sql="select id from proClass where parent="+classID; DataSet ds=inc.getDataSet(sql);//本類下一層子類 theClassProCountAll=theClassProCountAll+this.classCountPro(layer+1,theClassLayer,ds); ((Label)e.Item.FindControl("lblProCount")).Text=theClassProCount.ToString()+"/"+theClassProCountAll.ToString(); } } private int classCountPro(int start,int over,DataSet ds) { int count=0; string sql=""; Inc inc=new Inc(); if(start<=over) { foreach (DataRow row in ds.Tables[0].Rows) foreach (DataColumn column in ds.Tables[0].Columns) if (row[column] != null) { sql="select count(*) from product where proClassID="+row[column].ToString(); count=count+Convert.ToInt32(inc.getItem(sql)); sql="select id from proClass where parent="+row[column].ToString(); DataSet dsNew=inc.getDataSet(sql); count=count+this.classCountPro(start+1,over,dsNew); } return count; } return 0; }