Пример #1
0
 public static void Remove(int id)
 {
     using (var db = new IotContext())
     {
         db.Database.ExecuteSqlCommand(@"DELETE FROM CellCultivations WHERE Id=?;", id);
     }
 }
Пример #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            var processName  = Assembly.GetExecutingAssembly().GetName().Name;
            int processCount = Process.GetProcessesByName(processName).Length;

            if (processCount > 1)
            {
                MessageBox.Show("程序运行中,请关闭后重试");
                Environment.Exit(-2);
            }

            base.OnStartup(e);

            var bootstrapper = new Bootstrapper();

            bootstrapper.Run();
//            Application.Current.MainWindow.GoFullscreen();

            var _regionManager = bootstrapper.Container.Resolve <IRegionManager>();

            _regionManager?.RequestNavigate("ContentRegion", "Index");

            Config.DetectorId = 0x01;
            Task.Run(() =>
            {
                using (var ctx = new IotContext())
                {
                    ctx.Initialize();
                }
            });
        }
Пример #3
0
 public static IList <CellCultivation> GetCultivationsFromDb()
 {
     using (var db = new IotContext())
     {
         return(db.CellCultivations.ToList());
     }
 }
Пример #4
0
 public static IList <AppException> GetUnhandleException()
 {
     using (var db = new IotContext())
     {
         return(db.AppExceptions.ToList());
     }
 }
Пример #5
0
 public static void RemovePumpCultivationsByCultivationId(int id)
 {
     using (var db = new IotContext())
     {
         db.Database.ExecuteSqlCommand(@"DELETE FROM TPumpCultivation WHERE CultivationId=?;", id);
     }
 }
Пример #6
0
 public static void SaveGasRecord(GasRecord record)
 {
     using (var ctx = new IotContext())
     {
         ctx.GasRecords.Add(record);
         ctx.SaveChanges();
     }
 }
Пример #7
0
 public static void SaveTemperatureRecord(TemperatureRecord record)
 {
     using (var ctx = new IotContext())
     {
         ctx.TemperatureRecords.Add(record);
         ctx.SaveChanges();
     }
 }
Пример #8
0
 public static void MarkException(AppException exception)
 {
     using (var db = new IotContext())
     {
         db.AppExceptions.Remove(exception);
         db.SaveChanges();
     }
 }
Пример #9
0
 public static void Save(AppException exception)
 {
     using (var db = new IotContext())
     {
         db.AppExceptions.Add(exception);
         db.SaveChanges();
     }
 }
Пример #10
0
        public static IotContext GetIotContext()
        {
            var options = new DbContextOptionsBuilder <IotContext>()
                          .UseSqlite($"Data Source=augmento.db")
                          .Options;
            var context = new IotContext(options);

            context.Initilize();
            return(context);
        }
Пример #11
0
 public static string GetLastDbName()
 {
     using (var db = new IotContext())
     {
         var p = db.CellCultivations.OrderByDescending(each => each.CreatedAt).FirstOrDefault();
         if (p == null)
         {
             return(string.Empty);
         }
         return(p.CreatedAt + ".db");
     }
 }
Пример #12
0
        public static int GetLastCultivationId()
        {
            var id = CurrentContext.SysCache?.System?.CellCultivation?.Id ?? 0;

            if (id > 0)
            {
                return(id);
            }

            using (var db = new IotContext())
            {
                var p = db.CellCultivations.OrderByDescending(doc => doc.Id).FirstOrDefault();
                return(p?.Id ?? 0);
            }
        }
Пример #13
0
        public static SystemIntegration SaveCultivations(SystemIntegration schedule)
        {
            if (schedule == null)
            {
                return(null);
            }
            DeviceService.InitData();

            var tSchedule = schedule.CellCultivation;

            tSchedule.BatchNumber = CurrentContext.BatchNumber;
            tSchedule.CreatedAt   = Common.Utility.Common.ToUnixTime(DateTime.Now);

            using (var db = new IotContext())
            {
                db.CellCultivations.Add(tSchedule);
                db.SaveChanges();
            }

            using (var db = new IotContext())
            {
                schedule.Rocker.CultivationId = tSchedule.Id;
                db.Rockers.Add(schedule.Rocker);

                schedule.Gas.CultivationId = tSchedule.Id;
                db.Gases.Add(schedule.Gas);

                schedule.TemperatureGauge.DeviceId = tSchedule.Id;
                db.TemperatureGauges.Add(schedule.TemperatureGauge);

                var p = new List <Pump>()
                {
                    schedule.PumpIn, schedule.PumpOut
                };

                foreach (var each in p)
                {
                    each.CultivationId = tSchedule.Id;
                    db.Pumps.Add(each);
                }

                db.SaveChanges();
            }

            return(schedule);
        }
Пример #14
0
 public static void Initilize(this IotContext _context)
 {
     _context.Database.Migrate();
     _context.Database.EnsureCreated();
 }
Пример #15
0
 public SiteService(IotContext context)
 {
     _context = context;
 }
Пример #16
0
 public LocationService(IotContext context)
 {
     _context = context;
 }
Пример #17
0
 public BuildingService(IotContext context)
 {
     _context = context;
 }
Пример #18
0
 public RegionService(IotContext context)
 {
     _context = context;
 }