public void PrepareGraph(List <string> Auswahl, string Von, string Bis) { string sqlCommand = ""; sqlHelper.SQLBuilderHinzufuegen("SELECT ", SQLHelper.SQLBuilder.DeleteSQL); //sqlHelper.SQLBuilderHinzufuegen("SELECT", SQLHelper.SQLBuilder.DeleteSQL); int idx = 0; foreach (string spalte in Auswahl) { sqlHelper.SQLBuilderHinzufuegen(spalte); if (idx < Auswahl.Count - 1) { sqlHelper.SQLBuilderHinzufuegen(","); } idx++; } sqlHelper.SQLBuilderHinzufuegen("FROM MaschDaten"); sqlHelper.SQLBuilderHinzufuegen("WHERE"); sqlHelper.SQLBuilderHinzufuegen("("); sqlHelper.SQLBuilderHinzufuegen("da >="); sqlHelper.SQLBuilderHinzufuegen("CONVERT(DATETIME,"); sqlHelper.SQLBuilderHinzufuegen("'", SQLHelper.SQLBuilder.NoSpace); sqlHelper.SQLBuilderHinzufuegen(FuncString.ConvertDate2En(Von), SQLHelper.SQLBuilder.NoSpace); sqlHelper.SQLBuilderHinzufuegen("'"); sqlHelper.SQLBuilderHinzufuegen(","); sqlHelper.SQLBuilderHinzufuegen("102)"); sqlHelper.SQLBuilderHinzufuegen(")"); sqlHelper.SQLBuilderHinzufuegen("AND"); sqlHelper.SQLBuilderHinzufuegen("("); sqlHelper.SQLBuilderHinzufuegen("da <="); sqlHelper.SQLBuilderHinzufuegen("CONVERT(DATETIME,"); sqlHelper.SQLBuilderHinzufuegen("'", SQLHelper.SQLBuilder.NoSpace); sqlHelper.SQLBuilderHinzufuegen(FuncString.ConvertDate2En(Bis), SQLHelper.SQLBuilder.NoSpace); sqlHelper.SQLBuilderHinzufuegen("'"); sqlHelper.SQLBuilderHinzufuegen(","); sqlHelper.SQLBuilderHinzufuegen("102)"); sqlHelper.SQLBuilderHinzufuegen(")"); sqlCommand = sqlHelper.SQLBuilderHinzufuegen(""); this.BindData(sqlCommand, Auswahl, "da", this.BS_Graph); }
private void BackgroundWorkerPlcRead_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (e.ProgressPercentage == 1) { this.SetInfo(this.m_LblStatus, (string)this.m_InfoThread[e.ProgressPercentage]); } if (e.ProgressPercentage == 2) { this.SetProgressbar(this.m_ProgressBar, (int)this.m_InfoThread[e.ProgressPercentage]); } if (e.ProgressPercentage == 3) { this.m_errorCounter++; string varname = (string)this.m_InfoThread[e.ProgressPercentage]; string value = this.m_VarCollect.ReadValueString(varname); string sql_command = ""; if (value == "0") { if (this.m_errorCounter > 30) { this.m_errorCounter = 0; this.m_sqliteCommand.CommandText = "select count (id) as NumberOfRecords from errors"; if (this.m_sqliteDataReader != null) { this.m_sqliteDataReader.Close(); this.m_sqliteDataReader = null; } this.m_sqliteDataReader = this.m_sqliteCommand.ExecuteReader(); this.m_sqliteDataReader.Read(); int no_of_records = this.m_sqliteDataReader.GetInt32(0); this.m_sqliteDataReader.Close(); if (no_of_records > 100) { this.m_sqliteCommand.CommandText = "select id from errors order by id limit 1"; if (this.m_sqliteDataReader != null) { this.m_sqliteDataReader.Close(); this.m_sqliteDataReader = null; } this.m_sqliteDataReader = this.m_sqliteCommand.ExecuteReader(); this.m_sqliteDataReader.Read(); int record_number = this.m_sqliteDataReader.GetInt32(0); this.m_sqliteDataReader.Close(); record_number += 50; string sql = "Delete from Errors where id < " + record_number.ToString(); this.m_sqliteCommand.CommandText = sql; this.m_sqliteCommand.ExecuteNonQuery(); } this.m_sqliteDataReader.Close(); } string inComing = FuncString.GetTimestamp(); sql_command = ""; sql_command += "INSERT INTO Errors(VisuSymbol,InComing) "; sql_command += "SELECT "; sql_command += "'" + varname + "' "; sql_command += ","; sql_command += "'" + inComing + "' "; sql_command += "WHERE NOT EXISTS(SELECT 1 FROM Errors WHERE VisuSymbol = "; sql_command += "'" + varname + "' "; sql_command += "and outgoing is null)"; this.m_sqliteCommand.CommandText = sql_command; this.m_sqliteCommand.ExecuteNonQuery(); } else { string outComing = FuncString.GetTimestamp(); sql_command = ""; sql_command += "UPDATE errors SET OutGoing="; sql_command += "'" + outComing + "'"; sql_command += "WHERE OutGoing IS NULL AND VisuSymbol="; sql_command += "'" + varname + "'"; this.m_sqliteCommand.CommandText = sql_command; this.m_sqliteCommand.ExecuteNonQuery(); } } }
public void AddList(string adresse, string symbolName, string dataType, string comment, string symbolType, bool dataLog = false) { int byte_length = 0; ClsSingeltonVariablesCollecterDataType data_type = ClsSingeltonVariablesCollecterDataType.Null; if (dataType == "BOOL") { byte_length = 2; data_type = ClsSingeltonVariablesCollecterDataType.Int; } if (dataType == "INT") { byte_length = 2; data_type = ClsSingeltonVariablesCollecterDataType.Int; } if (dataType == "TIME") { byte_length = 4; data_type = ClsSingeltonVariablesCollecterDataType.Int; } if (dataType == "REAL") { byte_length = 4; data_type = ClsSingeltonVariablesCollecterDataType.Double; } int db_nr = 0; int byte_nr = 0; int bit_nr = 0; string[] adressen = adresse.Split('.'); if (adressen.Count() >= 2) { db_nr = Convert.ToInt32(FuncString.GetOnlyNumeric(adressen[0])); byte_nr = Convert.ToInt32(FuncString.GetOnlyNumeric(adressen[1])); if (adressen.Count() == 3) { bit_nr = Convert.ToInt32(FuncString.GetOnlyNumeric(adressen[2])); int rest = byte_nr % 2; byte_length = byte_length - rest; } if (this.m_DatabasesInfo.ContainsKey(db_nr)) { int value = Convert.ToInt32(this.m_DatabasesInfo[db_nr]); if ((byte_nr + byte_length) > value) { this.m_DatabasesInfo[db_nr] = byte_nr + byte_length; } } else { this.m_DatabasesInfo.Add(db_nr, byte_nr); this.m_DatabasesNr.Add(db_nr); } } ClsSingeltonPlcDatas data; data.Adress = adresse; data.DatabaseNumber = db_nr; data.ByteNumber = byte_nr; data.BitNumber = bit_nr; data.Symbolname = symbolName; data.DataType = dataType; data.Comment = comment; data.Value = "0.0"; data.DataLog = dataLog; data.SymbolType = symbolType; this.m_Daten.Add(data); string keyInfo = "DB" + db_nr + "." + symbolName; this.m_VarCollect.CreateVariable(keyInfo, data_type); if (!this.m_SymbolInfo.ContainsKey(keyInfo)) { this.m_SymbolInfo.Add(keyInfo, data); } }
public void AddList(string Adress, string Symbolname, string DataType, string Comment, bool DataLog) { int byteLaenge = 0; if (DataType == "BOOL") { byteLaenge = 2; } if (DataType == "INT") { byteLaenge = 2; } if ( DataType == "TIME" || DataType == "REAL" ) { byteLaenge = 4; } int dbNr = 0; int byteNr = 0; int bitNr = 0; string[] adress = Adress.Split('.'); if (adress.Count() >= 2) { dbNr = Convert.ToInt32(FuncString.GetOnlyNumeric(adress[0])); byteNr = Convert.ToInt32(FuncString.GetOnlyNumeric(adress[1])); if (adress.Count() == 3) { bitNr = Convert.ToInt32(FuncString.GetOnlyNumeric(adress[2])); int rest = byteNr % 2; byteLaenge = byteLaenge - rest; } if (DatabasesInfo.ContainsKey(dbNr)) { int value = Convert.ToInt32(DatabasesInfo[dbNr]); if ((byteNr + byteLaenge) > value) { DatabasesInfo[dbNr] = byteNr + byteLaenge; } } else { DatabasesInfo.Add(dbNr, byteNr); DatabasesNr.Add(dbNr); } } PLCDatas data; data.Adress = Adress; data.DatabaseNumber = dbNr; data.ByteNumber = byteNr; data.BitNumber = bitNr; data.Symbolname = Symbolname; data.DataType = DataType; data.Comment = Comment; data.Value = "0.0"; data.DataLog = DataLog; this.Daten.Add(data); string keyInfo = "DB" + dbNr + "." + Symbolname; if (!SymbolInfo.ContainsKey(keyInfo)) { SymbolInfo.Add(keyInfo, data); } }