using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using Procurement.ViewModel;
using System.Text.Json;
using Procurement.EntityFrameworkCore.SqlRepositories;
using Procurement.Controllers;
using System.Collections;
using Procurement.Enums;
using Volo.Abp.Domain.Repositories;
using Procurement.Services;
using Newtonsoft.Json.Linq;
using System.Data;
using System.Data.SqlClient;
using Procurement.Core;
namespace Procurement.Helpers
{
public class SqlHelper
{
///
/// 构建mysql参数数组
///
///
///
//public static async Task CreateSqlParameters(ISqlRepository sqlRepository,string proc,JsonElement json)
//{
// Dictionary dict = JsonSerializer.Deserialize>(json);
// Common common = new Common(sqlRepository);
// var items = await common.GetCommonItems("", "parameterlist", proc, "");
// List listParams = new List();
// foreach(KeyValuePair item in items)
// {
// foreach (var d in (ArrayList)item.Value)
// {
// Dictionary param = (Dictionary)d;
// string paramMode = param["ParamMode"].ToString().ToUpper();
// string paramName = param["ParamName"].ToString();
// string dataType = param["DataType"].ToString().ToLower();
// object paramValue = null;
// if (dict.ContainsKey(paramName))
// {
// JsonElement valueObj = dict[paramName];
// switch (valueObj.ValueKind)
// {
// case JsonValueKind.Null:
// paramValue = null;
// break;
// case JsonValueKind.Number:
// paramValue = valueObj.GetDouble();
// break;
// case JsonValueKind.False:
// paramValue = false;
// break;
// case JsonValueKind.True:
// paramValue = true;
// break;
// case JsonValueKind.Undefined:
// paramValue = null;
// break;
// case JsonValueKind.String:
// paramValue = valueObj.GetString();
// break;
// }
// }
// SqlParameterViewModel paramModel = new SqlParameterViewModel { ParameterName = "@" + paramName, Value = paramValue, SqlDbType = SqlDbTypes.VarChar };
// if (dataType == "tinyint")
// {
// paramModel.SqlDbType = SqlDbTypes.Int;
// }
// else if (dataType == "int")
// {
// paramModel.SqlDbType = SqlDbTypes.Int;
// }
// else if (dataType == "bigint")
// {
// paramModel.SqlDbType = SqlDbTypes.BigInt;
// }
// else if (dataType == "decimal")
// {
// paramModel.SqlDbType = SqlDbTypes.Decimal;
// }
// else if (dataType == "date" || dataType == "datetime")
// {
// paramModel.SqlDbType = SqlDbTypes.DateTime;
// }
// if (paramMode == "OUT")
// {
// paramModel.Direction = SqlParamDirection.Output;
// }
// listParams.Add(paramModel);
// }
// }
// return listParams.ToArray();
//}
///
/// 构建sql参数数组
///
///
///
public static SqlParameter[] CreateSqlParameters(JsonElement json)
{
new NLogHelper("Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker").Info("print", "print", json.ToString().Replace("\n","\r\n"));
Dictionary dict = JsonSerializer.Deserialize>(json);
List listParams = new List();
foreach (KeyValuePair d in dict)
{
string paramName = d.Key.ToString();
object paramValue = null;
JsonElement valueObj = dict[paramName];
switch (valueObj.ValueKind)
{
case JsonValueKind.Null:
paramValue = null;
break;
case JsonValueKind.Number:
paramValue = valueObj.GetDouble();
break;
case JsonValueKind.False:
paramValue = false;
break;
case JsonValueKind.True:
paramValue = true;
break;
case JsonValueKind.Undefined:
paramValue = null;
break;
case JsonValueKind.String:
paramValue = valueObj.GetString();
break;
}
SqlParameter param = new SqlParameter { ParameterName = "@" + paramName, Value = paramValue};
listParams.Add(param);
}
return listParams.ToArray();
}
}
}