IObject = (IClientForm)Assembly.LoadFile(str).CreateInstance(dyanmicloadobject.ClassName);
/// <summary>
/// 获取远程remoting对象
/// </summary>
/// <param name="type">远程remoting对象类型 </param>
/// <param name="url">远程remoting对象地址</param>
/// <returns>远程remoting对象</returns>
public static object GetRemotingObject(Type type ,string url)
{
IpCache ic = IpCache.GetIpCache();
string ipaddress = ic.GetIP(ConfigurationManager.AppSettings.Get(url));
return Activator.GetObject(type, ipaddress);
}
public class IpCache
{
private static Hashtable ipcache;
private static IpCache cc;
private IpCache()
{
}
public static IpCache GetIpCache()
{
if (cc == null)
{
cc = new IpCache();
ipcache = new Hashtable();
}
return cc;
}
public string GetIP(string hoststring)
{
//分解hoststring
string lsstr= hoststring.Trim();
string lsip;
lsstr = lsstr.Substring(lsstr.IndexOf("//") + 2);
lsstr = lsstr.Substring(0, lsstr.IndexOf(":"));
if (ipcache.ContainsKey(lsstr))
{
lsip = ipcache[lsstr].ToString();
}
else
{
lsip= Dns.GetHostAddresses(lsstr )[0].ToString();
ipcache.Add(lsstr, lsip);
}
//合成地址
return hoststring.Replace(lsstr, lsip); ;
}
}
#region ExecuteDataset
/// <summary>
/// 执行SQL语句或者存储过程 ,返回参数dataset(sql)
/// </summary>
/// <param name="connection">要执行SQL语句的连接</param>
/// <param name="commandType">SQL语句类型</param>
/// <param name="commandText">SQL语句或者存储过程名</param>
/// <param name="Table"> 填充的表名 </param>
/// <param name="commandParameters">SQL语句或者存储过程参数</param>
/// <returns>执行结果集</returns>
public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, DataTable Table, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
//ZJSDataSet ds = new ZJSDataSet();
Table.DataSet.RemotingFormat = SerializationFormat.Binary;
Table.DataSet.SchemaSerializationMode = SchemaSerializationMode.ExcludeSchema;
try
{
da.Fill(Table);
}
catch (Exception oe)
{
ExceptionManage ex = new ExceptionManage();
ex.ThrowException(3, SystemType.DATA, "", oe.Message + cmd.CommandText + oe.StackTrace);
}
cmd.Parameters.Clear();
if (mustCloseConnection)
connection.Close();
return Table.DataSet;
}
}
/// <summary>
/// 执行SQL语句或者存储过程 ,返回参数dataset(通用)
/// </summary>
/// <param name="connection">要执行SQL语句的连接</param>
/// <param name="commandType">SQL语句类型</param>
/// <param name="commandText">SQL语句或者存储过程名</param>
/// <param name="Table"> 填充的表名 </param>
/// <param name="commandParameters">SQL语句或者存储过程参数</param>
/// <returns>执行结果集</returns>
public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, DataTable Table, params DbParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
//ZJSDataSet ds = new ZJSDataSet();
Table.DataSet.RemotingFormat = SerializationFormat.Binary;
Table.DataSet.SchemaSerializationMode = SchemaSerializationMode.ExcludeSchema;
try
{
da.Fill(Table);
}
catch (Exception oe)
{
ExceptionManage ex = new ExceptionManage();
ex.ThrowException(3, SystemType.DATA, "", oe.Message + cmd.CommandText + oe.StackTrace);
}
cmd.Parameters.Clear();
if (mustCloseConnection)
connection.Close();
return Table.DataSet;
}
}
/// <summary>
/// 执行SQL语句或者存储过程 ,返回参数datatable(通用)------ty--------------
/// </summary>
/// <param name="DataType"></param>
/// <param name="commandType"></param>
/// <param name="commandText"></param>
/// <param name="Table"></param>
/// <param name="commandParameters"></param>
/// <returns>table</returns>
public static DataTable ExecuteDataTable(SystemType DataType, CommandType commandType, string commandText, DataTable Table, params DbParameter[] commandParameters)
{
//要检查参数
SqlConnection connection = GetDataBase.GetDataCon(DataType);
SqlCommand cmd = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
//ZJSDataSet ds = new ZJSDataSet();
//Table.DataSet.RemotingFormat = SerializationFormat.Binary;
// Table.DataSet.SchemaSerializationMode = SchemaSerializationMode.ExcludeSchema;
try
{
da.Fill(Table);
}
catch (Exception oe)
{
ExceptionManage ex = new ExceptionManage();
ex.ThrowException(3, SystemType.DATA, "", oe.Message + cmd.CommandText + oe.StackTrace);
}
cmd.Parameters.Clear();
if (mustCloseConnection)
connection.Close();
return Table;
}
}