📄 csqlbuildercomplus.cs
字号:
using System;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.EnterpriseServices;
using System.Reflection;
using System.IO;
[assembly:ApplicationNameAttribute("COM+ DR System")]
/*
作者:何林波
时间:2004年6月2日
作用:利用Com+组件实现通用数据存贮。
*/
namespace ENet.BCL
{
/// <summary>
/// Summary description for CSqlBuilderComPlus.
/// </summary>
[System.EnterpriseServices.TransactionAttribute(System.EnterpriseServices.TransactionOption.Required)]
public class CSqlBuilderComPlus:System.EnterpriseServices.ServicedComponent
{
private string m_TableName="";
private string m_ConnectionString="";
private OleDbCommand m_OleCmd;
private OleDbConnection m_OleConn;
public CSqlBuilderComPlus()
{
//
// TODO: Add constructor logic here
//
}
public string ConnectionString
{
get
{
return this.m_ConnectionString;
}
set
{
this.m_ConnectionString=value;
this.m_OleConn=new OleDbConnection(this.m_ConnectionString);
}
}
public bool CreateSQL(string TableName,string ActiveConnection)
{
try
{
this.m_TableName=TableName;
this.m_ConnectionString=ActiveConnection;
this.m_OleConn=new OleDbConnection(this.m_ConnectionString);
return true;
}
catch
{
return false;
}
}
private void ExecuteSql(OleDbCommand OleCmd,string StrSql)
{
OleCmd.CommandText=StrSql;
OleCmd.CommandType=CommandType.Text;
OleCmd.ExecuteNonQuery();
}
[System.EnterpriseServices.AutoComplete()]
public void ExecuteSql(string StrSql)
{
this.m_OleConn.Open();
this.m_OleCmd=new OleDbCommand();
this.m_OleCmd.Connection=this.m_OleConn;
this.m_OleCmd.CommandType=System.Data.CommandType.Text;
this.m_OleCmd.CommandText=StrSql;
this.m_OleCmd.ExecuteNonQuery();
this.m_OleConn.Close();
}
private void AppendFields(OleDbCommand OleCmd,Hashtable hsValue)
{
string FieldSql="";
string ValueSql="";
OleCmd.Parameters.Clear();
foreach(DictionaryEntry entry in hsValue)
{
FieldSql+=entry.Key.ToString()+",";
ValueSql+="?,";
OleCmd.Parameters.Add(entry.Key.ToString(),entry.Value);
}
FieldSql=FieldSql.Substring(0,FieldSql.Length-1);
ValueSql=ValueSql.Substring(0,ValueSql.Length-1);
string StrSql="";
StrSql="Insert into "+this.m_TableName+"("+FieldSql+")";
StrSql+=" Values("+ValueSql+")";
OleCmd.CommandText=StrSql;
OleCmd.CommandType=CommandType.Text;
OleCmd.ExecuteNonQuery();
}
[System.EnterpriseServices.AutoComplete()]
public bool SQLInserSingleRow(Hashtable hsData)
{
if(hsData.Count==0)
{
return false;
}
this.m_OleConn.Open();
this.m_OleCmd=new OleDbCommand();
this.m_OleCmd.Connection=this.m_OleConn;
AppendFields(m_OleCmd,hsData);
this.m_OleConn.Close();
return true;
}
[System.EnterpriseServices.AutoComplete()]
public bool SQLInserSingleRow(Hashtable hsData,string exeSql)
{
if(hsData.Count==0)
{
return false;
}
this.m_OleConn.Open();
this.m_OleCmd=new OleDbCommand();
this.m_OleCmd.Connection=this.m_OleConn;
if(exeSql!="")
this.ExecuteSql(this.m_OleCmd,exeSql);
AppendFields(m_OleCmd,hsData);
this.m_OleConn.Close();
return true;
}
[System.EnterpriseServices.AutoComplete()]
public DataTable GetDataTable(string StrSql)
{
this.m_OleConn.Open();
this.m_OleCmd=new OleDbCommand();
this.m_OleCmd.Connection=this.m_OleConn;
this.m_OleCmd.CommandType=System.Data.CommandType.Text;
this.m_OleCmd.CommandText=StrSql;
System.Data.OleDb.OleDbDataAdapter oda=new OleDbDataAdapter(this.m_OleCmd);
DataTable Dt=new DataTable();
oda.Fill(Dt);
this.m_OleConn.Close();
return Dt;
}
[System.EnterpriseServices.AutoComplete()]
public DataSet GetDataSet(string StrSql)
{
this.m_OleConn.Open();
this.m_OleCmd=new OleDbCommand();
this.m_OleCmd.Connection=this.m_OleConn;
this.m_OleCmd.CommandType=System.Data.CommandType.Text;
this.m_OleCmd.CommandText=StrSql;
System.Data.OleDb.OleDbDataAdapter oda=new OleDbDataAdapter(this.m_OleCmd);
DataSet ds=new DataSet();
oda.Fill(ds);
this.m_OleConn.Close();
return ds;
}
[System.EnterpriseServices.AutoComplete()]
public bool SQLInsertMutiRow(Hashtable hsData)
{
if(hsData.Count==0)
{
return false;
}
this.m_OleConn.Open();
this.m_OleCmd=new OleDbCommand();
this.m_OleCmd.Connection=this.m_OleConn;
foreach(DictionaryEntry entry in hsData)
{
AppendFields(m_OleCmd,(Hashtable)entry.Value);
}
this.m_OleConn.Close();
return true;
}
[System.EnterpriseServices.AutoComplete()]
public bool SQLInsertMutiRow(Hashtable hsData,string exeSql)
{
if(hsData.Count==0)
{
return false;
}
this.m_OleConn.Open();
this.m_OleCmd=new OleDbCommand();
this.m_OleCmd.Connection=this.m_OleConn;
if(exeSql!="")
this.ExecuteSql(this.m_OleCmd,exeSql);
foreach(DictionaryEntry entry in hsData)
{
AppendFields(m_OleCmd,(Hashtable)entry.Value);
}
this.m_OleConn.Close();
return true;
}
public bool IsManager()
{
SecurityCallContext ObjCallContext=SecurityCallContext.CurrentCall;
return ObjCallContext.IsCallerInRole("Managers");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -