コード例 #1
0
        private List <CommandViewModel> CreateControlPanelCommands()
        {
            List <CommandViewModel> m = new List <CommandViewModel>
            {
                new CommandViewModel(
                    Strings.MainWindowViewModel_Command_ViewAllCustomers,
                    new RelayCommand(param => ShowAllCustomers())),

                new CommandViewModel(
                    Strings.MainWindowViewModel_Command_CreateNewCustomer,
                    new RelayCommand(param => CreateNewCustomer())),

                new CommandViewModel(
                    Strings.MainWindowViewModel_Command_ExitButton,
                    new RelayCommand(param => OnMainWindowViewModelRequestClose()))
            };


            try
            {
                Diag.UpdateLog("(12) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t");
                foreach (CommandViewModel c in m)
                {
                    Diag.UpdateLog("\t" + c.ViewModelBaseInstanceName);
                }
            }
            catch (Exception ex)
            {
                Diag.UpdateLog("(12) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message);
            }



            return(m);
        }
コード例 #2
0
 private static List <Customer> LoadCustomers(string customerDataFile)
 {
     // In a real application, the data would come from an external source,
     // but for this demo let's keep things simple and use a resource file.
     using (Stream stream = GetResourceStream(customerDataFile))
         using (XmlReader xmlRdr = new XmlTextReader(stream))
         {
             {
                 try
                 {
                     Diag.UpdateLog("(3) CustomerRepository;  " + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t");
                 }
                 catch (Exception ex)
                 {
                     Diag.UpdateLog("(3) CustomerRepository;  " + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message);
                 }
                 return
                     ((from customerElem in XDocument.Load(xmlRdr).Element("customers").Elements("customer")
                       select Customer.CreateCustomer(
                           (double)customerElem.Attribute("totalSales"),
                           (string)customerElem.Attribute("firstName"),
                           (string)customerElem.Attribute("lastName"),
                           (bool)customerElem.Attribute("isCompany"),
                           (string)customerElem.Attribute("email")
                           )).ToList());
             }
         }
 }
コード例 #3
0
        /// <summary>
        /// Raises this object's PropertyChanged event.
        /// </summary>
        /// <param name="propertyName">The property that has a new value.</param>
        protected virtual void OnPropertyChanged(string propertyName)
        {
            VerifyPropertyName(propertyName);

            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                Diag.UpdateLog("(19) ViewModelBase():\t" + propertyName + "\t" + handler.Method + "\t" + handler.Target);
                PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName);
                handler.Invoke(this, e);
            }
        }
