|
|
@@ -3,6 +3,7 @@ using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Text;
|
|
|
+using UAS_DeviceMonitor.PublicMethod;
|
|
|
|
|
|
namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
@@ -11,7 +12,7 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
//系统默认的的连接字符串
|
|
|
private string ConnectionStrings = Properties.Settings.Default.Properties["MES"].DefaultValue.ToString();
|
|
|
//用户选择的数据库的连接字符串
|
|
|
- public static string DBConnectionString;
|
|
|
+ public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=UAS_MES_PROD;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.253.6)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
|
|
|
public static OracleConnection connection = null;
|
|
|
OracleCommand command = null;
|
|
|
/// <summary>
|
|
|
@@ -38,7 +39,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
command = new OracleCommand("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
@@ -53,16 +53,17 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
string sql = "select " + Field + " from " + TableName + " where " + Condition;
|
|
|
+ Console.WriteLine(sql);
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter();
|
|
|
ad.SelectCommand = command;
|
|
|
try
|
|
|
{
|
|
|
ad.Fill(dt);
|
|
|
}
|
|
|
- catch (Exception)
|
|
|
+ catch (Exception e)
|
|
|
{
|
|
|
+ LogManager.DoLog(e.StackTrace + e.Message);
|
|
|
connection = new OracleConnection(DBConnectionString);
|
|
|
connection.Open();
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
@@ -126,7 +127,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
DataTable dt = new DataTable();
|
|
|
string sql = "select count(1) from " + TableName + " where " + Condition;
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
@@ -144,7 +144,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
DataTable dt = new DataTable();
|
|
|
string sql = "select count(1) from " + TableName;
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
|
|
|
ad.Fill(dt);
|
|
|
@@ -163,7 +162,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
sql += AddField(Fields);
|
|
|
sql += " from " + TableName + " where " + Condition + " and rownum=1";
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
try
|
|
|
{
|
|
|
@@ -228,7 +226,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
sql.Append(" from " + TableName + ") A where ROWNUM <= " + CurrentPage * PageSize + ") where RN> " + (CurrentPage - 1) * PageSize);
|
|
|
}
|
|
|
command = new OracleCommand(sql.ToString(), connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
@@ -253,7 +250,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
sql += " from " + TableName + " where " + Condition;
|
|
|
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
try
|
|
|
{
|
|
|
@@ -283,7 +279,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
sql += Fields;
|
|
|
sql += " from " + TableName;
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.SelectCommand = command;
|
|
|
try
|
|
|
@@ -475,7 +470,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
string sql = "select count(1) from " + TableName + " where " + Condition;
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
DataTable dt = new DataTable();
|
|
|
try
|
|
|
@@ -506,7 +500,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
object result = null;
|
|
|
command = new OracleCommand(SQL, connection);
|
|
|
- Reconnect(command);
|
|
|
//用来拼接参数的
|
|
|
if (names.Length > 0)
|
|
|
{
|
|
|
@@ -543,8 +536,9 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
ad.Fill((DataTable)result);
|
|
|
}
|
|
|
- catch (Exception)
|
|
|
+ catch (Exception e)
|
|
|
{
|
|
|
+ LogManager.DoLog(e.StackTrace + e.Message);
|
|
|
connection = new OracleConnection(DBConnectionString);
|
|
|
connection.Open();
|
|
|
command = new OracleCommand(SQL, connection);
|
|
|
@@ -611,7 +605,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
DataTable dt = new DataTable();
|
|
|
string sql = "select distinct count('" + Field + "') from " + TableName;
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
try
|
|
|
{
|
|
|
@@ -649,12 +642,10 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
/// <param name="TableName">表名</param>
|
|
|
/// <param name="ID">主键</param>
|
|
|
/// <param name="DeleteID">需要删除主键ID的数组</param>
|
|
|
- public void DeleteDataByID(string TableName, string ID, string[] DeleteID)
|
|
|
+ public void DeleteDataByID(string TableName, string ID, int[] DeleteID)
|
|
|
{
|
|
|
string sql = "delete from " + TableName + " where " + ID + " =:DeleteID";
|
|
|
-
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
command.ArrayBindCount = DeleteID.Length;
|
|
|
command.Parameters.Add(new OracleParameter("DeleteID", OracleDbType.Long, DeleteID, ParameterDirection.Input));
|
|
|
try
|
|
|
@@ -806,7 +797,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
public void BatchInsert(string sql, params object[][] names)
|
|
|
{
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
command.ArrayBindCount = names[1].Length;
|
|
|
if (names[1].Length == 0)
|
|
|
{
|
|
|
@@ -834,7 +824,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
public void BatchInsertDataTable(string sql, string[] param, params object[][] param1)
|
|
|
{
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
command.ArrayBindCount = param1[0].Length;
|
|
|
//因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
|
|
|
//将第一个数组的下标固定为0作为循环添加的参数的名称
|
|
|
@@ -921,8 +910,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
string sql = "update " + TableName + " set " + update + " where " + condition;
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
-
|
|
|
- Reconnect(command);
|
|
|
try
|
|
|
{
|
|
|
command.ExecuteNonQuery();
|
|
|
@@ -946,7 +933,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
command = new OracleCommand(ProcedureName);
|
|
|
command.Connection = connection;
|
|
|
- Reconnect(command);
|
|
|
command.CommandText = ProcedureName;
|
|
|
command.CommandType = CommandType.StoredProcedure;
|
|
|
for (int i = 0; i < param.Length; i++)
|
|
|
@@ -1054,7 +1040,6 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
command = new OracleCommand(sql, connection);
|
|
|
- Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter();
|
|
|
ad.SelectCommand = command;
|
|
|
try
|
|
|
@@ -1118,13 +1103,5 @@ namespace UAS_DeviceMonitor.DataOperate
|
|
|
{
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- private void Reconnect(OracleCommand cmd)
|
|
|
- {
|
|
|
- if (cmd.Connection.State == ConnectionState.Closed)
|
|
|
- {
|
|
|
- cmd.Connection.Open();
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|