-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLDA.cs
88 lines (73 loc) · 3.71 KB
/
SQLDA.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System;
using System.Collections.Generic;
using ControlLoopProcessFor3Rates.Models;
namespace ControlLoopProcessFor3Rates
{
class SQLDA
{
private static readonly string _sqlConnection = ConfigurationManager.ConnectionStrings["myconnstring"].ConnectionString;
public List<ModeTagsDataModel> GetModeTagsToProcess()
{
var modeTagData = new List<ModeTagsDataModel>();
using (SqlConnection conn = new SqlConnection(_sqlConnection))
{
using (SqlCommand comm = new SqlCommand("[ThreeRates].[dbo].[SELECT_ModeTags]") { CommandType = CommandType.StoredProcedure })
{
comm.Connection = conn;
try
{
//comm.Parameters.Add("@Plant", SqlDbType.VarChar).Value = plant; //we need tags from all the plants
conn.Open();
using (SqlDataReader dr = comm.ExecuteReader())
{
if (dr.HasRows)
{
while (dr.Read())
{
var data = new ModeTagsDataModel
{
TagName = dr["ModeTag"].ToString(),
PlantLoadFilterTagName = dr["PlantLoadFilterTag"].ToString(),
ConditionFilter = Convert.ToBoolean(dr["HasConditionFilter"]),
ConditionFilterTagName = dr["ConditionFilterTag"].ToString(),
ConditionFilterType = Convert.ToInt32(dr["ConditionFilterTypeID"]),
ConditionFilterValue = Convert.ToDouble(dr["ConditionFilterValue"])
};
modeTagData.Add(data);
}
}
}
}
catch (Exception e) { Console.WriteLine("An errror occured during executing the SQL query: " + e.Message); modeTagData = null; }
if (conn.State == ConnectionState.Open) conn.Close();
}
}
return modeTagData;
}
public void InsertProcessedControlLoopData(ControlLoopDataCollection processedCLDataCollection, string dateId)
{
using (SqlConnection conn = new SqlConnection(_sqlConnection))
{
using (SqlCommand comm = new SqlCommand("[ThreeRates].[dbo].[INSERT_CurrentShiftControlLoopData]") { CommandType = CommandType.StoredProcedure })
{
comm.Connection = conn;
//comm.Parameters.Add("@Result", SqlDbType.Int).Direction = ParameterDirection.Output; //deleted from the db
comm.Parameters.Add("@DateID", SqlDbType.VarChar).Value = dateId;
comm.Parameters.Add("@CRData", SqlDbType.Structured).Value = processedCLDataCollection;
try
{
conn.Open();
comm.ExecuteNonQuery();
//result = Convert.ToInt32(comm.Parameters["@Result"].Value); //no returning value
conn.Close();
}
catch (SqlException e) { Console.WriteLine("An errror occured during executing the SQL query: " + e.Message); }
if (conn.State == ConnectionState.Open) conn.Close();
}
}
}
}
}