2718 lines
121 KiB
C#
2718 lines
121 KiB
C#
//using BasicData;
|
||
//using BizDataAccess;
|
||
//using LitJson;
|
||
using BasicData;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Runtime.Serialization.Json;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading.Tasks;
|
||
using System.Web.Script.Serialization;
|
||
|
||
namespace DataLinkMesWork
|
||
{
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public struct ParamData
|
||
{
|
||
|
||
/// <summary>
|
||
/// 变量名称
|
||
/// </summary>
|
||
public string name;
|
||
/// <summary>
|
||
/// 变量值
|
||
/// </summary>
|
||
public object value;
|
||
///// <summary>
|
||
///// 变量类型 int string bool datetime
|
||
///// </summary>
|
||
//public string datatype;
|
||
///// <summary>
|
||
///// 是否输出
|
||
///// </summary>
|
||
//public string output;
|
||
/// <summary>
|
||
/// 是否选择
|
||
/// </summary>
|
||
public bool isCheck;
|
||
/// <summary>
|
||
/// 逻辑操作 > = !=
|
||
/// </summary>
|
||
public string logicaloperator;
|
||
/// 是否输出
|
||
/// </summary>
|
||
public bool isOutPut;
|
||
|
||
}
|
||
|
||
|
||
public partial class DataLink
|
||
{
|
||
private static bool initSystemIsOk;
|
||
public static bool InitSystemIsOk
|
||
{
|
||
get
|
||
{
|
||
return initSystemIsOk;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 01,02,03,04,05,06,07,08,09,10
|
||
/// </summary>
|
||
///public string connType = "";
|
||
|
||
private static string connectionString ;
|
||
private static string connectionStringBakup ;
|
||
private static string connectionString01;
|
||
private static string connectionStringBakup01;
|
||
private static string connectionString02;
|
||
private static string connectionStringBakup02;
|
||
private static string connectionString03;
|
||
private static string connectionStringBakup03;
|
||
private static string connectionString04;
|
||
private static string connectionStringBakup04;
|
||
private static string connectionString05;
|
||
private static string connectionStringBakup05;
|
||
private static string connectionString06;
|
||
private static string connectionStringBakup06;
|
||
private static string connectionString07;
|
||
private static string connectionStringBakup07;
|
||
private static string connectionString08;
|
||
private static string connectionStringBakup08;
|
||
private static string connectionString09;
|
||
private static string connectionStringBakup09;
|
||
private static string connectionString10;
|
||
private static string connectionStringBakup10;
|
||
|
||
|
||
public static string isBakup = "0";
|
||
public static string isBakup01 = "0";
|
||
public static string isBakup02 = "0";
|
||
public static string isBakup03 = "0";
|
||
public static string isBakup04 = "0";
|
||
public static string isBakup05 = "0";
|
||
public static string isBakup06 = "0";
|
||
public static string isBakup07 = "0";
|
||
public static string isBakup08 = "0";
|
||
public static string isBakup09 = "0";
|
||
public static string isBakup10 = "0";
|
||
|
||
public static bool InitSystem(out string SerialNumberStr)
|
||
{
|
||
if(KeyWordTest.KeyWordNew(out SerialNumberStr))
|
||
{
|
||
|
||
|
||
|
||
connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
|
||
connectionStringBakup = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup"];
|
||
|
||
connectionString01 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString01"];
|
||
connectionStringBakup01 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup01"];
|
||
connectionString02 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString02"];
|
||
connectionStringBakup02 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup02"];
|
||
connectionString03 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString03"];
|
||
connectionStringBakup03 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup03"];
|
||
connectionString04 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString04"];
|
||
connectionStringBakup04 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup04"];
|
||
connectionString05 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString05"];
|
||
connectionStringBakup05 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup05"];
|
||
connectionString06 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString06"];
|
||
connectionStringBakup06 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup06"];
|
||
connectionString07 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString07"];
|
||
connectionStringBakup07 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup07"];
|
||
connectionString08 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString08"];
|
||
connectionStringBakup08 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup08"];
|
||
connectionString09 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString09"];
|
||
connectionStringBakup09 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup09"];
|
||
connectionString10 = System.Configuration.ConfigurationManager.AppSettings["ConnectionString10"];
|
||
connectionStringBakup10 = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringBakup10"];
|
||
|
||
|
||
if (connectionString == connectionStringBakup)
|
||
{
|
||
initSystemIsOk = false;
|
||
return false;
|
||
}
|
||
isBakup = System.Configuration.ConfigurationManager.AppSettings["IsBakup"];
|
||
isBakup01 = System.Configuration.ConfigurationManager.AppSettings["IsBakup01"];
|
||
isBakup02 = System.Configuration.ConfigurationManager.AppSettings["IsBakup02"];
|
||
isBakup03 = System.Configuration.ConfigurationManager.AppSettings["IsBakup03"];
|
||
isBakup04 = System.Configuration.ConfigurationManager.AppSettings["IsBakup04"];
|
||
isBakup05 = System.Configuration.ConfigurationManager.AppSettings["IsBakup05"];
|
||
isBakup06 = System.Configuration.ConfigurationManager.AppSettings["IsBakup06"];
|
||
isBakup07 = System.Configuration.ConfigurationManager.AppSettings["IsBakup07"];
|
||
isBakup08 = System.Configuration.ConfigurationManager.AppSettings["IsBakup08"];
|
||
isBakup09 = System.Configuration.ConfigurationManager.AppSettings["IsBakup09"];
|
||
isBakup10 = System.Configuration.ConfigurationManager.AppSettings["IsBakup10"];
|
||
initSystemIsOk = true;
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
Reg dlg = new Reg();
|
||
dlg.ShowDialog();
|
||
if (KeyWordTest.KeyWordNew(out SerialNumberStr))
|
||
{
|
||
initSystemIsOk = true;
|
||
}
|
||
else
|
||
{
|
||
initSystemIsOk = false;
|
||
}
|
||
return false;
|
||
}
|
||
catch(Exception e)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 1、执行存储过程,存储过程返回查询结果表,表以JSON字符串返回给页面。
|
||
/// 输入参数:参数名称1&参数&参数类型|参数名称1&参数&参数类型
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type1(jsonobj json)
|
||
{
|
||
string[] parmas;
|
||
string[] names;
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK;
|
||
bool isOutput = false;
|
||
DataSet ds = null;
|
||
DataTable dt1 = null;
|
||
try
|
||
{
|
||
names = json.Name.Split('&');
|
||
string name;
|
||
name = names[0];
|
||
if (json.Param == "" || json.Param == null)//执行没有参数的存储过程
|
||
{
|
||
|
||
isOK = SQLCommon.ExecuteStoredProcedure(name, connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
|
||
parmas = json.Param.Split('&');
|
||
thisParms = new SqlParameter[parmas.Length];
|
||
SQLCommon.GetCmdParam(json, ref thisParms, out isOutput);
|
||
isOK = SQLCommon.ExecuteStoredProcedure(name, connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
if (isOK)
|
||
{
|
||
//if (names.Length >= 2)
|
||
//{
|
||
// string type = names[1].Split('=')[1];
|
||
// DataTable dt = ds.Tables[0];
|
||
// result = DbComType.DbCallType(dt, type, json.Name);
|
||
//}
|
||
//else
|
||
{
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
if (json.Pagination == "" || json.Pagination == null) // 判断是否需要分页
|
||
{
|
||
// 以下操作为处理模型数据 *********************************************
|
||
//for (int i = 0; i < ds.Tables[0].Rows.Count; i++) // 通过循环拿到单个DIV的模型数据
|
||
//{
|
||
// string modelData = JsonHelper.ObjectToJson(ds.Tables[0].Rows[i]["模型数据"].ToString()); // 由于转JSON字符有限,单个转换
|
||
// result += modelData.Substring(1, modelData.Length - 2); // 去除首和尾的字符串引号并拼接
|
||
//}
|
||
//result = "[{\"模型数据\":\"" + result + "\"}]"; // 拼接成最终字符串
|
||
//**********************************************************************
|
||
result = JsonHelper.DataTableToJson(ds.Tables[0]);
|
||
}
|
||
else
|
||
{
|
||
int pageSize = int.Parse(json.Pagination.Split('&')[0]);
|
||
int pageList = int.Parse(json.Pagination.Split('&')[1]);
|
||
DataTable dt = ds.Tables[0];
|
||
dt1 = dt.Copy(); //复制dt
|
||
dt1.Rows.Clear();//清空内容,只保留dt结构。
|
||
for (int i = (pageSize - 1) * pageList; i < pageSize * pageList; i++)//循环需要显示的行
|
||
{
|
||
if (i < dt.Rows.Count)
|
||
{
|
||
dt1.ImportRow(dt.Rows[i]);//这是加入的是第i行
|
||
}
|
||
}
|
||
result = JsonHelper.CreateJsonParameters(dt1, true, dt.Rows.Count);
|
||
}
|
||
}
|
||
}
|
||
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"0\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// 1、执行存储过程,存储过程返回查询结果表,表以JSON字符串返回给页面。
|
||
/// 输入参数:参数名称1&参数&参数类型|参数名称1&参数&参数类型
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type1(jsonobj json,out DataTable dt)
|
||
{
|
||
string[] parmas;
|
||
string[] names;
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK;
|
||
bool isOutput = false;
|
||
dt = new DataTable();
|
||
DataSet ds = null;
|
||
DataTable dt1 = null;
|
||
try
|
||
{
|
||
names = json.Name.Split('&');
|
||
string name;
|
||
name = names[0];
|
||
if (json.Param == "" || json.Param == null)//执行没有参数的存储过程
|
||
{
|
||
|
||
isOK = SQLCommon.ExecuteStoredProcedure(name, connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
|
||
parmas = json.Param.Split('&');
|
||
thisParms = new SqlParameter[parmas.Length];
|
||
SQLCommon.GetCmdParam(json, ref thisParms, out isOutput);
|
||
isOK = SQLCommon.ExecuteStoredProcedure(name, connectionString, ref thisParms, out ds, out result);
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
dt = ds.Tables[0];
|
||
}
|
||
}
|
||
if (isOK)
|
||
{
|
||
//if (names.Length >= 2)
|
||
//{
|
||
// string type = names[1].Split('=')[1];
|
||
// DataTable dt = ds.Tables[0];
|
||
// result = DbComType.DbCallType(dt, type, json.Name);
|
||
//}
|
||
//else
|
||
{
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
if (json.Pagination == "" || json.Pagination == null) // 判断是否需要分页
|
||
{
|
||
// 以下操作为处理模型数据 *********************************************
|
||
//for (int i = 0; i < ds.Tables[0].Rows.Count; i++) // 通过循环拿到单个DIV的模型数据
|
||
//{
|
||
// string modelData = JsonHelper.ObjectToJson(ds.Tables[0].Rows[i]["模型数据"].ToString()); // 由于转JSON字符有限,单个转换
|
||
// result += modelData.Substring(1, modelData.Length - 2); // 去除首和尾的字符串引号并拼接
|
||
//}
|
||
//result = "[{\"模型数据\":\"" + result + "\"}]"; // 拼接成最终字符串
|
||
//**********************************************************************
|
||
result = JsonHelper.DataTableToJson(ds.Tables[0]);
|
||
}
|
||
else
|
||
{
|
||
int pageSize = int.Parse(json.Pagination.Split('&')[0]);
|
||
int pageList = int.Parse(json.Pagination.Split('&')[1]);
|
||
dt = ds.Tables[0];
|
||
dt1 = dt.Copy(); //复制dt
|
||
dt1.Rows.Clear();//清空内容,只保留dt结构。
|
||
for (int i = (pageSize - 1) * pageList; i < pageSize * pageList; i++)//循环需要显示的行
|
||
{
|
||
if (i < dt.Rows.Count)
|
||
{
|
||
dt1.ImportRow(dt.Rows[i]);//这是加入的是第i行
|
||
}
|
||
}
|
||
result = JsonHelper.CreateJsonParameters(dt1, true, dt.Rows.Count);
|
||
}
|
||
}
|
||
}
|
||
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"0\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// type = 2 Insert
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type2(jsonobj json)
|
||
{
|
||
string[] parmas;
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK;
|
||
bool isOutput = false;
|
||
try
|
||
{
|
||
if (json.Param == "" || json.Param == null)//执行没有参数的存储过程
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(json.Name, connectionString, ref thisParms, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
parmas = json.Param.Split('&');
|
||
thisParms = new SqlParameter[parmas.Length];
|
||
SQLCommon.GetCmdParam(json, ref thisParms, out isOutput);
|
||
isOK = SQLCommon.ExecuteStoredProcedure(json.Name, connectionString, ref thisParms, out result);
|
||
}
|
||
if (isOK)
|
||
{
|
||
result = "[{ \"result\":\"1\"}]";
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
result = "[{ \"result\":\"0\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// Type = 3
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type3(jsonobj json)
|
||
{
|
||
string result = "[{ \"result\":\"0\"}]";
|
||
bool isOK;
|
||
if (json.Name != null)
|
||
{
|
||
DataTable dt = null;
|
||
try
|
||
{
|
||
isOK = SQLCommon.ExecuteDataTable(json.Name, connectionString, out dt, out result);
|
||
if (isOK)
|
||
{
|
||
if (dt != null)
|
||
{
|
||
result = JsonHelper.DataTableToJson(dt);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"0\"}]";
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result = "[{ \"result\":\"0\"}]";
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// Type = 3
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type3(jsonobj json,out DataTable dt)
|
||
{
|
||
string result = "[{ \"result\":\"0\"}]";
|
||
bool isOK;
|
||
dt = new DataTable();
|
||
if (json.Name != null)
|
||
{
|
||
try
|
||
{
|
||
isOK = SQLCommon.ExecuteDataTable(json.Name, connectionString, out dt, out result);
|
||
if (isOK)
|
||
{
|
||
if (dt != null)
|
||
{
|
||
result = JsonHelper.DataTableToJson(dt);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"0\"}]";
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result = "[{ \"result\":\"0\"}]";
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// type = 4
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type4(jsonobj json)
|
||
{
|
||
string result = "[{ \"result\":\"0\"}]"; ;
|
||
bool isOK;
|
||
if (json.Name != null)
|
||
{
|
||
try
|
||
{
|
||
isOK = SQLCommon.ExecuteNonQuery(json.Name, connectionString, out result);
|
||
if (isOK)
|
||
{
|
||
result = "[{ \"result\":\"1\"}]";
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"0\"}]";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result = "[{ \"result\":\"0\"}]";
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// type=5
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type5(jsonobj json)
|
||
{
|
||
string result = "";
|
||
DataSet ds = null;
|
||
try
|
||
{
|
||
|
||
if (json.Param == "" || json.Param == null)//执行没有参数的存储过程
|
||
{
|
||
SQLCommon.ExecuteStoredProcedure(json.Name, connectionString, out ds, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
string[] parmas;
|
||
SqlParameter[] thisParms;
|
||
try
|
||
{
|
||
parmas = json.Param.Split('|');
|
||
thisParms = new SqlParameter[parmas.Length];
|
||
for (int i = 0; i < parmas.Length; i++)
|
||
{
|
||
string[] pp = parmas[i].Split('&');
|
||
object inputValue = null;
|
||
if (pp.Length == 3)
|
||
{
|
||
switch (pp[2])
|
||
{
|
||
case "Int":
|
||
inputValue = Convert.ToInt32(pp[1]);
|
||
break;
|
||
case "String":
|
||
inputValue = pp[2];
|
||
break;
|
||
case "Boolean":
|
||
inputValue = Convert.ToBoolean(pp[1]);
|
||
break;
|
||
case "DateTime":
|
||
inputValue = Convert.ToDateTime(pp[1]);
|
||
break;
|
||
default:
|
||
inputValue = pp[1];
|
||
break;
|
||
}
|
||
thisParms[i] = new SqlParameter(pp[0], inputValue);
|
||
}
|
||
else if (pp.Length == 2)
|
||
{
|
||
thisParms[i] = new SqlParameter(pp[0], pp[1]);
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return result = "参数有误,请检查参数的格式是否正确";
|
||
}
|
||
SQLCommon.ExecuteStoredProcedure(json.Name, connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
result = JsonHelper.DataTableToJson(ds.Tables[0]);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result = ex.Message;
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// 7 vue格式Excel 导入到创建并表中
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type7(JsonData json)
|
||
{
|
||
string result = "";
|
||
bool isOK = false;
|
||
JsonData jsonDataName;
|
||
JsonData jsonDataParam;
|
||
JsonData jsonDataParamRow;
|
||
string name;
|
||
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
JsonData param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData_Type7(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
|
||
name = jsonDataName.ToString();
|
||
|
||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||
{
|
||
try
|
||
{
|
||
conn.Open();
|
||
using (SqlCommand cmd = new SqlCommand(name, conn))
|
||
{
|
||
cmd.CommandTimeout = 0;
|
||
cmd.CommandType = CommandType.Text;
|
||
#region 首先删除并重建表
|
||
string createTableStr_key1 = "";
|
||
foreach (KeyValuePair<string, JsonData> jParamData in jsonDataParam[0])
|
||
{
|
||
createTableStr_key1 = createTableStr_key1 + "[" + jParamData.Key + "]" + " nvarchar(max),";
|
||
}
|
||
createTableStr_key1 = createTableStr_key1.TrimEnd(',');
|
||
//判断表是否存在,存在则删除重建,不存在直接重建
|
||
string dropsql = " if exists(select * from sysobjects where id = object_id(N'[" + name + "]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)" +
|
||
" begin "
|
||
+ " DROP TABLE " + name
|
||
+ " CREATE TABLE " + name
|
||
+ "(" + " TableId int identity(1,1), " + createTableStr_key1 + ")"
|
||
+ " end "
|
||
+ " else "
|
||
+ " begin "
|
||
+ " CREATE TABLE " + name
|
||
+ "(" + " TableId int identity(1,1), " + createTableStr_key1 + ")"
|
||
+ " end ";
|
||
//DataAccess.ExecuteSQL(dropsql);
|
||
cmd.CommandText = dropsql;
|
||
cmd.ExecuteNonQuery();
|
||
#endregion
|
||
#region 循环插入数据
|
||
|
||
for (int i = 0; i < jsonDataParam.Count; i++)
|
||
{
|
||
jsonDataParamRow = jsonDataParam[i];
|
||
string sqlInert;//sql字符串
|
||
string createTableStr_key = null;//列
|
||
string createTableStr_value = null;//值
|
||
sqlInert = "INSERT INTO " + name + "(";
|
||
foreach (KeyValuePair<string, JsonData> jParamData in jsonDataParamRow)
|
||
{
|
||
createTableStr_key = createTableStr_key + "[" + jParamData.Key + "]" + ",";
|
||
createTableStr_value = createTableStr_value + "'" + jParamData.Value.ToString().Replace("'", "''") + "'" + ",";
|
||
}
|
||
createTableStr_key = createTableStr_key.TrimEnd(',');
|
||
createTableStr_value = createTableStr_value.TrimEnd(',');
|
||
sqlInert += createTableStr_key + ")" + "values" + "(";
|
||
sqlInert += createTableStr_value + ")";//最终sql字符串
|
||
cmd.CommandText = sqlInert;
|
||
cmd.ExecuteNonQuery();
|
||
}
|
||
#endregion
|
||
}
|
||
isOK = true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
// errorMessage = e.ToString();
|
||
}
|
||
finally
|
||
{
|
||
if (conn.State == ConnectionState.Open)
|
||
{
|
||
conn.Close();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (isOK)
|
||
{
|
||
result = "[{ \"result\":\"1\"}]";
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
|
||
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// 1001
|
||
/// "UserID": $("#UserID").val(),
|
||
/// "Type": $("#TYPE").val(),
|
||
/// "Name": $("#NAME").val(),
|
||
/// "Param": $("#PARAM1value").val(),
|
||
/// "Pagination": $("#Pagination").val(),
|
||
/// HasReturn: $("#HASRETURN").get(0).checked
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExecuteInsertMesWork(JsonData json)
|
||
{
|
||
SqlParameter thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;
|
||
bool isOutput = false;
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称 Sql
|
||
JsonData jsonDataParam;//存储过程参数
|
||
long outputID = 0;
|
||
SqlParameter[] param = null;
|
||
string err;
|
||
List<SqlParameter> ilistSqlParameterStr = new List<SqlParameter>();
|
||
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转为JSON格式
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//执行没有参数的存储过程
|
||
{
|
||
isOK = SQLCommon.ExecuteInsertMesWork(jsonDataName.ToString(), ref param, connectionString,out err);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
//thisParms = new []SqlParameter();
|
||
//thisParms = new SqlParameter[jsonData.Count];
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
if (name == "output")
|
||
{
|
||
isOutput = true;
|
||
}
|
||
else
|
||
{
|
||
thisParms = new SqlParameter(name, value);
|
||
if (jsonData[i].ContainsKey("output"))
|
||
{
|
||
if(jsonData[i]["output"]!=null)
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
if(jsonData[i]["type"] != null)
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, output);
|
||
thisParms = new SqlParameter(name, inputValue);
|
||
}
|
||
}
|
||
if (output == "1")
|
||
{
|
||
|
||
thisParms.Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
ilistSqlParameterStr.Add(thisParms);
|
||
}
|
||
|
||
}
|
||
if (ilistSqlParameterStr.Count > 0)
|
||
{
|
||
param = ilistSqlParameterStr.ToArray();
|
||
}
|
||
if (isOutput)
|
||
{
|
||
|
||
isOK = SQLCommon.ExecuteInsertMesWork(jsonDataName.ToString(), ref param, connectionString, out outputID,out err);
|
||
}
|
||
else
|
||
{
|
||
isOK = SQLCommon.ExecuteInsertMesWork(jsonDataName.ToString(), ref param, connectionString,out err);
|
||
}
|
||
}
|
||
}
|
||
if (isOK)
|
||
{
|
||
result = "[{ \"result\":\"1\"}]";
|
||
string resultOutput = "";
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = outputID.ToString();// SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 1002
|
||
/// select * from Test where f1=@f1
|
||
/// [{\"name\":\"@f1\",\"value\":\"T002\"}]
|
||
/// "UserID": $("#UserID").val(),
|
||
/// "Type": $("#TYPE").val(),
|
||
/// "Name": $("#NAME").val(),
|
||
/// "Param": $("#PARAM1value").val(),
|
||
/// "Pagination": $("#Pagination").val(),
|
||
/// HasReturn: $("#HASRETURN").get(0).checked
|
||
/// {"type":"1002","name":"select * from Test where f1=@f1 ","param":"[{\"name\":\"@f1\",\"value\":\"T002\"}]"}
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExecuteSelectMesWork(JsonData json)
|
||
{
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;// 存储过程执行是否成功
|
||
bool isOutput = false;
|
||
DataTable dt = null;
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称 Sql
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//参数为空,执行没有参数的存储过程
|
||
{
|
||
string err;
|
||
isOK = SQLCommon.ExecuteSelectMesWork(jsonDataName.ToString(), ref thisParms, connectionString, out dt,out err);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
thisParms = new SqlParameter[jsonData.Count];//定义参数个数
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
//string value = jsonData[i]["value"].ToString();// 参数值
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
thisParms[i] = new SqlParameter(name, value);
|
||
if (jsonData[i].ContainsKey("output"))
|
||
{
|
||
if(jsonData[i]["output"] != null)
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
if(jsonData[i]["type"] != null)
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, value);
|
||
thisParms[i] = new SqlParameter(name, inputValue);
|
||
}
|
||
|
||
}
|
||
if (output == "1")
|
||
{
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
}
|
||
string err;
|
||
isOK = SQLCommon.ExecuteSelectMesWork(jsonDataName.ToString(), ref thisParms, connectionString, out dt,out err);
|
||
|
||
}
|
||
|
||
}
|
||
if (isOK)
|
||
{
|
||
|
||
if (dt != null && dt.Rows.Count > 0)
|
||
{
|
||
//DataTable dt = ds.Tables[0];
|
||
//result = JsonHelper.CreateJsonParameters(dt, true, dt.Rows.Count);
|
||
//result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
if (json.ContainsKey("pageSize") && json.ContainsKey("pageList")) // 判断是否需要分页
|
||
{
|
||
int pageSize = int.Parse(json["pageSize"].ToString());
|
||
int pageList = int.Parse(json["pageList"].ToString());
|
||
//DataTable dt = ds.Tables[0];
|
||
DataTable dt1 = dt.Copy(); //复制dt
|
||
dt1.Rows.Clear();//清空内容,只保留dt结构。
|
||
for (int i = (pageList - 1) * pageSize; i < pageList * pageSize; i++)//循环需要显示的行
|
||
{
|
||
if (i < dt.Rows.Count)
|
||
{
|
||
dt1.ImportRow(dt.Rows[i]);//这是加入的是第i行
|
||
}
|
||
}
|
||
result = JsonHelper.CreateJsonParameters(dt1, true, dt.Rows.Count);
|
||
|
||
}
|
||
else
|
||
{
|
||
result = JsonHelper.DataTableToJson(dt);
|
||
}
|
||
|
||
}
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// "UserID": $("#UserID").val(),
|
||
/// "Type": $("#TYPE").val(),
|
||
/// "Name": $("#NAME").val(),
|
||
/// "Param": $("#PARAM1value").val(),
|
||
/// "Pagination": $("#Pagination").val(),
|
||
/// HasReturn: $("#HASRETURN").get(0).checked
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <param name="dt"></param>
|
||
/// <returns></returns>
|
||
public static string ExecuteSelectMesWork(JsonData json,out DataTable dt)
|
||
{
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;// 存储过程执行是否成功
|
||
bool isOutput = false;
|
||
dt = new DataTable();
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称 Sql
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//参数为空,执行没有参数的存储过程
|
||
{
|
||
string err;
|
||
isOK = SQLCommon.ExecuteSelectMesWork(jsonDataName.ToString(), ref thisParms, connectionString, out dt,out err);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
thisParms = new SqlParameter[jsonData.Count];//定义参数个数
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
//string value = jsonData[i]["value"].ToString();// 参数值
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
thisParms[i] = new SqlParameter(name, value);
|
||
if (jsonData[i].ContainsKey("output") )
|
||
{
|
||
if(jsonData[i]["output"] != null)
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
if(jsonData[i]["type"] != null)
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
object inputValue = GetInputValue(type, value);
|
||
thisParms[i].Value = inputValue;
|
||
}
|
||
}
|
||
if (output == "1")
|
||
{
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
}
|
||
string err;
|
||
isOK = SQLCommon.ExecuteSelectMesWork(jsonDataName.ToString(), ref thisParms, connectionString, out dt,out err);
|
||
|
||
}
|
||
|
||
}
|
||
if (isOK)
|
||
{
|
||
|
||
if (dt != null && dt.Rows.Count > 0)
|
||
{
|
||
//DataTable dt = ds.Tables[0];
|
||
//result = JsonHelper.CreateJsonParameters(dt, true, dt.Rows.Count);
|
||
//result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
if (json.ContainsKey("pageSize") && json.ContainsKey("pageList")) // 判断是否需要分页
|
||
{
|
||
int pageSize = int.Parse(json["pageSize"].ToString());
|
||
int pageList = int.Parse(json["pageList"].ToString());
|
||
//DataTable dt = ds.Tables[0];
|
||
DataTable dt1 = dt.Copy(); //复制dt
|
||
dt1.Rows.Clear();//清空内容,只保留dt结构。
|
||
for (int i = (pageList - 1) * pageSize; i < pageList * pageSize; i++)//循环需要显示的行
|
||
{
|
||
if (i < dt.Rows.Count)
|
||
{
|
||
dt1.ImportRow(dt.Rows[i]);//这是加入的是第i行
|
||
}
|
||
}
|
||
result = JsonHelper.CreateJsonParameters(dt1, true, dt.Rows.Count);
|
||
|
||
}
|
||
else
|
||
{
|
||
result = JsonHelper.DataTableToJson(dt);
|
||
}
|
||
|
||
}
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// 11 存储过程方式查询
|
||
/// 查询 采用新协议 例:{"type":"11","name":"存储过程","param":"[{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]"}
|
||
/// "UserID": $("#UserID").val(),
|
||
/// "Type": $("#TYPE").val(),
|
||
/// "Name": $("#NAME").val(),
|
||
/// "Param": $("#PARAM1value").val(),
|
||
/// "Pagination": $("#Pagination").val(),
|
||
/// HasReturn: $("#HASRETURN").get(0).checked
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type11(JsonData json)
|
||
{
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;// 存储过程执行是否成功
|
||
bool isOutput = false;
|
||
DataSet ds = null;
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//参数为空,执行没有参数的存储过程
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
thisParms = new SqlParameter[jsonData.Count];//定义参数个数
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
//string value = jsonData[i]["value"].ToString();// 参数值
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
thisParms[i] = new SqlParameter(name, value);
|
||
if (jsonData[i].ContainsKey("output"))
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
}
|
||
if (output == "1")
|
||
{
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, output);
|
||
thisParms[i] = new SqlParameter(name, inputValue);
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
}
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
|
||
}
|
||
|
||
}
|
||
if (isOK)
|
||
{
|
||
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
//DataTable dt = ds.Tables[0];
|
||
//result = JsonHelper.CreateJsonParameters(dt, true, dt.Rows.Count);
|
||
//result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
if (json.ContainsKey("pageSize") && json.ContainsKey("pageList")) // 判断是否需要分页
|
||
{
|
||
int pageSize = int.Parse(json["pageSize"].ToString());
|
||
int pageList = int.Parse(json["pageList"].ToString());
|
||
DataTable dt = ds.Tables[0];
|
||
DataTable dt1 = dt.Copy(); //复制dt
|
||
dt1.Rows.Clear();//清空内容,只保留dt结构。
|
||
for (int i = (pageList - 1) * pageSize; i < pageList * pageSize; i++)//循环需要显示的行
|
||
{
|
||
if (i < dt.Rows.Count)
|
||
{
|
||
dt1.ImportRow(dt.Rows[i]);//这是加入的是第i行
|
||
}
|
||
}
|
||
result = JsonHelper.CreateJsonParameters(dt1, true, dt.Rows.Count);
|
||
|
||
}
|
||
else
|
||
{
|
||
result = JsonHelper.DataTableToJson(ds.Tables[0]);
|
||
}
|
||
|
||
}
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <param name="bytes"></param>
|
||
/// <param name="fileName"></param>
|
||
/// <param name="fileExtension"></param>
|
||
/// <returns></returns>
|
||
public static bool ExePROCEDURE_Type2004(JsonData json, out byte[]bytes, out string fileName, out string fileExtension)
|
||
{
|
||
DataTable dt;
|
||
bytes = null;
|
||
fileName = "";
|
||
fileExtension = "";
|
||
ExePROCEDURE_Type11_2004(json, out dt);
|
||
if(dt!=null)
|
||
{
|
||
if(dt.Rows.Count>0 )
|
||
{
|
||
bytes = (byte[])dt.Rows[0][0];
|
||
fileName = dt.Rows[0][1].ToString();
|
||
fileExtension = dt.Rows[0][2].ToString();
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
public static void ExePROCEDURE_Type11_2004(JsonData json,out DataTable dt)
|
||
{
|
||
dt = null;
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;// 存储过程执行是否成功
|
||
bool isOutput = false;
|
||
DataSet ds = null;
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
//string connectionString_connType = GetConnectionStringByConnType(connType);
|
||
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//参数为空,执行没有参数的存储过程
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
thisParms = new SqlParameter[jsonData.Count];//定义参数个数
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
//string value = jsonData[i]["value"].ToString();// 参数值
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
thisParms[i] = new SqlParameter(name, value);
|
||
if (jsonData[i].ContainsKey("output"))
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
}
|
||
if (output == "1")
|
||
{
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, output);
|
||
thisParms[i] = new SqlParameter(name, inputValue);
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
}
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
|
||
}
|
||
|
||
dt = ds.Tables[0];
|
||
|
||
}
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
//result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
//return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 11 存储过程方式查询
|
||
/// 查询 采用新协议 例:{"type":"11","name":"存储过程","param":"[{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]"}
|
||
/// "UserID": $("#UserID").val(),
|
||
/// "Type": $("#TYPE").val(),
|
||
/// "Name": $("#NAME").val(),
|
||
/// "Param": $("#PARAM1value").val(),
|
||
/// "Pagination": $("#Pagination").val(),
|
||
/// HasReturn: $("#HASRETURN").get(0).checked
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type13(JsonData json)
|
||
{
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;// 存储过程执行是否成功
|
||
bool isOutput = false;
|
||
DataSet ds = null;
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
if (jsonDataParam == null)
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
|
||
}
|
||
else
|
||
{
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//参数为空,执行没有参数的存储过程
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
|
||
thisParms = new SqlParameter[jsonData.Count];//定义参数个数
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
//string value = jsonData[i]["value"].ToString();// 参数值
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
thisParms[i] = new SqlParameter(name, value);
|
||
if (jsonData[i].ContainsKey("output"))
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
}
|
||
if (output == "1")
|
||
{
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, output);
|
||
thisParms[i] = new SqlParameter(name, inputValue);
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
}
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
if (isOK)
|
||
{
|
||
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
result = DatasetToJson(ds);
|
||
//result = DataTableToJson(ds.Tables[0]);// JsonHelper.DataTableToJson(ds.Tables[0]);
|
||
|
||
}
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
public static string ExePROCEDURE_Type15(JsonData json,string filename,string suffix,byte[]bytes)
|
||
{
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;// 存储过程执行是否成功
|
||
bool isOutput = false;
|
||
DataSet ds = null;
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
if (jsonDataParam == null)
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
|
||
}
|
||
else
|
||
{
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//参数为空,执行没有参数的存储过程
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
|
||
thisParms = new SqlParameter[jsonData.Count];//定义参数个数
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
//string value = jsonData[i]["value"].ToString();// 参数值
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
thisParms[i] = new SqlParameter(name, value);
|
||
if (jsonData[i].ContainsKey("output"))
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
}
|
||
if (output == "1")
|
||
{
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, output);
|
||
thisParms[i] = new SqlParameter(name, inputValue);
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
}
|
||
thisParms[thisParms.Length - 3].Value = filename;
|
||
thisParms[thisParms.Length - 2].Value = suffix;
|
||
thisParms[thisParms.Length - 1].Value = bytes;
|
||
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
if (isOK)
|
||
{
|
||
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
result = DatasetToJson(ds);
|
||
//result = DataTableToJson(ds.Tables[0]);// JsonHelper.DataTableToJson(ds.Tables[0]);
|
||
|
||
}
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
public static string ExePROCEDURE_Type16(JsonData json,out byte[]bytes, out string fileName, out string suffix)
|
||
{
|
||
bytes = null;
|
||
fileName = "";
|
||
suffix = "";
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;// 存储过程执行是否成功
|
||
bool isOutput = false;
|
||
DataSet ds = null;
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
if (jsonDataParam == null)
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
|
||
}
|
||
else
|
||
{
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//参数为空,执行没有参数的存储过程
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
|
||
thisParms = new SqlParameter[jsonData.Count];//定义参数个数
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
//string value = jsonData[i]["value"].ToString();// 参数值
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
thisParms[i] = new SqlParameter(name, value);
|
||
if (jsonData[i].ContainsKey("output"))
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
}
|
||
if (output == "1")
|
||
{
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, output);
|
||
thisParms[i] = new SqlParameter(name, inputValue);
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
}
|
||
|
||
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
}
|
||
}
|
||
if (isOK)
|
||
{
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
fileName = ds.Tables[0].Rows[0].ItemArray[0].ToString();
|
||
suffix = ds.Tables[0].Rows[0].ItemArray[1].ToString();
|
||
bytes = (byte[])ds.Tables[0].Rows[0].ItemArray[2];
|
||
//去掉后缀
|
||
if(fileName.Contains(suffix))
|
||
{
|
||
fileName = fileName.Split(new Char[] { '.' })[0];
|
||
}
|
||
result = "[{ \"result\":\"" + "1" + "\"}]";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
public static void GetString_JsonData_Type15(JsonData json, out string type, out string name, out string param, out string userID, out string pagination, out bool hasReturn, out string modularID)
|
||
{
|
||
type = null;
|
||
name = null;
|
||
param = "";
|
||
userID = null;
|
||
pagination = null;
|
||
hasReturn = false;
|
||
modularID = "";
|
||
if (json == null) return;
|
||
if (json.Keys.Contains("Type"))
|
||
{
|
||
if (json["Type"] != null)
|
||
type = json["Type"].ToString();
|
||
}
|
||
else if (json.Keys.Contains("type"))
|
||
{
|
||
if (json["type"] != null)
|
||
type = json["type"].ToString();
|
||
}
|
||
|
||
if (json.Keys.Contains("Name"))
|
||
{
|
||
if (json["Name"] != null)
|
||
name = json["Name"].ToString();
|
||
}
|
||
else if (json.Keys.Contains("name"))
|
||
{
|
||
if (json["name"] != null)
|
||
name = json["name"].ToString();
|
||
}
|
||
|
||
|
||
if (json.Keys.Contains("Param"))
|
||
{
|
||
if (json["Param"] != null)
|
||
param = json["Param"].ToString();
|
||
}
|
||
else if (json.Keys.Contains("param"))
|
||
{
|
||
if (json["param"] != null)
|
||
param = json["param"].ToString();
|
||
}
|
||
|
||
|
||
if (json.Keys.Contains("UserID"))
|
||
{
|
||
if (json["UserID"] != null)
|
||
userID = json["UserID"].ToString();
|
||
}
|
||
else if (json.Keys.Contains("userID"))
|
||
{
|
||
if (json["userID"] != null)
|
||
userID = json["userID"].ToString();
|
||
}
|
||
|
||
if (json.Keys.Contains("Pagination"))
|
||
{
|
||
if (json["Pagination"] != null)
|
||
pagination = json["Pagination"].ToString();
|
||
}
|
||
else if (json.Keys.Contains("pagination"))
|
||
{
|
||
if (json["pagination"] != null)
|
||
pagination = json["pagination"].ToString();
|
||
}
|
||
|
||
if (json.Keys.Contains("HasReturn"))
|
||
{
|
||
try
|
||
{
|
||
if (json["HasReturn"] != null)
|
||
hasReturn = Convert.ToBoolean(json["HasReturn"].ToString());
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
else if (json.Keys.Contains("hasReturn"))
|
||
{
|
||
try
|
||
{
|
||
if (json["hasReturn"] != null)
|
||
hasReturn = Convert.ToBoolean(json["hasReturn"].ToString());
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
|
||
if (json.Keys.Contains("ModularID"))
|
||
{
|
||
try
|
||
{
|
||
if (json["ModularID"] != null)
|
||
modularID = json["ModularID"].ToString();
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
else if (json.Keys.Contains("modularID"))
|
||
{
|
||
try
|
||
{
|
||
if (json["modularID"] != null)
|
||
modularID = json["modularID"].ToString();
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
//ModularID
|
||
}
|
||
public static string DataTableToJson(DataTable dt)
|
||
{
|
||
|
||
StringBuilder jsonBuilder = new StringBuilder();
|
||
//jsonBuilder.Append("{");
|
||
jsonBuilder.Append(JsonHelper.DataTableToJson(dt));
|
||
//jsonBuilder.Append("}");
|
||
return jsonBuilder.ToString();
|
||
}
|
||
public static string DataTableToJsonBak(DataTable dt)
|
||
{
|
||
|
||
StringBuilder jsonBuilder = new StringBuilder();
|
||
jsonBuilder.Append("{\"Name\":\"" + dt.TableName + "\",\"Rows\":");
|
||
jsonBuilder.Append(JsonHelper.DataTableToJson(dt));
|
||
jsonBuilder.Append("}");
|
||
return jsonBuilder.ToString();
|
||
}
|
||
|
||
public static string DatasetToJson(System.Data.DataSet ds)
|
||
{
|
||
StringBuilder json = new StringBuilder();
|
||
//json.Append("{");
|
||
json.Append("[");
|
||
foreach (System.Data.DataTable dt in ds.Tables)
|
||
{
|
||
json.Append(DataTableToJson(dt));
|
||
json.Append(",");
|
||
}
|
||
json.Remove(json.Length - 1, 1);
|
||
json.Append("]");
|
||
//json.Append("}");
|
||
return json.ToString();
|
||
}
|
||
public static string DatasetToJsonBak(System.Data.DataSet ds)
|
||
{
|
||
StringBuilder json = new StringBuilder();
|
||
json.Append("{\"Tables\":");
|
||
json.Append("[");
|
||
foreach (System.Data.DataTable dt in ds.Tables)
|
||
{
|
||
json.Append(DataTableToJson(dt));
|
||
json.Append(",");
|
||
}
|
||
json.Remove(json.Length - 1, 1);
|
||
json.Append("]");
|
||
json.Append("}");
|
||
return json.ToString();
|
||
}
|
||
/// <summary>
|
||
/// 分页查询
|
||
/// "UserID": $("#UserID").val(),
|
||
/// "Type": $("#TYPE").val(),
|
||
/// "Name": $("#NAME").val(),
|
||
/// "Param": $("#PARAM1value").val(),
|
||
/// "Pagination": $("#Pagination").val(),
|
||
/// HasReturn: $("#HASRETURN").get(0).checked
|
||
/// </summary>
|
||
/// <param name="tbname">要分页显示的表名</param>
|
||
/// <param name="fieldkey">用于定位记录的主键(惟一键)字段,只能是单个字段</param>
|
||
/// <param name="where">查询条件</param>
|
||
/// <param name="fieldshow">以逗号分隔的要显示的字段列表,如果不指定,则显示所有字段</param>
|
||
/// <param name="fieldOrder">以逗号分隔的排序字段列表,可以指定在字段后面指定DESC / ASC--用于指定排序顺序</param>
|
||
/// <param name="PageCurrent">要显示的页码</param>
|
||
/// <param name="PageSizeint">每页的大小(记录数)</param>
|
||
/// <param name="dt">返回的结果表</param>
|
||
/// <param name="PageCount">总页数</param>
|
||
/// <param name="itemCount">数据总数</param>
|
||
public static bool ExePROCEDURE_Type1003(string tbname,string fieldkey,string where,string fieldshow,string fieldorder,int pagecurrent,int pagesize ,
|
||
out DataTable dt,out int pagecount,out int itemcount)
|
||
{
|
||
dt = new DataTable();
|
||
DataSet ds;
|
||
itemcount = 0;
|
||
string ErrorMessage;
|
||
return DataAccess.ExecPageQuery(tbname, connectionString, fieldkey, where, fieldshow, fieldorder, pagecurrent, pagesize, out pagecount, out itemcount, out ds, out ErrorMessage);
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <param name="dt"></param>
|
||
/// <param name="pagecount"></param>
|
||
/// <param name="itemcount"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type1003(JsonData json, out DataTable dt, out int pagecount,out int itemcount)
|
||
{
|
||
string tbname="";
|
||
string fieldkey="";
|
||
string where="";
|
||
string fieldshow="";
|
||
string fieldorder="";
|
||
int pagecurrent=1;
|
||
int pagesize=15;
|
||
pagecount=0;
|
||
dt = new DataTable();
|
||
|
||
DataSet ds;
|
||
itemcount = 0;
|
||
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;// 存储过程执行是否成功
|
||
bool isOutput = false;
|
||
dt = new DataTable();
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
if(jsonData.Count>0)
|
||
{
|
||
if (jsonData[0]["tbname"] != null)
|
||
{
|
||
tbname = jsonData[0]["tbname"].ToString();
|
||
}
|
||
if (jsonData[0]["fieldkey"] != null)
|
||
{
|
||
fieldkey = jsonData[0]["fieldkey"].ToString();
|
||
}
|
||
if (jsonData[0]["where"] != null)
|
||
{
|
||
where = jsonData[0]["where"].ToString();
|
||
}
|
||
if (jsonData[0]["fieldshow"] != null)
|
||
{
|
||
fieldshow = jsonData[0]["fieldshow"].ToString();
|
||
}
|
||
if (jsonData[0]["fieldorder"] != null)
|
||
{
|
||
fieldorder = jsonData[0]["fieldorder"].ToString();
|
||
}
|
||
if (jsonData[0]["pagecurrent"] != null)
|
||
{
|
||
pagecurrent = Convert.ToInt32(jsonData[0]["pagecurrent"]);
|
||
}
|
||
if (jsonData[0]["pagesize"] != null)
|
||
{
|
||
pagesize = Convert.ToInt32(jsonData[0]["pagesize"]);
|
||
}
|
||
}
|
||
|
||
isOK = ExePROCEDURE_Type1003(tbname, fieldkey, where, fieldshow, fieldorder, pagecurrent, pagesize, out dt, out pagecount, out itemcount);
|
||
|
||
}
|
||
if (isOK)
|
||
{
|
||
|
||
if (dt != null)
|
||
{
|
||
result = JsonHelper.DataTableToJson(dt);
|
||
}
|
||
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
//resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
{
|
||
resultOutput = resultOutput + "\"" + "pagecount" + "\":" + "\"" + pagecount.ToString() + "\"";
|
||
}
|
||
{
|
||
resultOutput = resultOutput + "," + "\"" + "itemcount" + "\":" + "\"" + itemcount.ToString() + "\"";
|
||
}
|
||
resultOutput = "[{" + resultOutput + "}]";
|
||
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public static string ExePROCEDURE_Type11(JsonData json,out DataTable dt)
|
||
{
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;// 存储过程执行是否成功
|
||
bool isOutput = false;
|
||
DataSet ds = null;
|
||
dt = new DataTable();
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//参数为空,执行没有参数的存储过程
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
thisParms = new SqlParameter[jsonData.Count];//定义参数个数
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
//string value = jsonData[i]["value"].ToString();// 参数值
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
thisParms[i] = new SqlParameter(name, value);
|
||
if (jsonData[i].ContainsKey("output"))
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
}
|
||
if (output == "1")
|
||
{
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, output);
|
||
thisParms[i] = new SqlParameter(name, inputValue);
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
}
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out ds, out result);
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
dt = ds.Tables[0];
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
if (isOK)
|
||
{
|
||
|
||
if (ds != null && ds.Tables.Count > 0)
|
||
{
|
||
//DataTable dt = ds.Tables[0];
|
||
//result = JsonHelper.CreateJsonParameters(dt, true, dt.Rows.Count);
|
||
//result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
if (json.ContainsKey("pageSize") && json.ContainsKey("pageList")) // 判断是否需要分页
|
||
{
|
||
int pageSize = int.Parse(json["pageSize"].ToString());
|
||
int pageList = int.Parse(json["pageList"].ToString());
|
||
dt = ds.Tables[0];
|
||
DataTable dt1 = dt.Copy(); //复制dt
|
||
dt1.Rows.Clear();//清空内容,只保留dt结构。
|
||
for (int i = (pageList - 1) * pageSize; i < pageList * pageSize; i++)//循环需要显示的行
|
||
{
|
||
if (i < dt.Rows.Count)
|
||
{
|
||
dt1.ImportRow(dt.Rows[i]);//这是加入的是第i行
|
||
}
|
||
}
|
||
result = JsonHelper.CreateJsonParameters(dt1, true, dt.Rows.Count);
|
||
|
||
}
|
||
else
|
||
{
|
||
result = JsonHelper.DataTableToJson(ds.Tables[0]);
|
||
}
|
||
|
||
}
|
||
string resultOutput = "";
|
||
//[{"name1":"value1","name2":"value2"}]
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
/// <summary>
|
||
/// 12
|
||
/// 增删改 DbCallType2 的更新版 采用新协议 {"type":"12","name":"存储过程","param":"[{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]"}
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
/// <returns></returns>
|
||
public static string ExePROCEDURE_Type12(JsonData json)
|
||
{
|
||
SqlParameter[] thisParms = null;
|
||
string result = "";
|
||
bool isOK = false;
|
||
bool isOutput = false;
|
||
JsonData jsonData;
|
||
JsonData jsonDataName;//存储过程名称
|
||
JsonData jsonDataParam;//存储过程参数
|
||
try
|
||
{
|
||
{
|
||
|
||
string type1;
|
||
string name1;
|
||
string param1;
|
||
string userID1;
|
||
string pagination1;
|
||
bool hasReturn1;
|
||
string modularID1;
|
||
GetString_JsonData(json, out type1, out name1, out param1, out userID1, out pagination1, out hasReturn1, out modularID1);
|
||
|
||
jsonDataName = name1;//存储过程名称
|
||
jsonDataParam = param1; //存储过程参数 json格式 [{\"name\":\"name1\",\"value\":\"value1\"},{\"name\":\"name2\",\"value\":\"value1\"}]
|
||
jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转为JSON格式
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//执行没有参数的存储过程
|
||
{
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out result);
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
thisParms = new SqlParameter[jsonData.Count];
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
thisParms[i] = new SqlParameter(name, value);
|
||
if(jsonData[i].ContainsKey("output"))
|
||
{
|
||
if(jsonData[i]["output"] != null)
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
}
|
||
if(jsonData[i].ContainsKey("type"))
|
||
{
|
||
if(jsonData[i]["type"] != null)
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
}
|
||
}
|
||
|
||
if (output == "1")
|
||
{
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, output);
|
||
thisParms[i] = new SqlParameter(name, inputValue);
|
||
thisParms[i].Direction = ParameterDirection.Output;
|
||
isOutput = true;// 存在输出参数
|
||
}
|
||
}
|
||
isOK = SQLCommon.ExecuteStoredProcedure(jsonDataName.ToString(), connectionString, ref thisParms, out result);
|
||
}
|
||
|
||
}
|
||
if (isOK)
|
||
{
|
||
result = "[{ \"result\":\"1\"}]";
|
||
string resultOutput = "";
|
||
if (isOutput)//存储过程有输出参数
|
||
{
|
||
resultOutput = SQLCommon.GetOutputValue(thisParms);
|
||
string jsonStr;
|
||
jsonStr = "{\"result\":" + result + "," + "\"output\":" + resultOutput + "}";
|
||
result = jsonStr;
|
||
}
|
||
}
|
||
|
||
else
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result = "[{ \"result\":\"" + "0" + "\"}]";
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Unicode解码
|
||
/// </summary>
|
||
/// <param name="str"></param>
|
||
/// <returns></returns>
|
||
public static string DeUnicode(string str)
|
||
{
|
||
//最直接的方法Regex.Unescape(str);
|
||
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
|
||
return reg.Replace(str, delegate (Match m) { return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString(); });
|
||
}
|
||
|
||
public static void GetParamData(JsonData jsonDataParam, out ParamData[] paramData)
|
||
{
|
||
|
||
JsonData jsonData = JsonMapper.ToObject(jsonDataParam.ToString()); //转格式
|
||
if (jsonDataParam.ToString() == "" || jsonDataParam.ToString() == null)//参数为空,执行没有参数的存储过程
|
||
{
|
||
paramData = null;
|
||
}
|
||
else//执行有参数的存储过程
|
||
{
|
||
paramData = new ParamData[jsonData.Count];//定义参数个数
|
||
for (int i = 0; i < jsonData.Count; i++)
|
||
{
|
||
string name = jsonData[i]["name"].ToString();// 参数名
|
||
//string value = jsonData[i]["value"].ToString();// 参数值
|
||
string value = null;
|
||
try
|
||
{
|
||
//判断是否为数组,若为数组转为字符串格式
|
||
if (jsonData[i]["value"].IsArray == true)
|
||
{
|
||
//数组转字符串
|
||
value = jsonData[i]["value"].ToJson().ToString().Replace("[", "").Replace("]", "").Replace("\"", "");// 数组参数值转字符串
|
||
// unicode解码
|
||
value = DeUnicode(value);
|
||
}
|
||
else//不是数组格式直接转字符串
|
||
{
|
||
value = jsonData[i]["value"].ToString();// 参数值
|
||
}
|
||
|
||
}
|
||
catch (Exception E)//value为null时。Tostring()会报错,需要手动赋值
|
||
{
|
||
value = null;
|
||
}
|
||
string output = null;// 参数是否为输出类型
|
||
string type = null;// 参数类型
|
||
paramData[i].name = name;
|
||
paramData[i].value = value;
|
||
if (jsonData[i].ContainsKey("output"))
|
||
{
|
||
if (jsonData[i]["output"] != null)
|
||
{
|
||
output = jsonData[i]["output"].ToString();// 参数是否为输出类型
|
||
}
|
||
}
|
||
if (jsonData[i].ContainsKey("type"))
|
||
{
|
||
if (jsonData[i]["type"] != null)
|
||
{
|
||
type = jsonData[i]["type"].ToString();// 参数类型
|
||
object inputValue = null; ;
|
||
inputValue = GetInputValue(type, value);
|
||
paramData[i].name = name;
|
||
paramData[i].value = inputValue;
|
||
}
|
||
}
|
||
if (output == "1")
|
||
{
|
||
paramData[i].isOutPut = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 返回输出参数类型
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
/// <param name="output"></param>
|
||
/// <returns></returns>
|
||
public static object GetInputValue(object type, object output)
|
||
{
|
||
object inputValue = null;
|
||
switch (type.ToString())
|
||
{
|
||
case "int":
|
||
inputValue = Convert.ToInt32(output);
|
||
break;
|
||
case "string":
|
||
inputValue = output;
|
||
break;
|
||
case "boolean":
|
||
case "bool":
|
||
if (output.ToString() == "1" || output.ToString() == "true")
|
||
{
|
||
inputValue = true;
|
||
}
|
||
else
|
||
{
|
||
inputValue = false;
|
||
}
|
||
break;
|
||
case "datetime":
|
||
inputValue = Convert.ToDateTime(output);
|
||
break;
|
||
default:
|
||
inputValue = output.ToString();
|
||
break;
|
||
}
|
||
|
||
return inputValue;
|
||
|
||
}
|
||
/// <summary>
|
||
/// 返回输出参数类型
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
/// <param name="output"></param>
|
||
/// <returns></returns>
|
||
static object GetInputStringValue(object type, string value)
|
||
{
|
||
object inputValue = value;
|
||
try
|
||
{
|
||
if (type == null)
|
||
{
|
||
return inputValue;
|
||
}
|
||
switch (type.ToString())
|
||
{
|
||
case "int":
|
||
inputValue = Convert.ToInt32(value);
|
||
break;
|
||
case "string":
|
||
inputValue = value;
|
||
break;
|
||
case "boolean":
|
||
case "bool":
|
||
if (value.ToString() == "1" || value.ToString() == "true")
|
||
{
|
||
inputValue = true;
|
||
}
|
||
else
|
||
{
|
||
inputValue = false;
|
||
}
|
||
break;
|
||
case "datetime":
|
||
inputValue = Convert.ToDateTime(value);
|
||
break;
|
||
default:
|
||
inputValue = value.ToString();
|
||
break;
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
|
||
return inputValue;
|
||
|
||
}
|
||
/// <summary>
|
||
/// 根据结构数组变量,获得对应Json字符串
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
/// <param name="name"></param>
|
||
/// <param name="paramData"></param>
|
||
/// <returns></returns>
|
||
static string GetExeSqlCmd(string type, string name, ParamData[] paramData)
|
||
{
|
||
string jsonStr = "";
|
||
string paramDataJson;
|
||
paramDataJson = GetParamJson(paramData);
|
||
jsonStr = GetExeSqlCmd(type, name, paramDataJson);
|
||
|
||
|
||
return jsonStr;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据表结构数组变量,获得对应Json字符串
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
/// <param name="name"></param>
|
||
/// <param name="paramDataTable"></param>
|
||
/// <returns></returns>
|
||
static string GetExeSqlCmd(string type, string name, DataTable paramDataTable)
|
||
{
|
||
string jsonStr = "";
|
||
string paramDataJson;
|
||
paramDataJson = GetParamJson(paramDataTable);
|
||
jsonStr = GetExeSqlCmd(type, name, paramDataJson);
|
||
return jsonStr;
|
||
}
|
||
/// <summary>
|
||
/// 根据结构数组变量,获得对应Json字符串
|
||
/// </summary>
|
||
/// <param name="paramData"></param>
|
||
/// <returns></returns>
|
||
private static string GetParamJson(ParamData[] paramData)
|
||
{
|
||
string jsonStr = "";
|
||
List<ParamData> listParamData = new List<ParamData>();
|
||
for (int i = 0; i < paramData.Length; i++)
|
||
{
|
||
listParamData.Add(paramData[i]);
|
||
}
|
||
|
||
MemoryStream stream1 = new MemoryStream();
|
||
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<ParamData>));
|
||
ser.WriteObject(stream1, listParamData);
|
||
stream1.Position = 0;
|
||
StreamReader sr = new StreamReader(stream1);
|
||
jsonStr = sr.ReadToEnd();
|
||
|
||
jsonStr = jsonStr.Replace("\"", "\\\"");
|
||
|
||
return jsonStr;
|
||
}
|
||
/// <summary>
|
||
/// 根据表结构数组变量,获得对应Json字符串
|
||
/// </summary>
|
||
/// <param name="paramData"></param>
|
||
/// <returns></returns>
|
||
private static string GetParamJson(DataTable paramDataTable)
|
||
{
|
||
ParamData[] paramData;
|
||
string jsonStr = "";
|
||
if (paramDataTable != null & paramDataTable.Rows.Count > 0)
|
||
{
|
||
//paramData = new ParamData[paramDataTable.Rows.Count];
|
||
//for (int i = 0; i < paramDataTable.Rows.Count; i++)
|
||
//{
|
||
// paramData[i].name = paramDataTable.Rows[i]["name"].ToString();
|
||
// paramData[i].value = paramDataTable.Rows[i]["value"].ToString();
|
||
// paramData[i].type = paramDataTable.Rows[i]["type"].ToString();
|
||
// paramData[i].output = paramDataTable.Rows[i]["output"].ToString();
|
||
//}
|
||
|
||
paramData = GetParam(paramDataTable);
|
||
jsonStr = GetParamJson(paramData);
|
||
//List<ParamData> listParamData = new List<ParamData>();
|
||
//for (int i = 0; i < paramData.Length; i++)
|
||
//{
|
||
// listParamData.Add(paramData[i]);
|
||
//}
|
||
|
||
//MemoryStream stream1 = new MemoryStream();
|
||
//DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<ParamData>));
|
||
//ser.WriteObject(stream1, listParamData);
|
||
//stream1.Position = 0;
|
||
//StreamReader sr = new StreamReader(stream1);
|
||
}
|
||
return jsonStr;
|
||
}
|
||
|
||
public static ParamData[] GetParam(DataTable paramDataTable)
|
||
{
|
||
ParamData[] paramData=null;
|
||
if (paramDataTable != null & paramDataTable.Rows.Count > 0)
|
||
{
|
||
paramData = new ParamData[paramDataTable.Rows.Count];
|
||
for (int i = 0; i < paramDataTable.Rows.Count; i++)
|
||
{
|
||
paramData[i].name = paramDataTable.Rows[i]["name"].ToString();
|
||
paramData[i].value = paramDataTable.Rows[i]["value"].ToString();
|
||
//paramData[i].datatype = paramDataTable.Rows[i]["type"].ToString();
|
||
if(paramDataTable.Rows[i]["output"].ToString().Length>0)
|
||
{
|
||
paramData[i].isOutPut =true;
|
||
}
|
||
else
|
||
{
|
||
paramData[i].isOutPut = false;
|
||
}
|
||
}
|
||
}
|
||
return paramData;
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
/// <param name="name"></param>
|
||
/// <param name="param"></param>
|
||
/// <returns></returns>
|
||
private static string GetExeSqlCmd(string type, string name, string paramJson)
|
||
{
|
||
//{ "type":"1002","name":"select * from test","param":"[{\"name\":\"检测点代码\",\"value\":15},{\"name\":\"原材料_check\",\"value\":1},{\"name\":\"原材料代码\",\"value\":12}]"}
|
||
//{"type":"1002","name":"select * from test","param":""}
|
||
string jsonStr = "";
|
||
string jsonStrParam;
|
||
if (paramJson.Length > 0)
|
||
{
|
||
jsonStrParam = "\"" + paramJson + "\"";
|
||
}
|
||
else
|
||
{
|
||
jsonStrParam = "\"\"";
|
||
}
|
||
jsonStr = "{\"type\":\"" + type + "\",\"name\":\"" + name + "\",\"param\":" + jsonStrParam + "}";
|
||
return jsonStr;
|
||
}
|
||
}
|
||
}
|