Ejemplo n.º 1
0
 /// <summary>
 /// 添加数据
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <typeparam name="modelType">模型类型</typeparam>
 /// <param name="sqlTool">SQL操作工具</param>
 /// <param name="connection">SQL连接</param>
 /// <param name="value">添加数据</param>
 /// <param name="query">添加数据查询信息</param>
 /// <returns></returns>
 internal override ReturnType Insert <valueType, modelType>(Sql.Table <valueType, modelType> sqlTool, ref DbConnection connection, valueType value, ref InsertQuery query)
 {
     sqlTool.Log.Error(query.Sql, LogLevel.Error | LogLevel.AutoCSer);
     if ((DataModel.Model <modelType> .Identity != null || DataModel.Model <modelType> .PrimaryKeys.Length != 0) && !query.NotQuery)
     {
         GetQuery <modelType> getQuery = new GetQuery <modelType> {
             MemberMap = DataModel.Model <modelType> .MemberMap, Sql = query.Sql
         };
         ReturnType returnType = Get(sqlTool, ref connection, value, ref getQuery);
         if (returnType != ReturnType.Success)
         {
             return(returnType);
         }
     }
     else
     {
         ReturnValue <int> returnValue = executeNonQuery(ref connection, query.Sql);
         if (returnValue.ReturnType != ReturnType.Success)
         {
             return(returnValue.ReturnType);
         }
         if (returnValue.Value <= 0)
         {
             return(ReturnType.ExecuteFailed);
         }
     }
     sqlTool.CallOnInserted(value);
     return(ReturnType.Success);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 添加数据
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <typeparam name="modelType">模型类型</typeparam>
 /// <param name="sqlTool">SQL操作工具</param>
 /// <param name="transaction">事务操作</param>
 /// <param name="value">添加数据</param>
 /// <param name="query">添加数据查询信息</param>
 /// <returns></returns>
 internal override bool Insert <valueType, modelType>(Sql.Table <valueType, modelType> sqlTool, Transaction transaction, valueType value, ref InsertQuery query)
 {
     if (sqlTool.CallOnInsert(value) && executeNonQuery(transaction, query.InsertSql) > 0)
     {
         sqlTool.CallOnInserted(transaction, value);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 添加数据
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <typeparam name="modelType">模型类型</typeparam>
 /// <param name="sqlTool">SQL操作工具</param>
 /// <param name="transaction">事务操作</param>
 /// <param name="value">添加数据</param>
 /// <param name="query">添加数据查询信息</param>
 /// <returns></returns>
 internal override ReturnType Insert <valueType, modelType>(Sql.Table <valueType, modelType> sqlTool, Transaction transaction, valueType value, ref InsertQuery query)
 {
     if (sqlTool.CallOnInsert(value))
     {
         if (executeNonQuery(transaction, query.Sql) > 0)
         {
             sqlTool.CallOnInserted(transaction, value);
             return(ReturnType.Success);
         }
         return(ReturnType.ExecuteFailed);
     }
     return(ReturnType.EventCancel);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 添加数据
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <typeparam name="modelType">模型类型</typeparam>
 /// <param name="sqlTool">SQL操作工具</param>
 /// <param name="transaction">事务操作</param>
 /// <param name="array">数据数组</param>
 /// <returns></returns>
 internal override SubArray <valueType> Insert <valueType, modelType>(Sql.Table <valueType, modelType> sqlTool, Transaction transaction, ref SubArray <valueType> array)
 {
     if (sqlTool.CallOnInsert(ref array))
     {
         MemberMap <modelType> memberMap = MemberMap <modelType> .Default;
         InsertQuery           query     = new InsertQuery();
         foreach (valueType value in array)
         {
             insert(sqlTool, value, memberMap, ref query);
             if (executeNonQuery(transaction, query.InsertSql) <= 0)
             {
                 return(default(SubArray <valueType>));
             }
         }
         sqlTool.CallOnInserted(transaction, array);
         return(array);
     }
     return(default(SubArray <valueType>));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 添加数据
 /// </summary>
 /// <typeparam name="valueType">数据类型</typeparam>
 /// <typeparam name="modelType">模型类型</typeparam>
 /// <param name="sqlTool">SQL操作工具</param>
 /// <param name="connection">SQL连接</param>
 /// <param name="value">添加数据</param>
 /// <param name="query">添加数据查询信息</param>
 /// <returns></returns>
 internal override bool Insert <valueType, modelType>(Sql.Table <valueType, modelType> sqlTool, ref DbConnection connection, valueType value, ref InsertQuery query)
 {
     if (executeNonQuery(ref connection, query.InsertSql) > 0)
     {
         if ((DataModel.Model <modelType> .Identity != null || DataModel.Model <modelType> .PrimaryKeys.Length != 0) && !query.NotQuery)
         {
             GetQuery <modelType> getQuery = new GetQuery <modelType> {
                 MemberMap = DataModel.Model <modelType> .MemberMap, Sql = query.Sql
             };
             if (!Get(sqlTool, ref connection, value, ref getQuery))
             {
                 return(false);
             }
         }
         sqlTool.CallOnInserted(value);
         return(true);
     }
     return(false);
 }