C#無限欄目分級程式碼分享 好東西第1/3頁_C#教程

來源:互聯網
上載者:User
資料庫表的結構必須有以下欄位:  
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
各個欄位的說明:
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
3,本樣本核心為idb.cs,db.cs和action.cs,分別說明下作用
idb.cs:資料庫操作類的介面,代碼如下: using System;
using System.Data;

namespace catalog
{
/// <summary>
/// idb 的摘要說明。
/// </summary>
interface idb
{
  //
  //void open();建構函式當然不能在介面裡聲明

  System.Data.IDbConnection getcon
  {
   get;
   //set;
  }

  string constr
  {
   get;
  }

  System.Data.IDbCommand command(string sql);

  int exesql(string sql);

  object getvalue(string sql);

  void close();

  DataTable getdata(string sql);

  System.Data.IDataReader getdr(string sql);
}
}





db.cs執行個體這個介面: using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Configuration;
//using System.Web;

namespace catalog
{
/// <summary>
/// db 的摘要說明。
/// </summary>
public class db:idb
{
  private IDbConnection con;
  private IDbCommand cm;
  private string dbtype="access";

  public db()
  {
   //
   // TODO: 在此處添加建構函式邏輯
   //
   dbtype=ConfigurationSettings.AppSettings["dbtype"];
   if (dbtype==null)
    dbtype="";
   if (dbtype.ToLower()=="sqlserver")
   {
    con=new SqlConnection();
    cm= new SqlCommand();
   }
   else
   {
    con=new OleDbConnection();
    cm= new OleDbCommand();
   }

   string cnstring=ConfigurationSettings.AppSettings["cnstr"];
   con.ConnectionString=cnstring;

   open();
   cm.Connection=con;
  }

  public db(string constr)
  {
   //
   // TODO: 在此處添加建構函式邏輯
   //
   dbtype=ConfigurationSettings.AppSettings["dbtype"];
   if (dbtype==null)
    dbtype="";
   if (dbtype.ToLower()=="sqlserver")
   {
    con=new SqlConnection();
    cm= new SqlCommand();
   }
   else
   {
    con=new OleDbConnection();
    cm= new OleDbCommand();
   }

   con.ConnectionString=constr;
   open();
   cm.Connection=con;
  }

  private void open()
  {
   con.Open();
  }

  public System.Data.IDbConnection getcon
  {
   get{return con;}
   //set{};
  }

  public int exesql(string sql)
  {
   cm.CommandText=sql;
   return cm.ExecuteNonQuery();
  }

  public object getvalue(string sql)
  {
   cm.CommandText=sql;
   //return cm.ExecuteScalar();
   object o=cm.ExecuteScalar();
   return o;
  }

  public void close()
  {
   cm.Dispose();
   con.Close();
   con.Dispose();
   con=null;
  }

  public DataTable getdata(string sql)
  {
   DataTable dt=new DataTable();
   if (dbtype.ToLower()=="sqlserver")
   {
    SqlDataAdapter adapter = new SqlDataAdapter();
    cm.CommandText=sql;
    adapter.SelectCommand=(SqlCommand)cm;
    adapter.Fill(dt);
   }
   else
   {
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    cm.CommandText=sql;
    adapter.SelectCommand=(OleDbCommand)cm;
    adapter.Fill(dt);
   }
   return dt;
  }

  public IDataReader getdr(string sql)
  {
   cm.CommandText=sql;
   return cm.ExecuteReader();

  }

  public string constr
  {
   get{return ConfigurationSettings.AppSettings["cnstr"];}
  }

  public System.Data.IDbCommand command(string sql)
  {
   cm.CommandText=sql;
   return cm;
  }
}
}
C#無限欄目分級程式碼分享[2] 核心類說明

本程式採用C#為指令碼編寫,同時支援ACCESS/SQL SERVER資料庫。 
本程式功能:欄目無限分級,欄目的移動,添加,排序,刪除(欄目樹),操作方便,部署、使用更為簡單,提供統一的介面程式。 
本程式才開發完畢,難免有錯誤或者BUG,歡迎提出,不甚感激。 

核心類檔案方法調用說明 
public void deleteAllCatalog(string table) //清空欄目表 
public int downClass(string table,int classid) //欄目向下移動一位 
public int upClass(string table,int classid)//欄目向上移動一位 
public int moveClass(string table,int classid,int target)//欄目的移動 
public int deleteTree(string table,int classid)//刪除欄目樹 
public DataTable list(string table)//用於列出欄目列表 
public int getClassidOrderNum(string table,int classid)//得到欄目的排序ID 
public bool checkExist(string table,int classid)//檢查欄目是否存在 
public string getChildren(string table,int classid)//列出一個欄目所有的子欄目 
public int modiClass(string table,int classid,string classname)//修改欄目 
public string classMap(string table,int classid)//欄目導航,地圖 
public string getClassName(string table,int classid)//得到欄目名稱 
public int reset(string table)//重新置位全部類別為一級欄目 
public int deleteClass(string table,int classid)//刪除欄目 
public static void itemcreated(Object Sender, System.Web.UI.WebControls.RepeaterItemEventArgs e,string ctlname,string ctlname2)//列欄目的時候的repeater的事件 
public static string getOptions(string table,int type,int selected)//用於select的options 
public object addClass(string table,string classname,int parentid)//添加類別
當前1/3頁 123下一頁閱讀全文

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.