238 lines
6.7 KiB
C#
238 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Configuration;
|
|
using System.Collections.Specialized;
|
|
|
|
using System.Data;
|
|
using System.Collections;
|
|
using WMS.Common;
|
|
using Oracle.ManagedDataAccess.Client;
|
|
|
|
namespace WMS.Business
|
|
{
|
|
#region 业务层进行实例化
|
|
/// <summary>
|
|
/// 返回对业务层的对象进行实例化
|
|
/// </summary>
|
|
public class IBussFactory<T> where T : new()
|
|
{
|
|
private static T m_instance;
|
|
private static object m_lock = new object();
|
|
#region 通过Singleton模式返回当前实例
|
|
/// <summary>
|
|
/// 通过Singleton模式返回当前实例
|
|
/// </summary>
|
|
public static T Instance()
|
|
{
|
|
|
|
if (m_instance == null)
|
|
{
|
|
lock (m_lock)
|
|
{
|
|
if (m_instance == null)
|
|
{
|
|
// NameValueCollection nc = (NameValueCollection)ConfigurationManager.GetSection("CLOUDS/BussValue");
|
|
// string bussness = nc[className].ToString();
|
|
m_instance = new T();
|
|
}
|
|
}
|
|
}
|
|
|
|
return m_instance;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// 业务层类的
|
|
/// </summary>
|
|
public class IBussFactory
|
|
{
|
|
private string errText = string.Empty;
|
|
/// <summary>
|
|
/// 数据库连不上时错误日志
|
|
/// </summary>
|
|
public string ErrText
|
|
{
|
|
get
|
|
{
|
|
string err = errText;
|
|
errText = string.Empty;
|
|
return err;
|
|
|
|
}
|
|
set
|
|
{
|
|
if (errText.Trim().Length > 0) { errText = string.Empty; }
|
|
errText = value;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 日志的集合,主要是当事务提交时统一交 sql语句进行写日志表
|
|
/// </summary>
|
|
protected readonly List<WMS.Model.Base.LogDataModel> logList = new List<Model.Base.LogDataModel>();
|
|
|
|
#region 事务处理属性 -- 属性值 Transaction
|
|
/// <summary>
|
|
/// 事务处理
|
|
/// </summary>
|
|
private OracleTransaction tranSaction;
|
|
/// <summary>
|
|
/// 存储过程事务的处理
|
|
/// </summary>
|
|
protected OracleTransaction Transaction
|
|
{
|
|
get { return tranSaction; }
|
|
set {if(tranSaction==null) tranSaction = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region 事务提交或者回滚
|
|
/// <summary>
|
|
/// 事务提交或者回滚
|
|
/// </summary>
|
|
protected void TaCmtOrRak()
|
|
{
|
|
lock("cm")
|
|
{
|
|
try
|
|
{
|
|
if (logList.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
if (tranSaction == null)
|
|
{
|
|
return;
|
|
}
|
|
foreach (WMS.Model.Base.LogDataModel log in logList)
|
|
{
|
|
if (log.Content.Trim().Length > 0)
|
|
{
|
|
TranRollback();
|
|
errText = log.Content;
|
|
return;
|
|
}
|
|
}
|
|
|
|
WMS.DBUtility.OracleHelper.CommitTransaction(tranSaction);
|
|
|
|
WMS.IData.DataProvider.Instance.ErrLog.InsertLog(logList);
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string errText = string.Empty;
|
|
ErrText = "出错了,请联系管理员,异常内容" + ex.Message.ToString();
|
|
LogWriteText.WriteLog(ErrText);
|
|
|
|
}
|
|
finally
|
|
{
|
|
if (tranSaction != null)
|
|
//if (tranSaction != null || ErrText.Trim().Length > 0)
|
|
{
|
|
if (tranSaction.Connection != null)
|
|
//if (tranSaction != null || ErrText.Trim().Length > 0)
|
|
{
|
|
if (tranSaction.Connection.State == ConnectionState.Open)
|
|
{
|
|
tranSaction.Connection.Close();
|
|
tranSaction.Dispose();
|
|
tranSaction = null;
|
|
}
|
|
|
|
}
|
|
tranSaction.Dispose();
|
|
tranSaction = null;
|
|
}
|
|
|
|
if (logList.Count > 0)
|
|
{
|
|
logList.Clear();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 事务回滚
|
|
/// <summary>
|
|
/// 事务回滚
|
|
/// </summary>
|
|
protected void TranRollback()
|
|
{
|
|
|
|
try
|
|
{
|
|
|
|
WMS.DBUtility.OracleHelper.RollbackTransaction(tranSaction);
|
|
logList.Clear();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrText = "可能数据库联系错误,请联系管理员,异常内容" + ex.Message.ToString();
|
|
|
|
}
|
|
finally
|
|
{
|
|
|
|
if (tranSaction != null || ErrText.Trim().Length > 0)
|
|
{
|
|
tranSaction.Dispose();
|
|
tranSaction = null;
|
|
}
|
|
logList.Clear();
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 查询日志的处理当查询时必须调用该方法
|
|
/// <summary>
|
|
/// 查询日志的处理当查询时必须调用该方法
|
|
/// </summary>
|
|
/// <param name="ds">查询出的dataset</param>
|
|
/// <returns>返回</returns>
|
|
public bool DataLogErrWrite(DataTable ds, string errCaption)
|
|
{
|
|
if (ds == null )
|
|
{
|
|
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 是否存在错误
|
|
/// </summary>
|
|
/// <param name="errCaption">操作</param>
|
|
/// <returns>返回</returns>
|
|
public bool DataLogErrWrite(string errCaption)
|
|
{
|
|
if (WMS.IData.DataProvider.Instance.logData.Content.Trim().Length > 0)
|
|
{
|
|
if (WMS.IData.DataProvider.Instance.logData.Content.Trim().Length > 0)
|
|
{
|
|
|
|
|
|
ErrText = errCaption + WMS.IData.DataProvider.Instance.logData.Content;
|
|
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|