商业网站之通用行业分类

现在众多的商业网站,在提供服务时,按行业分类是个很重要、的
      《Classcode》    原码:
/*
 *
 *
 *  类别操作
 *
 *
 *
 * */
using System;
using System.Data;

/// <summary>
/// classCode 的摘要说明
/// </summary>
namespace cls
{
    public class classCode
    {
        string connstr;
        public classCode()
        {
            //this.connstr = System.Configuration.ConfigurationManager.ConnectionStrings[1].ConnectionString;
            this.connstr = System.Configuration.ConfigurationManager.ConnectionStrings[1].ConnectionString;
        }
        //顶级类别获取
        public System.Data.DataTable getClsTop(int flg)
        {
            string sql=null;
            if(flg==1)
                sql="select * from class where classdeep=1 ";
            else
                sql="select * from class where classdeep=2 and cast(substring(classcode,7,2) as tinyint) between 1 and 5";

            return (new DBCore.SqlCommand(sql,
                    this.connstr,
                    false,
                    CommandType.Text))
                 .Execute().Table;
        }
        //二级类别获取
        public System.Data.DataTable getClsTop2()
        {
            return new DataTable();
        }
        //获取指定类别的所有子类别
        public DataView getClsByCode(string code)
        {
            int i = code.Length / 4 + 1;

            return (new DBCore.SqlCommand(String.Format("select * from [class] where left(classcode,{0})='{1}' and classdeep={2}"
                , code.Length, code, i),
                connstr,
                false,
                CommandType.Text))
                .Execute();
        }
        //获取导航菜单
        public System.Data.SqlClient.SqlDataReader getNavigation(string code)
        {
            int i = code.Length ;
            string sql = null;
            sql="select * from class where classcode='"+code.Substring(0,4)+"'";
            if (i > 4)
                sql += " union select * from class where classcode='" + code.Substring(0, 8) + "'";
            if (i > 8)
                sql += " union select * from class where classcode='" + code + "'";
           
            return (new DBCore.SqlCommand(sql,
                   connstr,
                   false,
                  CommandType.Text))
                .ExecuteReader(false);          

        }
        //获取导航总数
        public System.Data.SqlClient.SqlDataReader getNavigation()
        {
            return (new DBCore.SqlCommand("select *  from countnum where id=1",
                   connstr,
                   false,
                  CommandType.Text))
                .ExecuteReader(false);
        }
        //获取店铺类型
        public DataView getShopType(Int16 flg)
        {
            string sql;
            if(flg==1)
                sql="select * from mixType where pid=3";
            else
                sql="select * from mixType where pid=4";
            return (new DBCore.SqlCommand(sql, connstr, false, CommandType.Text)).Execute();
        }
    }
}
由于时间原因,没做调整
               表示层:
                        private void InitPage()
    {
       cls.classcode code=new cls.classcode();
        dt1=code.getclstop(1);
        dt2=code.getclstop(2);
        this.DataList1.DataSource = dt1.DefaultView;
        this.DataList1.DataBind();

    }
         dt1 和dt2 是两个虚表,DataTable
     绑定子项:
                  protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemIndex > -1)
        {
            Literal lt = (Literal)e.Item.Controls[1];
            int l = 0;
            string name;
            foreach (DataRow dr in dt2.Select("classcode like '" +
                dt1.Rows[e.Item.ItemIndex]["classcode"].ToString() + "%'"))
            {
                name = dr["classname"].ToString();
                l += name.Length;
                if (l > 16 || l + name.Length > 16)
                    break;
                lt.Text += String.Format("<a style='font-size:12.5px;color:#666666'target='_blank' href=\"corpshow.aspx?cd={0}\" >{1}</a> ", dr["classcode"], dr["classname"]);
            }

        }

    }
由于没做调整,直接把原码倒过来的,所以不是很容易看懂,  仅供参考!
                            
                             

posted @ 2007-01-02 14:50  上海-天浩  阅读(451)  评论(0)    收藏  举报

Living in ShangHai

Copyright © 2008 天浩阁 Corporation, All Rights Reserved