106 lines
3.7 KiB
C#
106 lines
3.7 KiB
C#
using APT.Infrastructure.Core;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Data.SqlClient;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace APT.Utility
|
|
{
|
|
public static partial class DBHelper
|
|
{
|
|
/// <summary>
|
|
/// 执行存储过程
|
|
/// </summary>
|
|
/// <param name="orgID"></param>
|
|
/// <param name="proName"></param>
|
|
/// <param name="dicParms">参数 key:@XXX value:val </param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
public static DataSet ExecProcedure(string strConn, string proName, Dictionary<string, object> dicParms, string errorPath)
|
|
{
|
|
DataSet dataSet = new DataSet();
|
|
|
|
using (SqlConnection connection = new SqlConnection(strConn))
|
|
{
|
|
try
|
|
{
|
|
connection.Open();
|
|
string sql = proName;
|
|
using (SqlCommand Com = new SqlCommand(sql, connection))
|
|
{
|
|
Com.CommandType = CommandType.StoredProcedure;
|
|
foreach (var item in dicParms)
|
|
{
|
|
Com.Parameters.Add(new SqlParameter(item.Key, item.Value));
|
|
}
|
|
using (var adapter = new SqlDataAdapter(Com))
|
|
{
|
|
adapter.Fill(dataSet); // 自动处理多个结果集!
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!string.IsNullOrEmpty(ex.StackTrace))
|
|
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
|
|
else
|
|
throw new Exception("【" + errorPath + "】错误日志:[Message]" + ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
}
|
|
return dataSet;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取视图数据
|
|
/// </summary>
|
|
/// <param name="conn"></param>
|
|
/// <param name="listVNAME"></param>
|
|
/// <param name="DataADP">数据集</param>
|
|
/// <exception cref="Exception"></exception>
|
|
public static DataSet GetViewData(string conn, List<string> listVNAME, string errorPath)
|
|
{
|
|
DataSet ds = new DataSet();
|
|
using (SqlConnection connection = new SqlConnection(conn))
|
|
{
|
|
try
|
|
{
|
|
connection.Open();
|
|
string sql = string.Empty;
|
|
foreach (var item in listVNAME)
|
|
{
|
|
sql += string.Format(" select * from {0} ", item);
|
|
}
|
|
|
|
using (SqlCommand Com = new SqlCommand(sql, connection))
|
|
{
|
|
SqlDataAdapter DataADP = new SqlDataAdapter(Com);
|
|
DataADP.Fill(ds);
|
|
}
|
|
connection.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!string.IsNullOrEmpty(ex.StackTrace))
|
|
throw new Exception("错误日志:[StackTrace]" + ex.StackTrace);
|
|
else
|
|
throw new Exception("【" + errorPath + "】错误日志:[Message]" + ex.Message);
|
|
}
|
|
}
|
|
return ds;
|
|
}
|
|
}
|
|
}
|