Esempio n. 1
0
        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(TbtUserName.Text))
            {
                tblInfoAcount.Text = ResourceUtil.EmptyAccountInfo;
                tblInfoAcount.Foreground = new SolidColorBrush(Colors.Red);
            }
            else
            {
                try
                {
                    var context = new cctvEntities();
                    //var list = from user in context.its_evt_login
                    //           where user.name == TbtUserName.Text && user.password == TptPassword.Password
                    //           select user;
                    var list = context.CheckAccount(TbtUserName.Text, TptPassword.Password);


                    if (list.ToArray().Count() > 0)
                    {
                        Account.Username = TbtUserName.Text;
                        this.Close();
                    }
                    else
                    {
                        Account.Username = String.Empty;
                        tblInfoAcount.Text = ResourceUtil.WrongAccountInfo;
                        tblInfoAcount.Foreground = new SolidColorBrush(Colors.Red);
                    }
                }
                catch (Exception ex)
                {
                    tblInfoAcount.Text = "Error";
                }
                
            }
        }
        /// <summary>
        /// Get camera info from database
        /// </summary>
        public void GetCameraData()
        {
            var en = new cctvEntities();
            try
            {
                var ls = en.GetCameraByUser(Account.Username);
                Dictionary<String, List<CameraItem>> camgroupbyname = new Dictionary<string, List<CameraItem>>();
                foreach (ComplexType1 complexType1 in ls)
                {
                    ComplexType1 com = complexType1;
                    var camItem = new CameraItem { Id = com.id, CameraUrl = com.cameraurl, Ip = com.ip, Type = com.type };
                    if (!camgroupbyname.ContainsKey(com.group_name))
                    {
                        camgroupbyname.Add(com.group_name, new List<CameraItem> { camItem });
                    }
                    else
                    {
                        camgroupbyname[com.group_name].Add(camItem);
                    }

                }
                var highgroup = new ObservableCollection<CameraGroupViewModel>();
                foreach (var cams in camgroupbyname)
                {
                    highgroup.Add(new CameraGroupViewModel(new CameraGroup { GroupName = cams.Key, CameraList = cams.Value }));
                }
                _viewModel.SetCameraGroupViewModel(highgroup);

            }
            catch (Exception ex)
            {
            }
        }