|
|
@@ -26,18 +26,12 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
//如果选择的是默认数据则直接用配置文件的信息连接,否则选择数据库的账套信息
|
|
|
if (DBConnectionString == null || DBConnectionString == ConnectionStrings)
|
|
|
- {
|
|
|
connection = new OracleConnection(ConnectionStrings);
|
|
|
- }
|
|
|
else
|
|
|
- {
|
|
|
connection = new OracleConnection(DBConnectionString);
|
|
|
- }
|
|
|
connection.Open();
|
|
|
- command = new OracleCommand();
|
|
|
- command.Connection = connection;
|
|
|
}
|
|
|
- catch (Exception ) { }
|
|
|
+ catch (Exception e) { }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -46,12 +40,12 @@ namespace UAS_XmlAnalysor
|
|
|
public DataTable GetColumnDataType(string TableName)
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
- command.CommandText = "select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')";
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ 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();
|
|
|
+ command.Dispose();
|
|
|
return dt;
|
|
|
}
|
|
|
|
|
|
@@ -62,13 +56,14 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
string sql = "select " + Field + " from " + TableName + " where " + Condition;
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter();
|
|
|
ad.SelectCommand = command;
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
if (dt.Rows.Count > 0)
|
|
|
{
|
|
|
return dt.Rows[0][0];
|
|
|
@@ -79,6 +74,7 @@ namespace UAS_XmlAnalysor
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 执行打印的SQL
|
|
|
/// </summary>
|
|
|
@@ -98,17 +94,18 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
sb.Append(Param[i] + ":Param" + i);
|
|
|
}
|
|
|
- command.CommandText = sb.ToString();
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sb.ToString(), connection);
|
|
|
+
|
|
|
for (int i = 0; i < ParamNum; i++)
|
|
|
{
|
|
|
command.Parameters.Add("Param" + i, OracleDbType.Varchar2, Parameters[i], ParameterDirection.Input);
|
|
|
}
|
|
|
+
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
DataTable dt = new DataTable();
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
- command.Parameters.Clear();
|
|
|
+ command.Dispose();
|
|
|
return dt;
|
|
|
}
|
|
|
return "参数错误,请检查SQL语句";
|
|
|
@@ -122,12 +119,13 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
string sql = "select count(1) from " + TableName + " where " + Condition;
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
return int.Parse(dt.Rows[0][0].ToString());
|
|
|
}
|
|
|
|
|
|
@@ -140,12 +138,13 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
string sql = "select count(1) from " + TableName;
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
+
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
return int.Parse(dt.Rows[0][0].ToString());
|
|
|
}
|
|
|
|
|
|
@@ -158,15 +157,32 @@ namespace UAS_XmlAnalysor
|
|
|
string sql = "select ";
|
|
|
sql += AddField(Fields);
|
|
|
sql += " from " + TableName + " where " + Condition + " and rownum=1";
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
return dt;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 将DataTable导入到指定的表中
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="DataTable"></param>
|
|
|
+ /// <param name="TableName"></param>
|
|
|
+ public void InsertDataTable(DataTable DataTable, string TableName)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < DataTable.Rows.Count; i++)
|
|
|
+ {
|
|
|
+ for (int j = 0; j < DataTable.Columns.Count; j++)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 按分页获取数据
|
|
|
/// </summary>
|
|
|
@@ -195,12 +211,12 @@ namespace UAS_XmlAnalysor
|
|
|
else
|
|
|
sql.Append(" from " + TableName + ") A where ROWNUM <= " + CurrentPage * PageSize + ") where RN> " + (CurrentPage - 1) * PageSize);
|
|
|
}
|
|
|
- command.CommandText = sql.ToString();
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql.ToString(), connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
dt.Columns.RemoveAt(0);
|
|
|
foreach (DataColumn dc in dt.Columns)
|
|
|
{
|
|
|
@@ -219,12 +235,13 @@ namespace UAS_XmlAnalysor
|
|
|
string sql = "select ";
|
|
|
sql += AddField(Fields);
|
|
|
sql += " from " + TableName + " where " + Condition;
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
return dt;
|
|
|
}
|
|
|
|
|
|
@@ -237,8 +254,7 @@ namespace UAS_XmlAnalysor
|
|
|
string sql = "select ";
|
|
|
sql += Fields;
|
|
|
sql += " from " + TableName;
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.SelectCommand = command;
|
|
|
@@ -248,6 +264,7 @@ namespace UAS_XmlAnalysor
|
|
|
dc.Caption = "测试测试";
|
|
|
}
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
return dt;
|
|
|
}
|
|
|
|
|
|
@@ -326,6 +343,7 @@ namespace UAS_XmlAnalysor
|
|
|
//不是新增行的启用更新的方法
|
|
|
sb.Append("update " + TableName + " set ");
|
|
|
//拼接语句,特殊处理日期
|
|
|
+
|
|
|
foreach (DataColumn dc in DataTable.Columns)
|
|
|
{
|
|
|
if (!dc.DataType.ToString().Equals("System.DateTime"))
|
|
|
@@ -339,8 +357,7 @@ namespace UAS_XmlAnalysor
|
|
|
}
|
|
|
sb.Remove(sb.Length - 1, 1);
|
|
|
sb.Append(" where " + PrimaryKey + "=:" + PrimaryKey);
|
|
|
- command.CommandText = sb.ToString();
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sb.ToString(), connection);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
// 参数的长度是DataTable的行数决定的
|
|
|
command.ArrayBindCount = DataTable.Rows.Count;
|
|
|
@@ -369,7 +386,169 @@ namespace UAS_XmlAnalysor
|
|
|
ad.UpdateCommand = command;
|
|
|
ad.Update(DataTable);
|
|
|
ad.Dispose();
|
|
|
- command.Parameters.Clear();
|
|
|
+ command.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取DbFind的数据的DataTable的结构
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="field"></param>
|
|
|
+ /// <param name="caller"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public DataTable GetDbFindDataTable(string field, string caller)
|
|
|
+ {
|
|
|
+ string sql = "select * from dbfindsetui where ds_caller='" + caller + "' and ds_whichui='" + field + "'";
|
|
|
+ DataTable dt = (DataTable)ExecuteSql(sql, "select");
|
|
|
+ if (dt.Rows.Count != 0)
|
|
|
+ {
|
|
|
+ //通过#号分割字段
|
|
|
+ string[] dbfield = dt.Rows[0]["ds_findtoui"].ToString().Split('#');
|
|
|
+ string[] cnfield = dt.Rows[0]["ds_dbcaption"].ToString().Split('#');
|
|
|
+ //获取查询要查询的Table
|
|
|
+ string dbtable = dt.Rows[0]["ds_tables"].ToString();
|
|
|
+ //拼接查询的字段
|
|
|
+ for (int i = 0; i < dbfield.Length; i++)
|
|
|
+ {
|
|
|
+ dbfield[i] = dbfield[i].Split(',')[0];
|
|
|
+ }
|
|
|
+ //新建一个空的DataTable
|
|
|
+ DataTable dt1 = new DataTable();
|
|
|
+ //往空的DataTable添加结构,ColumnName是中文,Caption是实际的字段名称
|
|
|
+ for (int i = 0; i < cnfield.Length; i++)
|
|
|
+ {
|
|
|
+ dt1.Columns.Add(cnfield[i]);
|
|
|
+ dt1.Columns[i].Caption = dbfield[i];
|
|
|
+ }
|
|
|
+ //返回一个带有结构的空的DataTable
|
|
|
+ //DbFind.BindTable1 = dbtable;
|
|
|
+ return dt1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取配置列表中的数据,支持DaatList,Form,DetailGrid
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="Caller"></param>
|
|
|
+ /// <param name="Type"></param>
|
|
|
+ /// <param name="condition"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public DataTable GetConfigureData(string Caller, string Type, string condition)
|
|
|
+ {
|
|
|
+ DataTable dt = new DataTable();
|
|
|
+ //用于拼接SQL语句
|
|
|
+ StringBuilder Sql = new StringBuilder();
|
|
|
+ //用于设置不同Type时设置对应表的字段
|
|
|
+ string getField = "";
|
|
|
+ string getCaption = "";
|
|
|
+ string getTable = "";
|
|
|
+ switch (Type.ToUpper())
|
|
|
+ {
|
|
|
+ case "DATALIST":
|
|
|
+ getField = "dld_field"; getCaption = "dld_caption"; getTable = "dld_table";
|
|
|
+ Sql.Append("select * from datalistdetail where dld_caller='" + Caller + "'");
|
|
|
+ break;
|
|
|
+ case "FORM":
|
|
|
+ getField = "fd_field"; getCaption = "fd_caption"; getTable = "fd_table";
|
|
|
+ Sql.Append("select * from formdetail where fd_foid=( select fo_id from form where fo_caller='" + Caller + "')");
|
|
|
+ break;
|
|
|
+ case "DETAILGRID":
|
|
|
+ getField = "dg_field"; getCaption = "dg_caption"; getTable = "dg_table";
|
|
|
+ Sql.Append("select * from detailgrid where dg_caller='" + Caller + "'");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ command = new OracleCommand(Sql.ToString(), connection);
|
|
|
+ OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
+ ad.Fill(dt);
|
|
|
+ //清除掉之前的内容重新拼接
|
|
|
+ Sql.Clear();
|
|
|
+ Sql.Append("select ");
|
|
|
+ string[] field = new string[dt.Rows.Count];
|
|
|
+ string[] caption = new string[dt.Rows.Count];
|
|
|
+ DataTable dt1 = new DataTable();
|
|
|
+ //记录描述和字段名称
|
|
|
+ foreach (DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ field[dt.Rows.IndexOf(dr)] = dr[getCaption].ToString();
|
|
|
+ caption[dt.Rows.IndexOf(dr)] = dr[getField].ToString();
|
|
|
+ Sql.Append(dr[getField] + ",");
|
|
|
+ }
|
|
|
+ //调用substring是为了去除之前拼接多出来的一个逗号
|
|
|
+ string sql = Sql.Remove(Sql.Length - 1, 1).ToString() + " from " + dt.Rows[0][getTable] + " where " + condition;
|
|
|
+ //调用一个新的构造DataTable用来存放返回的数据
|
|
|
+ dt1 = (DataTable)ExecuteSql(sql, "select");
|
|
|
+ //给DataTable加上列名和描述,列名是中文字段,描述是数据库实际的字段名称
|
|
|
+ for (int i = 0; i < field.Length; i++)
|
|
|
+ {
|
|
|
+ dt1.Columns[i].ColumnName = field[i];
|
|
|
+ dt1.Columns[i].Caption = caption[i];
|
|
|
+ }
|
|
|
+ //返回的第一条数据是SQL,后面的是实际的列名
|
|
|
+ ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
+ return dt1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询配置的字段,Type是查询DataList,Form还是DetailGrid
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="Caller"></param>
|
|
|
+ /// <param name="Type"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public DataTable GetConfigureData(string Caller, string Type)
|
|
|
+ {
|
|
|
+ DataTable dt = new DataTable();
|
|
|
+ //用于拼接SQL语句
|
|
|
+ StringBuilder Sql = new StringBuilder();
|
|
|
+ //用于设置不同Type时设置对应表的字段
|
|
|
+ string getField = "";
|
|
|
+ string getCaption = "";
|
|
|
+ string getTable = "";
|
|
|
+ switch (Type.ToUpper())
|
|
|
+ {
|
|
|
+ case "DATALIST":
|
|
|
+ getField = "dld_field"; getCaption = "dld_caption"; getTable = "dld_table";
|
|
|
+ Sql.Append("select * from datalistdetail where dld_caller='" + Caller + "'");
|
|
|
+ break;
|
|
|
+ case "FORM":
|
|
|
+ getField = "fd_field"; getCaption = "fd_caption"; getTable = "fd_table";
|
|
|
+ Sql.Append("select * from formdetail where fd_foid=( select fo_id from form where fo_caller='" + Caller + "')");
|
|
|
+ break;
|
|
|
+ case "DETAILGRID":
|
|
|
+ getField = "dg_field"; getCaption = "dg_caption"; getTable = "dg_table";
|
|
|
+ Sql.Append("select * from detailgrid where dg_caller='" + Caller + "'");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ command = new OracleCommand(Sql.ToString(), connection);
|
|
|
+ OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
+ ad.Fill(dt);
|
|
|
+ //清除掉之前的内容重新拼接
|
|
|
+ Sql.Clear();
|
|
|
+ Sql.Append("select ");
|
|
|
+ //用于记录实际的列名,+1的目的是为了存放SQL
|
|
|
+ string[] field = new string[dt.Rows.Count];
|
|
|
+ string[] caption = new string[dt.Rows.Count];
|
|
|
+ DataTable dt1 = new DataTable();
|
|
|
+ foreach (DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ field[dt.Rows.IndexOf(dr)] = dr[getCaption].ToString();
|
|
|
+ caption[dt.Rows.IndexOf(dr)] = dr[getField].ToString();
|
|
|
+ Sql.Append(dr[getField] + ",");
|
|
|
+ }
|
|
|
+ string sql = Sql.Remove(Sql.Length - 1, 1).ToString() + " from " + dt.Rows[0][getTable];
|
|
|
+ dt1 = (DataTable)ExecuteSql(sql, "select");
|
|
|
+ //设置DataTable的列名和描述
|
|
|
+ for (int i = 0; i < field.Length; i++)
|
|
|
+ {
|
|
|
+ dt1.Columns[i].ColumnName = field[i];
|
|
|
+ dt1.Columns[i].Caption = caption[i];
|
|
|
+ }
|
|
|
+ ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
+ return dt1;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -381,14 +560,14 @@ namespace UAS_XmlAnalysor
|
|
|
public bool CheckExist(string TableName, string Condition)
|
|
|
{
|
|
|
string sql = "select count(1) from " + TableName + " where " + Condition;
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
DataTable dt = new DataTable();
|
|
|
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
return int.Parse(dt.Rows[0][0].ToString()) > 0;
|
|
|
}
|
|
|
|
|
|
@@ -401,8 +580,7 @@ namespace UAS_XmlAnalysor
|
|
|
public object ExecuteSql(string SQL, string Type, params object[] names)
|
|
|
{
|
|
|
object result = null;
|
|
|
- command.CommandText = SQL;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(SQL, connection);
|
|
|
Reconnect(command);
|
|
|
//用来拼接参数的
|
|
|
if (names.Length > 0)
|
|
|
@@ -435,9 +613,24 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
case "SELECT":
|
|
|
result = new DataTable();
|
|
|
- OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
- ad.Fill((DataTable)result);
|
|
|
- ad.Dispose();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
+ ad.Fill((DataTable)result);
|
|
|
+ ad.Dispose();
|
|
|
+ //成功执行后将重复连接数置为0
|
|
|
+ ReconnectTime = 0;
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ if (ReconnectTime == 0)
|
|
|
+ {
|
|
|
+ //重置的数据库链接后只执行一次
|
|
|
+ ReconnectTime = ReconnectTime + 1;
|
|
|
+ connection = new OracleConnection(DBConnectionString);
|
|
|
+ result = ExecuteSql(SQL, Type, names);
|
|
|
+ }
|
|
|
+ }
|
|
|
break;
|
|
|
case "DELETE":
|
|
|
result = command.ExecuteNonQuery();
|
|
|
@@ -449,21 +642,33 @@ namespace UAS_XmlAnalysor
|
|
|
result = command.ExecuteNonQuery();
|
|
|
break;
|
|
|
}
|
|
|
- command.Parameters.Clear();
|
|
|
+ command.Dispose();
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 为了同步BS端的条码维护,检测时允许问号的存在,在检测时默认将问号换成:Param参数
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="SQL"></param>
|
|
|
+ public void CheckSQL(string SQL)
|
|
|
+ {
|
|
|
+ SQL = SQL.Replace("?", ":Param");
|
|
|
+ command = new OracleCommand(SQL, connection);
|
|
|
+ command.ExecuteNonQuery();
|
|
|
+ command.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
public int GetDistinctRowCount(string TableName, string Field)
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
string sql = "select distinct count('" + Field + "') from " + TableName;
|
|
|
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
return int.Parse(dt.Rows[0][0].ToString());
|
|
|
}
|
|
|
|
|
|
@@ -489,13 +694,12 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
string sql = "delete from " + TableName + " where " + ID + " =:DeleteID";
|
|
|
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
command.ArrayBindCount = DeleteID.Length;
|
|
|
command.Parameters.Add(new OracleParameter("DeleteID", OracleDbType.Long, DeleteID, ParameterDirection.Input));
|
|
|
command.ExecuteNonQuery();
|
|
|
- command.Parameters.Clear();
|
|
|
+ command.Dispose();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -633,11 +837,9 @@ namespace UAS_XmlAnalysor
|
|
|
/// <param name="names"></param>
|
|
|
public void BatchInsert(string sql, params object[][] names)
|
|
|
{
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
command.ArrayBindCount = names[1].Length;
|
|
|
-
|
|
|
//因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
|
|
|
//将第一个数组的下标固定为0作为循环添加的参数的名称
|
|
|
for (int i = 1; i <= names[0].Length; i++)
|
|
|
@@ -645,13 +847,12 @@ namespace UAS_XmlAnalysor
|
|
|
command.Parameters.Add(new OracleParameter(names[0][i - 1].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
|
|
|
}
|
|
|
command.ExecuteNonQuery();
|
|
|
- command.Parameters.Clear();
|
|
|
+ command.Dispose();
|
|
|
}
|
|
|
|
|
|
public void BatchInsertDataTable(string sql, string[] param, params object[][] param1)
|
|
|
{
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
command.ArrayBindCount = param1[0].Length;
|
|
|
//因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
|
|
|
@@ -661,7 +862,7 @@ namespace UAS_XmlAnalysor
|
|
|
command.Parameters.Add(new OracleParameter(param[i].ToString(), OracleDbType.Varchar2, param1[i], ParameterDirection.Input));
|
|
|
}
|
|
|
command.ExecuteNonQuery();
|
|
|
- command.Parameters.Clear();
|
|
|
+ command.Dispose();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -675,12 +876,12 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
string SQL = " select listagg(dld_field,',') within group (order by dld_id) from datalistdetail where dld_caller='" + Caller + "'";
|
|
|
- command.CommandText = SQL;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(SQL, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter(command);
|
|
|
ad.Fill(dt);
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
return dt.Rows[0][0].ToString();
|
|
|
}
|
|
|
|
|
|
@@ -750,10 +951,10 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
string sql = "update " + TableName + " set " + update + " where " + condition;
|
|
|
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
command.ExecuteNonQuery();
|
|
|
+ command.Dispose();
|
|
|
return sql;
|
|
|
}
|
|
|
|
|
|
@@ -764,15 +965,17 @@ namespace UAS_XmlAnalysor
|
|
|
/// <param name="param"></param>
|
|
|
public void CallProcedure(string ProcedureName, ref string[] param)
|
|
|
{
|
|
|
- command.CommandText = ProcedureName;
|
|
|
+ command = new OracleCommand(ProcedureName);
|
|
|
+ command.Connection = connection;
|
|
|
Reconnect(command);
|
|
|
+ command.CommandText = ProcedureName;
|
|
|
command.CommandType = CommandType.StoredProcedure;
|
|
|
for (int i = 0; i < param.Length; i++)
|
|
|
command.Parameters.Add(new OracleParameter(param[i].ToString(), OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
|
|
|
command.ExecuteNonQuery();
|
|
|
for (int i = 0; i < command.Parameters.Count; i++)
|
|
|
param[i] = command.Parameters[i].Value.ToString();
|
|
|
- command.Parameters.Clear();
|
|
|
+ command.Dispose();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -782,8 +985,9 @@ namespace UAS_XmlAnalysor
|
|
|
public void ExecuteSQLTran(params string[] SQL)
|
|
|
{
|
|
|
OracleTransaction tx = connection.BeginTransaction();
|
|
|
+ command = new OracleCommand();
|
|
|
+ command.Connection = connection;
|
|
|
command.Transaction = tx;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
try
|
|
|
{
|
|
|
foreach (string sql in SQL)
|
|
|
@@ -801,6 +1005,7 @@ namespace UAS_XmlAnalysor
|
|
|
{
|
|
|
tx.Rollback();
|
|
|
}
|
|
|
+ command.Dispose();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -850,8 +1055,7 @@ namespace UAS_XmlAnalysor
|
|
|
public object GetLabelParam(string sql)
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
- command.CommandText = sql;
|
|
|
- command.CommandType = CommandType.Text;
|
|
|
+ command = new OracleCommand(sql, connection);
|
|
|
Reconnect(command);
|
|
|
OracleDataAdapter ad = new OracleDataAdapter();
|
|
|
ad.SelectCommand = command;
|
|
|
@@ -859,10 +1063,12 @@ namespace UAS_XmlAnalysor
|
|
|
if (dt.Rows.Count > 0)
|
|
|
{
|
|
|
ad.Dispose();
|
|
|
+ command.Dispose();
|
|
|
return dt.Rows[0][0];
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ command.Dispose();
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
@@ -878,6 +1084,7 @@ namespace UAS_XmlAnalysor
|
|
|
//新建一个char类型的数组用来存储每个字节的变量
|
|
|
char[] c = par[i + 1].ToCharArray();
|
|
|
addpar[i] = new StringBuilder();
|
|
|
+
|
|
|
for (int j = 0; j < c.Length; j++)
|
|
|
{
|
|
|
if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
|
|
|
@@ -897,13 +1104,9 @@ namespace UAS_XmlAnalysor
|
|
|
return param;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 释放资源
|
|
|
- /// </summary>
|
|
|
public void Dispose()
|
|
|
{
|
|
|
- command.Dispose();
|
|
|
- connection.Dispose();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void Reconnect(OracleCommand cmd)
|