Ejemplo n.º 1
0
        public void UpdateCustomer( Customer customer )
        {
            if ( customer == null )
                throw new ArgumentNullException( "customer" );

            // Check business rules.
            BusinessRulesManager.Assert( "UpdateCustomer",
                                         new OldNewPair<Customer>( (Customer) customer.GetVanilla(), customer ) );

            StorageContext.Current.Update( customer );
        }
Ejemplo n.º 2
0
        public Customer CreateCustomer( Customer customer )
        {
            if ( customer == null )
                throw new ArgumentNullException( "customer" );

            // Check business rules.
            BusinessRulesManager.Assert( "InsertCustomer", customer );

            StorageContext.Current.Insert( customer );
            return customer;
        }
Ejemplo n.º 3
0
 private void SelectCustomer()
 {
     if ( this.customersListView.SelectedItems.Count == 0 )
     {
         MessageBox.Show( this, "No customer selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
         return;
     }
     else
     {
         this.selectedCustomer = (Customer) this.customersListView.SelectedItems[0].Tag;
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
 }
Ejemplo n.º 4
0
        private void updateButton_Click( object sender, EventArgs e )
        {
            if ( this.customer == null )
            {
                this.customer = new Customer();
                this.customer.FirstName = this.firstNameTextBox.Text;
                this.customer.LastName = this.lastNameTextBox.Text;
                this.customer.CustomerId = this.customerIdTextBox.Text;
                this.customer = this.customerProcesses.Value.CreateCustomer( this.customer );
            }
            else
            {
                this.customer.FirstName = this.firstNameTextBox.Text;
                this.customer.LastName = this.lastNameTextBox.Text;
                this.customerProcesses.Value.UpdateCustomer( this.customer );
            }

            CustomerForm customerForm = new CustomerForm();
            customerForm.Customer = this.customer;
            customerForm.MdiParent = this.MdiParent;
            customerForm.Show();
            this.Close();
        }
Ejemplo n.º 5
0
        private void ReloadData()
        {
            CustomerInfo customerInfo =
                this.customerProcesses.Value.GetCustomerInfo( this.customer, !this.checkBoxOnlyPendingRentals.Checked );
            this.customer = customerInfo.Customer;


            this.Text =
                string.Format( "Customer {0} ({1} {2})",
                               this.customer.CustomerId,
                               this.customer.FirstName,
                               this.customer.LastName );

            this.customerNameLabel.Text = string.Format( "{0} ({1} {2})",
                                                         this.customer.CustomerId,
                                                         this.customer.FirstName,
                                                         this.customer.LastName );

            this.balanceLabel.Text = string.Format( "Balance: {0} EUR",
                                                    this.customer.CurrentBalance );
            this.balanceLabel.ForeColor = this.customer.CurrentBalance > 0
                                              ?
                                                  Color.Green
                                              : Color.Red;

            this.rentaledBooksLabel.Text = string.Format( "{0} book(s) rentaled.",
                                                        customerInfo.Rentals.Count );

            int delayed = 0;
            foreach ( RentalInfo rental in customerInfo.Rentals )
            {
                if ( !rental.Rental.Closed && rental.Rental.ScheduledReturnDate < DateTime.Now )
                {
                    delayed++;
                }
            }

            this.delayedBooksLabel.Text = string.Format( "{0} with delay.",
                                                         delayed );

            this.delayedBooksLabel.Visible = delayed != 0;

            this.booksListView.BeginUpdate();
            this.booksListView.Items.Clear();
            foreach ( RentalInfo rentalInfo in customerInfo.Rentals )
            {
                ListViewItem lvi = new ListViewItem(
                    new string[]
                        {
                            rentalInfo.Book.BookId,
                            rentalInfo.Book.Authors,
                            rentalInfo.Book.Title,
                            rentalInfo.Rental.StartDate.ToShortDateString(),
                            rentalInfo.Rental.ScheduledReturnDate.ToShortDateString(),
                            rentalInfo.Rental.ReturnDate.HasValue ? rentalInfo.Rental.ReturnDate.Value.ToShortDateString() : "",
                            rentalInfo.Notes.Count.ToString()
                        } );
                lvi.Tag = rentalInfo.Rental;

                if ( rentalInfo.Rental.IsDelayed() )
                {
                    lvi.ForeColor = Color.Red;
                }
                else if ( rentalInfo.Rental.Closed )
                {
                    lvi.ForeColor = Color.Gray;
                }

                this.booksListView.Items.Add( lvi );
            }
            this.booksListView.EndUpdate();

            this.listViewAccountLines.BeginUpdate();
            this.listViewAccountLines.Items.Clear();
            foreach ( CustomerAccountLine line in customerInfo.AccountLines )
            {
                ListViewItem lvi = new ListViewItem(
                    new string[]
                        {
                            line.Date.ToShortDateString(),
                            line.Employee.Entity.Login,
                            line.Description,
                            line.Amount.ToString()
                        } );
                lvi.Tag = line;
                this.listViewAccountLines.Items.Add( lvi );
            }
            this.listViewAccountLines.EndUpdate();
        }