2025-03-27 15:05:14 +08:00

152 lines
6.9 KiB
C#

using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using SuperMap.RealEstate.Configuration;
using SuperMap.RealEstate.ServiceModel;
using SuperMap.RealEstate.ServiceModel.Logging;
using SuperMap.RealEstate.Personnel.Running.Model;
using SuperMap.RealEstate.Personnel.Running.Interface;
namespace SuperMap.RealEstate.Personnel.Running
{
/// <summary>
/// 服务类 T_TRAIN 部分
/// </summary>
partial class Service:IService
{
#region TRAIN_Insert
/// <summary>
/// 插入数据
/// </summary>
/// <param name="tRAIN">TRAIN类</param>
/// <param name="loggingInfo">日志信息</param>
/// <returns>TRAIN类</returns>
public TRAIN TRAIN_Insert(TRAIN tRAIN, ServiceLoggingInfo loggingInfo)
{
using (SQLStringHelper<TRAIN> _SQLStringHelper = new SQLStringHelper<TRAIN>(typeof(TableSchema_TRAIN)))
{
System.Int32 _TRAIN_ID=0;
using (DbCommand _DbCommand = DataBaseHelper.CreateCommand(
_SQLStringHelper.GetInsertSQL(tRAIN, DataBaseHelper.IsOracleClientFactory)))
{
Dictionary<string, object> _Parameters = _SQLStringHelper.Parameters;
if (DataBaseHelper.IsOracleClientFactory)
{
if (tRAIN.TRAIN_ID == null)
_TRAIN_ID= DataBaseHelper.ExecuteScalar<System.Int32>("select "+ TableSchema_TRAIN.SequenceName +".nextval from dual");
else
_TRAIN_ID = tRAIN.TRAIN_ID.Value;
if (_Parameters.ContainsKey(TableSchema_TRAIN.TRAIN_ID.ToLower()))
_Parameters[TableSchema_TRAIN.TRAIN_ID.ToLower()]=_TRAIN_ID;
else
_Parameters.Add(TableSchema_TRAIN.TRAIN_ID.ToLower(),_TRAIN_ID);
}
DataBaseHelper.PrepareCommandParameters(_DbCommand, _Parameters);
_DbCommand.ExecuteNonQuery();
if (DataBaseHelper.IsAccessClientFactory)
{
if (tRAIN.TRAIN_ID == null)
_TRAIN_ID = DataBaseHelper.ExecuteScalar<System.Int32>("select @@IDENTITY");
else
_TRAIN_ID = tRAIN.TRAIN_ID.Value;
}
if (DataBaseHelper.IsSqlClientFactory)
{
if (tRAIN.TRAIN_ID == null)
_TRAIN_ID = DataBaseHelper.ExecuteScalar<System.Int32>("select IDENT_CURRENT('"+ TableSchema_TRAIN.TableName +"');");
else
_TRAIN_ID = tRAIN.TRAIN_ID.Value;
}
if (_DbCommand.Transaction == null)
_DbCommand.Connection.Close();
}
tRAIN.TRAIN_ID = _TRAIN_ID;
LoggingDataForInsert<TRAIN, TableSchema_TRAIN>(tRAIN, loggingInfo);
}
return tRAIN;
}
#endregion
#region TRAIN_Update
/// <summary>
/// 更新数据
/// </summary>
/// <param name="tRAIN">TRAIN类</param>
/// <param name="loggingInfo">日志信息</param>
/// <returns>TRAIN类</returns>
public bool TRAIN_Update(TRAIN tRAIN, ServiceLoggingInfo loggingInfo)
{
using (SQLStringHelper<TRAIN> _SQLStringHelper = new SQLStringHelper<TRAIN>(typeof(TableSchema_TRAIN)))
{
string _SQLStr = _SQLStringHelper.GetUpDateSQL(tRAIN, DataBaseHelper.IsOracleClientFactory);
if (string.IsNullOrEmpty(_SQLStr)) return true;
if (!LoggingDataForUpdate<TRAIN, TableSchema_TRAIN>(tRAIN, loggingInfo))
return true;
if (ConfigurationSetting.HttpRuntimeCache_Enabled == true)
ServiceCacheHelper<TRAIN>.Remove(tRAIN.TRAIN_ID.ToString());
Dictionary<string, object> _Parameters = _SQLStringHelper.Parameters;
return (DataBaseHelper.ExecuteNonQuery(_SQLStr, _Parameters) == 1);
}
}
#endregion
#region TRAIN_Delete
/// <summary>
/// 删除数据
/// </summary>
/// <param name="tRAIN_ID">主键字段</param>
/// <param name="loggingInfo">日志信息</param>
public void TRAIN_Delete(System.Int32 tRAIN_ID, ServiceLoggingInfo loggingInfo)
{
if (ConfigurationSetting.HttpRuntimeCache_Enabled == true)
ServiceCacheHelper<TRAIN>.Remove(tRAIN_ID.ToString());
using (SQLStringHelper<TRAIN> _SQLStringHelper =
new SQLStringHelper<TRAIN>(typeof(TableSchema_TRAIN)))
{
string _SQLStr = _SQLStringHelper.GetDeleteSQL(tRAIN_ID,DataBaseHelper.IsOracleClientFactory);
LoggingDataForDelete<TRAIN, TableSchema_TRAIN>(tRAIN_ID, loggingInfo);
DataBaseHelper.ExecuteNonQuery(_SQLStr, _SQLStringHelper.Parameters);
}
}
#endregion
#region TRAIN_Search
/// <summary>
/// 查询数据
/// </summary>
/// <param name="parameters">参数集合</param>
/// <param name="loggingInfo">日志信息</param>
/// <returns>TRAIN类</returns>
public TRAIN TRAIN_Search(List<SearchParameter> parameters, ServiceLoggingInfo loggingInfo)
{
TRAIN _TRAIN = null;
if (parameters.Count == 0)
return _TRAIN;
if ((ConfigurationSetting.HttpRuntimeCache_Enabled == true) && (parameters.Count == 1) &&
(parameters[0].Name.Equals(TableSchema_TRAIN.TRAIN_ID,System.StringComparison.CurrentCultureIgnoreCase)) &&
ServiceCacheHelper<TRAIN>.Read(parameters[0].Value.ToString(),out _TRAIN))
{
return _TRAIN;
}
using (SQLStringHelper<TRAIN> _SQLStringHelper = new SQLStringHelper<TRAIN>(typeof(TableSchema_TRAIN)))
{
string _SQLStr = _SQLStringHelper.GetSelectSQL(parameters,
DataBaseHelper.IsOracleClientFactory);
DataSet _DataSet = DataBaseHelper.ExecuteDataSet(_SQLStr, _SQLStringHelper.Parameters);
if ((_DataSet.Tables.Count>0) && (_DataSet.Tables[0].Rows.Count > 0))
{
_TRAIN = new TRAIN();
_SQLStringHelper.DataRowToObject(ref _TRAIN, _DataSet.Tables[0].Rows[0]);
}
}
if ((ConfigurationSetting.HttpRuntimeCache_Enabled == true) && (_TRAIN != null))
{
ServiceCacheHelper<TRAIN>.Insert( _TRAIN.TRAIN_ID.ToString(),_TRAIN);
}
return _TRAIN;
}
#endregion
}
}