初始化
This commit is contained in:
22
Face.DBUtility/App.config
Normal file
22
Face.DBUtility/App.config
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</configSections>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
|
||||
<parameters>
|
||||
<parameter value="mssqllocaldb" />
|
||||
</parameters>
|
||||
</defaultConnectionFactory>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
|
||||
</entityFramework>
|
||||
<system.data>
|
||||
<DbProviderFactories>
|
||||
<remove invariant="MySql.Data.MySqlClient" />
|
||||
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
|
||||
</DbProviderFactories>
|
||||
</system.data></configuration>
|
||||
75
Face.DBUtility/CommandInfo.cs
Normal file
75
Face.DBUtility/CommandInfo.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AUTS.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, MySqlParameter[] para)
|
||||
{
|
||||
this.CommandText = sqlText;
|
||||
this.Parameters = para;
|
||||
}
|
||||
public CommandInfo(string sqlText, MySqlParameter[] para, EffentNextType type)
|
||||
{
|
||||
this.CommandText = sqlText;
|
||||
this.Parameters = para;
|
||||
this.EffentNextType = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
323
Face.DBUtility/Common/DALHelper.cs
Normal file
323
Face.DBUtility/Common/DALHelper.cs
Normal file
@@ -0,0 +1,323 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AUTS.DBUtility
|
||||
{
|
||||
public class DALHelper<TEntity> where TEntity : class, new()
|
||||
{
|
||||
private string databasetablename; //数据库表名前缀
|
||||
|
||||
//private DbConfigsInfo confInfi;
|
||||
|
||||
public DALHelper()
|
||||
{
|
||||
databasetablename = "TBL_UTS_Manage";
|
||||
}
|
||||
public DALHelper(string _databaseprefix)
|
||||
{
|
||||
databasetablename = _databaseprefix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在该记录
|
||||
/// </summary>
|
||||
public bool Exists(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select count(1) from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
return DbHelperMySQL.Exists(strSql.ToString(), parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到最大ID
|
||||
/// </summary>
|
||||
public int GetMaxId(TEntity entity, string strField)
|
||||
{
|
||||
return DbHelperMySQL.GetMaxID(strField, databasetablename);
|
||||
}
|
||||
|
||||
public bool Add(TEntity entity)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("insert into " + databasetablename + "(");
|
||||
|
||||
PropertyInfo[] propertys = entity.GetType().GetProperties();// 获得此模型的公共属性
|
||||
|
||||
List<MySqlParameter> parameters = new List<MySqlParameter>();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
strSql.Append(pi.Name + ",");
|
||||
strSql.Append(" values (");
|
||||
}
|
||||
strSql.Append(" ) values (");
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
strSql.Append(pi.Name + "@,");
|
||||
parameters.Add(new MySqlParameter("@" + pi.Name, pi.GetValue(entity)));
|
||||
}
|
||||
strSql.Append(");select @@IDENTITY");
|
||||
int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters.ToArray());
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改一个实体数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="strField"></param>
|
||||
/// <param name="keyValue"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("update " + databasetablename + " set ");
|
||||
|
||||
PropertyInfo[] propertys = entity.GetType().GetProperties();// 获得此模型的公共属性
|
||||
|
||||
List<MySqlParameter> parameters = new List<MySqlParameter>();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
strSql.Append(pi.Name + "=@" + pi.Name + ",");
|
||||
parameters.Add(new MySqlParameter("@" + pi.Name, pi.GetValue(entity)));
|
||||
}
|
||||
strSql.Append(" where " + strField + "=@strValue");
|
||||
parameters.Add(new MySqlParameter("@strValue", keyValue));
|
||||
int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters.ToArray());
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改一列数据
|
||||
/// </summary>
|
||||
public int UpdateField(TEntity entity, string strField, object strValue, string strWhere)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("update " + databasetablename);
|
||||
strSql.Append(" set " + strField + "=@strValue");
|
||||
if (!string.IsNullOrEmpty(strWhere))
|
||||
{
|
||||
strSql.Append(" where " + strWhere);
|
||||
}
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@strValue",strValue)
|
||||
};
|
||||
|
||||
return DbHelperMySQL.ExecuteSql(strSql.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除一条数据
|
||||
/// </summary>
|
||||
public bool Delete(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("delete from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
|
||||
int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到一个对象实体
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <returns></returns>
|
||||
public TEntity GetModel(TEntity entity, string strField, string keyValue)
|
||||
{
|
||||
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select * from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
strSql.Append(" LIMIT 0,1;");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
|
||||
DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModel(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<TEntity> GetList(string strWhere = null)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select * from " + databasetablename);
|
||||
if (!string.IsNullOrEmpty(strWhere))
|
||||
{
|
||||
strSql.Append(" where " + strWhere);
|
||||
}
|
||||
//strSql.Append(" LIMIT 0,1;");
|
||||
TEntity entity = new TEntity();
|
||||
DataSet ds = DbHelperMySQL.Query(strSql.ToString());
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModels(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable转换得到一个对象实体
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public TEntity DataRowToModel(TEntity model, DataTable dt)
|
||||
{
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
TEntity t = new TEntity();
|
||||
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (dt.Columns.Contains(pi.Name))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
var value = dt.Rows[0][pi.Name];
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
switch (pi.PropertyType.FullName)
|
||||
{
|
||||
case "System.Decimal":
|
||||
pi.SetValue(t, decimal.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.String":
|
||||
pi.SetValue(t, value.ToString(), null);
|
||||
break;
|
||||
case "System.Single":
|
||||
pi.SetValue(t, float.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Double":
|
||||
pi.SetValue(t, double.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Int32":
|
||||
pi.SetValue(t, int.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.DateTime":
|
||||
pi.SetValue(t, DateTime.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
pi.SetValue(t, bool.Parse(value.ToString()), null);
|
||||
break;
|
||||
default:
|
||||
pi.SetValue(t, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable转换得到一个对象实体集合
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public List<TEntity> DataRowToModels(TEntity model, DataTable dt)
|
||||
{
|
||||
List<TEntity> ts = new List<TEntity>();// 定义集合
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
TEntity t = new TEntity();
|
||||
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (dt.Columns.Contains(pi.Name))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
var value = dr[pi.Name];
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
switch (pi.PropertyType.FullName)
|
||||
{
|
||||
case "System.Decimal":
|
||||
pi.SetValue(t, decimal.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.String":
|
||||
pi.SetValue(t, value.ToString(), null);
|
||||
break;
|
||||
case "System.Single":
|
||||
pi.SetValue(t, float.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Double":
|
||||
pi.SetValue(t, double.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Int32":
|
||||
pi.SetValue(t, int.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.DateTime":
|
||||
pi.SetValue(t, DateTime.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
pi.SetValue(t, bool.Parse(value.ToString()), null);
|
||||
break;
|
||||
default:
|
||||
pi.SetValue(t, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ts.Add(t);
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
1191
Face.DBUtility/Common/DbHelperMySQL.cs
Normal file
1191
Face.DBUtility/Common/DbHelperMySQL.cs
Normal file
File diff suppressed because it is too large
Load Diff
351
Face.DBUtility/Custom/DALHelperCustom.cs
Normal file
351
Face.DBUtility/Custom/DALHelperCustom.cs
Normal file
@@ -0,0 +1,351 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AUTS.DBUtility
|
||||
{
|
||||
public class DALHelperCustom<TEntity> where TEntity : class, new()
|
||||
{
|
||||
private string databasetablename; //数据库表名前缀
|
||||
|
||||
//private DbConfigsInfo confInfi;
|
||||
|
||||
public DALHelperCustom()
|
||||
{
|
||||
databasetablename = "TBL_UTS_Manage";
|
||||
}
|
||||
public DALHelperCustom(string _databaseprefix)
|
||||
{
|
||||
databasetablename = _databaseprefix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在该记录
|
||||
/// </summary>
|
||||
public bool Exists(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select count(1) from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
return DbHelperMySqlCustom.Exists(strSql.ToString(), parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到最大ID
|
||||
/// </summary>
|
||||
public int GetMaxId(TEntity entity, string strField)
|
||||
{
|
||||
return DbHelperMySqlCustom.GetMaxID(strField, databasetablename);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一条数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public bool Add(TEntity entity)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("insert into " + databasetablename + "(");
|
||||
|
||||
PropertyInfo[] propertys = entity.GetType().GetProperties();// 获得此模型的公共属性
|
||||
|
||||
List<MySqlParameter> parameters = new List<MySqlParameter>();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
strSql.Append(pi.Name + ",");
|
||||
}
|
||||
strSql.Remove(strSql.Length - 1, 1);//移除最后一个逗号
|
||||
strSql.Append(" ) values (");
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
strSql.Append("@" + pi.Name + ",");
|
||||
parameters.Add(new MySqlParameter("@" + pi.Name, pi.GetValue(entity)));
|
||||
}
|
||||
strSql.Remove(strSql.Length - 1, 1);//移除最后一个逗号
|
||||
strSql.Append(");select @@IDENTITY");
|
||||
int rows = DbHelperMySqlCustom.ExecuteSql(strSql.ToString(), parameters.ToArray());
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改一列数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="strField"></param>
|
||||
/// <param name="keyValue"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("update " + databasetablename + " set ");
|
||||
|
||||
PropertyInfo[] propertys = entity.GetType().GetProperties();// 获得此模型的公共属性
|
||||
|
||||
List<MySqlParameter> parameters = new List<MySqlParameter>();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
strSql.Append(pi.Name + "=@" + pi.Name + ",");
|
||||
parameters.Add(new MySqlParameter("@" + pi.Name, pi.GetValue(entity)));
|
||||
}
|
||||
strSql.Remove(strSql.Length - 1, 1);//移除最后一个逗号
|
||||
strSql.Append(" where " + strField + "=@strValue");
|
||||
|
||||
System.Type keyType = keyValue.GetType();
|
||||
switch (keyType.Name)
|
||||
{
|
||||
case "Int32":
|
||||
MySqlParameter strValue = new MySqlParameter("@strValue", MySqlDbType.Int32)
|
||||
{
|
||||
Value = keyValue
|
||||
};
|
||||
parameters.Add(strValue);
|
||||
break;
|
||||
default:
|
||||
parameters.Add(new MySqlParameter("@strValue", keyValue));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
int rows = DbHelperMySqlCustom.ExecuteSql(strSql.ToString(), parameters.ToArray());
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改一列数据
|
||||
/// </summary>
|
||||
public int UpdateField(TEntity entity, string strField, object strValue, string strWhere)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("update " + databasetablename);
|
||||
strSql.Append(" set " + strField + "=@strValue");
|
||||
if (!string.IsNullOrEmpty(strWhere))
|
||||
{
|
||||
strSql.Append(" where " + strWhere);
|
||||
}
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@strValue",strValue)
|
||||
};
|
||||
|
||||
return DbHelperMySqlCustom.ExecuteSql(strSql.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除一条数据
|
||||
/// </summary>
|
||||
public bool Delete(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("delete from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
|
||||
int rows = DbHelperMySqlCustom.ExecuteSql(strSql.ToString(), parameters);
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到一个对象实体
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <returns></returns>
|
||||
public TEntity GetModel(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select * from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
strSql.Append(" LIMIT 0,1;");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
|
||||
DataSet ds = DbHelperMySqlCustom.Query(strSql.ToString(), parameters);
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModel(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到数据列表
|
||||
/// </summary>
|
||||
/// <param name="strWhere"></param>
|
||||
/// <returns></returns>
|
||||
public List<TEntity> GetList(string strWhere = null)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select * from " + databasetablename);
|
||||
if (!string.IsNullOrEmpty(strWhere))
|
||||
{
|
||||
strSql.Append(" where " + strWhere);
|
||||
}
|
||||
//strSql.Append(" LIMIT 0,1;");
|
||||
TEntity entity = new TEntity();
|
||||
DataSet ds = DbHelperMySqlCustom.Query(strSql.ToString());
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModels(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable转换得到一个对象实体
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public TEntity DataRowToModel(TEntity model, DataTable dt)
|
||||
{
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
TEntity t = new TEntity();
|
||||
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (dt.Columns.Contains(pi.Name))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
var value = dt.Rows[0][pi.Name];
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
switch (pi.PropertyType.FullName)
|
||||
{
|
||||
case "System.Decimal":
|
||||
pi.SetValue(t, decimal.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.String":
|
||||
pi.SetValue(t, value.ToString(), null);
|
||||
break;
|
||||
case "System.Single":
|
||||
pi.SetValue(t, float.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Double":
|
||||
pi.SetValue(t, double.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Int32":
|
||||
pi.SetValue(t, int.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.DateTime":
|
||||
pi.SetValue(t, DateTime.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
pi.SetValue(t, bool.Parse(value.ToString()), null);
|
||||
break;
|
||||
default:
|
||||
pi.SetValue(t, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable转换得到一个对象实体集合
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public List<TEntity> DataRowToModels(TEntity model, DataTable dt)
|
||||
{
|
||||
List<TEntity> ts = new List<TEntity>();// 定义集合
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
TEntity t = new TEntity();
|
||||
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (dt.Columns.Contains(pi.Name))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
var value = dr[pi.Name];
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
switch (pi.PropertyType.FullName)
|
||||
{
|
||||
case "System.Decimal":
|
||||
pi.SetValue(t, decimal.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.String":
|
||||
pi.SetValue(t, value.ToString(), null);
|
||||
break;
|
||||
case "System.Single":
|
||||
pi.SetValue(t, float.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Double":
|
||||
pi.SetValue(t, double.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Int32":
|
||||
pi.SetValue(t, int.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.DateTime":
|
||||
pi.SetValue(t, DateTime.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
pi.SetValue(t, bool.Parse(value.ToString()), null);
|
||||
break;
|
||||
default:
|
||||
pi.SetValue(t, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ts.Add(t);
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
1215
Face.DBUtility/Custom/DbHelperMySqlCustom.cs
Normal file
1215
Face.DBUtility/Custom/DbHelperMySqlCustom.cs
Normal file
File diff suppressed because it is too large
Load Diff
58
Face.DBUtility/DbConfigsInfo.cs
Normal file
58
Face.DBUtility/DbConfigsInfo.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using AUTS.Domain.Application;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AUTS.DBUtility
|
||||
{
|
||||
public partial class DbConfigsInfo
|
||||
{
|
||||
|
||||
private static string onUserOperationSessionName = "UserOperationSessionName";//用户当前选择库
|
||||
|
||||
private static List<DBCofinStrModel> cacheSysDBCofinStrList
|
||||
{
|
||||
// get选择器获取Lazyk懒加载数据
|
||||
get { return AUTS.Services.Cache.CacheHelp.GetDBCofinStrList(); }
|
||||
}
|
||||
|
||||
#region 获取用户当前选择库数据库连接串
|
||||
/// <summary>
|
||||
/// 获取用户当前选择库信息
|
||||
/// </summary>
|
||||
/// <param name="userID">用户ID</param>
|
||||
/// <returns></returns>
|
||||
public static DBCofinStrModel GerOnUserDBCofinStr()
|
||||
{
|
||||
//var dbList = CacheHelp.GetSysDBList();
|
||||
|
||||
var onCustomer = System.Web.HttpContext.Current.Session[onUserOperationSessionName];
|
||||
if (onCustomer != null)
|
||||
{
|
||||
return cacheSysDBCofinStrList.SingleOrDefault(x => x.ID == (int)onCustomer);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取用户当前选择数据库连接串
|
||||
/// <summary>
|
||||
/// 获取用户当前选择数据库连接串
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GerOnUserCofin()
|
||||
{
|
||||
var connectionString = "";
|
||||
connectionString = GerOnUserDBCofinStr().CofinStr;
|
||||
if (!String.IsNullOrEmpty(connectionString))
|
||||
{
|
||||
return connectionString;
|
||||
}
|
||||
|
||||
return System.Configuration.ConfigurationManager.ConnectionStrings["Uts_Manage"].ConnectionString;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
86
Face.DBUtility/Face.DBUtility.csproj
Normal file
86
Face.DBUtility/Face.DBUtility.csproj
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{2D329474-A40D-47BA-9CAD-036A794E80DD}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>AUTS.DBUtility</RootNamespace>
|
||||
<AssemblyName>AUTS.DBUtility</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.6.9.12\lib\net45\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data.Entity.EF6, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.Entity.6.9.12\lib\net45\MySql.Data.Entity.EF6.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CommandInfo.cs" />
|
||||
<Compile Include="Common\DALHelper.cs" />
|
||||
<Compile Include="Custom\DALHelperCustom.cs" />
|
||||
<Compile Include="DbConfigsInfo.cs" />
|
||||
<Compile Include="Common\DbHelperMySQL.cs" />
|
||||
<Compile Include="Custom\DbHelperMySqlCustom.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AUTS.Domain\AUTS.Domain.csproj">
|
||||
<Project>{709aa98f-388f-44dd-b64b-ad44e695c34c}</Project>
|
||||
<Name>AUTS.Domain</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\AUTS.Services\AUTS.Services.csproj">
|
||||
<Project>{56438f1c-ba3a-4272-964e-c6739ae0b4ec}</Project>
|
||||
<Name>AUTS.Services</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
10
Face.DBUtility/Face.DBUtility.csproj.vspscc
Normal file
10
Face.DBUtility/Face.DBUtility.csproj.vspscc
Normal file
@@ -0,0 +1,10 @@
|
||||
""
|
||||
{
|
||||
"FILE_VERSION" = "9237"
|
||||
"ENLISTMENT_CHOICE" = "NEVER"
|
||||
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
|
||||
}
|
||||
36
Face.DBUtility/Properties/AssemblyInfo.cs
Normal file
36
Face.DBUtility/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("AUTS.DBUtility")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("AUTS.DBUtility")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2021")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("2d329474-a40d-47ba-9cad-036a794e80dd")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
6
Face.DBUtility/packages.config
Normal file
6
Face.DBUtility/packages.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
|
||||
<package id="MySql.Data" version="6.9.12" targetFramework="net461" />
|
||||
<package id="MySql.Data.Entity" version="6.9.12" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user