Exemple #1
0
        // các xử lí của mainviewmodel
        public MainViewModel()
        {
            // ẩn mainWindow trước khi thực hiện đăng nhập - sử dụng truyền parameter p_Window
            LoadedWindowCommand = new RelayCommand <Window>((p_Window) => { return(true); }, (p_Window) => {
                if (p_Window == null)
                {
                    return;
                }
                else
                {
                    p_Window.Hide();
                    Isloaded = true;
                    LoginWindow loginWindow = new LoginWindow();
                    loginWindow.ShowDialog();

                    // dùng datacontext để lấy biến islogin bên LoginViewModel
                    if (loginWindow.DataContext == null)
                    {
                        return;
                    }

                    var login = loginWindow.DataContext as LoginViewModel;

                    if (login.IsLogin == true)
                    {
                        p_Window.Show();
                    }
                    else
                    {
                        p_Window.Close();
                    }
                }
            });

            // các comment
            SellCommand     = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { SellWindow wd = new SellWindow(); wd.ShowDialog(); });
            BillCommand     = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { BillWindow wd = new BillWindow(); wd.ShowDialog(); });
            RegisterCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { RegisterWindow wd = new RegisterWindow(); wd.ShowDialog(); });

            // những chức năng chỉ người chủ mới được thực hiện
            StatisticCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { StatisticWindow wd = new StatisticWindow(); wd.ShowDialog(); });
            InputCommand     = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { InputWindow wd = new InputWindow(); wd.ShowDialog(); });

            ShopCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { ShopWindow wd = new ShopWindow(); wd.ShowDialog(); });
            QTVCommand  = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { QTVWindow wd = new QTVWindow(); wd.ShowDialog(); });
        }
        public MainViewModel()
        {
            ImportWindow = new RelayCommand <Window>((p) => { return(true); }, (p) =>
            {
                if (_UserIDRole != 1)
                {
                    LoadDialogErrorNotPermission();
                    return;
                }
                ImportWindow wd = new ImportWindow();
                wd.ShowDialog();
            });
            SellWindow     = new RelayCommand <Window>((p) => { return(true); }, (p) => { SellWindow wd = new SellWindow(); wd.ShowDialog(); });
            CustomerWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1)
                                                                                          {
                                                                                              LoadDialogErrorNotPermission(); return;
                                                                                          }
                                                                                          CustomerWindow wd = new CustomerWindow(); wd.ShowDialog(); });
            ProductWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1)
                                                                                         {
                                                                                             LoadDialogErrorNotPermission(); return;
                                                                                         }
                                                                                         ProductWindow wd = new ProductWindow(); wd.ShowDialog(); });
            SupplierWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1)
                                                                                          {
                                                                                              LoadDialogErrorNotPermission(); return;
                                                                                          }
                                                                                          SupplierWindow wd = new SupplierWindow(); wd.ShowDialog(); });
            StatisticalWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1)
                                                                                             {
                                                                                                 LoadDialogErrorNotPermission(); return;
                                                                                             }
                                                                                             StatisticalWindow wd = new StatisticalWindow(); wd.ShowDialog(); });
            UnitWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1)
                                                                                      {
                                                                                          LoadDialogErrorNotPermission(); return;
                                                                                      }
                                                                                      UnitWindow wd = new UnitWindow(); wd.ShowDialog(); });
            UserListWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1)
                                                                                          {
                                                                                              LoadDialogErrorNotPermission(); return;
                                                                                          }
                                                                                          UserListWindow wd = new UserListWindow(); wd.ShowDialog(); });
            AccountCreateWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1)
                                                                                               {
                                                                                                   LoadDialogErrorNotPermission(); return;
                                                                                               }
                                                                                               AccountCreateWindow wd = new AccountCreateWindow(); wd.ShowDialog(); });
            BillWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1)
                                                                                      {
                                                                                          LoadDialogErrorNotPermission(); return;
                                                                                      }
                                                                                      BillWindow wd = new BillWindow(); wd.ShowDialog(); });
            LoadMainWindow = new RelayCommand <Window>((p) => { return(true); }, (p) =>
            {
                if (!isLoaded)
                {
                    isLoaded = true;
                    if (p == null)
                    {
                        return;
                    }

                    p.Hide();
                    LoginWindow wd = new LoginWindow();
                    wd.ShowDialog();
                    var loginViewModel = wd.DataContext as LoginViewModel;
                    if (loginViewModel == null)
                    {
                        return;
                    }
                    if (loginViewModel.isLogin)
                    {
                        loadUserCurrentLogin();
                        p.Show();
                    }
                    else
                    {
                        p.Close();
                    }
                }
            });

            LoadEditCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { LoadDialogAccountEdit(); });
        }