Beispiel #1
0
        private void MessageView_Load(object sender, EventArgs e)
        {
            using (var db = new ICMServer.Models.ICMDBContext())
            {
                /**
                 * Query modify item
                 **/
                var query = from zz in db.Publishinfoes
                            where zz.id == m_MsgId
                            select zz;
                foreach (var Msg in query)
                {
                    textBox.Visible    = false;
                    pictureBox.Visible = true;
                    textBoxTitle.Text  = Msg.title;
                    textBoxTime.Text   = Msg.time.ToString();
                    if (Msg.type == 1)
                    {
                        textBoxType.Text = "Image";
                    }
                    else
                    {
                        textBoxType.Text = "Text";
                    }
                    textBoxAddress.Text = DevicesAddressConverter.RoToChStr(Msg.dstaddr);

                    string picPath = Path.GetAppExeFolderPath() + @"\" + Msg.filepath;
                    pictureBox.Image = new Bitmap(picPath);
                }
            }
        }
 public static bool DatabaseExists()
 {
     using (var db = new ICMDBContext())
     {
         return(db.Database.Exists());
     }
 }
 public static Device GetDeviceByAddress(string DeviceAddress)
 {
     using (var db = new ICMDBContext())
     {
         var result = (from Device in db.Devices
                       where Device.roomid == DeviceAddress
                       select Device).FirstOrDefault();
         return(result);
     }
 }
 public static user GetUserByName(string name)
 {
     using (var db = new ICMDBContext())
     {
         var result = (from user in db.Users
                       where user.C_username == name
                       select user).FirstOrDefault();
         return(result);
     }
 }
 private void BtnOK_Click(object sender, EventArgs e)
 {
     using (var db = new ICMServer.Models.ICMDBContext())
     {
         holderinfo ResidentIndfo = new holderinfo();
         ResidentIndfo.C_name     = textBoxName.Text;
         ResidentIndfo.C_roomid   = textBoxRoomID.Text;
         ResidentIndfo.C_sex      = ComboBoxSex.SelectedIndex;
         ResidentIndfo.C_isholder = ComboBoxIsResident.SelectedIndex;
         ResidentIndfo.C_phoneno  = textBoxPhone.Text;
         //ResidentIndfo.birth = dateTimePickerBirth.Value;
         //ResidentIndfo.PID = textBoxPID.Text;
         db.Holderinfoes.Add(ResidentIndfo);
         db.SaveChanges();
     }
     this.Close();
 }
        public static void AddDevices(AddrList addrList, IProgress <int> progress = null)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            using (var db = new ICMDBContext())
            {
                db.Database.ExecuteSqlCommand("DELETE FROM Device");
                db.Database.ExecuteSqlCommand("ALTER TABLE Device AUTO_INCREMENT = 1");
                int processCount = 0;
                int reportedProgressPercentage = -1;
                foreach (var d in addrList.dev)
                {
                    Device dev = new Device
                    {
                        ip       = d.ip,
                        roomid   = d.ro,
                        Alias    = (d.IsaliasNull()) ? null : d.alias,
                        group    = (d.IsgroupNull()) ? null : d.group,
                        mac      = (d.IsmcNull()) ? null : d.mc,
                        type     = d.ty,
                        sm       = d.sm,
                        gw       = d.gw,
                        cameraid = (d.IsidNull()) ? null : d.id,
                        camerapw = (d.IspwNull()) ? null : d.pw
                    };
                    db.Devices.Add(dev);
                    processCount++;
                    if (progress != null)
                    {
                        int currentProgressPercentage = (processCount * 99 / addrList.dev.Count);
                        if (reportedProgressPercentage != currentProgressPercentage)
                        {
                            reportedProgressPercentage = currentProgressPercentage;
                            progress.Report(reportedProgressPercentage);
                        }
                    }
                }
                db.SaveChanges();
                if (progress != null)
                {
                    progress.Report(100);
                }
            }
            stopwatch.Stop();
            //DebugLog.TraceMessage(string.Format("done: {0}", stopwatch.Elapsed));
        }