private void ClearSearchValues()
 {
     FoundCustomers.Clear();
     SelectedView           = 0;
     ActiveView             = 0;
     PhoneNumberSearchText  = "";
     AddressSearchText      = "";
     CustomerNameSearchText = "";
 }
 internal void DisplayCustomerAccount(Customer customer)
 {
     FoundCustomers.Clear();
     if (customer != null)
     {
         FoundCustomers.Add(new CustomerViewModel(customer));
     }
     RaisePropertyChanged("SelectedCustomer");
     OnDisplayCustomerAccount("");
 }
        private void OnCreateCustomer(string obj)
        {
            FoundCustomers.Clear();
            var c = new Customer
            {
                Address     = AddressSearchText,
                Name        = CustomerNameSearchText,
                PhoneNumber = PhoneNumberSearchText
            };

            FoundCustomers.Add(new CustomerViewModel(c));
            SelectedView = 1;
            RaisePropertyChanged("SelectedCustomer");
        }
        private void ResetTimer()
        {
            _updateTimer.Stop();

            if (!string.IsNullOrEmpty(PhoneNumberSearchText) ||
                !string.IsNullOrEmpty(CustomerNameSearchText) ||
                !string.IsNullOrEmpty(AddressSearchText))
            {
                _updateTimer.Start();
            }
            else
            {
                FoundCustomers.Clear();
            }
        }
        private void UpdateFoundCustomers()
        {
            IEnumerable <Customer> result = new List <Customer>();

            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += delegate
                {
                    bool searchPn = string.IsNullOrEmpty(PhoneNumberSearchText);
                    bool searchCn = string.IsNullOrEmpty(CustomerNameSearchText);
                    bool searchAd = string.IsNullOrEmpty(AddressSearchText);

                    result = Dao.Query <Customer>(
                        x =>
                        (searchPn || x.PhoneNumber.Contains(PhoneNumberSearchText)) &&
                        (searchCn || x.Name.ToLower().Contains(CustomerNameSearchText.ToLower())) &&
                        (searchAd || x.Address.ToLower().Contains(AddressSearchText.ToLower())));
                };

                worker.RunWorkerCompleted +=
                    delegate
                {
                    AppServices.MainDispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                               delegate
                    {
                        FoundCustomers.Clear();
                        FoundCustomers.AddRange(result.Select(x => new CustomerViewModel(x)));

                        if (SelectedCustomer != null && PhoneNumberSearchText == SelectedCustomer.PhoneNumber)
                        {
                            SelectedView = 1;
                            SelectedCustomer.UpdateDetailedInfo();
                        }

                        RaisePropertyChanged("SelectedCustomer");

                        CommandManager.InvalidateRequerySuggested();
                    }));
                };

                worker.RunWorkerAsync();
            }
        }
        public void RefreshSelectedCustomer()
        {
            ClearSearchValues();

            if (AppServices.MainDataContext.SelectedTicket != null && AppServices.MainDataContext.SelectedTicket.CustomerId > 0)
            {
                var customer = Dao.SingleWithCache <Customer>(x => x.Id == AppServices.MainDataContext.SelectedTicket.CustomerId);
                if (customer != null)
                {
                    FoundCustomers.Add(new CustomerViewModel(customer));
                }
                if (SelectedCustomer != null)
                {
                    SelectedView = 1;
                    SelectedCustomer.UpdateDetailedInfo();
                }
            }
            RaisePropertyChanged("SelectedCustomer");
            RaisePropertyChanged("IsClearVisible");
            RaisePropertyChanged("IsResetCustomerVisible");
            RaisePropertyChanged("IsMakePaymentVisible");
            ActiveView = 0;
            SelectedCustomerTransactions.Clear();
        }
 private void OnMakePaymentToCustomerCommand(string obj)
 {
     SelectedCustomer.Model.PublishEvent(EventTopicNames.MakePaymentToCustomer);
     FoundCustomers.Clear();
 }
 private void OnAddLiability(string obj)
 {
     SelectedCustomer.Model.PublishEvent(EventTopicNames.AddLiabilityAmount);
     FoundCustomers.Clear();
 }
 private void OnAddReceivable(string obj)
 {
     SelectedCustomer.Model.PublishEvent(EventTopicNames.AddReceivableAmount);
     FoundCustomers.Clear();
 }