public string[] Select(string tableread, string kezdo, string veg) { using (var context = new tc_dataCollectionContext()) { DateTime Dkezdo = DateTime.ParseExact(kezdo, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); DateTime Dveg = DateTime.ParseExact(veg, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); context.DBMS = "MySQL"; context.ConnectionString = ConnectionString; context.Tablename = tableread; var Records = context.Chambers.Where <RecordModell>(r => r.Dátum > Dkezdo && r.Dátum < Dveg); RecordModell[] dataarray = new RecordModell[Records.Count()]; int i = 0; foreach (var record in Records) { //var data = new StringBuilder(); //data.AppendLine($"Dátum: {record.Dátum}"); //data.AppendLine($"temp_set: {record.temp_set}"); //data.AppendLine($"temp_act: {record.temp_act}"); //data.AppendLine($"hum_set: {record.hum_set}"); //data.AppendLine($"hum_act: {record.hum_act}"); //Console.WriteLine(data.ToString()); dataarray[i] = record; i++; } return(recordmodell_arr_to_str_arr(dataarray)); } }
public void Insert(string tablewrite, RecordModell record) { string strSQL = "INSERT INTO " + tablewrite + "(Dátum, temp_set, temp_act, hum_set, hum_act) VALUES('" + DateTime.Now.ToString() + "', @temp_set, @temp_act, @hum_set, @hum_act)"; OleDbCommand cmd = new OleDbCommand(); cmd.CommandText = strSQL; cmd.Parameters.AddWithValue("@temp_set", record.temp_set); cmd.Parameters.AddWithValue("@temp_act", record.temp_act); cmd.Parameters.AddWithValue("@hum_set", record.hum_set); cmd.Parameters.AddWithValue("@hum_act", record.hum_act); cmd.Connection = Connection; if (Connected == true) { try { cmd.ExecuteNonQuery(); Console.WriteLine("struct written to access database"); } catch (Exception) { Console.WriteLine("failed writing to access db"); throw; } } else { Console.WriteLine("Not connected to Access DB.. connect first to write"); } }
public void Insert(string tablewrite, RecordModell record) { var collection = db.GetCollection <RecordModell>(tablewrite); collection.InsertOne(record); Console.WriteLine("record inserted to MongoDB DB"); }
public string[] get_recordmodell_property_array(RecordModell record) { PropertyInfo[] mypropertyinfo; mypropertyinfo = record.GetType().GetProperties(); string[] recordmodell_properties = new string[mypropertyinfo.Length]; for (int i = 0; i < mypropertyinfo.Length; i++) { recordmodell_properties[i] = mypropertyinfo[i].Name; } return(recordmodell_properties); }
public void Insert(string tablewrite, RecordModell record) { using (var context = new tc_dataCollectionContext()) { context.ConnectionString = ConnectionString; context.DBMS = "SQLite"; context.Tablename = tablewrite; context.Chambers.Add(record); context.SaveChanges(); } Console.WriteLine("record successfully inserted to : " + tablewrite); }
public void Insert(string tablewrite, RecordModell record) { using (var context = new tc_dataCollectionContext()) { // context.ConnectionString = ConnectionString; context.DBMS = "MySQL"; context.ConnectionString = ConnectionString; context.Tablename = tablewrite; context.Chambers.Add(record); try { context.SaveChanges(); } catch (Exception) { Console.WriteLine("error inserting to MySQL DB"); throw; } } Console.WriteLine("record successfully inserted to : " + tablewrite); }
public void Insert(string tablewrite, RecordModell record) { SQLiteCommand cmd = new SQLiteCommand(); cmd.CommandText = "INSERT INTO '" + tablewrite + "' ('Dátum', 'temp_set', 'temp_act', 'hum_set', 'hum_act') Values(datetime('now','localtime'), @temp_set, @temp_act, @hum_set, @hum_act);"; cmd.Parameters.AddWithValue("@temp_set", record.temp_set); cmd.Parameters.AddWithValue("@temp_act", record.temp_act); cmd.Parameters.AddWithValue("@hum_set", record.hum_set); cmd.Parameters.AddWithValue("@hum_act", record.hum_act); cmd.Connection = con; try { cmd.ExecuteNonQuery(); Console.WriteLine("record written to SQLite database"); } catch (Exception) { Console.WriteLine("failed writing to SQLite database"); throw; } }
public string[] Select(string tableread, string kezdo, string veg) { DateTime Dkezdo = DateTime.ParseExact(kezdo, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); DateTime Dveg = DateTime.ParseExact(veg, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); using (var context = new tc_dataCollectionContext()) { context.ConnectionString = ConnectionString; context.DBMS = "SQLite"; context.Tablename = tableread; var Records = context.Chambers.Where <RecordModell>(r => r.Dátum > Dkezdo && r.Dátum < Dveg); RecordModell[] dataarray = new RecordModell[Records.Count()]; int i = 0; foreach (var record in Records) { dataarray[i] = record; i++; } Console.WriteLine("select lefutott"); return(recordmodell_arr_to_str_arr(dataarray)); } }
public void OnNotification(object sender, AdsNotificationEventArgs e) { e.DataStream.Position = e.Offset; if (e.NotificationHandle == TCC.hConnect) { TCC.connect = TCC.binread.ReadBoolean(); if (TCC.connect == true && TCC.prevconnect == false) {///rising edge on ConnectDB.bconnect TCC.ReadVariables(); currDB = GetDBInstance(); currDB.Connect(TCC.ads); TCC.connected = true; TCC.WriteVariables(); } if (TCC.connect == false && TCC.prevconnect == true) {/// falling edge on ConnectDB.bconnect currDB.Disconnect(); TCC.connected = false; TCC.WriteVariables(); } } if (e.NotificationHandle == TCC.hExecuteDataReturn) { TCC.ExecuteDataReturn = TCC.binread.ReadBoolean(); if (TCC.ExecuteDataReturn == true) //&& TCC.PrevExecuteDataReturn == false) { ///rising edge on DataReturn.bexecute while (Convert.ToBoolean(TCC.ads.ReadAny(TCC.hReturnReady, typeof(Boolean)))) { // addig nem kezdi amig b ready igaz } Console.WriteLine("rising edge on bexecute"); TCC.ReadVariables(); TCC.recordarray_to_TC(currDB.Select(TCC.tableread, TCC.kezdo, TCC.veg)); TCC.ReturnReady = true; while (!Convert.ToBoolean(TCC.ads.ReadAny(TCC.hReturnReady, typeof(Boolean)))) { // addig csinálja amíg BReady hamis TCC.WriteReadyFlags(); } Console.WriteLine("ready flag elküldve " + TCC.ReturnReady + ""); TCC.ReturnReady = false; } } if (e.NotificationHandle == TCC.hWriteExecute) { TCC.WriteExecute = TCC.binread.ReadBoolean(); if (TCC.WriteExecute == true && TCC.PrevWriteExecute == false) {///rising edge on DBWrite.bExecute TCC.ReadVariables(); TCC.getRecordFromTC(RecordmodellProperties); RecordModell record = new RecordModell(TCC.WriteArray); record.Dátum = DateTime.Now; currDB.Insert(TCC.tablewrite, record); TCC.WriteReady = true; TCC.WriteReadyFlags(); TCC.WriteReady = false; } } if (e.NotificationHandle == TCC.hExecuteTableCreate) { TCC.ExecuteTableCreate = TCC.binread.ReadBoolean(); if (TCC.ExecuteTableCreate == true && TCC.PrevExecuteTableCreate == false) {/// rising edge on CreateTable.bExecute TCC.ReadVariables(); currDB.CreateTable(TCC.tablecreate); TCC.TableReady = true; TCC.WriteReadyFlags(); TCC.TableReady = false; } } TCC.PrevExecuteTableCreate = TCC.ExecuteTableCreate; TCC.PrevWriteExecute = TCC.WriteExecute; TCC.PrevExecuteDataReturn = TCC.ExecuteDataReturn; TCC.prevconnect = TCC.connect; }