using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TankService.Models;
using System.Web;
using Newtonsoft.Json;
namespace TankService
{
public partial class Service1 : ServiceBase
{
protected override async void OnStart(string[] args)
{
//************************************
TimerCallback timeCB = new TimerCallback(Count);
Timer time = new Timer(timeCB, null, 0, 60000);
//************************************
}
public static asopnEntities db1 = new asopnEntities();
public static ChemLabEntities db2 = new ChemLabEntities();
public class TankInventt
{
public DateTime Data { get; set; }
public int Filial { get; set; }
}
//--------------------------------------------------------------
public class tankRadar
{
}
public class tankRadarObert
{
public List<tankRadar> ReadResults { get; set; }
}
//Создадим класс для заполнения данных уровней и темпреатур резервуаров
public class tankdatas
{
}
public class CalculatorData
{
/// <summary>
/// Oil density at a temperature of 15 °C.
/// </summary>
public double Dens15 { get; set; }
public double DensTP { get; set; }
}
public class Density636 : ICloneable
{
public Density636()
{
}
public object Clone()
{
return new Density636
{
};
}
}
public class Asopn
{
public static List<LastTanksResultMoz> LM = new List<LastTanksResultMoz>(); //список записей из представления химанализа по Мозырю
public static List<LastTanksResultPol> LP = new List<LastTanksResultPol>(); //список записей из представления по Полоцку
public static List<LastMechanResultMoz> LMM = new List<LastMechanResultMoz>(); //список записей механических примесей в резервуарах ЛПДС Мозырь
public class Person
{
public string name { get; set; }
public int age { get; set; }
}
public async static Task<List<TankInventt>> Spis()
{
List<TagCorrespondence> tagcorrespond = new List<TagCorrespondence>();
tagcorrespond = db1.TagCorrespondence.Where(tu => tu.FilialID == 1 && tu.Enable == 1).ToList();
List<string> listdata = new List<string>();
foreach (var item in tagcorrespond)
{
listdata.Add(item.lev);
listdata.Add(item.temp);
}
List<string> listdataPolock = new List<string>();
foreach (var item in tagcorrespondPolock)
{
listdataPolock.Add(item.lev);
listdataPolock.Add(item.temp);
}
//Заполним список данными уровней и температур
List<tankdatas> listtankdatas = new List<tankdatas>();
foreach (var ty in tagcorrespond)
{
listtankdatas.Add(tankdatasITEM);
}
foreach (var tPol in tagcorrespondPolock)
{
listtankdatas.Add(tankdatasITEM);
}
LP = db2.LastTanksResultPol.ToList();
LM = db2.LastTanksResultMoz.ToList();
LMM = db2.LastMechanResultMoz.ToList();
ListLastInv = db1.DonnyOstat.ToList();
TankI.Clear();
foreach (var item in listtankdatas)
{
string dt = Convert.ToString(item.Dat).Substring(0, 14) + "00:00.000";
DateTime dtTime = Convert.ToDateTime(dt);
TankI.Add(new TankInventt() { Data = dtTime, Filial = item.FilialID, Rezer = item.tankid, Urov = Convert.ToInt32(lev), UrovH2O = Convert.ToInt32(UrovH2O), UrovNeft = Convert.ToInt32(UrovNeft), V = V, P = PCalc, Temp = Temp1, MassaBrutto = MassaBrutto, H2O = H2O, Salt = SaltProc, Meh = Meh, BalProc = BalProc, BalTonn = BalTonn, MassaNetto = MassaNetto, Hmin = Hmin, Vmin = MVmin, dMBalmin = MMin, dMNettomin = MNmin, type = type, VH2O = VH2ORasch, VNeft = VNeft }); ;
}
return TankI;
}
}
public Service1()
{
InitializeComponent();
}
public static async void Count(object obj)
{
string writePath = "log.txt";
filials hhh = new filials();
tankinfo hj = new tankinfo();
TankInv TankinV = new TankInv();
try
{
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "-----------ИНВЕНТАРИЗАЦИЯ НА " + DateTime.Now.ToString() + "\n");
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "-----------------------------------------------------------------\n");
foreach (var item in await Asopn.Spis())
{
//---Запись таблицы в БД---------------------------------------------------------------------
TankinV.Data = item.Data;
TankinV.Filial = item.Filial;
TankinV.Rezer = item.Rezer;
TankinV.Urov = item.Urov;
TankinV.UrovH2O = item.UrovH2O;
TankinV.UrovNeft = item.UrovNeft;
TankinV.V = Convert.ToDecimal(Math.Round(item.V, 3));
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", item.Data + " | " + item.Filial + " | " + item.Rezer + " | " + item.Urov + " | " + item.UrovH2O + " | " + item.UrovNeft + " | " + item.V + " | " + item.Temp + " | " + item.P + " | " + item.MassaBrutto + " | " + item.H2O + " | " + item.Salt + " | " + "\n");
}
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "Запись инвентаризации успешно добавлена в БД " + DateTime.Now + "\n");
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "-----------------------------------------------------------------\n");
}
catch (Exception ex)
{
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "Ошибка записи! Код ошибки: " + ex.ToString() + "\n");
}
List<TankInv> TableInv = new List<TankInv>();
TableInv = db1.TankInv.OrderByDescending(o => o.Data).ToList();
DateTime LastDate = TableInv.FirstOrDefault().Data;
if (LastDate.ToShortDateString() == "00:00")
{
try
{
{
SvodkaSutki SutSv = new SvodkaSutki();
var TabInv = TableInv.Where(y => y.Data == LastDate).GroupBy(k => k.Filial);
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "СУТОЧНАЯ СВОДКА НА " + DateTime.Now.ToString() + "\n");
foreach (var t in TabInv)
{
int kol = 0;
foreach (var i in t)
{
}
db1.SvodkaSutki.Add(SutSv);
db1.SaveChanges();
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", t.Key + " | " + LastDate + " | " + VNeftItog + " | " + MassaBalItog + " | " + MassaNettoItog + " | " + MassaBruttoOstat + " | " + MassaBruttoOstat + " | " + MassaNettoMinItog + " | " + (MassaNettoItog - MassaNettoMinItog) + " | " + "\n");
}
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "Данные суточной сводки записаны " + DateTime.Now + "\n");
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "----------------------------------------------------\n");
}
}
catch (Exception ex)
{
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "Ошибка записи! Код ошибки: " + ex.ToString() + "\n");
}
}
else
{
File.AppendAllText(@"C:/Users/sov/Downloads/Test.txt", "Время не равно 00:00!!! Запись в БД не производится!!!\n");
}
}
protected override void OnStop()
{
}
}
}