编写OracleMembershipProvider,让SharePoint2007使用Oralce中的用户数据实现Form验证。 (第三天)

最近好忙呀,一直没有完整的时间来安静的编写OracleMembershipProvider,周末领导都去开会了,终于可以偷点时间出来写这个东东了,因为MembershipProvider接口众多,实现起来代码量大,所以下面列出的代码仅仅是截止发帖时部分完成的代码,后续几天还会继续编写,以下代码并未测试,打算所有实现写完后再测试,为了方便大家读代码,我尽量多多添加注释,自定义函数的注释是自己编写的,MembershipProvider的成员注释全部来源于MSDN。

项目里有两个类,OracleMembershipProvider是继承并实现抽象类MembershipProvider并扩充了一些辅助成员,OracleTools是自己定义的一些与Oracle交互的基础成员。

OracleMembershipProvider

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace BoooLee
{
    
class OracleTools
    
{
        
/// <summary>
        
/// 私有变量
        
/// </summary>

        private string _ConnectionString = "";  //数据库连接串


        
/// <summary>
        
/// 数据库连接串
        
/// </summary>

        public string ConnectionString
        
{
            
get
            
{
                
return _ConnectionString;
            }


            
set
            
{
                _ConnectionString
=value;
            }

        }


        
/// <summary>
        
/// 运行无返回值的Sql语句。
        
/// </summary>
        
/// <param name="SqlString">指定要运行的Sql语句。</param>
        
/// <param name="Conn">指定数据库连接。</param>
        
/// <returns>成功返回true,失败返回false。</returns>

        public bool RunSqlNonQuery(string SqlString)
        
{
            OleDbConnection Conn
=null;

            
try
            
{
                
using (OleDbCommand Command = new OleDbCommand())
                
{
                    Command.CommandText 
= SqlString;
                    Conn 
= GetConnection();
                    Conn.Open();
                    Command.Connection 
= Conn;                    
                    Command.ExecuteNonQuery();
                }

                
return true;
            }

            
catch (Exception)
            
{
                
return false;
            }

            
finally 
            
{
                
//关闭数据库连接
                if (Conn != null && Conn.State==ConnectionState.Open)
                    Conn.Close();
            }

        }


        
/// <summary>
        
/// 运行返回一个值的Select语句。
        
/// </summary>
        
/// <param name="SqlString">指定要运行的Sql语句。</param>
        
/// <param name="Conn">指定数据库连接。</param>
        
/// <returns>成功返回Select语句结果,失败返回空字符串。</returns>

        public string RunSqlScalar(string SqlString)
        
{
            OleDbConnection Conn 
= null;

            
try
            
{
                Conn 
= GetConnection();
                Conn.Open();

                
using (OleDbCommand Command = new OleDbCommand())
                
{
                    Command.CommandText 
= SqlString;
                    Command.Connection 
= Conn;
                    
return Command.ExecuteScalar().ToString();
                }

            }

            
catch (Exception)
            
{
                
return "";
            }

            
finally
            
{
                
if (Conn != null && Conn.State == ConnectionState.Open)
                    Conn.Close();
            }

        }


        
/// <summary>
        
/// 运行返回DataTable的Sql语句。
        
/// </summary>
        
/// <param name="SqlString">指定要运行的Sql语句。</param>
        
/// <param name="Conn">指定数据库连接。</param>
        
/// <returns>成功返回Select语句结果DataTable。</returns>

        public DataTable RunSqlDataTable(string SqlString)
        
{
            OleDbConnection Conn 
= null;

            
try
            
{
                
using (OleDbDataAdapter DataAdapter = new OleDbDataAdapter())
                
{
                    Conn 
= GetConnection();
                    Conn.Open();
                    OleDbCommand SC 
= new OleDbCommand();
                    SC.CommandText 
= SqlString;
                    SC.Connection 
= Conn;
                    DataAdapter.SelectCommand 
= SC;
                    DataTable dt 
= new DataTable();
                    DataAdapter.Fill(dt);
                    
return dt;
                }

            }

            
catch (Exception)
            
{
                
return new DataTable();
            }

            
finally
            
{
                
if (Conn != null && Conn.State == ConnectionState.Open)
                    Conn.Close();
            }

        }


        
/// <summary>
        
/// 返回一个OleDbConnection对象。
        
/// </summary>
        
/// <returns>成功返回的OleDbConnection对象,失败返回null。</returns>

        public OleDbConnection GetConnection()
        
{
            
try
            
{
                OleDbConnection result 
= new OleDbConnection();
                result.ConnectionString 
= _ConnectionString;
                
return result;
            }

            
catch (Exception)
            
{
                
return null;
            }

        }

    }

}


废话时间:
昨天跟伙计去了一个傣家菜馆,虽然经常去,但昨天有些特别,特别到哪里呢,俺终于鼓足勇气点了一盘竹虫,

看着蛮XX的,把在座的其他几个伙计看的好难受,俺也有点怕了,吃还是不吃呢???我让服务员先吃一个给我看,没想到女服务还真大方,抓起一个就吃,好象很享受的样子,俺心想,人家女子都吃列,大老爷们还怕啥,吃!!!


哈哈,还真香,有点蚕蛹的味道,都是高蛋白嘛,这么一小碟不便宜呢,除了给老婆硬吃了一条,其他全被我吃光了,边喝小酒边吃虫子,乐哉!乐哉!
posted @ 2007-01-26 17:38  电电儿  阅读(1497)  评论(4编辑  收藏  举报