diff options
Diffstat (limited to 'src/app/Cmpp298.Assignment3.Desktop.UI/InvoicesMainView.cs')
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Desktop.UI/InvoicesMainView.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/app/Cmpp298.Assignment3.Desktop.UI/InvoicesMainView.cs b/src/app/Cmpp298.Assignment3.Desktop.UI/InvoicesMainView.cs new file mode 100644 index 0000000..809d6d7 --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Desktop.UI/InvoicesMainView.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic;
+using System.Windows.Forms;
+using Cmpp298.Assignment3.Desktop.Adapters;
+using Cmpp298.Assignment3.Dto;
+using Cmpp298.Assignment3.Presentation;
+
+namespace Cmpp298.Assignment3.Desktop.UI {
+ public partial class InvoicesMainView : Form, IInvoicesMainView {
+ private DesktopDropDownList _vendorsDropDown;
+ private InvoicesMainPresenter _presenter;
+
+ public InvoicesMainView( ) {
+ InitializeComponent( );
+ _vendorsDropDown = new DesktopDropDownList( uxVendorsDropDown );
+ _presenter = new InvoicesMainPresenter( this );
+ _presenter.Initialize( );
+
+ HookupEventHandlers( );
+ _presenter.LoadInvoices( );
+ }
+
+ public IDropDownListAdapter VendorNames {
+ get { return _vendorsDropDown; }
+ }
+
+ public void BindTo( IEnumerable< DisplayInvoiceDto > invoices ) {
+ uxInvoicesGridView.DataSource = invoices;
+ }
+
+ private delegate void Callback( string invoiceId );
+
+ private void OpenDeleteScreen( ) {
+ OpenScreen( delegate( string invoiceId ) { new DeleteInvoiceView( invoiceId ).ShowDialog( ); } );
+ }
+
+ private void OpenEditScreen( ) {
+ OpenScreen( delegate( string invoiceId ) { new EditInvoiceView( invoiceId ).ShowDialog( ); } );
+ }
+
+ private void OpenScreen( Callback callback ) {
+ if ( uxInvoicesGridView.SelectedRows.Count == 1 ) {
+ string invoiceId = uxInvoicesGridView.SelectedRows[ 0 ].Cells[ "InvoiceId" ].Value.ToString( );
+ callback( invoiceId );
+ _presenter.LoadInvoices( );
+ }
+ else {
+ MessageBox.Show( "Please select a single row", "Select a Row", MessageBoxButtons.OK, MessageBoxIcon.Error );
+ }
+ }
+
+ private void HookupEventHandlers( ) {
+ uxNewButton.Click += delegate { OpenNewWindow( ); };
+ uxEditButton.Click += delegate { OpenEditScreen( ); };
+ uxDeleteButton.Click += delegate { OpenDeleteScreen( ); };
+ uxRefreshButton.Click += delegate { _presenter.LoadInvoices( ); };
+ uxVendorsDropDown.SelectedIndexChanged += delegate { _presenter.LoadInvoices( ); };
+ }
+
+ private void OpenNewWindow( ) {
+ new NewInvoiceView( _vendorsDropDown.SelectedItem.Value ).ShowDialog( );
+ _presenter.LoadInvoices( );
+ }
+ }
+}
\ No newline at end of file |
