Esempio n. 1
0
        private async void AddUser()
        {
            ErrorMsgVisibility = Visibility.Collapsed;
            if (!CheckAllInputFields())
            {
                return;
            }

            var _searchedCustomer = CustomerCollection.FirstOrDefault(s => s.CustomerName == CustomerName);

            // Check if there is already a book with same name and same authorname

            if (_searchedCustomer != null && _searchedCustomer.PhoneNo == PhoneNo)
            {
                ErrorMsg           = Properties.Resources.UserAlreadyExistMsg;
                ErrorMsgVisibility = Visibility.Visible;
                return;
            }


            CustomerModel customer = new CustomerModel()
            {
                CustomerId   = DateTime.Now.ToString().GetHashCode().ToString("x"),
                CustomerName = this.CustomerName,
                Address      = this.Address,
                PhoneNo      = this.PhoneNo
            };

            _log.Message("Adding New User having UserId :" + customer.CustomerId);
            await _customerDataAccess.InsertData(customer, Properties.Resources.AddUser);

            GetAllCustomer();
            ClearAllField();
            InvokeCustomerUpdateEvent();
        }
Esempio n. 2
0
        private async void UpdateCustomer()
        {
            ErrorMsgVisibility = Visibility.Collapsed;
            if (SelectedCustomer == null || !CheckAllInputFields())
            {
                ErrorMsg           = Properties.Resources.UserNotSelectedErrorMsg;
                ErrorMsgVisibility = Visibility.Visible;
                return;
            }


            var _searchedCustomer = CustomerCollection.FirstOrDefault(s => s.CustomerName == CustomerName);

            // Check if there is already a book with same name and same authorname
            // Restrict Admin to create a new user with same name,phoneno and address.

            if (_searchedCustomer != null && _searchedCustomer.PhoneNo == PhoneNo && _searchedCustomer.Address == Address)
            {
                ErrorMsg           = Properties.Resources.UserAlreadyExistMsg;
                ErrorMsgVisibility = Visibility.Visible;
                return;
            }


            CustomerModel customer = new CustomerModel()
            {
                CustomerId   = SelectedCustomer.CustomerId,
                CustomerName = this.CustomerName,
                Address      = this.Address,
                PhoneNo      = this.PhoneNo
            };

            _log.Message("Updating Customer Having Customer Id: " + customer.CustomerId);
            await _customerDataAccess.UpdateData(customer, Properties.Resources.UpdateCustomer);

            GetAllCustomer();
            ClearAllField();
            InvokeCustomerUpdateEvent();
        }
Esempio n. 3
0
        async void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (cts != null)
            {
                cts.Cancel();
            }

            if (popup.IsOpen)
            {
                popup.IsOpen = false;
            }
            if (textBox1.Text.Length == 0)
            {
                CustomersListBox.SelectedItem = null;
                CustomersListBox.ScrollIntoView(CustomersListBox.Items[0]);
            }
            else if (textBox1.Text.StartsWith("70") || textBox1.Text.StartsWith("71") ||
                     textBox1.Text.StartsWith("76") || textBox1.Text.StartsWith("78") || textBox1.Text.StartsWith("03") ||
                     textBox1.Text.StartsWith("79") || textBox1.Text.StartsWith("81"))
            {
                CustomerCollection col = CustomersListBox.Items.SourceCollection as CustomerCollection;
                Customer           ddd = col.FirstOrDefault(c => c.PhoneNumber.StartsWith(textBox1.Text));
                foreach (Customer user in CustomersListBox.Items)
                {
                    if (user.PhoneNumber.StartsWith(textBox1.Text))
                    {
                        CustomersListBox.SelectedItem = user;
                        CustomersListBox.ScrollIntoView(user);
                        return;
                    }
                }
                CustomersListBox.SelectedItem = null;
            }
            else
            {
                foreach (Customer user in CustomersListBox.Items)
                {
                    if (user.Username.StartsWith(textBox1.Text))
                    {
                        CustomersListBox.SelectedItem = user;
                        CustomersListBox.ScrollIntoView(user);
                        return;
                    }
                }
                CustomersListBox.SelectedItem = null;

                try
                {
                    cts = new CancellationTokenSource();
                    await Task.Delay(2000, cts.Token);

                    cts = null;
                    CustomerCollection equalList = new CustomerCollection();

                    if (textBox1.Text.Contains("ismaelr") && (ResellersComboBox.SelectedItem as Reseller).Name.Equals("ahkvoip0", StringComparison.OrdinalIgnoreCase))
                    {
                        foreach (Customer c in CustomersListBox.Items)
                        {
                            if (c.Username.Equals("ismael"))
                            {
                                equalList.Add(c);

                                didMeanText.Text = "You must select";
                                possibleCustomers.ItemsSource = equalList;
                                popup.IsOpen = true;
                                CustomersListBox.IsEnabled = false;
                                CustomersListBox.Opacity   = 0.5;

                                return;
                            }
                        }
                    }

                    foreach (Customer c in CustomersListBox.Items)
                    {
                        if (LevenshteinDistance(c.Username, textBox1.Text) < 3)
                        {
                            equalList.Add(c);
                        }
                    }

                    if (equalList.Count > 0)
                    {
                        didMeanText.Text = "Did you mean:";
                        possibleCustomers.ItemsSource = equalList;
                        popup.IsOpen = true;
                        CustomersListBox.IsEnabled = false;
                        CustomersListBox.Opacity   = 0.5;
                    }
                }
                catch
                {
                }
            }
        }