Ejemplo n.º 1
0
        /// <summary>
        /// 显示历史数据
        /// </summary>
        /// <param name="dtStart">开始时间</param>
        /// <param name="dtEnd">结束时间</param>
        private void ShowLog(DateTime dtStart, DateTime dtEnd)
        {
            using (GISContext context = new GISContext())
            {
                var logs = context.Infoes.Where(info => info.Time >= dtStart && info.Time <= dtEnd).OrderByDescending(x => x.Id);

                if (logs == null || logs.Count() == 0)
                {
                    MessageBox.Show("没有该数据!");

                    this.Close();
                }

                dataLogs.Rows.Clear();

                foreach (var log in logs)
                {
                    var row = new DataGridViewRow();

                    row.CreateCells(dataLogs);

                    row.Cells[0].Value = log.Temp;
                    row.Cells[1].Value = log.NH3;
                    row.Cells[2].Value = log.Light;
                    row.Cells[3].Value = log.Hum;
                    row.Cells[4].Value = log.Time;

                    dataLogs.Rows.Add(row);
                }
            }
        }
Ejemplo n.º 2
0
        public GISController(GISContext context)
        {
            _context = context;

            if (_context.GISItems.Count() == 0)
            {
                // Create a new GISItem if collection is empty,
                // which means you can't delete all GISItems.
                _context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="info">元数据</param>
        public void SaveData(Info info)
        {
            using (GISContext context = new GISContext())
            {
                try
                {
                    context.Infoes.Add(info);

                    context.SaveChanges();

                    this.ShowMsg("保存数据成功!");
                }
                catch (Exception ex)
                {
                    this.ShowMsg("保存数据失败! " + ex.Message);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        private void InitDB()
        {
            using (GISContext context = new GISContext())
            {
                this.ShowMsg("正在迁移数据库,请稍后...");

                // 迁移数据库
                context.Database.Migrate();

                try
                {
                    // 初始化数据
                    if (!context.Users.Any())
                    {
                        List <User> users = new List <User>();

                        for (int i = 0; i < 9; i++)
                        {
                            users.Add(new User {
                                UserName = "******" + (i + 1), Password = "******".Encryption("00" + (i + 1))
                            });
                        }

                        context.Users.AddRange(users);
                        context.SaveChanges();
                    }

                    this.ShowMsg("数据库迁移成功!");

                    LogHelper.MigrateDbOk();
                }
                catch (Exception e)
                {
                    this.ShowMsg("数据库迁移失败! " + e.Message);

                    this.ShowMsg("遇到大麻烦了。。。。。。。。。");
                }
            }
        }
Ejemplo n.º 5
0
 public InfoModel(GISContext context)
 {
     _context = context;
 }
Ejemplo n.º 6
0
 public BaseRepository(GISContext contextParam)
 {
     Context = contextParam;
 }
Ejemplo n.º 7
0
 public LoginModel(GISContext context)
 {
     _context = context;
 }