Skip to content

Commit

Permalink
add new project
Browse files Browse the repository at this point in the history
  • Loading branch information
daowzq committed Nov 23, 2014
1 parent 00a4ba8 commit 7dee25d
Show file tree
Hide file tree
Showing 32 changed files with 5,954 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Razor/DBUtility/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("Maticsoft.DBUtility(20090623)")]
[assembly: AssemblyDescription("Data Access Application Model By LiTianPing")]
[assembly: AssemblyConfiguration("LiTianPing")]
[assembly: AssemblyCompany("Maticsoft")]
[assembly: AssemblyProduct("Maticsoft.DBUtility")]
[assembly: AssemblyCopyright("Copyright (C) Maticsoft 2004-2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("3.5.0")]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
262 changes: 262 additions & 0 deletions Razor/DBUtility/BaseSqlMapDao.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;

using IBatisNet.Common;
using IBatisNet.Common.Pagination;
using IBatisNet.DataMapper;
using IBatisNet.DataMapper.Exceptions;
using IBatisNet.DataMapper.Configuration;

namespace Maticsoft.DBUtility
{
/// <summary>
/// 基于IBatisNet的数据访问基类
/// </summary>
public class BaseSqlMapDao
{
private ISqlMapper sqlMap;
public BaseSqlMapDao()
{
//DomSqlMapBuilder builder = new DomSqlMapBuilder(true);
//sqlMap = builder.Configure();

Assembly assembly = Assembly.Load("IBatisNetDemo");
Stream stream = assembly.GetManifestResourceStream("IBatisNetDemo.sqlmap.config");

DomSqlMapBuilder builder = new DomSqlMapBuilder();
sqlMap = builder.Configure(stream);
}

///// <summary>
///// IsqlMapper实例
///// </summary>
///// <returns></returns>
//public static ISqlMapper sqlMap = (ContainerAccessorUtil.GetContainer())["sqlServerSqlMap"] as ISqlMapper;

//public SqlMapper SqlMap
//{
// get
// {
// Assembly assembly = Assembly.Load("IBatisNetDemo");
// Stream stream = assembly.GetManifestResourceStream("IBatisNetDemo.sqlmap.config");

// DomSqlMapBuilder builder = new DomSqlMapBuilder();
// builder.
// SqlMapper sqlMap = builder.Configure(stream);
// }
//}

/// <summary>
/// 得到列表
/// </summary>
/// <typeparam name="T">实体类型</typeparam>
/// <param name="statementName">操作名称,对应xml中的Statement的id</param>
/// <param name="parameterObject">参数</param>
/// <returns></returns>
protected IList<T> ExecuteQueryForList<T>(string statementName, object parameterObject)
{
try
{
return sqlMap.QueryForList<T>(statementName, parameterObject);
}
catch (Exception e)
{
throw new DataMapperException("Error executing query '" + statementName + "' for list. Cause: " + e.Message, e);
}
}

/// <summary>
/// 得到指定数量的记录数
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="statementName"></param>
/// <param name="parameterObject">参数</param>
/// <param name="skipResults">跳过的记录数</param>
/// <param name="maxResults">最大返回的记录数</param>
/// <returns></returns>
protected IList<T> ExecuteQueryForList<T>(string statementName, object parameterObject, int skipResults, int maxResults)
{
try
{
return sqlMap.QueryForList<T>(statementName, parameterObject, skipResults, maxResults);
}
catch (Exception e)
{
throw new DataMapperException("Error executing query '" + statementName + "' for list. Cause: " + e.Message, e);
}
}

/// <summary>
/// 得到分页的列表
/// </summary>
/// <param name="statementName">操作名称</param>
/// <param name="parameterObject">参数</param>
/// <param name="pageSize">每页记录数</param>
/// <returns></returns>
protected IPaginatedList ExecuteQueryForPaginatedList(string statementName, object parameterObject, int pageSize)
{
try
{
return sqlMap.QueryForPaginatedList(statementName, parameterObject, pageSize);
}
catch (Exception e)
{
throw new DataMapperException("Error executing query '" + statementName + "' for paginated list. Cause: " + e.Message, e);
}
}

/// <summary>
/// 查询得到对象的一个实例
/// </summary>
/// <typeparam name="T">对象type</typeparam>
/// <param name="statementName">操作名</param>
/// <param name="parameterObject">参数</param>
/// <returns></returns>
protected T ExecuteQueryForObject<T>(string statementName, object parameterObject)
{
try
{
return sqlMap.QueryForObject<T>(statementName, parameterObject);
}
catch (Exception e)
{
throw new DataMapperException("Error executing query '" + statementName + "' for object. Cause: " + e.Message, e);
}
}

/// <summary>
/// 执行添加
/// </summary>
/// <param name="statementName">操作名</param>
/// <param name="parameterObject">参数</param>
protected void ExecuteInsert(string statementName, object parameterObject)
{
try
{
sqlMap.Insert(statementName, parameterObject);
}
catch (Exception e)
{
throw new DataMapperException("Error executing query '" + statementName + "' for insert. Cause: " + e.Message, e);
}
}

/// <summary>
/// 执行修改
/// </summary>
/// <param name="statementName">操作名</param>
/// <param name="parameterObject">参数</param>
protected void ExecuteUpdate(string statementName, object parameterObject)
{
try
{
sqlMap.Update(statementName, parameterObject);
}
catch (Exception e)
{
throw new DataMapperException("Error executing query '" + statementName + "' for update. Cause: " + e.Message, e);
}
}

/// <summary>
/// 执行删除
/// </summary>
/// <param name="statementName">操作名</param>
/// <param name="parameterObject">参数</param>
protected void ExecuteDelete(string statementName, object parameterObject)
{
try
{
sqlMap.Delete(statementName, parameterObject);
}
catch (Exception e)
{
throw new DataMapperException("Error executing query '" + statementName + "' for delete. Cause: " + e.Message, e);
}
}

///// <summary>
///// 得到流水号
///// </summary>
///// <param name="tableName">表名</param>
///// <returns></returns>
//public int GetId(string tableName)
//{
// try
// {
// Stream stream = sqlMap.QueryForObject("GetStreamId", tableName) as Stream;
// return stream.IMaxID;
// }
// catch (Exception e)
// {
// throw (e);
// }
//}

}


///// <summary>
///// Stream
///// </summary>
//public class Stream
//{
// public Stream()
// {

// }

// private string ctablename;

// public string CTableName
// {
// get { return ctablename; }
// set { ctablename = value; }
// }
// private int imaxid;

// public int IMaxID
// {
// get { return imaxid; }
// set { imaxid = value; }
// }
//}

//public class ContainerAccessorUtil
//{
// private ContainerAccessorUtil()
// {
// }

// /// <summary>
// /// Obtain the Cuyahoga container.
// /// </summary>
// /// <returns></returns>
// public static IWindsorContainer GetContainer()
// {
// IContainerAccessor containerAccessor = HttpContext.Current.ApplicationInstance as IContainerAccessor;

// if (containerAccessor == null)
// {
// throw new Exception("You must extend the HttpApplication in your web project " +
// "and implement the IContainerAccessor to properly expose your container instance");
// }

// IWindsorContainer container = containerAccessor.Container as IWindsorContainer;

// if (container == null)
// {
// throw new Exception("The container seems to be unavailable in " +
// "your HttpApplication subclass");
// }

// return container;
// }
//}


}
72 changes: 72 additions & 0 deletions Razor/DBUtility/CommandInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace Maticsoft.DBUtility
{
public enum EffentNextType
{
/// <summary>
/// 对其他语句无任何影响
/// </summary>
None,
/// <summary>
/// 当前语句必须为"select count(1) from .."格式,如果存在则继续执行,不存在回滚事务
/// </summary>
WhenHaveContine,
/// <summary>
/// 当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
/// </summary>
WhenNoHaveContine,
/// <summary>
/// 当前语句影响到的行数必须大于0,否则回滚事务
/// </summary>
ExcuteEffectRows,
/// <summary>
/// 引发事件-当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
/// </summary>
SolicitationEvent
}
public class CommandInfo
{
public object ShareObject = null;
public object OriginalData = null;
event EventHandler _solicitationEvent;
public event EventHandler SolicitationEvent
{
add
{
_solicitationEvent += value;
}
remove
{
_solicitationEvent -= value;
}
}
public void OnSolicitationEvent()
{
if (_solicitationEvent != null)
{
_solicitationEvent(this,new EventArgs());
}
}
public string CommandText;
public System.Data.Common.DbParameter[] Parameters;
public EffentNextType EffentNextType = EffentNextType.None;
public CommandInfo()
{

}
public CommandInfo(string sqlText, SqlParameter[] para)
{
this.CommandText = sqlText;
this.Parameters = para;
}
public CommandInfo(string sqlText, SqlParameter[] para, EffentNextType type)
{
this.CommandText = sqlText;
this.Parameters = para;
this.EffentNextType = type;
}
}
}
Loading

0 comments on commit 7dee25d

Please sign in to comment.