コード例 #4
0
 private void OnMainWindowViewModelRequestClose()
 {
     try
     {
         Diag.UpdateLog("(13) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name);
     }
     catch (Exception ex)
     {
         Diag.UpdateLog("(13) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message);
     }
     if (MainWindowViewModelRequestClose != null)
     {
         MainWindowViewModelRequestClose.Invoke(this, EventArgs.Empty);
     }
 }
コード例 #5
0
        private void CreateAllCustomers()
        {
            List <CustomerViewModel> all =
                (from cust in _customerRepository.GetCustomers()
                 select new CustomerViewModel(cust, _customerRepository)).ToList();

            foreach (CustomerViewModel cvm in all)
            {
                cvm.PropertyChanged += OnCustomerViewModelPropertyChanged;
                Diag.UpdateLog("(521654)\tCreateAllCustomers()\t " + cvm.ToString());
            }

            AllCustomers = new ObservableCollection <CustomerViewModel>(all);
            AllCustomers.CollectionChanged += OnCollectionChanged;
        }
コード例 #6
0
        /// <summary>
        /// Creates a new repository of customers.
        /// </summary>
        /// <param name="customerDataFile">The relative path to an XML resource file that contains customer data.</param>
        public CustomerRepository(string customerDataFile)
        {
            Diag.DataBindingPresentation();

            _customers = LoadCustomers(customerDataFile);


            try
            {
                Diag.UpdateLog("(2) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + _customers.Count.ToString());
            }
            catch (Exception ex)
            {
                Diag.UpdateLog("(2) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message);
            }
        }
コード例 #7
0
        public AllCustomersViewModel(CustomerRepository customerRepository)
        {
            Diag.DataBindingPresentation();

            if (customerRepository == null)
            {
                throw new ArgumentNullException("customerRepository");
            }

            base.ViewModelBaseInstanceName = Strings.AllCustomersViewModel_DisplayName;
            Diag.UpdateLog("(547865\tAllCustomersViewModel(C )\tbase.ViewModelBaseInstanceName \t" + base.ViewModelBaseInstanceName);
            _customerRepository = customerRepository;

            // Subscribe for notifications of when a new customer is saved.
            _customerRepository.CustomerAdded += OnCustomerAddedToRepository;

            // Populate the AllCustomers collection with CustomerViewModels.
            CreateAllCustomers();
        }
コード例 #8
0
        private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null && e.NewItems.Count != 0)
            {
                foreach (CustomerViewModel cvm in e.NewItems)
                {
                    cvm.PropertyChanged += OnCustomerViewModelPropertyChanged;
                    Diag.UpdateLog("(742342)\tOnCollectionChanged\te.NewItems\t" + cvm.ToString() + "\t" + e.NewItems.ToString());
                }
            }

            if (e.OldItems != null && e.OldItems.Count != 0)
            {
                foreach (CustomerViewModel cvm in e.OldItems)
                {
                    cvm.PropertyChanged -= OnCustomerViewModelPropertyChanged;
                    Diag.UpdateLog("(742109)\tOnCollectionChanged\te.OldItems\t" + cvm.ToString() + "\t" + e.OldItems.ToString());
                }
            }
        }
コード例 #9
0
        public CommandViewModel(string displayName, ICommand command)
        {
            Diag.DataBindingPresentation();
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            base.ViewModelBaseInstanceName = displayName;
            Diag.UpdateLog("(789056\tCommandViewModel( )\tbase.ViewModelBaseInstanceName \t" + base.ViewModelBaseInstanceName);

            ControlPanelHyperlinkInvokeCommand = command;


            try
            {
                Diag.UpdateLog("(6)\t" + this.GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + displayName + ";\t" + command.ToString());
            }
            catch (Exception ex)
            {
                Diag.UpdateLog("(6)\t" + this.GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message);
            }
        }
コード例 #10
0
        /// <summary>
        /// Raised when ToggleButtonClicked is clicked
        /// </summary>

        public void OnToggleButtonClicked()
        {
            try
            {
                Diag.UpdateLog("(590213) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t");
            }
            catch (Exception ex)
            {
                Diag.UpdateLog("(590213) " + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message);
            }

            if (ToggleButtonPosition == System.Windows.HorizontalAlignment.Left)
            {
                ToggleButtonPosition = _rightAlignment;
                ToggleButtonMargins  = _rightThickness;
                ToggleButtonColor    = _rightColor;
            }
            else
            {
                ToggleButtonPosition = _leftAlignment;
                ToggleButtonMargins  = _leftThickness;
                ToggleButtonColor    = _leftColor;
            }
        }
コード例 #11
0
        public MainWindowViewModel(string customerDataFile)
        {
            Diag.DataBindingPresentation();


            base.ViewModelBaseInstanceName = Strings.MainWindowViewModel_DisplayName;
            Diag.UpdateLog("(451289)\tMainWindowViewModel()\tbase.ViewModelBaseInstanceName\t" +
                           base.ViewModelBaseInstanceName);

            _customerRepository = new CustomerRepository(customerDataFile);


            try
            {
                Diag.UpdateLog("(8)\t" + GetType().FullName + ";\t" +
                               System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" +
                               base.ViewModelBaseInstanceName + ";\t" +
                               _customerRepository.ToString());
            }
            catch (Exception ex)
            {
                Diag.UpdateLog("(8)\t" + GetType().FullName + ";\t" + System.Reflection.MethodBase.GetCurrentMethod().Name + ";\t" + ex.Message);
            }
        }
コード例 #12
0
 protected ViewModelBase()
 {
     Diag.UpdateLog("(18)\tViewModelBase()\t" + this.GetType().FullName);
 }