/* GROUPS AND ITEMS for variables in all WHERES!!!!!!!!!!! * Create the GROUPs for the OPC client * base just on the WHERES clauses * Store groups in WhereGroups in array */ private List <OPCGroup_t> InitWhereGroup() { string sqlQuery; sqlQuery = "select OpcName from PLC2DB_Tags, PLC2DB_TagsInWhere where PLC2DB_Tags.Tag = PLC2DB_TagsInWhere.Tag and len(rtrim(OpcName))>1 group by OpcName"; Logging log = new Logging(); List <OPCGroup_t> whereGroups = new List <OPCGroup_t>(); try { using (SqlConnection connection = new SqlConnection(IntData.CfgConn)) { connection.Open(); SqlCommand cmd = new SqlCommand(sqlQuery, connection); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { OPCGroup_t og = new OPCGroup_t { tagEvent = "", opcgroup = new OPCController { ServerName = sdr[0].ToString(), GroupName = "whereGrp" + whereGroups.Count } }; whereGroups.Add(og); sqlQuery = "select PLC2DB_Tags.Tag as Tag, Description, PLCName, Register from PLC2DB_Tags, PLC2DB_TagsInWhere where OPCName ='" + sdr[0].ToString() + "' and PLC2DB_Tags.Tag = PLC2DB_TagsInWhere.tag group by PLC2DB_Tags.Tag, Description, PLCName, Register"; CreateItemsFromSelect(sqlQuery, ref og.opcgroup); } sdr.Close(); } log.Success(); } catch (Exception ex) { log.Fatal(ex); } return(whereGroups); }
private List <OPCGroup_t> InitVarGroup() { string sqlQuery; sqlQuery = "select TagEvent, OpcName from PLC2DB_Tags, PLC2DB_Cfg, PLC2DB_TagsInFormula where type = 'VAR' and PLC2DB_Tags.Tag = PLC2DB_TagsInFormula.tag and PLC2DB_TagsInFormula.CfgID = PLC2DB_CFg.ID and len(rtrim(OpcName))>1 group by OpcName, TagEvent"; Logging log = new Logging(sqlQuery); List <OPCGroup_t> varGroups = new List <OPCGroup_t>(); try { using (SqlConnection connection = new SqlConnection(IntData.CfgConn)) { connection.Open(); SqlCommand cmd = new SqlCommand(sqlQuery, connection); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { OPCGroup_t og = new OPCGroup_t { tagEvent = sdr[0].ToString(), opcgroup = new OPCController() }; og.opcgroup.ServerName = sdr[1].ToString().Trim(); og.opcgroup.GroupName = "varGroup" + varGroups.Count; sqlQuery = "select PLC2DB_Tags.Tag, Register, Description, PLCName from PLC2DB_Tags, PLC2DB_Cfg, PLC2DB_TagsInFormula where type = 'VAR' and OPCName ='" + og.opcgroup.ServerName + "' and PLC2DB_Tags.Tag = PLC2DB_TagsInFormula.tag and PLC2DB_TagsInFormula.CfgID = PLC2DB_CFg.ID and PLC2DB_Cfg.TagEvent= '" + og.tagEvent + "'"; CreateItemsFromSelect(sqlQuery, ref og.opcgroup); varGroups.Add(og); } sdr.Close(); } log.Success(); } catch (Exception ex) { log.Fatal(ex); } return(varGroups); }
private List <OPCGroup_t> InitEventsGroup() { string sqlQuery; sqlQuery = "select OpcName from PLC2DB_Tags where type = 'EV' group by OpcName"; Logging log = new Logging(sqlQuery); List <OPCGroup_t> opt = new List <OPCGroup_t>(); try { using (SqlConnection connection = new SqlConnection(IntData.CfgConn)) { connection.Open(); SqlCommand cmd = new SqlCommand(sqlQuery, connection); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { OPCGroup_t og = new OPCGroup_t { tagEvent = "", opcgroup = new OPCController() }; og.opcgroup.ServerName = sdr[0].ToString().Trim(); og.opcgroup.GroupName = "evGroup" + opt.Count; opt.Add(og); sqlQuery = "select PLCName, Tag, Register, Description from PLC2DB_Tags where type = 'EV' and OPCName='" + og.opcgroup.ServerName + "'"; CreateItemsFromSelect(sqlQuery, ref og.opcgroup); } sdr.Close(); } log.Success(); return(opt); } catch (Exception ex) { log.Fatal(ex); return(null); } }