private async void tmrSensor_Tick(object sender, EventArgs e) //подія таймера (500мс) { double TValue = (double)TBase + random.NextDouble() * (double)TRange; //обраховуємо потчне значення параметра double FValue = (double)FBase + random.NextDouble() * (double)FRange; double PValue = (double)PBase + random.NextDouble() * (double)PRange; gasMnemo1.lblFIR.Text = FValue.ToString("0.000"); //показуємо значення параметра gasMnemo1.lblPIR.Text = PValue.ToString("0.000"); gasMnemo1.lblTIR.Text = TValue.ToString("0.000"); tblGasTrends trend = new tblGasTrends() { Flow = (decimal)FValue, Preasure = (decimal)PValue, Temperature = (decimal)TValue }; using (var client = new HttpClient()) //використовуючи Web.Api записуємо дані в базу даних { client.BaseAddress = new Uri("http://gasaudit.gear.host/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PostAsJsonAsync("api/GasAudit/insert", trend); }; }
public void Insert(tblGasTrends gasTrends) { using (DbContext context = this.CreateDbContext()) { context.Set <tblGasTrends>().Add(gasTrends); //записуємо тренди в таблицю context.SaveChanges(); //відправляємо зміни до бази даних } }
public void Insert(tblGasTrends trend) { string connectionString = ConfigurationManager.ConnectionStrings["GasAuditEntities_Web"].ConnectionString; IGasTrendsRepository gasTrendsRepository = new GasTrendsRepository(connectionString); trend.Time = DateTime.Now; //встановлюємо час сервера gasTrendsRepository.Insert(trend); string ip = GetClientIp(); ip = string.IsNullOrEmpty(ip) ? "0.0.0.0" : ip; logger.Info(string.Format("Recived data drom user : {0}", ip)); }