コード例 #1
0
 public void UpdateOrders()
 {
     App.Current.Dispatcher.BeginInvoke(new Action(() =>
     {
         app.RefreshOrders();
         app.RefreshBooks();
     }));
 }
コード例 #2
0
        private void SellBook(object sender, RoutedEventArgs e)
        {
            if (SelectedBook != null)
            {
                if (SelectedBook.quantity >= sellQuantity.Value)
                {
                    if (ClientName.Text != "")
                    {
                        long   qtd        = (long)sellQuantity.Value;
                        double price      = SelectedBook.price;
                        string clientName = ClientName.Text;

                        ClientName.Text = "";

                        app.clientProxy.sellBook(SelectedBook, (int)qtd);

                        new Printer.MainWindow(Window.GetWindow(this), SelectedBook.title, qtd, price, (double)qtd * price, clientName).Show();

                        refreshBookList(null, null);
                    }
                    else
                    {
                        System.Windows.MessageBox.Show(Window.GetWindow(this), "Specify the name of the client!", "No client name", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    if (ClientEmail.Text != "" && Regex.IsMatch(ClientEmail.Text,
                                                                @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                                                @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
                                                                RegexOptions.IgnoreCase) && OrderAddress.Text != "")
                    {
                        long   qtd   = (long)sellQuantity.Value;
                        double price = SelectedBook.price;

                        Response rep = app.clientProxy.orderBook(SelectedBook, qtd, ClientName.Text, ClientEmail.Text, ClientPassword.Password, OrderAddress.Text);

                        if (rep.State == "success")
                        {
                            refreshBookList(null, null);
                            app.RefreshOrders();

                            ClientName.Text         = "";
                            ClientEmail.Text        = "";
                            ClientPassword.Password = "";
                            OrderAddress.Text       = "";
                        }
                        else
                        {
                            System.Windows.MessageBox.Show(Window.GetWindow(this), "Create a new account for the client!", "No client account", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        System.Windows.MessageBox.Show(Window.GetWindow(this), "Enter a valid client email and an address for the order!", "Bad info error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            else
            {
                System.Windows.MessageBox.Show(Window.GetWindow(this), "Select a book first!", "No book selected", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }