Ejemplo n.º 1
0
        public Menu_ViewModel()
        {
            Select_Command = new RelayCommand <ListView>(p =>
            {
                return(true);
            }, p =>
            {
                foreach (ListViewItem item in MyStaticMethods.FindVisualChildren <ListViewItem>(p))
                {
                    BrushConverter bc = new BrushConverter();
                    item.Foreground   = (Brush)bc.ConvertFrom("#FF5C99D6");
                }

                Window wd = MyStaticMethods.getWindowParent(p) as Window;

                ListViewItem selectedItem = p.SelectedItem as ListViewItem;
                int i = Convert.ToInt32(selectedItem.Uid);

                if (wd != null)
                {
                    foreach (Frame item in MyStaticMethods.FindVisualChildren <Frame>(wd))
                    {
                        if (item.Name == "main_content")
                        {
                            Dieuhuong(i, item);
                        }
                        break;
                    }
                }

                selectedItem.Foreground = Brushes.White;
            });
        }
Ejemplo n.º 2
0
        public ControlBar_ViewModel()
        {
            IsOpen  = false;
            Content = "  Đóng ứng dụng ???";

            Minimize_Command = new RelayCommand <UserControl>(p =>
            {
                if (IsOpen == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Window windowparent = MyStaticMethods.getWindowParent(p) as Window;

                if (windowparent != null)
                {
                    windowparent.WindowState = WindowState.Minimized;
                }
            });

            Maximize_Command = new RelayCommand <UserControl>(p =>
            {
                if (IsOpen == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Window windowparent = MyStaticMethods.getWindowParent(p) as Window;

                if (windowparent != null)
                {
                    if (windowparent.WindowState == WindowState.Maximized)
                    {
                        windowparent.WindowState = WindowState.Normal;
                    }
                    else
                    {
                        windowparent.WindowState = WindowState.Maximized;
                    }
                }
            });


            Close_Command = new RelayCommand <UserControl>(p =>
            {
                if (IsOpen == false)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                Application.Current.Shutdown();
            });

            Drag_Command = new RelayCommand <UserControl>(p =>
            {
                return(true);
            }, p =>
            {
                Window windowparent = MyStaticMethods.getWindowParent(p) as Window;

                if (windowparent != null)
                {
                    windowparent.DragMove();
                }
            });

            OpenDialog_Command = new RelayCommand <UserControl>(p =>
            {
                if (IsOpen == true)
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                IsOpen = true;
            });

            CloseDialog_Command = new RelayCommand <UserControl>(p =>
            {
                return(true);
            }, p =>
            {
                IsOpen = false;
            });

            OpenDetail_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                Views.UserInfo w = new Views.UserInfo();
                w.ShowDialog();
            });
        }
Ejemplo n.º 3
0
        public Login_ViewModel()
        {
            IsActive           = false;
            CloseAlert_Command = new RelayCommand <object>(x =>
            {
                return(true);
            }, x =>
            {
                IsActive = false;
            });

            #region login
            GetPassLogin_Command = new RelayCommand <PasswordBox>(x =>
            {
                return(true);
            }, x =>
            {
                if (!String.IsNullOrEmpty(x.Password))
                {
                    Password = x.Password;
                }
            });

            Login_Command = new RelayCommand <Button>(p =>
            {
                if (String.IsNullOrEmpty(UserName) || String.IsNullOrEmpty(Password))
                {
                    return(false);
                }

                return(true);
            }, p =>
            {
                var list = new List <Models.User>(Models.DataProvider.Ins.DB.Users);

                if (list.Where(x => x.acc == UserName && x.pass == MyStaticMethods.MD5Hash(Password)).Count() != 0)
                {
                    Models.User user = list.Where(x => x.acc == UserName && x.pass == MyStaticMethods.MD5Hash(Password)).SingleOrDefault();
                    if (user.user_role == 0)
                    {
                        if (chkLoginTime(user) == false)
                        {
                            IsActive = true;
                            Message  = "Tài khoản không được phân ca trực";
                        }
                        else
                        {
                            CurrentUser = user;

                            Views.Main view = new Views.Main();
                            view.Show();

                            Window wd = MyStaticMethods.getWindowParent(p) as Window;
                            if (wd != null)
                            {
                                wd.Close();
                            }

                            resetData();
                        }
                    }
                    else
                    {
                        CurrentUser = user;

                        Views.Main view = new Views.Main();
                        view.Show();

                        Window wd = MyStaticMethods.getWindowParent(p) as Window;
                        if (wd != null)
                        {
                            wd.Close();
                        }

                        resetData();
                    }
                }
                else
                {
                    IsActive = true;
                    Message  = "Sai tên đăng nhập hoặc mật khẩu";
                }
            });

            CloseLoginform_Command = new RelayCommand <object>(p =>
            {
                return(true);
            }, p =>
            {
                Application.Current.Shutdown();
            });
            #endregion
        }