189 lines
6.5 KiB
C#
189 lines
6.5 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DtWebApiDT
|
|
{
|
|
public class PLC
|
|
{
|
|
public static void WritePLC(string tagID, string tagValue)
|
|
{
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "PLC1";
|
|
string actionStr = "WritePLC";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("tagID", tagID);
|
|
dic.Add("tagValue", tagValue);
|
|
string str = new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
|
|
|
}
|
|
public static string ReadPLC(string tagID)
|
|
{
|
|
string tagValue;
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "PLC1";
|
|
string actionStr = "ReadPLC";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("tagID", tagID);
|
|
|
|
tagValue = new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
|
return tagValue;
|
|
}
|
|
}
|
|
public class DataAccess
|
|
{
|
|
|
|
|
|
public static void GetProjectCodeAndProjectName(out string ProjectCode,out string ProjectName)
|
|
{
|
|
ProjectCode = "";
|
|
ProjectName = "";
|
|
//return PP.ProjectCode + "|" + PP.ProjectName;
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "SQLCommon";
|
|
string actionStr = "GetProjectCodeAndProjectName";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
|
|
string str = new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
|
string[] strList = str.Split('|');
|
|
try
|
|
{
|
|
ProjectCode = strList[0];
|
|
ProjectName = strList[1];
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
public static bool ExecuteNonQuery(StringCollection sql, string connectionString, out string errorMessage)
|
|
{
|
|
errorMessage = "";
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "SQLCommon";
|
|
string actionStr = "ExecuteNonQuery1";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("sql", JsonConvert.SerializeObject(sql));
|
|
|
|
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
|
}
|
|
public static bool ExecuteNonQuery(string sql, string connectionString, out string errorMessage)
|
|
{
|
|
errorMessage = "";
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "SQLCommon";
|
|
string actionStr = "ExecuteNonQuery";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("sql", sql);
|
|
|
|
return new CallWebApi().InvokeWebapiBool(controlStr, actionStr, api, type, dic);
|
|
}
|
|
|
|
|
|
public static bool ExecuteOutNum(string sql, string connectionString, out int count, out string errorMessage)
|
|
{
|
|
errorMessage = "";
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "SQLCommon";
|
|
string actionStr = "ExecuteOutNum";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("sql", sql);
|
|
|
|
count = new CallWebApi().InvokeWebapiInt(controlStr, actionStr, api, type, dic);
|
|
return true;
|
|
}
|
|
|
|
public static bool ExecuteDataset(string sql, string connectionString, out DataSet ds, out string errorMessage)
|
|
{
|
|
errorMessage = "";
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "SQLCommon";
|
|
string actionStr = "ExecuteDataset";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
|
|
|
|
dic.Add("sql", sql);
|
|
ds = new CallWebApi().InvokeWebapiDataSet(controlStr, actionStr, api, type, dic);
|
|
return true;
|
|
}
|
|
|
|
public static bool ExecuteDataTable(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
|
{
|
|
errorMessage = "";
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "SQLCommon";
|
|
string actionStr = "ExecuteDataTable";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("sql", sql);
|
|
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
|
return true;
|
|
}
|
|
|
|
|
|
public static bool ExecuteDataReader(string sql, string connectionString, out SqlDataReader dr, out string errorMessage)
|
|
{
|
|
errorMessage = "";
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "SQLCommon";
|
|
string actionStr = "ExecuteDataReader";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("sql", sql);
|
|
dr = new CallWebApi().InvokeWebapiSqlDataReader(controlStr, actionStr, api, type, dic);
|
|
return true;
|
|
}
|
|
|
|
public static bool ExecuteSql(string sql, string connectionString, out string errorMessage)
|
|
{
|
|
errorMessage = "";
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "SQLCommon";
|
|
string actionStr = "ExecuteSql";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("sql", sql);
|
|
new CallWebApi().InvokeWebapiString(controlStr, actionStr, api, type, dic);
|
|
return true;
|
|
}
|
|
public static bool ExecuteSql(string sql, string connectionString, out DataTable dt, out string errorMessage)
|
|
{
|
|
errorMessage = "";
|
|
|
|
string api = "";
|
|
string type = "GET";
|
|
string controlStr = "SQLCommon";
|
|
string actionStr = "ExecuteSqlDataTable";
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
dic.Add("sql", sql);
|
|
dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic);
|
|
return true;
|
|
}
|
|
}
|
|
}
|