<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-295  評(píng)論-26  文章-1  trackbacks-0

    using System;
    using System.Data;
    using System.Data.SqlClient;

    namespace com.hua..li
    {
    ?/// <summary>
    ?/// 數(shù)據(jù)庫操作
    ?/// </summary>
    ?public class pathDB:pathPage
    ?{

    ??override protected void OnInit(EventArgs e)
    ??{
    ???pathInit();
    ???base.OnInit(e);
    ??}

    ??protected void pathInit()
    ??{
    ???this.ConnectDb();
    ??}

    ??protected void ConnectDb()
    ??{
    ???if(doh == null)
    ???{
    ????System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connString"]);
    ????doh = new com.path.SqlDbOperHandler(conn);
    ???}
    ??}
    ?}
    }
    using System;

    namespace com.hua.li
    ?{
    ??/// <summary>
    ??/// 表示數(shù)據(jù)庫連接類型。
    ??/// </summary>
    ??public enum DatabaseType:byte{SqlServer,OleDb};
    ??/// <summary>
    ??/// DbOperHandler 的摘要說明。
    ??/// </summary>
    ??public abstract class DbOperHandler
    ??{
    ???/// <summary>
    ???/// 析構(gòu)函數(shù),釋放申請(qǐng)的資源。
    ???/// </summary>
    ???~DbOperHandler()
    ???{
    ????conn.Close();
    ???}
    ???/// <summary>
    ???/// 表示數(shù)據(jù)庫連接的類型,目前支持SqlServer和OLEDB
    ???/// </summary>
    ???protected DatabaseType dbType=DatabaseType.OleDb;
    ???/// <summary>
    ???/// 返回當(dāng)前使用的數(shù)據(jù)庫連接對(duì)象。
    ???/// </summary>
    ???/// <returns></returns>
    ???public System.Data.IDbConnection GetConnection()
    ???{
    ????return conn;
    ???}
    ???/// <summary>
    ???/// 條件表達(dá)式,用于在數(shù)據(jù)庫操作時(shí)篩選記錄,通常用于僅需指定表名稱和某列名稱的操作,如GetValue(),Delete()等,支持查詢參數(shù),由AddConditionParameters指定。。
    ???/// </summary>
    ???public string ConditionExpress=string.Empty;
    ???/// <summary>
    ???/// 當(dāng)前的SQL語句。
    ???/// </summary>
    ???public string SqlCmd=string.Empty;
    ???/// <summary>
    ???/// 當(dāng)前操作所涉及的數(shù)據(jù)表名稱。
    ???/// </summary>
    ???protected string tableName=string.Empty;
    ???/// <summary>
    ???/// 當(dāng)前操作所設(shè)計(jì)的字段名稱。
    ???/// </summary>
    ???protected string fieldName=string.Empty;
    ???/// <summary>
    ???/// 當(dāng)前所使用的數(shù)據(jù)庫連接。
    ???/// </summary>
    ???protected System.Data.IDbConnection conn;
    ???/// <summary>
    ???/// 當(dāng)前所使用的命令對(duì)象。
    ???/// </summary>
    ???protected System.Data.IDbCommand cmd;
    ???/// <summary>
    ???/// 當(dāng)前所使用的數(shù)據(jù)庫適配器。
    ???/// </summary>
    ???protected System.Data.IDbDataAdapter da;

    ??
    ???/// <summary>
    ???/// 用于存儲(chǔ)字段/值配對(duì)。
    ???/// </summary>
    ???protected System.Collections.ArrayList alFieldItems=new System.Collections.ArrayList(10);
    ???/// <summary>
    ???/// 用于存儲(chǔ)SQL語句中的查詢參數(shù)。
    ???/// </summary>
    ???protected System.Collections.ArrayList alSqlCmdParameters=new System.Collections.ArrayList(5);
    ???/// <summary>
    ???/// 用于存儲(chǔ)條件表達(dá)式中的查詢參數(shù)。
    ???/// </summary>
    ???protected System.Collections.ArrayList alConditionParameters=new System.Collections.ArrayList(5);
    ???/// <summary>
    ???/// 重值該對(duì)象,使之恢復(fù)到構(gòu)造時(shí)的狀態(tài)。
    ???/// </summary>
    ???public void Reset()
    ???{
    ????this.alFieldItems.Clear();
    ????this.alSqlCmdParameters.Clear();
    ????this.alConditionParameters.Clear();
    ????this.ConditionExpress=string.Empty;
    ????this.SqlCmd=string.Empty;
    ????this.cmd.Parameters.Clear();
    ????this.cmd.CommandText=string.Empty;
    ???}
    ???/// <summary>
    ???/// 添加一個(gè)字段/值對(duì)到數(shù)組中。
    ???/// </summary>
    ???/// <param name="_fieldName">字段名稱。</param>
    ???/// <param name="_fieldValue">字段值。</param>
    ???public void AddFieldItem(string _fieldName,object _fieldValue)
    ???{

    ????for(int i=0;i<this.alFieldItems.Count;i++)
    ????{
    ?????if(((DbKeyItem)this.alFieldItems[i]).fieldName==_fieldName)
    ?????{
    ??????throw new ArgumentException("The field name has existed!");
    ?????}
    ????}
    ????this.alFieldItems.Add(new DbKeyItem(_fieldName,_fieldValue));
    ???}
    ???/// <summary>
    ???/// 添加條件表達(dá)式中的查詢參數(shù)到數(shù)組中。注意:當(dāng)數(shù)據(jù)庫連接為SqlServer時(shí),參數(shù)名稱必須和SQL語句匹配。其它則只需保持添加順序一致,名稱無需匹配。
    ???/// </summary>
    ???/// <param name="_conditionName">條件名稱。</param>
    ???/// <param name="_conditionValue">條件值。</param>
    ???public void AddConditionParameter(string _conditionName,object _conditionValue)
    ???{
    ????for(int i=0;i<this.alConditionParameters.Count;i++)
    ????{
    ?????if(((DbKeyItem)this.alConditionParameters[i]).fieldName==_conditionName)
    ?????{
    ??????throw new ArgumentException("The condition name has existed!");
    ?????}
    ????}
    ????this.alConditionParameters.Add(new DbKeyItem(_conditionName,_conditionValue));
    ???}

    ???/// <summary>
    ???/// 添加SQL語句中的查詢參數(shù)到數(shù)組中。注意:當(dāng)數(shù)據(jù)庫連接為SqlServer時(shí),參數(shù)名稱必須和SQL語句匹配。其它則只需保持添加順序一致,名稱無需匹配。
    ???/// </summary>
    ???/// <param name="_paraName">參數(shù)名稱。</param>
    ???/// <param name="_paraValue">參數(shù)值。</param>
    ???public void AddSqlCmdParameters(string _paraName,object _paraValue)
    ???{
    ????for(int i=0;i<this.alSqlCmdParameters.Count;i++)
    ????{
    ?????if(((DbKeyItem)this.alSqlCmdParameters[i]).fieldName==_paraName)
    ?????{
    ??????throw new ArgumentException("The sqlcmd parameter name has existed!");
    ?????}
    ????}
    ????this.alSqlCmdParameters.Add(new DbKeyItem(_paraName,_paraValue));
    ???}

    ???public bool Exist(string tableName)
    ???{
    ????return this.GetValue(tableName,"count(*)").ToString()!="0";
    ???}
    ???/// <summary>
    ???/// 抽象函數(shù)。用于產(chǎn)生Command對(duì)象所需的參數(shù)。
    ???/// </summary>
    ???protected abstract void GenParameters();
    ???/// <summary>
    ???/// 根據(jù)當(dāng)前alFieldItem數(shù)組中存儲(chǔ)的字段/值向指定表中添加一條數(shù)據(jù)。在該表無觸發(fā)器的情況下返回添加數(shù)據(jù)所獲得的自動(dòng)增長id值。
    ???/// </summary>
    ???/// <param name="_tableName">要插入數(shù)據(jù)的表名稱。</param>
    ???/// <returns>返回本數(shù)據(jù)連接上產(chǎn)生的最后一個(gè)自動(dòng)增長id值。</returns>
    ???public int Insert(string _tableName)
    ???{
    ???
    ????this.tableName=_tableName;
    ????this.fieldName=string.Empty;
    ????this.SqlCmd="insert into "+this.tableName+"(";
    ????string tempValues=" values(";
    ????for(int i=0;i<this.alFieldItems.Count-1;i++)
    ????{
    ?????this.SqlCmd+=((DbKeyItem)alFieldItems[i]).fieldName;
    ?????this.SqlCmd+=",";

    ?????tempValues+="@para";
    ?????tempValues+=i.ToString();

    ?????tempValues+=",";
    ????}
    ????this.SqlCmd+=((DbKeyItem)alFieldItems[alFieldItems.Count-1]).fieldName;
    ????this.SqlCmd+=") ";

    ????tempValues+="@para";
    ????tempValues+=(alFieldItems.Count-1).ToString();

    ????tempValues+=")";
    ????this.SqlCmd+=tempValues;
    ????this.cmd.CommandText=this.SqlCmd;
    ????this.GenParameters();
    ????cmd.ExecuteNonQuery();
    ????cmd.CommandText="select @@identity as id";
    ????int autoId=Convert.ToInt32(cmd.ExecuteScalar());
    ????return autoId;
    ???}

    ???/// <summary>
    ???/// 根據(jù)當(dāng)前alFieldItem數(shù)組中存儲(chǔ)的字段/值和條件表達(dá)式所指定的條件來更新數(shù)據(jù)庫中的記錄,返回所影響的行數(shù)。
    ???/// </summary>
    ???/// <param name="_tableName">要更新的數(shù)據(jù)表名稱。</param>
    ???/// <returns>返回此次操作所影響的數(shù)據(jù)行數(shù)。</returns>
    ???public int Update(string _tableName)
    ???{
    ????this.tableName=_tableName;
    ????this.fieldName=string.Empty;
    ????this.SqlCmd="update "+this.tableName+" set ";
    ????for(int i=0;i<this.alFieldItems.Count-1;i++)
    ????{
    ?????this.SqlCmd+=((DbKeyItem)alFieldItems[i]).fieldName;
    ?????this.SqlCmd+="=";

    ?????this.SqlCmd+="@para";
    ?????this.SqlCmd+=i.ToString();

    ?????this.SqlCmd+=",";
    ????}
    ????this.SqlCmd+=((DbKeyItem)alFieldItems[alFieldItems.Count-1]).fieldName;
    ????this.SqlCmd+="=";

    ????this.SqlCmd+="@para";
    ????this.SqlCmd+=(alFieldItems.Count-1).ToString();


    ????if(this.ConditionExpress!=string.Empty)
    ????{
    ?????this.SqlCmd=this.SqlCmd+" where "+this.ConditionExpress;
    ????}
    ????this.cmd.CommandText=this.SqlCmd;
    ????this.GenParameters();
    ????int effectedLines=this.cmd.ExecuteNonQuery();
    ????return effectedLines;
    ???}

    ???/// <summary>
    ???/// 執(zhí)行SqlCmd中的SQL語句,參數(shù)由AddSqlCmdParameters指定,與ConditionExpress無關(guān)。
    ???/// </summary>
    ???/// <returns>返回此次操作所影響的數(shù)據(jù)行數(shù)。</returns>
    ???public int ExecuteSqlNonQuery()
    ???{
    ????this.cmd.CommandText=this.SqlCmd;
    ????this.GenParameters();
    ????return cmd.ExecuteNonQuery();
    ???}
    ???/// <summary>
    ???/// 獲取指定表,指定列,指定條件的第一個(gè)符合條件的值。
    ???/// </summary>
    ???/// <param name="_tableName">表名稱。</param>
    ???/// <param name="_fieldName">字段名稱。</param>
    ???/// <returns>獲取的值。如果為空則返回null。</returns>
    ???public object GetValue(string _tableName,string _fieldName)
    ???{
    ????this.tableName=_tableName;
    ????this.fieldName=_fieldName;
    ????this.SqlCmd="select "+this.fieldName+" from "+this.tableName;
    ????if(this.ConditionExpress!=string.Empty)
    ????{
    ?????this.SqlCmd=this.SqlCmd+" where "+this.ConditionExpress;
    ????}
    ????this.cmd.CommandText=this.SqlCmd;
    ????this.GenParameters();
    ????return cmd.ExecuteScalar();
    ???}
    ???/// <summary>
    ???/// 根據(jù)當(dāng)前指定的SqlCmd獲取DataTable。如果ConditionExpress不為空則會(huì)將其清空,所以條件表達(dá)式需要包含在SqlCmd中。
    ???/// </summary>
    ???/// <returns>返回查詢結(jié)果DataTable。</returns>
    ???public System.Data.DataTable GetDataTable()
    ???{
    ????System.Data.DataSet ds=this.GetDataSet();
    ????return ds.Tables[0];
    ???}
    ???/// <summary>
    ???/// 根據(jù)當(dāng)前指定的SqlCmd獲取DataSet。如果ConditionExpress不為空則會(huì)將其清空,所以條件表達(dá)式需要包含在SqlCmd中。
    ???/// </summary>
    ???/// <returns>返回查詢結(jié)果DataSet。</returns>
    ???public System.Data.DataSet GetDataSet()
    ???{
    ????this.alConditionParameters.Clear();
    ????this.ConditionExpress=string.Empty;
    ????this.cmd.CommandText=this.SqlCmd;
    ????this.GenParameters();
    ????System.Data.DataSet ds=new System.Data.DataSet();
    ????this.da.SelectCommand=this.cmd;
    ????this.da.Fill(ds);
    ????return ds;
    ???}
    ???/// <summary>
    ???/// 對(duì)指定表,指定字段執(zhí)行加一計(jì)數(shù),返回計(jì)數(shù)后的值。條件由ConditionExpress指定。
    ???/// </summary>
    ???/// <param name="_tableName">表名稱。</param>
    ???/// <param name="_fieldName">字段名稱。</param>
    ???/// <returns>返回計(jì)數(shù)后的值。</returns>
    ???public int Count(string _tableName,string _fieldName)
    ???{
    ????this.tableName=_tableName;
    ????this.fieldName=_fieldName;
    ????int count=Convert.ToInt32(this.GetValue(this.tableName,this.fieldName));
    ????count++;
    ????this.cmd.Parameters.Clear();
    ????this.cmd.CommandText=string.Empty;
    ????this.AddFieldItem(_fieldName,count);
    ????this.Update(this.tableName);
    ????return count;
    ???}

    ???/// <summary>
    ???/// 對(duì)指定表,指定字段執(zhí)行減一計(jì)數(shù),返回計(jì)數(shù)后的值。條件由ConditionExpress指定。
    ???/// </summary>
    ???/// <param name="_tableName">表名稱。</param>
    ???/// <param name="_fieldName">字段名稱。</param>
    ???/// <returns>返回計(jì)數(shù)后的值。</returns>
    ???public int Substract(string _tableName,string _fieldName)
    ???{
    ????this.tableName=_tableName;
    ????this.fieldName=_fieldName;
    ????int count=Convert.ToInt32(this.GetValue(this.tableName,this.fieldName));
    ????if(count>0)count--;
    ????this.cmd.Parameters.Clear();
    ????this.cmd.CommandText=string.Empty;
    ????this.AddFieldItem(_fieldName,count);
    ????this.Update(this.tableName);
    ????return count;
    ???}

    ???/// <summary>
    ???/// 根據(jù)ConditionExpress指定的條件在指定表中刪除記錄。返回刪除的記錄數(shù)。
    ???/// </summary>
    ???/// <param name="_tableName">指定的表名稱。</param>
    ???/// <returns>返回刪除的記錄數(shù)。</returns>
    ???public int Delete(string _tableName)
    ???{
    ????this.tableName=_tableName;
    ????this.SqlCmd="delete from "+this.tableName;
    ????if(this.ConditionExpress!=string.Empty)
    ????{
    ?????this.SqlCmd=this.SqlCmd+" where "+this.ConditionExpress;
    ????}
    ????this.cmd.CommandText=this.SqlCmd;
    ????this.GenParameters();
    ????return cmd.ExecuteNonQuery();
    ???}
    ??????????? /// <summary>
    ??????????? /// 函數(shù)sendMsg需要 __Receive接受者 如果是系統(tǒng)則為 admin 否則為手機(jī)號(hào)碼
    ??????????? /// </summary>
    ??????????? /// <param name="_PHONE">手機(jī)號(hào)碼</param>
    ??????????? /// <param name="_KeyWorld">關(guān)鍵字</param>
    ??????????? /// <param name="_INFO">信息的基本內(nèi)容</param>
    ??????????? /// <param name="_Receive">接受者</param>
    ??????????? /// <returns></returns>
    ??????????? public bool SendMsg(string _PHONE, string _KeyWorld, string _INFO, string _Receive)
    ??????????? {
    ??????????????? bool SendOk;
    ??????????????? if (_PHONE != null || _KeyWorld != null)
    ??????????????? {
    ??????????????????? this.Reset();
    ??????????????????? this.AddFieldItem("PHONE", _PHONE);
    ??????????????????? this.AddFieldItem("KeyWorld", _KeyWorld);
    ??????????????????? this.AddFieldItem("INFO", _INFO);
    ??????????????????? this.AddFieldItem("Receive", _Receive);
    ??????????????????? this.Insert("smsRawRecv").ToString();
    ??????????????????? SendOk = true;
    ??????????????? }
    ??????????????? else
    ??????????????? {
    ??????????????????? SendOk = false;
    ???????????????????
    ??????????????? }
    ??????????????? return SendOk;
    ??????????? }
    ??????????? /// <summary>
    ??????????? ///
    ??????????? /// </summary>
    ??????????? /// <param name="_PHONE"></param>
    ??????????? /// <param name="_KeyWorld"></param>
    ??????????? /// <param name="_INFO"></param>
    ??????????? /// <param name="_Receive"></param>
    ??????????? /// <returns></returns>
    ???????????? //public bool Received(string _PHONE, string _KeyWorld, string _INFO, string _Receive)
    ???????????? //{
    ???????????? //??? bool Received, SendOk;
    ???????????? //??? if (SendOk)
    ???????????? //??? {
    ???????????? //??????? if (_PHONE != null || _KeyWorld != null)
    ???????????? //??????? {
    ???????????? //??????????? this.Reset();
    ???????????? //??????????? this.AddFieldItem("PHONE", _PHONE);
    ???????????? //??????????? this.AddFieldItem("KeyWorld", _KeyWorld);
    ???????????? //??????????? this.AddFieldItem("INFO", _INFO);
    ???????????? //??????????? this.AddFieldItem("Receive", _Receive);
    ???????????? //??????????? this.Insert("smsSended").ToString();
    ???????????? //??????????? Received = true;
    ???????????? //??????? }
    ???????????? //??????? else
    ???????????? //??????? {
    ???????????? //??????????? Received = false;
    ???????????? //??????? }
    ???????????? //??? }
    ???????????? //??? else
    ???????????? //??? {
    ???????????? //??????? Received = false;
    ???????????? //??? }
    ???????????? //}
    ???/// <summary>
    ???/// 審核函數(shù)。將指定表,指定字段的值進(jìn)行翻轉(zhuǎn),如:1->0或0->1。條件由ConditionExpress指定。
    ???/// </summary>
    ???/// <param name="_tableName">表名稱。</param>
    ???/// <param name="_fieldName">字段名稱。</param>
    ???/// <returns>返回影響的行數(shù)。</returns>
    ???public int Audit(string _tableName,string _fieldName)
    ???{
    ????this.tableName=_tableName;
    ????this.fieldName=_fieldName;
    ????this.SqlCmd="update "+this.tableName+" set "+this.fieldName+"=1-"+this.fieldName;
    ????if(this.ConditionExpress!=string.Empty)
    ????{
    ?????this.SqlCmd=this.SqlCmd+" where "+this.ConditionExpress;
    ????}
    ????this.cmd.CommandText=this.SqlCmd;
    ????this.GenParameters();
    ????return cmd.ExecuteNonQuery();
    ???}

    ???/// <summary>
    ???/// 釋放資源
    ???/// </summary>
    ???public void Dispose()
    ???{
    ????conn.Close();
    ???}
    ??
    ??}

    ??/// <summary>
    ??/// 數(shù)據(jù)表中的字段屬性,包括字段名,字段值。
    ??/// 常用于保存要提交的數(shù)據(jù)。
    ??/// </summary>
    ??public class DbKeyItem
    ??{
    ???/// <summary>
    ???/// 構(gòu)造函數(shù)。
    ???/// </summary>
    ???/// <param name="_fieldName">字段名稱。</param>
    ???/// <param name="_fieldValue">字段值。</param>
    ???public DbKeyItem(string _fieldName,object _fieldValue)
    ???{
    ????this.fieldName=_fieldName;
    ????this.fieldValue=_fieldValue.ToString();
    ???}
    ???/// <summary>
    ???/// 字段名稱。
    ???/// </summary>
    ???public string fieldName;
    ???/// <summary>
    ???/// 字段值。
    ???/// </summary>
    ???public string fieldValue;
    ??}
    ?}



    大盤預(yù)測 國富論
    posted on 2007-07-27 11:09 華夢(mèng)行 閱讀(335) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲综合伊人久久大杳蕉| 亚洲AV成人精品日韩一区| 亚洲中文字幕久久久一区| 久久狠狠躁免费观看| 在线看片无码永久免费aⅴ| 亚洲成在人天堂一区二区| 亚洲国产精品无码久久九九大片| 成人久久久观看免费毛片| 国产精品久久久久影院免费| 亚洲中文无码线在线观看| 免费人成大片在线观看播放| 嫩草影院在线免费观看| 激情亚洲一区国产精品| 亚洲国产成人久久综合野外| 美女视频黄a视频全免费网站一区| 午夜老司机免费视频| 99麻豆久久久国产精品免费| 亚洲AV无码之日韩精品| 日韩人妻一区二区三区免费| 亚洲va久久久噜噜噜久久男同| 中国毛片免费观看| 亚洲精品成人片在线播放| 91视频免费观看| 亚洲中文字幕无码久久2020| 亚洲色欲色欲www在线丝| 中国国产高清免费av片| 中文字幕亚洲综合久久综合| 成人免费看黄20分钟| 亚洲成a人片在线不卡一二三区| 亚洲春色在线视频| 美女内射毛片在线看免费人动物| 久久精品a亚洲国产v高清不卡| 无码囯产精品一区二区免费| 亚洲中文久久精品无码1| 亚洲精品亚洲人成在线观看| 日韩免费观看一级毛片看看| 四虎免费影院ww4164h| 亚洲熟妇AV日韩熟妇在线| 亚洲国产精品久久久久婷婷软件| 波多野结衣在线免费视频| 国产综合成人亚洲区|