9 changed files with 315 additions and 5 deletions
@ -0,0 +1,123 @@ |
|||||
|
using LiveChartsCore.Kernel; |
||||
|
using SunlightCentralizedControlManagement_SCCM_.UserClass; |
||||
|
using SunlightCentralizedControlManagement_SCCM_.ViewModel; |
||||
|
using SunlightCentralizedControlManagement_SCCM_.WindowsView; |
||||
|
using System; |
||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Data; |
||||
|
using System.Data.SqlClient; |
||||
|
using System.IO; |
||||
|
using System.Runtime.Remoting; |
||||
|
using System.Runtime.Remoting.Contexts; |
||||
|
using System.Security.Principal; |
||||
|
using System.Threading.Tasks; |
||||
|
using TouchSocket.Core; |
||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; |
||||
|
|
||||
|
namespace SunlightCentralizedControlManagement_SCCM_.EX.Exchange |
||||
|
{ |
||||
|
public class BDC_SQL |
||||
|
{ |
||||
|
public class BDCSqlHelper |
||||
|
{ |
||||
|
// SqlConnection conn_SC = new SqlConnection();//数据库
|
||||
|
string db; |
||||
|
public void Config(string IP, string DATABASE, string USER, string PAWSSD, bool MODE)//连接dbc数据库
|
||||
|
{ |
||||
|
if (MODE) //连接数据库测试
|
||||
|
{ |
||||
|
db="server=" + IP + ";database=" + DATABASE + ";Trusted_Connection=SSPI"; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
db="server=" + IP + ";database=" + DATABASE + ";User ID=" + USER + ";Password=" + PAWSSD; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public async Task<int> UPDATA(string name,string where,DataRow entity)//dbc数据库
|
||||
|
{ |
||||
|
string DAT = null; |
||||
|
int rowsAffected = 0; |
||||
|
int type = 0; |
||||
|
try { type = entity.Field<int>("Type"); } catch { } |
||||
|
try |
||||
|
{ |
||||
|
|
||||
|
DAT = "DispenseDyelot='" + entity.Field<string>("Dyelot") + "',DispenseReDye='" + entity.Field<int>("Redye")+"',"; |
||||
|
if (type == 2) |
||||
|
{ |
||||
|
DAT = DAT+"DyeCallOff=" + entity.Field<int>("Step") + ",DyeState = 201,DyeTank=" + |
||||
|
entity.Field<int>("Tank"); |
||||
|
} |
||||
|
else if (type == 3) |
||||
|
{ |
||||
|
DAT = DAT+"PowderCallOff=" + entity.Field<int>("Step") +",PowderState=201,PowderTank=" + |
||||
|
entity.Field<int>("Tank"); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
DAT = DAT+"ChemicalCallOff=" + entity.Field<int>("Step") +",ChemicalState=201,ChemicalTank=" + |
||||
|
entity.Field<int>("Tank"); |
||||
|
} |
||||
|
|
||||
|
using (var connection = new SqlConnection(db)) |
||||
|
{ |
||||
|
await connection.OpenAsync(); |
||||
|
var command = connection.CreateCommand(); |
||||
|
command.CommandText = "UPDATE "+ name + " SET "+ DAT + " WHERE "+ where; |
||||
|
// command.Parameters.AddWithValue("@table", name);
|
||||
|
// command.Parameters.AddWithValue("@Id", where);
|
||||
|
// command.Parameters.AddWithValue("@data", DAT);
|
||||
|
rowsAffected = await command.ExecuteNonQueryAsync(); |
||||
|
|
||||
|
LogGing.ExchangeDATA( command.CommandText.ToString()); |
||||
|
} |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
LogGing.ERRDATA(ex); |
||||
|
} |
||||
|
return rowsAffected; |
||||
|
} |
||||
|
|
||||
|
public async Task<DataTable> SELECT(string name, string where)//dbc数据库
|
||||
|
{ |
||||
|
DataTable rowsAffected = new DataTable(); |
||||
|
try |
||||
|
{ |
||||
|
using (var connection = new SqlConnection(db)) |
||||
|
{ |
||||
|
await connection.OpenAsync(); |
||||
|
var command = connection.CreateCommand(); |
||||
|
command.CommandText = "SELECT * FROM " + name + " WHERE " + where; |
||||
|
var dat = await command.ExecuteReaderAsync(); |
||||
|
rowsAffected.Load(dat); |
||||
|
|
||||
|
LogGing.ExchangeDATA(command.CommandText.ToString()); |
||||
|
} |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
LogGing.ERRDATA(ex); |
||||
|
} |
||||
|
return rowsAffected; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue