public static void OMSFolder() { var gateway = Gateway.GatewayList(); foreach (var g in gateway) { string[] files = Directory .GetFiles(@"C:\JizFTP\" + g); foreach (var file in files) { using (SqlConnection connection = new SqlConnection(SmartDB.ConnectionString())) { connection.Open(); if (new DirectoryInfo(file).Name.Contains("GTW_OMS_RAW_") && !new DirectoryInfo(file).Name.Contains("lock")) { //Retrieve all lines in CSV System.Data.DataTable newMeter = ReadFile(file); //BulkCopy InsertMeterBulkCopy(connection, newMeter); } } Console.WriteLine(file); } } }
public static bool LatestReading() { try { SqlConnection connection = new SqlConnection(SmartDB.ConnectionString()); SqlCommand command; command = new SqlCommand( "DELETE * FROM tblLatest", connection); command.ExecuteNonQuery(); return(true); } catch (Exception) { return(false); } }
public static bool LatestReading(string gatewayId) { try { using (SqlConnection connection = new SqlConnection(SmartDB.ConnectionString())) { using (SqlCommand cmd = new SqlCommand("LATEST_METER_READING", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@GatewayId", gatewayId); connection.Open(); cmd.ExecuteNonQuery(); return(true); } } } catch (Exception) { return(false); } }
static void Main(string[] args) { SqlConnection connection = new SqlConnection(SmartDB.ConnectionString()); if (connection.State == ConnectionState.Closed) { try { connection.Open(); Console.WriteLine("Open"); } catch (Exception e) { Console.WriteLine(e); throw; } } GetOMS.OMSFolder(); GetLatest(); ToBackup.MoveMD(); Console.ReadLine(); }
public static DataSet LatestReading(string gatewayId) { try { SqlConnection connection = new SqlConnection(SmartDB.ConnectionString()); SqlCommand cmd = new SqlCommand(); //SqlDataAdapter da = new SqlDataAdapter( // "SELECT DISTINCT MeterAddress, ReadingDate, RawTelegram FROM tblLatest WHERE GatewayId="+ ,+'" // connection); cmd.CommandText = "SELECT DISTINCT MeterAddress, ReadingDate, RawTelegram FROM tblLatest WHERE GatewayId=@GatewayId"; cmd.Parameters.AddWithValue("@GatewayId", gatewayId); cmd.Connection = connection; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "MeterReading"); return(ds); } catch (Exception e) { Console.WriteLine(e); throw; } //DataRelation relation = ds.Relations.Add("CustOrders", // ds.Tables["Customers"].Columns["CustomerID"], // ds.Tables["Orders"].Columns["CustomerID"]); //foreach (DataRow pRow in ds.Tables["Customers"].Rows) //{ // Console.WriteLine(pRow["CustomerID"]); // foreach (DataRow cRow in pRow.GetChildRows(relation)) // Console.WriteLine("\t" + cRow["OrderID"]); //} }