【苏飞分布式数据框架】V2.0.1版本发布新增UtilDAL类和BaseModel类
下载网址:
http://www.sufeinet.com/thread-10549-1-1.html
新增加了增加UtilDAL类,具体如上
[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
namespace SufeiDistributedBLL
{
/// <summary>
/// SQl参数帮助类
/// </summary>
public static class UtilDAL
{
/// <summary>
/// 获取SQl参数名
/// </summary>
/// <param name="name">字段名</param>
/// <returns>不管带不带@都会自动添加并返回带@的参数</returns>
private static string GetParameterName(string name)
{
if (name.StartsWith("@"))
{
return name;
}
return "@" + name;
}
/// <summary>
/// 创建一个普通参数对象
/// </summary>
/// <param name="name">参数名,@带不带都行会自动填充</param>
/// <param name="value">列的值</param>
/// <returns>得到SqlParameter对象</returns>
public static SqlParameter CreateParameter(string name, object value)
{
name = UtilDAL.GetParameterName(name);
if (value == null)
{
return new SqlParameter(name, DBNull.Value);
}
return new SqlParameter(name, value);
}
/// <summary>
/// 创建一个output参数对象
/// </summary>
/// <param name="name">参数名,@带不带都行会自动填充</param>
/// <param name="dbType">参数的类型</param>
/// <returns>得到SqlParameter对象</returns>
public static SqlParameter CreateOutParameter(string name, SqlDbType dbType)
{
name = UtilDAL.GetParameterName(name);
var p = new SqlParameter(name, dbType);
p.Direction = ParameterDirection.Output;
return p;
}
/// <summary>
/// 创建一个Return参数对象,默认名称为@ret
/// </summary>
/// <param name="dbType">数据类型</param>
/// <returns>得到SqlParameter对象</returns>
public static SqlParameter CreateReturnParameter(SqlDbType dbType)
{
return CreateReturnParameter("@ret", dbType);
}
/// <summary>
/// 创建一个Return参数对象
/// </summary>
/// <param name="name">参数名</param>
/// <param name="dbType">数据类型</param>
/// <returns>得到SqlParameter对象</returns>
public static SqlParameter CreateReturnParameter(string name, SqlDbType dbType)
{
name = UtilDAL.GetParameterName(name);
var p = new SqlParameter(name, dbType);
p.Direction = ParameterDirection.ReturnValue;
return p;
}
}
}
增加BaseModel类
[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SufeiDistributedModel
{
/// <summary>
/// 模型层附加数据基类
/// </summary>
[Serializable]
public class BaseModel
{
private Dictionary<string, object> _exData = new Dictionary<string, object>();
/// <summary>
/// 附件数据
/// </summary>
public Dictionary<string, object> ExData
{
get { return _exData; }
set { _exData = value; }
}
/// <summary>
/// 得到附加数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="name"></param>
/// <returns></returns>
public T GetExData<T>(string name)
{
object data;
if (_exData.TryGetValue(name, out data))
{
return (T)data;
}
return default(T);
}
/// <summary>
/// 添加附加数据
/// </summary>
/// <param name="name"></param>
/// <param name="obj"></param>
public void AddExData(string name, object obj)
{
_exData.Add(name, obj);
}
/// <summary>
/// 检测附加数据是否存在
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public bool ExistsExData(string name)
{
return _exData.ContainsKey(name);
}
}
}
|