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 dic = new Dictionary(); 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 dic = new Dictionary(); 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 dic = new Dictionary(); 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 dic = new Dictionary(); 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 dic = new Dictionary(); 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 dic = new Dictionary(); 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 dic = new Dictionary(); 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 dic = new Dictionary(); 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 dic = new Dictionary(); 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 dic = new Dictionary(); 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 dic = new Dictionary(); dic.Add("sql", sql); dt = new CallWebApi().InvokeWebapiDataTable(controlStr, actionStr, api, type, dic); return true; } } }