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
{
///
/// 执行存储过程
///
///
///
/// 参数 key:@XXX value:val
///
///
public static DataSet ExecProcedure(string strConn, string proName, Dictionary 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;
}
///
/// 获取视图数据
///
///
///
/// 数据集
///
public static DataSet GetViewData(string conn, List 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;
}
}
}