235 lines
6.9 KiB
C#
235 lines
6.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
//using System.Data.OracleClient;
|
|
using System.Data.SqlClient;
|
|
using System.Data.OleDb;
|
|
using DeiNiu.Utils;
|
|
|
|
namespace DeiNiu.Data.DataAccess
|
|
{
|
|
[Serializable]
|
|
public class Connection
|
|
{
|
|
|
|
¡¡ //static string sqlcon_str = System.Configuration.ConfigurationManager.AppSettings["SqlConnectionString"];
|
|
|
|
// private static string _ConnectionString = null;
|
|
|
|
private string sqlcon_str
|
|
{
|
|
get
|
|
{
|
|
/*
|
|
if (_ConnectionString == null)
|
|
_ConnectionString = (dt == enumDbInstance.wms? wmsConString() : platformConString());// System.Configuration.ConfigurationManager.AppSettings["SqlConnectionString"];
|
|
return _ConnectionString;
|
|
*/
|
|
|
|
//return dt == enumDbInstance.platForm ?platformConString() : wmsConString() ;
|
|
|
|
|
|
switch (dt){
|
|
|
|
case enumDbInstance.platForm:
|
|
return platformConString();
|
|
case enumDbInstance.wms:
|
|
return wmsConString();
|
|
case enumDbInstance.tms:
|
|
return wmsConString();
|
|
case enumDbInstance.wms_erp:
|
|
return wms_erpConString();
|
|
default:
|
|
return wmsConString();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
private int operater;
|
|
private enumDbInstance dt = enumDbInstance.platForm;
|
|
//private OracleConnection _OrclCon = null;
|
|
private SqlConnection _sqlCon = null;
|
|
// private OleDbConnection _oledbCon = null;
|
|
public SqlConnection getSqlCon(enumDbInstance dt)
|
|
{
|
|
this.operater = operater;
|
|
this.dt = dt;
|
|
try
|
|
{
|
|
_sqlCon = new SqlConnection(sqlcon_str);
|
|
//SqlConnection.ClearPool(_sqlCon); //https://stackoverflow.com/questions/26340644/sql-server-pre-login-handshake
|
|
_sqlCon.Open();
|
|
return _sqlCon;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLog(typeof(Connection), ex);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/*
|
|
public OracleConnection getOraCon()
|
|
{
|
|
try
|
|
{
|
|
_OrclCon = new OracleConnection(oracon_str);
|
|
_OrclCon.Open();
|
|
return _OrclCon;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
public OleDbConnection getOleCon()
|
|
{
|
|
try
|
|
{
|
|
//oledb_str = "Provider=OraOLEDB.Oracle.1;Password=welcome;Persist Security Info=True;User ID=hradmin;Data Source=cpor";
|
|
_oledbCon = new OleDbConnection(oledb_str);
|
|
_oledbCon.Open();
|
|
return _oledbCon;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
*/
|
|
|
|
/// <summary>
|
|
/// Êý¾Ý¿âÁ¬½Ó×Ö·û´®£¬×Ô¶¯ÅжϼÓÃÜ״̬²¢»ñÈ¡¶ÔÓ¦Á¬½Ó×Ö·û´®¡£
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string wmsConString()
|
|
{
|
|
if (!string.IsNullOrEmpty(WmsConstants.SQL_CONN_WMS))
|
|
{
|
|
return WmsConstants.SQL_CONN_WMS;
|
|
}
|
|
string cstr = System.Configuration.ConfigurationManager.AppSettings["SqlConnWMS"];
|
|
WmsConstants.SQL_CONN_WMS = cstr;
|
|
if (IsEncrypt())
|
|
{
|
|
// string cstr = System.Configuration.ConfigurationManager.AppSettings["SqlConnectionString"];
|
|
try
|
|
{
|
|
//½âÃܺóµÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®
|
|
cstr = DeiNiu.Utils.DESEncrypt.Decrypt(cstr);
|
|
WmsConstants.SQL_CONN_WMS = cstr;
|
|
return cstr;
|
|
}
|
|
catch
|
|
{
|
|
//Èç¹û¹´Ñ¡¼ÓÃÜ£¬µÚÒ»´ÎµÇ½ʱȡµ½µÄÊÇδ¼ÓÃÜÁ¬½Ó×Ö·û´®£¬ËùÒÔÖ±½Ó·µ»Ø¡£Èç¹û·µ»Ø¿Õ×Ö·û´®»áµ¼ÖÂÊ״εǽʧ°Ü¡£
|
|
//ConfigurationManager.AppSettings["ConnectionString"] = string.Empty;
|
|
//return string.Empty;
|
|
WmsConstants.SQL_CONN_WMS = cstr;
|
|
return cstr;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//ÎÞÐë½âÃܵÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®
|
|
|
|
return cstr;// System.Configuration.ConfigurationManager.AppSettings["SqlConnectionString"];
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// Êý¾Ý¿âÁ¬½Ó×Ö·û´®£¬×Ô¶¯ÅжϼÓÃÜ״̬²¢»ñÈ¡¶ÔÓ¦Á¬½Ó×Ö·û´®¡£
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string platformConString()
|
|
{
|
|
if (!string.IsNullOrEmpty(WmsConstants.SQL_CONN_PLATFORM))
|
|
{
|
|
return WmsConstants.SQL_CONN_PLATFORM;
|
|
}
|
|
string cstr = System.Configuration.ConfigurationManager.AppSettings["SqlConnPlatform"];
|
|
WmsConstants.SQL_CONN_PLATFORM = cstr;
|
|
if (IsEncrypt())
|
|
{
|
|
|
|
try
|
|
{
|
|
//½âÃܺóµÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®
|
|
cstr = DeiNiu.Utils.DESEncrypt.Decrypt(cstr);
|
|
WmsConstants.SQL_CONN_PLATFORM = cstr;
|
|
return cstr;
|
|
}
|
|
catch
|
|
{
|
|
|
|
WmsConstants.SQL_CONN_PLATFORM = cstr;
|
|
return cstr;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//ÎÞÐë½âÃܵÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®
|
|
|
|
return cstr;// System.Configuration.ConfigurationManager.AppSettings["SqlConnectionString"];
|
|
}
|
|
|
|
}
|
|
|
|
public static string wms_erpConString()
|
|
{
|
|
if (!string.IsNullOrEmpty(WmsConstants.SQL_CONN_WMS_ERP))
|
|
{
|
|
return WmsConstants.SQL_CONN_WMS_ERP;
|
|
}
|
|
string cstr = System.Configuration.ConfigurationManager.AppSettings["SqlconnWms_erp"];
|
|
WmsConstants.SQL_CONN_WMS_ERP = cstr;
|
|
if (IsEncrypt())
|
|
{
|
|
|
|
try
|
|
{
|
|
//½âÃܺóµÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®
|
|
cstr = DeiNiu.Utils.DESEncrypt.Decrypt(cstr);
|
|
WmsConstants.SQL_CONN_WMS_ERP = cstr;
|
|
return cstr;
|
|
}
|
|
catch
|
|
{
|
|
|
|
WmsConstants.SQL_CONN_WMS_ERP = cstr;
|
|
return cstr;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//ÎÞÐë½âÃܵÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®
|
|
|
|
return cstr;// System.Configuration.ConfigurationManager.AppSettings["SqlConnectionString"];
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// ÑéÖ¤ÊÇ·ñÒѼÓÃÜ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static bool IsEncrypt()
|
|
{
|
|
switch (System.Configuration.ConfigurationManager.AppSettings["ConStringEncrypt"])
|
|
{
|
|
case "1":
|
|
case "TRUE":
|
|
case "true":
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|