1570 lines
58 KiB
C#
1570 lines
58 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Data.Common;
|
|||
|
|
using System.Data.SqlClient;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using CYQ.Data.SQL;
|
|||
|
|
using CYQ.Data.Cache;
|
|||
|
|
using CYQ.Data.Table;
|
|||
|
|
|
|||
|
|
using CYQ.Data.Aop;
|
|||
|
|
using CYQ.Data.Tool;
|
|||
|
|
using CYQ.Data.UI;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace CYQ.Data
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Manipulate<74><65>table / view / custom statement
|
|||
|
|
///<para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><>ͼ/<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class MAction : IDisposable
|
|||
|
|
{
|
|||
|
|
#region ȫ<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
internal DbBase dalHelper;//<2F><><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD>
|
|||
|
|
private SqlCreate _sqlCreate;
|
|||
|
|
private InsertOp _option = InsertOp.ID;
|
|||
|
|
private NoSqlAction _noSqlAction = null;
|
|||
|
|
private MDataRow _Data;//<2F><>ʾһ<CABE><D2BB>
|
|||
|
|
/// <summary>
|
|||
|
|
/// Archive the rows of the data structure
|
|||
|
|
/// <para><3E>浵<EFBFBD><E6B5B5><EFBFBD>ݽṹ<DDBD><E1B9B9><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public MDataRow Data
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _Data;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>/<2F><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]<5D><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
private string _sourceTableName;
|
|||
|
|
private string _TableName; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// Table name (if the view statement is the operation, the final view of the name)
|
|||
|
|
///<para><3E><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>䣬<EFBFBD><E4A3AC>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD></para> <20><>
|
|||
|
|
/// </summary>
|
|||
|
|
public string TableName
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _TableName;
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_TableName = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// The database connection string
|
|||
|
|
///<para><3E><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public string ConnectionString
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (dalHelper != null)
|
|||
|
|
{
|
|||
|
|
return dalHelper.conn;
|
|||
|
|
}
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private string _debugInfo = string.Empty;
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get or set debugging information [need to set App Config.Debug.Open DebugInfo to ture]
|
|||
|
|
///<para><3E><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>Ϣ[<5B><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>AppConfig.Debug.OpenDebugInfoΪture]</para>
|
|||
|
|
/// </summary>
|
|||
|
|
public string DebugInfo
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (dalHelper != null)
|
|||
|
|
{
|
|||
|
|
return dalHelper.debugInfo.ToString();
|
|||
|
|
}
|
|||
|
|
return _debugInfo;
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
if (dalHelper != null)
|
|||
|
|
{
|
|||
|
|
dalHelper.debugInfo.Length = 0;
|
|||
|
|
dalHelper.debugInfo.Append(value);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// The database type
|
|||
|
|
/// <para><3E><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public DalType DalType
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return dalHelper.dalType;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// The database name
|
|||
|
|
/// <para><3E><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public string DataBase
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return dalHelper.DataBase;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// The database version
|
|||
|
|
/// <20><><EFBFBD>ݿ<EFBFBD><DDBF>İ汾<C4B0><E6B1BE>
|
|||
|
|
/// </summary>
|
|||
|
|
public string DalVersion
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return dalHelper.Version;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// The number of rows affected when executing a SQL command (-2 is an exception)
|
|||
|
|
/// <para>ִ<><D6B4>SQL<51><4C><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-2<><32>Ϊ<EFBFBD>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public int RecordsAffected
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return dalHelper.recordsAffected;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Command Timeout[seconds]
|
|||
|
|
///<para><3E><><EFBFBD>ʱ<EEB3AC><CAB1><EFBFBD><EFBFBD>[<5B><>λ<EFBFBD><CEBB>]</para>
|
|||
|
|
/// </summary>
|
|||
|
|
public int TimeOut
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (dalHelper.Com != null)
|
|||
|
|
{
|
|||
|
|
return dalHelper.Com.CommandTimeout;
|
|||
|
|
}
|
|||
|
|
return -1;
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
if (dalHelper.Com != null)
|
|||
|
|
{
|
|||
|
|
dalHelper.Com.CommandTimeout = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private bool _AllowInsertID = false;
|
|||
|
|
/// <summary>
|
|||
|
|
/// Whether to allow manual insertion of IDs for self-incrementing primary key identification
|
|||
|
|
///<para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD>ģ<EFBFBD><C4A3>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>ID</para>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool AllowInsertID
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _AllowInsertID;
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_AllowInsertID = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private bool _isInsertCommand; //<2F>Ƿ<EFBFBD>ִ<EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Update<74><65><EFBFBD><EFBFBD>)
|
|||
|
|
|
|||
|
|
private bool _setIdentityResult = true;
|
|||
|
|
/// <summary>
|
|||
|
|
/// MSSQL<51><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶIDʱ<44><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>[<5B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ч]
|
|||
|
|
/// </summary>
|
|||
|
|
internal void SetIdentityInsertOn()
|
|||
|
|
{
|
|||
|
|
_setIdentityResult = true;
|
|||
|
|
if (dalHelper != null && dalHelper.isOpenTrans)
|
|||
|
|
{
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.MsSql:
|
|||
|
|
case DalType.Sybase:
|
|||
|
|
if (_Data.Columns.FirstPrimary.IsAutoIncrement)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string lastTable = Convert.ToString(CacheManage.LocalInstance.Get("MAction_IdentityInsertForSql"));
|
|||
|
|
if (!string.IsNullOrEmpty(lastTable))
|
|||
|
|
{
|
|||
|
|
lastTable = "set identity_insert " + SqlFormat.Keyword(lastTable, dalHelper.dalType) + " off";
|
|||
|
|
dalHelper.ExeNonQuery(lastTable, false);
|
|||
|
|
}
|
|||
|
|
_setIdentityResult = dalHelper.ExeNonQuery("set identity_insert " + SqlFormat.Keyword(_TableName, dalHelper.dalType) + " on", false) > -2;
|
|||
|
|
if (_setIdentityResult)
|
|||
|
|
{
|
|||
|
|
CacheManage.LocalInstance.Set("MAction_IdentityInsertForSql", _TableName, 30);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
_AllowInsertID = true;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// MSSQL<51><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶID<49><44><EFBFBD>رմ<D8B1>ѡ<EFBFBD><D1A1>[<5B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ч]
|
|||
|
|
/// </summary>;
|
|||
|
|
internal void SetIdentityInsertOff()
|
|||
|
|
{
|
|||
|
|
if (_setIdentityResult && dalHelper != null && dalHelper.isOpenTrans)
|
|||
|
|
{
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.MsSql:
|
|||
|
|
case DalType.Sybase:
|
|||
|
|
if (_Data.Columns.FirstPrimary.IsAutoIncrement)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (dalHelper.ExeNonQuery("set identity_insert " + SqlFormat.Keyword(_TableName, DalType.MsSql) + " off", false) > -2)
|
|||
|
|
{
|
|||
|
|
_setIdentityResult = false;
|
|||
|
|
CacheManage.LocalInstance.Remove("MAction_IdentityInsertForSql");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
_AllowInsertID = false;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>DeleteField<6C><64><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>ɾ<EFBFBD><C9BE>ת<EFBFBD><D7AA><EFBFBD>²<EFBFBD><C2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊtrue<75><65>
|
|||
|
|
/// </summary>
|
|||
|
|
internal bool IsIgnoreDeleteField = false;
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Instantiation
|
|||
|
|
/// <para>ʵ<><CAB5><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="tableNamesEnum">Parameters: table name, view, custom statement, DataRow
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䡢MDataRow</para></param>
|
|||
|
|
public MAction(object tableNamesEnum)
|
|||
|
|
{
|
|||
|
|
Init(tableNamesEnum, AppConfig.DB.DefaultConn);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="conn">Database connection statement or configuration key
|
|||
|
|
/// <para><3E><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Key</para></param>
|
|||
|
|
public MAction(object tableNamesEnum, string conn)
|
|||
|
|
{
|
|||
|
|
Init(tableNamesEnum, conn);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
private void Init(object tableObj, string conn)
|
|||
|
|
{
|
|||
|
|
tableObj = SqlCreate.SqlToViewSql(tableObj);
|
|||
|
|
string dbName = StaticTool.GetDbName(ref tableObj);
|
|||
|
|
if (conn == AppConfig.DB.DefaultConn && !string.IsNullOrEmpty(dbName))
|
|||
|
|
{
|
|||
|
|
if (dbName.ToLower().EndsWith("conn") && !string.IsNullOrEmpty(AppConfig.GetConn(dbName)))
|
|||
|
|
{
|
|||
|
|
conn = dbName;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
conn = dbName + "Conn";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
MDataRow newRow;
|
|||
|
|
InitConn(tableObj, conn, out newRow);//<2F><><EFBFBD>Դ<EFBFBD>MDataRow<6F><77>ȡ<EFBFBD>µ<EFBFBD>Conn<6E><6E><EFBFBD><EFBFBD>
|
|||
|
|
InitSqlHelper(newRow, dbName);
|
|||
|
|
InitRowSchema(newRow, true);
|
|||
|
|
InitGlobalObject(true);
|
|||
|
|
//Aop.IAop myAop = Aop.InterAop.Instance.GetFromConfig();//<2F><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>Aop
|
|||
|
|
//if (myAop != null)
|
|||
|
|
//{
|
|||
|
|
// SetAop(myAop);
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
private void InitConn(object tableObj, string conn, out MDataRow newRow)
|
|||
|
|
{
|
|||
|
|
if (tableObj is MDataRow)
|
|||
|
|
{
|
|||
|
|
newRow = tableObj as MDataRow;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
newRow = new MDataRow();
|
|||
|
|
newRow.TableName = SqlFormat.NotKeyword(tableObj.ToString());
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(conn))
|
|||
|
|
{
|
|||
|
|
newRow.Conn = conn;
|
|||
|
|
}
|
|||
|
|
else if (_Data != null)//<2F>¼ӵĴ<D3B5><C4B4><EFBFBD>
|
|||
|
|
{
|
|||
|
|
newRow.Conn = _Data.Conn;
|
|||
|
|
}
|
|||
|
|
_sourceTableName = newRow.TableName;
|
|||
|
|
}
|
|||
|
|
private void InitSqlHelper(MDataRow newRow, string newDbName)
|
|||
|
|
{
|
|||
|
|
if (dalHelper == null)// || newCreate
|
|||
|
|
{
|
|||
|
|
dalHelper = DalCreate.CreateDal(newRow.Conn);
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
|
|||
|
|
if (dalHelper.IsOnExceptionEventNull)
|
|||
|
|
{
|
|||
|
|
dalHelper.OnExceptionEvent += new DbBase.OnException(_DataSqlHelper_OnExceptionEvent);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
dalHelper.ClearParameters();//oracle 11g(ij<>û<EFBFBD><C3BB>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ϻ<EFBFBD><CFBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>壩
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(newDbName))//<2F><>Ҫ<EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD>ݿ⡣
|
|||
|
|
{
|
|||
|
|
if (string.Compare(dalHelper.DataBase, newDbName, StringComparison.OrdinalIgnoreCase) != 0)//<2F><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>ͬ<EFBFBD><CDAC>
|
|||
|
|
{
|
|||
|
|
if (newRow.TableName.Contains(" "))//<2F><>ͼ<EFBFBD><CDBC><EFBFBD>䣬<EFBFBD><E4A3AC>ֱ<EFBFBD><D6B1><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ӡ<EFBFBD>
|
|||
|
|
{
|
|||
|
|
dalHelper.ChangeDatabase(newDbName);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
bool isWithDbName = newRow.TableName.Contains(".");//<2F>Ƿ<EFBFBD>DBName.TableName
|
|||
|
|
string fullTableName = isWithDbName ? newRow.TableName : newDbName + "." + newRow.TableName;
|
|||
|
|
string sourceDbName = dalHelper.DataBase;
|
|||
|
|
DbResetResult result = dalHelper.ChangeDatabaseWithCheck(fullTableName);
|
|||
|
|
switch (result)
|
|||
|
|
{
|
|||
|
|
case DbResetResult.Yes://<2F><><EFBFBD>ݿ<EFBFBD><DDBF>л<EFBFBD><D0BB><EFBFBD> (<28><><EFBFBD><EFBFBD>Ҫǰ<C7B0><D7BA>
|
|||
|
|
case DbResetResult.No_SaveDbName:
|
|||
|
|
case DbResetResult.No_DBNoExists:
|
|||
|
|
if (isWithDbName) //<2F><><EFBFBD><EFBFBD>ǰ<C7B0>ģ<EFBFBD>ȡ<EFBFBD><C8A1>ǰ
|
|||
|
|
{
|
|||
|
|
_sourceTableName = newRow.TableName = SqlFormat.NotKeyword(fullTableName);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case DbResetResult.No_Transationing:
|
|||
|
|
if (!isWithDbName)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ݿ⣬<DDBF><E2A3AC>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ǰ
|
|||
|
|
{
|
|||
|
|
_sourceTableName = newRow.TableName = fullTableName;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
void _DataSqlHelper_OnExceptionEvent(string msg)
|
|||
|
|
{
|
|||
|
|
_aop.OnError(msg);
|
|||
|
|
}
|
|||
|
|
private static DateTime lastGCTime = DateTime.Now;
|
|||
|
|
private void InitRowSchema(MDataRow row, bool resetState)
|
|||
|
|
{
|
|||
|
|
_Data = row;
|
|||
|
|
_TableName = SqlCompatible.Format(_sourceTableName, dalHelper.dalType);
|
|||
|
|
_TableName = DBTool.GetMapTableName(dalHelper.useConnBean.ConfigName, _TableName);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
|
|||
|
|
if (_Data.Count == 0)
|
|||
|
|
{
|
|||
|
|
if (!TableSchema.FillTableSchema(ref _Data, ref dalHelper, _TableName, _sourceTableName))
|
|||
|
|
{
|
|||
|
|
if (!dalHelper.TestConn(AllowConnLevel.MaterBackupSlave))
|
|||
|
|
{
|
|||
|
|
Error.Throw(dalHelper.dalType + "." + dalHelper.DataBase + ":open database failed! check the connectionstring is be ok!" + AppConst.NewLine + "error:" + dalHelper.debugInfo.ToString());
|
|||
|
|
}
|
|||
|
|
Error.Throw(dalHelper.dalType + "." + dalHelper.DataBase + ":check the tablename \"" + _TableName + "\" is exist?" + AppConst.NewLine + "error:" + dalHelper.debugInfo.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (resetState)
|
|||
|
|
{
|
|||
|
|
_Data.SetState(0);
|
|||
|
|
}
|
|||
|
|
_Data.Conn = row.Conn;//FillTableSchema<6D><61><EFBFBD>ı<EFBFBD>_Row<6F>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Toggle Table Action: To switch between other tables, use this method
|
|||
|
|
/// <para><3E>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD>л<EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="tableObj">Parameters: table name, view, custom statement, DataRow
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䡢MDataRow</para></param>
|
|||
|
|
public void ResetTable(object tableObj)
|
|||
|
|
{
|
|||
|
|
ResetTable(tableObj, true, null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="resetState">Reset Row State (defaultValue:true)
|
|||
|
|
/// <para><3E>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>Ĭ<EFBFBD><C4AC>true)</para></param>
|
|||
|
|
public void ResetTable(object tableObj, bool resetState)
|
|||
|
|
{
|
|||
|
|
ResetTable(tableObj, resetState, null);
|
|||
|
|
}
|
|||
|
|
/// <param name="newDbName">Other DataBaseName
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD></para></param>
|
|||
|
|
public void ResetTable(object tableObj, bool resetState, string newDbName)
|
|||
|
|
{
|
|||
|
|
tableObj = SqlCreate.SqlToViewSql(tableObj);
|
|||
|
|
newDbName = newDbName ?? StaticTool.GetDbName(ref tableObj);
|
|||
|
|
MDataRow newRow;
|
|||
|
|
InitConn(tableObj, string.Empty, out newRow);
|
|||
|
|
|
|||
|
|
//newRow.Conn = newDbName;//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|||
|
|
InitSqlHelper(newRow, newDbName);
|
|||
|
|
InitRowSchema(newRow, resetState);
|
|||
|
|
InitGlobalObject(false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void InitGlobalObject(bool allowCreate)
|
|||
|
|
{
|
|||
|
|
if (_Data != null)
|
|||
|
|
{
|
|||
|
|
if (_sqlCreate == null)
|
|||
|
|
{
|
|||
|
|
_sqlCreate = new SqlCreate(this);
|
|||
|
|
}
|
|||
|
|
if (_UI != null)
|
|||
|
|
{
|
|||
|
|
_UI._Data = _Data;
|
|||
|
|
}
|
|||
|
|
else if (allowCreate)
|
|||
|
|
{
|
|||
|
|
_UI = new MActionUI(ref _Data, dalHelper, _sqlCreate);
|
|||
|
|
}
|
|||
|
|
if (_noSqlAction != null)
|
|||
|
|
{
|
|||
|
|
_noSqlAction.Reset(ref _Data, _TableName, dalHelper.Con.DataSource, dalHelper.dalType);
|
|||
|
|
}
|
|||
|
|
else if (allowCreate)
|
|||
|
|
{
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.Txt:
|
|||
|
|
case DalType.Xml:
|
|||
|
|
_noSqlAction = new NoSqlAction(ref _Data, _TableName, dalHelper.Con.DataSource, dalHelper.dalType);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
private bool InsertOrUpdate(string sqlCommandText)
|
|||
|
|
{
|
|||
|
|
bool returnResult = false;
|
|||
|
|
if (_sqlCreate.isCanDo)
|
|||
|
|
{
|
|||
|
|
#region ִ<EFBFBD><EFBFBD>Insert<EFBFBD><EFBFBD>Update<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (_isInsertCommand) //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
_isInsertCommand = false;
|
|||
|
|
object ID;
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.MsSql:
|
|||
|
|
case DalType.Sybase:
|
|||
|
|
case CYQ.Data.DalType.PostgreSQL:
|
|||
|
|
ID = dalHelper.ExeScalar(sqlCommandText, false);
|
|||
|
|
if (ID == null && AllowInsertID && dalHelper.recordsAffected > -2)
|
|||
|
|
{
|
|||
|
|
ID = _Data.PrimaryCell.Value;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
#region MyRegion
|
|||
|
|
bool isTrans = dalHelper.isOpenTrans;
|
|||
|
|
int groupID = DataType.GetGroup(_Data.PrimaryCell.Struct.SqlType);
|
|||
|
|
bool isNum = groupID == 1 && _Data.PrimaryCell.Struct.Scale <= 0;
|
|||
|
|
if (!isTrans && (isNum || _Data.PrimaryCell.Struct.IsAutoIncrement) && (!AllowInsertID || _Data.PrimaryCell.IsNullOrEmpty)) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
dalHelper.isOpenTrans = true;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
dalHelper.TranLevel = IsolationLevel.ReadCommitted;//Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F1BCB6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD>Դ˵<D4B4>Ӱ<EFBFBD>졣
|
|||
|
|
}
|
|||
|
|
ID = dalHelper.ExeNonQuery(sqlCommandText, false);//<2F><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (_option != InsertOp.None && ID != null && Convert.ToInt32(ID) > 0)
|
|||
|
|
{
|
|||
|
|
if (AllowInsertID && !_Data.PrimaryCell.IsNullOrEmpty)//<2F>ֹ<EFBFBD><D6B9><EFBFBD>ID
|
|||
|
|
{
|
|||
|
|
ID = _Data.PrimaryCell.Value;
|
|||
|
|
}
|
|||
|
|
else if (isNum)
|
|||
|
|
{
|
|||
|
|
ClearParameters();
|
|||
|
|
ID = dalHelper.ExeScalar(_sqlCreate.GetMaxID(), false);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ID = null;
|
|||
|
|
returnResult = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
if (!isTrans)
|
|||
|
|
{
|
|||
|
|
dalHelper.EndTransaction();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
if ((ID != null && Convert.ToString(ID) != "-2") || (dalHelper.recordsAffected > -2 && _option == InsertOp.None))
|
|||
|
|
{
|
|||
|
|
if (_option != InsertOp.None)
|
|||
|
|
{
|
|||
|
|
_Data.PrimaryCell.Value = ID;
|
|||
|
|
}
|
|||
|
|
returnResult = (_option == InsertOp.Fill) ? Fill(ID) : true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
returnResult = dalHelper.ExeNonQuery(sqlCommandText, false) > 0;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
else if (!_isInsertCommand && _Data.GetState() == 1 && dalHelper.recordsAffected != -2) // <20><><EFBFBD>²<EFBFBD><C2B2><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
else if (dalHelper.isOpenTrans && dalHelper.recordsAffected == -2) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD>ع<EFBFBD>
|
|||
|
|
{
|
|||
|
|
dalHelper.WriteError(_isInsertCommand ? "Insert" : "Update" + "():");
|
|||
|
|
}
|
|||
|
|
return returnResult;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Insert To DataBase
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool Insert()
|
|||
|
|
{
|
|||
|
|
return Insert(false, _option);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="option">InsertOp
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1></para></param>
|
|||
|
|
public bool Insert(InsertOp option)
|
|||
|
|
{
|
|||
|
|
return Insert(false, option);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <param name="autoSetValue">Automatic get values from context
|
|||
|
|
/// <para><3E>Զ<EFBFBD>ȡֵ<C8A1><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>У<EFBFBD></para></param>
|
|||
|
|
public bool Insert(bool autoSetValue)
|
|||
|
|
{
|
|||
|
|
return Insert(autoSetValue, _option);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="option">InsertOp
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1></para></param>
|
|||
|
|
public bool Insert(bool autoSetValue, InsertOp option)
|
|||
|
|
{
|
|||
|
|
if (CheckDisposed()) { return false; }
|
|||
|
|
if (autoSetValue)
|
|||
|
|
{
|
|||
|
|
_UI.GetAll(!AllowInsertID);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IDʱ<44><CAB1>Ҳ<EFBFBD><D2B2>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
AopResult aopResult = AopResult.Default;
|
|||
|
|
if (_aop.IsLoadAop)
|
|||
|
|
{
|
|||
|
|
_aop.Para.MAction = this;
|
|||
|
|
_aop.Para.TableName = _sourceTableName;
|
|||
|
|
_aop.Para.Row = _Data;
|
|||
|
|
_aop.Para.AutoSetValue = autoSetValue;
|
|||
|
|
_aop.Para.InsertOp = option;
|
|||
|
|
_aop.Para.IsTransaction = dalHelper.isOpenTrans;
|
|||
|
|
aopResult = _aop.Begin(Aop.AopEnum.Insert);
|
|||
|
|
}
|
|||
|
|
if (aopResult == AopResult.Default || aopResult == AopResult.Continue)
|
|||
|
|
{
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.Txt:
|
|||
|
|
case DalType.Xml:
|
|||
|
|
_aop.Para.IsSuccess = _noSqlAction.Insert(dalHelper.isOpenTrans);
|
|||
|
|
dalHelper.recordsAffected = _aop.Para.IsSuccess ? 1 : 0;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
ClearParameters();
|
|||
|
|
string sql = _sqlCreate.GetInsertSql();
|
|||
|
|
_isInsertCommand = true;
|
|||
|
|
_option = option;
|
|||
|
|
_aop.Para.IsSuccess = InsertOrUpdate(sql);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (option != InsertOp.None)
|
|||
|
|
{
|
|||
|
|
_Data = _aop.Para.Row;
|
|||
|
|
InitGlobalObject(false);
|
|||
|
|
}
|
|||
|
|
if (_aop.IsLoadAop && (aopResult == AopResult.Break || aopResult == AopResult.Continue))
|
|||
|
|
{
|
|||
|
|
_aop.End(Aop.AopEnum.Insert);
|
|||
|
|
}
|
|||
|
|
if (dalHelper.recordsAffected == -2)
|
|||
|
|
{
|
|||
|
|
OnError();
|
|||
|
|
}
|
|||
|
|
return _aop.Para.IsSuccess;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// Update to database [Will automatically try to fetch from the UI when conditions are not passed]
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[<5B><><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>Դ<EFBFBD>UI<55><49>ȡ]</para>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool Update()
|
|||
|
|
{
|
|||
|
|
return Update(null, true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <param name="where">Sql statement where the conditions: 88, "id = 88"
|
|||
|
|
/// <para>sql<71><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>88<38><38>"id=88"</para></param>
|
|||
|
|
public bool Update(object where)
|
|||
|
|
{
|
|||
|
|
return Update(where, false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <param name="autoSetValue">Automatic get values from context
|
|||
|
|
/// <para><3E>Զ<EFBFBD>ȡֵ<C8A1><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>У<EFBFBD></para></param>
|
|||
|
|
public bool Update(bool autoSetValue)
|
|||
|
|
{
|
|||
|
|
return Update(null, autoSetValue);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="autoSetValue">Automatic get values from context
|
|||
|
|
/// <para><3E>Զ<EFBFBD>ȡֵ<C8A1><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>У<EFBFBD></para></param>
|
|||
|
|
public bool Update(object where, bool autoSetValue)
|
|||
|
|
{
|
|||
|
|
if (CheckDisposed()) { return false; }
|
|||
|
|
if (autoSetValue)
|
|||
|
|
{
|
|||
|
|
_UI.GetAll(false);
|
|||
|
|
}
|
|||
|
|
if (where == null || Convert.ToString(where) == "")
|
|||
|
|
{
|
|||
|
|
where = _sqlCreate.GetPrimaryWhere();
|
|||
|
|
}
|
|||
|
|
AopResult aopResult = AopResult.Default;
|
|||
|
|
if (_aop.IsLoadAop)
|
|||
|
|
{
|
|||
|
|
_aop.Para.MAction = this;
|
|||
|
|
_aop.Para.TableName = _sourceTableName;
|
|||
|
|
_aop.Para.Row = _Data;
|
|||
|
|
_aop.Para.Where = where;
|
|||
|
|
//_aop.Para.AopPara = aopPara;
|
|||
|
|
_aop.Para.AutoSetValue = autoSetValue;
|
|||
|
|
_aop.Para.UpdateExpression = _sqlCreate.updateExpression;
|
|||
|
|
_aop.Para.IsTransaction = dalHelper.isOpenTrans;
|
|||
|
|
aopResult = _aop.Begin(Aop.AopEnum.Update);
|
|||
|
|
}
|
|||
|
|
if (aopResult == AopResult.Default || aopResult == AopResult.Continue)
|
|||
|
|
{
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.Txt:
|
|||
|
|
case DalType.Xml:
|
|||
|
|
int count;
|
|||
|
|
_aop.Para.IsSuccess = _noSqlAction.Update(_sqlCreate.FormatWhere(where), out count);
|
|||
|
|
dalHelper.recordsAffected = count;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
ClearParameters();
|
|||
|
|
string sql = _sqlCreate.GetUpdateSql(where);
|
|||
|
|
_aop.Para.IsSuccess = InsertOrUpdate(sql);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (_aop.IsLoadAop && (aopResult == AopResult.Break || aopResult == AopResult.Continue))
|
|||
|
|
{
|
|||
|
|
_aop.End(Aop.AopEnum.Update);
|
|||
|
|
}
|
|||
|
|
if (dalHelper.recordsAffected == -2)
|
|||
|
|
{
|
|||
|
|
OnError();
|
|||
|
|
}
|
|||
|
|
return _aop.Para.IsSuccess;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Delete from database [Will automatically try to fetch from the UI when conditions are not passed]
|
|||
|
|
/// <para>ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[<5B><><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>Դ<EFBFBD>UI<55><49>ȡ]</para>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool Delete()
|
|||
|
|
{
|
|||
|
|
return Delete(null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="where">Sql statement where the conditions: 88, "id = 88"
|
|||
|
|
/// <para>sql<71><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>88<38><38>"id=88"</para></param>
|
|||
|
|
public bool Delete(object where)
|
|||
|
|
{
|
|||
|
|
if (CheckDisposed()) { return false; }
|
|||
|
|
if (where == null || Convert.ToString(where) == "")
|
|||
|
|
{
|
|||
|
|
_UI.PrimayAutoGetValue();
|
|||
|
|
where = _sqlCreate.GetPrimaryWhere();
|
|||
|
|
}
|
|||
|
|
AopResult aopResult = AopResult.Default;
|
|||
|
|
if (_aop.IsLoadAop)
|
|||
|
|
{
|
|||
|
|
_aop.Para.MAction = this;
|
|||
|
|
_aop.Para.TableName = _sourceTableName;
|
|||
|
|
_aop.Para.Row = _Data;
|
|||
|
|
_aop.Para.Where = where;
|
|||
|
|
//_aop.Para.AopPara = aopPara;
|
|||
|
|
_aop.Para.IsTransaction = dalHelper.isOpenTrans;
|
|||
|
|
aopResult = _aop.Begin(Aop.AopEnum.Delete);
|
|||
|
|
}
|
|||
|
|
if (aopResult == AopResult.Default || aopResult == AopResult.Continue)
|
|||
|
|
{
|
|||
|
|
string deleteField = AppConfig.DB.DeleteField;
|
|||
|
|
bool isToUpdate = !IsIgnoreDeleteField && !string.IsNullOrEmpty(deleteField) && _Data.Columns.Contains(deleteField);
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.Txt:
|
|||
|
|
case DalType.Xml:
|
|||
|
|
string sqlWhere = _sqlCreate.FormatWhere(where);
|
|||
|
|
int count;
|
|||
|
|
if (isToUpdate)
|
|||
|
|
{
|
|||
|
|
_Data.Set(deleteField, true);
|
|||
|
|
_aop.Para.IsSuccess = _noSqlAction.Update(sqlWhere, out count);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
_aop.Para.IsSuccess = _noSqlAction.Delete(sqlWhere, out count);
|
|||
|
|
}
|
|||
|
|
dalHelper.recordsAffected = count;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
ClearParameters();
|
|||
|
|
string sql = isToUpdate ? _sqlCreate.GetDeleteToUpdateSql(where) : _sqlCreate.GetDeleteSql(where);
|
|||
|
|
_aop.Para.IsSuccess = dalHelper.ExeNonQuery(sql, false) > 0;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (_aop.IsLoadAop && (aopResult == AopResult.Break || aopResult == AopResult.Continue))
|
|||
|
|
{
|
|||
|
|
_aop.End(Aop.AopEnum.Delete);
|
|||
|
|
}
|
|||
|
|
if (dalHelper.recordsAffected == -2)
|
|||
|
|
{
|
|||
|
|
OnError();
|
|||
|
|
}
|
|||
|
|
return _aop.Para.IsSuccess;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// select all data
|
|||
|
|
///<para>ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public MDataTable Select()
|
|||
|
|
{
|
|||
|
|
int count;
|
|||
|
|
return Select(0, 0, null, out count);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="where">Sql statement where the conditions: 88, "id = 88"
|
|||
|
|
/// <para>sql<71><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>88<38><38>"id=88"</para></param>
|
|||
|
|
public MDataTable Select(object where)
|
|||
|
|
{
|
|||
|
|
int count;
|
|||
|
|
return Select(0, 0, where, out count);
|
|||
|
|
}
|
|||
|
|
public MDataTable Select(int topN, object where)
|
|||
|
|
{
|
|||
|
|
int count;
|
|||
|
|
return Select(0, topN, where, out count);
|
|||
|
|
}
|
|||
|
|
/// <param name="pageIndex">pageIndex<para><3E>ڼ<EFBFBD>ҳ</para></param>
|
|||
|
|
/// <param name="pageSize">pageSize<para>ÿҳ<C3BF><D2B3><EFBFBD><EFBFBD>[Ϊ0ʱĬ<CAB1><C4AC>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]</para></param>
|
|||
|
|
public MDataTable Select(int pageIndex, int pageSize)
|
|||
|
|
{
|
|||
|
|
int count;
|
|||
|
|
return Select(pageIndex, pageSize, null, out count);
|
|||
|
|
}
|
|||
|
|
public MDataTable Select(int pageIndex, int pageSize, object where)
|
|||
|
|
{
|
|||
|
|
int count;
|
|||
|
|
return Select(pageIndex, pageSize, where, out count);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="rowCount">The total number of records returned
|
|||
|
|
/// <para><3E><><EFBFBD>صļ<D8B5>¼<EFBFBD><C2BC><EFBFBD><EFBFBD></para></param>
|
|||
|
|
public MDataTable Select(int pageIndex, int pageSize, object where, out int rowCount)
|
|||
|
|
{
|
|||
|
|
if (CheckDisposed()) { rowCount = -1; return new MDataTable(_TableName); }
|
|||
|
|
rowCount = 0;
|
|||
|
|
AopResult aopResult = AopResult.Default;
|
|||
|
|
if (_aop.IsLoadAop)
|
|||
|
|
{
|
|||
|
|
_aop.Para.MAction = this;
|
|||
|
|
_aop.Para.PageIndex = pageIndex;
|
|||
|
|
_aop.Para.PageSize = pageSize;
|
|||
|
|
_aop.Para.TableName = _sourceTableName;
|
|||
|
|
_aop.Para.Row = _Data;
|
|||
|
|
_aop.Para.Where = where;
|
|||
|
|
_aop.Para.SelectColumns = _sqlCreate.selectColumns;
|
|||
|
|
//_aop.Para.AopPara = aopPara;
|
|||
|
|
_aop.Para.IsTransaction = dalHelper.isOpenTrans;
|
|||
|
|
aopResult = _aop.Begin(Aop.AopEnum.Select);
|
|||
|
|
}
|
|||
|
|
if (aopResult == AopResult.Default || aopResult == AopResult.Continue)
|
|||
|
|
{
|
|||
|
|
string primaryKey = SqlFormat.Keyword(_Data.Columns.FirstPrimary.ColumnName, dalHelper.dalType);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.Txt:
|
|||
|
|
case DalType.Xml:
|
|||
|
|
_aop.Para.Table = _noSqlAction.Select(pageIndex, pageSize, _sqlCreate.FormatWhere(where), out rowCount, _sqlCreate.selectColumns);
|
|||
|
|
dalHelper.recordsAffected = rowCount;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
_aop.Para.Table = new MDataTable(_TableName.Contains("(") ? "SysDefaultCustomTable" : _TableName);
|
|||
|
|
_aop.Para.Table.LoadRow(_Data);
|
|||
|
|
ClearParameters();//------------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
DbDataReader sdReader = null;
|
|||
|
|
string whereSql = string.Empty;//<2F>Ѹ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>whereSql<71><6C><EFBFBD><EFBFBD>
|
|||
|
|
if (_sqlCreate != null)
|
|||
|
|
{
|
|||
|
|
whereSql = _sqlCreate.FormatWhere(where);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
whereSql = SqlFormat.Compatible(where, dalHelper.dalType, dalHelper.Com.Parameters.Count == 0);
|
|||
|
|
}
|
|||
|
|
bool byPager = pageIndex > 0 && pageSize > 0;//<2F><>ҳ<EFBFBD><D2B3>ѯ(<28><>һҳҲҪ<D2B2><D2AA>ҳ<EFBFBD><D2B3>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>ΪҪ<CEAA><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (byPager && AppConfig.DB.PagerBySelectBase && dalHelper.dalType == DalType.MsSql && !dalHelper.Version.StartsWith("08"))// || dalHelper.dalType == DalType.Oracle
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>
|
|||
|
|
if (dalHelper.Com.Parameters.Count > 0)
|
|||
|
|
{
|
|||
|
|
dalHelper.debugInfo.Append(AppConst.HR + "error : select method deny call SetPara() method to add custom parameters!");
|
|||
|
|
}
|
|||
|
|
dalHelper.AddParameters("@PageIndex", pageIndex, DbType.Int32, -1, ParameterDirection.Input);
|
|||
|
|
dalHelper.AddParameters("@PageSize", pageSize, DbType.Int32, -1, ParameterDirection.Input);
|
|||
|
|
dalHelper.AddParameters("@TableName", _sqlCreate.GetSelectTableName(ref whereSql), DbType.String, -1, ParameterDirection.Input);
|
|||
|
|
|
|||
|
|
whereSql = _sqlCreate.AddOrderByWithCheck(whereSql, primaryKey);
|
|||
|
|
|
|||
|
|
dalHelper.AddParameters("@Where", whereSql, DbType.String, -1, ParameterDirection.Input);
|
|||
|
|
sdReader = dalHelper.ExeDataReader("SelectBase", true);
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
#region SQL<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳִ<EFBFBD><EFBFBD>
|
|||
|
|
if (byPager)
|
|||
|
|
{
|
|||
|
|
rowCount = GetCount(whereSql);//<2F><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>棬<EFBFBD><E6A3AC><EFBFBD><EFBFBD>ÿ<EFBFBD>η<EFBFBD>ҳ<EFBFBD><D2B3>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
_aop.Para.Where = where;//<2F>ָ<EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD>컺<EFBFBD><ECBBBA>key
|
|||
|
|
_aop.isHasCache = false;//<2F><><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0>Select<63>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//rowCount = Convert.ToInt32(dalHelper.ExeScalar(_sqlCreate.GetCountSql(whereSql), false));//<2F><>ҳ<EFBFBD><D2B3>ѯ<EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
if (!byPager || (rowCount > 0 && (pageIndex - 1) * pageSize < rowCount))
|
|||
|
|
{
|
|||
|
|
string sql = SqlCreateForPager.GetSql(dalHelper.dalType, dalHelper.Version, pageIndex, pageSize, whereSql, SqlFormat.Keyword(_TableName, dalHelper.dalType), rowCount, _sqlCreate.GetColumnsSql(), primaryKey, _Data.PrimaryCell.Struct.IsAutoIncrement);
|
|||
|
|
sdReader = dalHelper.ExeDataReader(sql, false);
|
|||
|
|
}
|
|||
|
|
else if (_sqlCreate.selectColumns != null)
|
|||
|
|
{
|
|||
|
|
_aop.Para.Table = _aop.Para.Table.Select(0, 0, null, _sqlCreate.selectColumns);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
if (sdReader != null)
|
|||
|
|
{
|
|||
|
|
// _aop.Para.Table.ReadFromDbDataReader(sdReader);//<2F>ڲ<EFBFBD><DAB2>йرա<D8B1>
|
|||
|
|
_aop.Para.Table = sdReader;
|
|||
|
|
if (!byPager)
|
|||
|
|
{
|
|||
|
|
rowCount = _aop.Para.Table.Rows.Count;
|
|||
|
|
}
|
|||
|
|
else if (dalHelper.dalType == DalType.MsSql && AppConfig.DB.PagerBySelectBase)
|
|||
|
|
{
|
|||
|
|
rowCount = dalHelper.ReturnValue;
|
|||
|
|
}
|
|||
|
|
_aop.Para.Table.RecordsAffected = rowCount;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
_aop.Para.Table.Rows.Clear();//Ԥ<><D4A4>֮ǰ<D6AE>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
|
|||
|
|
}
|
|||
|
|
_aop.Para.IsSuccess = _aop.Para.Table.Rows.Count > 0;
|
|||
|
|
ClearParameters();//------------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (_aop.Para.Table.RecordsAffected > 0)
|
|||
|
|
{
|
|||
|
|
rowCount = _aop.Para.Table.RecordsAffected;//<2F><><EFBFBD>ؼ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
if (_aop.IsLoadAop && (aopResult == AopResult.Break || aopResult == AopResult.Continue))
|
|||
|
|
{
|
|||
|
|
_aop.End(Aop.AopEnum.Select);
|
|||
|
|
}
|
|||
|
|
_aop.Para.Table.TableName = TableName;//Aop<6F><70>Json<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ᶪʧ<E1B6AA><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
_aop.Para.Table.Conn = _Data.Conn;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>DataType<70><65>Size<7A><65>Scale
|
|||
|
|
for (int i = 0; i < _aop.Para.Table.Columns.Count; i++)
|
|||
|
|
{
|
|||
|
|
MCellStruct msTable = _aop.Para.Table.Columns[i];
|
|||
|
|
MCellStruct ms = _Data.Columns[msTable.ColumnName];
|
|||
|
|
if (ms != null)
|
|||
|
|
{
|
|||
|
|
msTable.Load(ms);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (_sqlCreate != null)
|
|||
|
|
{
|
|||
|
|
_sqlCreate.selectColumns = null;
|
|||
|
|
}
|
|||
|
|
return _aop.Para.Table;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Select top one row to fill this.Data
|
|||
|
|
/// <para>ѡ<><D1A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䵽Data<74><61><EFBFBD><EFBFBD>[<5B><><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>Դ<EFBFBD>UI<55><49>ȡ]</para>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool Fill()
|
|||
|
|
{
|
|||
|
|
return Fill(null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="where">Sql statement where the conditions: 88, "id = 88"
|
|||
|
|
/// <para>sql<71><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>88<38><38>"id=88"</para></param>
|
|||
|
|
public bool Fill(object where)
|
|||
|
|
{
|
|||
|
|
if (CheckDisposed()) { return false; }
|
|||
|
|
if (where == null || Convert.ToString(where) == "")
|
|||
|
|
{
|
|||
|
|
_UI.PrimayAutoGetValue();
|
|||
|
|
where = _sqlCreate.GetPrimaryWhere();
|
|||
|
|
}
|
|||
|
|
AopResult aopResult = AopResult.Default;
|
|||
|
|
if (_aop.IsLoadAop)
|
|||
|
|
{
|
|||
|
|
_aop.Para.MAction = this;
|
|||
|
|
_aop.Para.TableName = _sourceTableName;
|
|||
|
|
_aop.Para.Row = _Data;
|
|||
|
|
_aop.Para.Where = where;
|
|||
|
|
_aop.Para.SelectColumns = _sqlCreate.selectColumns;
|
|||
|
|
//_aop.Para.AopPara = aopPara;
|
|||
|
|
_aop.Para.IsTransaction = dalHelper.isOpenTrans;
|
|||
|
|
aopResult = _aop.Begin(Aop.AopEnum.Fill);
|
|||
|
|
}
|
|||
|
|
if (aopResult == AopResult.Default || aopResult == AopResult.Continue)
|
|||
|
|
{
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.Txt:
|
|||
|
|
case DalType.Xml:
|
|||
|
|
_aop.Para.IsSuccess = _noSqlAction.Fill(_sqlCreate.FormatWhere(where));
|
|||
|
|
dalHelper.recordsAffected = _aop.Para.IsSuccess ? 1 : 0;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
ClearParameters();
|
|||
|
|
MDataTable mTable = dalHelper.ExeDataReader(_sqlCreate.GetTopOneSql(where), false);
|
|||
|
|
// dalHelper.ResetConn();//<2F><><EFBFBD><EFBFBD>Slave
|
|||
|
|
if (mTable != null && mTable.Rows.Count > 0)
|
|||
|
|
{
|
|||
|
|
_Data.Clear();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>
|
|||
|
|
_Data.LoadFrom(mTable.Rows[0], RowOp.None, true);//setselectcolumn("aa as bb")ʱ
|
|||
|
|
_aop.Para.IsSuccess = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
_aop.Para.IsSuccess = false;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (_aop.Para.IsSuccess)
|
|||
|
|
{
|
|||
|
|
_Data.Clear();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>
|
|||
|
|
_Data.LoadFrom(_aop.Para.Row, RowOp.None, true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (_aop.IsLoadAop && (aopResult == AopResult.Break || aopResult == AopResult.Continue))
|
|||
|
|
{
|
|||
|
|
_aop.Para.Row = _Data;
|
|||
|
|
_aop.End(Aop.AopEnum.Fill);
|
|||
|
|
}
|
|||
|
|
if (_aop.Para.IsSuccess)
|
|||
|
|
{
|
|||
|
|
if (_sqlCreate.selectColumns != null)
|
|||
|
|
{
|
|||
|
|
string name;
|
|||
|
|
string[] items;
|
|||
|
|
foreach (object columnName in _sqlCreate.selectColumns)
|
|||
|
|
{
|
|||
|
|
items = columnName.ToString().Split(' ');
|
|||
|
|
name = items[items.Length - 1];
|
|||
|
|
MDataCell cell = _Data[name];
|
|||
|
|
if (cell != null)
|
|||
|
|
{
|
|||
|
|
cell.State = 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
items = null;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
_Data.SetState(1, BreakOp.Null);//<2F><>ѯʱ<D1AF><CAB1><EFBFBD><EFBFBD>λ״̬Ϊ1
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (dalHelper.recordsAffected == -2)
|
|||
|
|
{
|
|||
|
|
OnError();
|
|||
|
|
}
|
|||
|
|
if (_sqlCreate != null)
|
|||
|
|
{
|
|||
|
|
_sqlCreate.selectColumns = null;
|
|||
|
|
}
|
|||
|
|
return _aop.Para.IsSuccess;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Returns the number of records
|
|||
|
|
/// <para><3E><><EFBFBD>ؼ<EFBFBD>¼<EFBFBD><C2BC></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public int GetCount()
|
|||
|
|
{
|
|||
|
|
return GetCount(null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="where">Sql statement where the conditions: 88, "id = 88"
|
|||
|
|
/// <para>sql<71><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>88<38><38>"id=88"</para></param>
|
|||
|
|
public int GetCount(object where)
|
|||
|
|
{
|
|||
|
|
if (CheckDisposed()) { return -1; }
|
|||
|
|
AopResult aopResult = AopResult.Default;
|
|||
|
|
if (_aop.IsLoadAop)
|
|||
|
|
{
|
|||
|
|
_aop.Para.MAction = this;
|
|||
|
|
_aop.Para.TableName = _sourceTableName;
|
|||
|
|
_aop.Para.Row = _Data;
|
|||
|
|
_aop.Para.Where = where;
|
|||
|
|
_aop.Para.IsTransaction = dalHelper.isOpenTrans;
|
|||
|
|
aopResult = _aop.Begin(Aop.AopEnum.GetCount);
|
|||
|
|
}
|
|||
|
|
if (aopResult == AopResult.Default || aopResult == AopResult.Continue)
|
|||
|
|
{
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.Txt:
|
|||
|
|
case DalType.Xml:
|
|||
|
|
_aop.Para.RowCount = _noSqlAction.GetCount(_sqlCreate.FormatWhere(where));
|
|||
|
|
_aop.Para.IsSuccess = _aop.Para.RowCount > 0;
|
|||
|
|
dalHelper.recordsAffected = _aop.Para.RowCount;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
ClearParameters();//<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
|
|||
|
|
string countSql = _sqlCreate.GetCountSql(where);
|
|||
|
|
object result = dalHelper.ExeScalar(countSql, false);
|
|||
|
|
|
|||
|
|
_aop.Para.IsSuccess = result != null;
|
|||
|
|
if (_aop.Para.IsSuccess)
|
|||
|
|
{
|
|||
|
|
_aop.Para.RowCount = Convert.ToInt32(result);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
_aop.Para.RowCount = -1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//ClearSysPara(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[FormatWhere<72><65><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (_aop.IsLoadAop && (aopResult == AopResult.Break || aopResult == AopResult.Continue))
|
|||
|
|
{
|
|||
|
|
_aop.End(Aop.AopEnum.GetCount);
|
|||
|
|
}
|
|||
|
|
if (dalHelper.recordsAffected == -2)
|
|||
|
|
{
|
|||
|
|
OnError();
|
|||
|
|
}
|
|||
|
|
return _aop.Para.RowCount;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Whether or not the specified condition exists
|
|||
|
|
/// <para><3E>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool Exists()
|
|||
|
|
{
|
|||
|
|
return Exists(null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="where">Sql statement where the conditions: 88, "id = 88"
|
|||
|
|
/// <para>sql<71><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>88<38><38>"id=88"</para></param>
|
|||
|
|
public bool Exists(object where)
|
|||
|
|
{
|
|||
|
|
if (CheckDisposed()) { return false; }
|
|||
|
|
if (where == null || Convert.ToString(where) == "")
|
|||
|
|
{
|
|||
|
|
_UI.PrimayAutoGetValue();
|
|||
|
|
where = _sqlCreate.GetPrimaryWhere();
|
|||
|
|
}
|
|||
|
|
AopResult aopResult = AopResult.Default;
|
|||
|
|
if (_aop.IsLoadAop)
|
|||
|
|
{
|
|||
|
|
_aop.Para.MAction = this;
|
|||
|
|
_aop.Para.TableName = _sourceTableName;
|
|||
|
|
_aop.Para.Row = _Data;
|
|||
|
|
_aop.Para.Where = where;
|
|||
|
|
_aop.Para.IsTransaction = dalHelper.isOpenTrans;
|
|||
|
|
aopResult = _aop.Begin(Aop.AopEnum.Exists);
|
|||
|
|
}
|
|||
|
|
if (aopResult == AopResult.Default || aopResult == AopResult.Continue)
|
|||
|
|
{
|
|||
|
|
switch (dalHelper.dalType)
|
|||
|
|
{
|
|||
|
|
case DalType.Txt:
|
|||
|
|
case DalType.Xml:
|
|||
|
|
_aop.Para.IsSuccess = _noSqlAction.Exists(_sqlCreate.FormatWhere(where));
|
|||
|
|
_aop.Para.ExeResult = _aop.Para.IsSuccess;
|
|||
|
|
dalHelper.recordsAffected = _aop.Para.IsSuccess ? 1 : 0;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
ClearParameters();//<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
|
|||
|
|
string countSql = _sqlCreate.GetExistsSql(where);
|
|||
|
|
_aop.Para.ExeResult = Convert.ToString(dalHelper.ExeScalar(countSql, false)) == "1" ? true : false;
|
|||
|
|
_aop.Para.IsSuccess = dalHelper.recordsAffected != -2;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (_aop.IsLoadAop && (aopResult == AopResult.Break || aopResult == AopResult.Continue))
|
|||
|
|
{
|
|||
|
|
_aop.End(Aop.AopEnum.Exists);
|
|||
|
|
}
|
|||
|
|
if (dalHelper.recordsAffected == -2)
|
|||
|
|
{
|
|||
|
|
OnError();
|
|||
|
|
}
|
|||
|
|
return Convert.ToBoolean(_aop.Para.ExeResult);
|
|||
|
|
|
|||
|
|
//switch (dalHelper.dalType)
|
|||
|
|
//{
|
|||
|
|
// case DalType.Txt:
|
|||
|
|
// case DalType.Xml:
|
|||
|
|
// return _noSqlAction.Exists(_sqlCreate.FormatWhere(where));
|
|||
|
|
// default:
|
|||
|
|
// return GetCount(where) > 0;
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get value from this.Data
|
|||
|
|
/// <para><3E><>Data<74><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡֵ</para>
|
|||
|
|
/// </summary>
|
|||
|
|
public T Get<T>(object key)
|
|||
|
|
{
|
|||
|
|
return _Data.Get<T>(key);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <param name="defaultValue">defaultValue<para>ֵΪNullʱ<6C><CAB1>Ĭ<EFBFBD><C4AC><EFBFBD>滻ֵ</para></param>
|
|||
|
|
public T Get<T>(object key, T defaultValue)
|
|||
|
|
{
|
|||
|
|
return _Data.Get<T>(key, defaultValue);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Set value to this.Data
|
|||
|
|
/// <para>ΪData<74><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ</para>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="key">columnName<para><3E><><EFBFBD><EFBFBD></para></param>
|
|||
|
|
/// <param name="value">value<para>ֵ</para></param>
|
|||
|
|
public MAction Set(object key, object value)
|
|||
|
|
{
|
|||
|
|
return Set(key, value, -1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="state">set value state (0: unchanged; 1: assigned, the same value [insertable]; 2: assigned, different values [updateable])
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD>ֵ״̬[0:δ<><CEB4><EFBFBD>ģ<EFBFBD>1:<3A>Ѹ<EFBFBD>ֵ,ֵ<><D6B5>ͬ[<5B>ɲ<EFBFBD><C9B2><EFBFBD>]<5D><>2:<3A>Ѹ<EFBFBD>ֵ,ֵ<><D6B5>ͬ[<5B>ɸ<EFBFBD><C9B8><EFBFBD>]]</para></param>
|
|||
|
|
public MAction Set(object key, object value, int state)
|
|||
|
|
{
|
|||
|
|
MDataCell cell = _Data[key];
|
|||
|
|
if (cell != null)
|
|||
|
|
{
|
|||
|
|
cell.Value = value;
|
|||
|
|
if (state >= 0 && state < 3)
|
|||
|
|
{
|
|||
|
|
cell.State = state;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
dalHelper.debugInfo.Append(AppConst.HR + "Alarm : can't find the ColumnName:" + key);
|
|||
|
|
}
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Sets a custom expression for the Update operation.
|
|||
|
|
/// <para>ΪUpdate<74><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="updateExpression">as<61><73>"a=a+1"<para><3E>磺"a=a+1"</para></param>
|
|||
|
|
public MAction SetExpression(string updateExpression)
|
|||
|
|
{
|
|||
|
|
_sqlCreate.updateExpression = updateExpression;
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Parameterized pass [used when the Where condition is a parameterized (such as: name = @ name) statement]
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[<5B><>Where<72><65><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28>磺name=@name)<29><><EFBFBD><EFBFBD>ʱʹ<CAB1><CAB9>]</para>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="paraName">paraName<para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para></param>
|
|||
|
|
/// <param name="value">value<para><3E><><EFBFBD><EFBFBD>ֵ</para></param>
|
|||
|
|
public MAction SetPara(object paraName, object value)
|
|||
|
|
{
|
|||
|
|
return SetPara(paraName, value, DbType.String);
|
|||
|
|
}
|
|||
|
|
List<AopCustomDbPara> customParaNames = new List<AopCustomDbPara>();
|
|||
|
|
|
|||
|
|
/// <param name="dbType">dbType<para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para></param>
|
|||
|
|
public MAction SetPara(object paraName, object value, DbType dbType)
|
|||
|
|
{
|
|||
|
|
if (dalHelper.AddParameters(Convert.ToString(paraName), value, dbType, -1, ParameterDirection.Input))
|
|||
|
|
{
|
|||
|
|
AopCustomDbPara para = new AopCustomDbPara();
|
|||
|
|
para.ParaName = Convert.ToString(paraName).Replace(":", "").Replace("@", "");
|
|||
|
|
para.Value = value;
|
|||
|
|
para.ParaDbType = dbType;
|
|||
|
|
customParaNames.Add(para);
|
|||
|
|
if (_aop.IsLoadAop)
|
|||
|
|
{
|
|||
|
|
_aop.Para.CustomDbPara = customParaNames;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Aop scenes can only be used by the parameterization of the Senate
|
|||
|
|
/// <para>Aop<6F><70><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD><C5BF><EFBFBD>ʹ<EFBFBD>õIJ<C3B5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="customParas">Paras<para><3E><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD></para></param>
|
|||
|
|
public MAction SetPara(List<AopCustomDbPara> customParas)
|
|||
|
|
{
|
|||
|
|
if (customParas != null && customParas.Count > 0)
|
|||
|
|
{
|
|||
|
|
foreach (AopCustomDbPara para in customParas)
|
|||
|
|
{
|
|||
|
|
SetPara(para.ParaName, para.Value, para.ParaDbType);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Clears paras (from SetPara method)
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD>(SetPara<72><61><EFBFBD>õ<EFBFBD>)<29>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public void ClearPara()
|
|||
|
|
{
|
|||
|
|
if (customParaNames.Count > 0)
|
|||
|
|
{
|
|||
|
|
if (dalHelper != null && dalHelper.Com.Parameters.Count > 0)
|
|||
|
|
{
|
|||
|
|
string paraName = string.Empty;
|
|||
|
|
foreach (AopCustomDbPara item in customParaNames)
|
|||
|
|
{
|
|||
|
|
for (int i = dalHelper.Com.Parameters.Count - 1; i > -1; i--)
|
|||
|
|
{
|
|||
|
|
if (string.Compare(dalHelper.Com.Parameters[i].ParameterName.TrimStart(dalHelper.Pre), item.ParaName.ToString()) == 0)
|
|||
|
|
{
|
|||
|
|
dalHelper.Com.Parameters.RemoveAt(i);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
customParaNames.Clear();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]
|
|||
|
|
/// </summary>
|
|||
|
|
private void ClearParameters()
|
|||
|
|
{
|
|||
|
|
if (dalHelper != null)
|
|||
|
|
{
|
|||
|
|
if (customParaNames.Count > 0)//<2F><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
{
|
|||
|
|
if (dalHelper.Com.Parameters.Count > 0)
|
|||
|
|
{
|
|||
|
|
bool isBreak = false;
|
|||
|
|
for (int i = dalHelper.Com.Parameters.Count - 1; i > -1; i--)
|
|||
|
|
{
|
|||
|
|
for (int j = 0; j < customParaNames.Count; j++)
|
|||
|
|
{
|
|||
|
|
if (string.Compare(dalHelper.Com.Parameters[i].ParameterName.TrimStart(dalHelper.Pre), customParaNames[j].ParaName.ToString()) == 0)
|
|||
|
|
{
|
|||
|
|
isBreak = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (!isBreak)
|
|||
|
|
{
|
|||
|
|
dalHelper.Com.Parameters.RemoveAt(i);
|
|||
|
|
isBreak = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
dalHelper.ClearParameters();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Specifies the column to read
|
|||
|
|
/// <para>ָ<><D6B8><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="columnNames">as<61><73>"columnA","columnB as B"</param>
|
|||
|
|
public MAction SetSelectColumns(params object[] columnNames)
|
|||
|
|
{
|
|||
|
|
bool isSplit = false;
|
|||
|
|
if (columnNames.Length == 1)
|
|||
|
|
{
|
|||
|
|
string column = Convert.ToString(columnNames[0]);
|
|||
|
|
if (column.IndexOf(" as ", StringComparison.OrdinalIgnoreCase) == -1)//<2F>ܿ<EFBFBD>"'xx,xx' as A
|
|||
|
|
{
|
|||
|
|
string[] items = Convert.ToString(columnNames[0]).Split(',');
|
|||
|
|
if (items.Length > 1)
|
|||
|
|
{
|
|||
|
|
isSplit = true;
|
|||
|
|
_sqlCreate.selectColumns = items;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (!isSplit)
|
|||
|
|
{
|
|||
|
|
_sqlCreate.selectColumns = columnNames;
|
|||
|
|
}
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get where statement
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>where<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="isAnd">connect by and/or<para>trueΪand<6E><64><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD>֮Ϊor<6F><72><EFBFBD><EFBFBD></para></param>
|
|||
|
|
public string GetWhere(bool isAnd, params MDataCell[] cells)
|
|||
|
|
{
|
|||
|
|
List<MDataCell> cs = new List<MDataCell>(cells.Length);
|
|||
|
|
if (cells.Length > 0)
|
|||
|
|
{
|
|||
|
|
cs.AddRange(cells);
|
|||
|
|
}
|
|||
|
|
return SqlCreate.GetWhere(DalType, isAnd, cs);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <param name="cells">MDataCell<para><3E><>Ԫ<EFBFBD><D4AA></para></param>
|
|||
|
|
public string GetWhere(params MDataCell[] cells)
|
|||
|
|
{
|
|||
|
|
return GetWhere(true, cells);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// Set the transaction level
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="level">IsolationLevel</param>
|
|||
|
|
public MAction SetTransLevel(IsolationLevel level)
|
|||
|
|
{
|
|||
|
|
dalHelper.TranLevel = level;
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Begin Transation
|
|||
|
|
/// <para><3E><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public void BeginTransation()
|
|||
|
|
{
|
|||
|
|
dalHelper.isOpenTrans = true;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Commit Transation
|
|||
|
|
/// <para><3E>ύ<EFBFBD><E1BDBB><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool EndTransation()
|
|||
|
|
{
|
|||
|
|
if (dalHelper != null && dalHelper.isOpenTrans)
|
|||
|
|
{
|
|||
|
|
return dalHelper.EndTransaction();
|
|||
|
|
}
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// RollBack Transation
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool RollBack()
|
|||
|
|
{
|
|||
|
|
if (dalHelper != null && dalHelper.isOpenTrans)
|
|||
|
|
{
|
|||
|
|
return dalHelper.RollBack();
|
|||
|
|
}
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region IDisposable <EFBFBD><EFBFBD>Ա
|
|||
|
|
public void Dispose()
|
|||
|
|
{
|
|||
|
|
Dispose(false);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Dispose
|
|||
|
|
/// <para><3E>ͷ<EFBFBD><CDB7><EFBFBD>Դ</para>
|
|||
|
|
/// </summary>
|
|||
|
|
internal void Dispose(bool isOnError)
|
|||
|
|
{
|
|||
|
|
hasDisposed = true;
|
|||
|
|
if (dalHelper != null)
|
|||
|
|
{
|
|||
|
|
if (!dalHelper.IsOnExceptionEventNull)
|
|||
|
|
{
|
|||
|
|
dalHelper.OnExceptionEvent -= new DbBase.OnException(_DataSqlHelper_OnExceptionEvent);
|
|||
|
|
}
|
|||
|
|
_debugInfo = dalHelper.debugInfo.ToString();
|
|||
|
|
dalHelper.Dispose();
|
|||
|
|
if (!isOnError)
|
|||
|
|
{
|
|||
|
|
dalHelper = null;
|
|||
|
|
|
|||
|
|
if (_sqlCreate != null)
|
|||
|
|
{
|
|||
|
|
_sqlCreate = null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (!isOnError)
|
|||
|
|
{
|
|||
|
|
if (_noSqlAction != null)
|
|||
|
|
{
|
|||
|
|
_noSqlAction.Dispose();
|
|||
|
|
}
|
|||
|
|
if (_aop != null)
|
|||
|
|
{
|
|||
|
|
_aop = null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
internal void OnError()
|
|||
|
|
{
|
|||
|
|
if (dalHelper != null && dalHelper.isOpenTrans)
|
|||
|
|
{
|
|||
|
|
Dispose(true);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
bool hasDisposed = false;
|
|||
|
|
private bool CheckDisposed()
|
|||
|
|
{
|
|||
|
|
if (hasDisposed || _Data.Columns.Count == 0)
|
|||
|
|
{
|
|||
|
|
Error.Throw("The current object 'MAction' has been disposed");
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
//AOP <20><><EFBFBD><EFBFBD>
|
|||
|
|
public partial class MAction
|
|||
|
|
{
|
|||
|
|
#region Aop<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
private InterAop _aop = new InterAop();
|
|||
|
|
/// <summary>
|
|||
|
|
/// Set Aop State
|
|||
|
|
/// <para><3E><><EFBFBD><EFBFBD>Aop״̬</para>
|
|||
|
|
/// </summary>
|
|||
|
|
public MProc SetAopState(AopOp op)
|
|||
|
|
{
|
|||
|
|
_aop.aopOp = op;
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Pass additional parameters for Aop use
|
|||
|
|
/// <para><3E><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>Aopʹ<70><CAB9></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public MAction SetAopPara(object para)
|
|||
|
|
{
|
|||
|
|
_aop.Para.AopPara = para;
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
//UI <20><><EFBFBD><EFBFBD>
|
|||
|
|
public partial class MAction
|
|||
|
|
{
|
|||
|
|
private MActionUI _UI;
|
|||
|
|
/// <summary>
|
|||
|
|
/// Manipulate UI
|
|||
|
|
/// <para>UI<55><49><EFBFBD><EFBFBD></para>
|
|||
|
|
/// </summary>
|
|||
|
|
public MActionUI UI
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _UI;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|