Example #1
0
		public InvoiceViewController ()
		{
			SetTitle ();
			Settings.Shared.SubscribeToProperty ("TestMode", SetTitle);
			var searchBar = new ItemSearchView{ Frame = new System.Drawing.RectangleF (0, 0, 200, 30) };
			searchBar.ItemSelected += (Item obj) => {
				Invoice.AddItem (obj);
			};
			NavigationItem.RightBarButtonItem = new UIBarButtonItem (searchBar);
			NavigationItem.LeftBarButtonItem = new UIBarButtonItem (UIImage.FromBundle ("menu").ImageWithRenderingMode (UIImageRenderingMode.AlwaysTemplate), UIBarButtonItemStyle.Plain, (s, e) => {
				//Show simple actionsheet
				if (sheet != null) {
					sheet.DismissWithClickedButtonIndex (-1, true);
					return;
				}
				sheet = new SimpleActionSheet { 
					{"New Invoice",async() =>{
							if(await AskSave())
								NewInvoice();
						}
					},
					{"Load Invoice",() => {
							if(popover != null)
							{
								popover.Dismiss(true);
							}
							popover = new UIPopoverController(new UINavigationController(new LoadInvoiceViewController(){
								InvoiceSelected = async (i) =>{
									popover.Dismiss(true);
									try{
										BigTed.BTProgressHUD.ShowContinuousProgress();
										if(Invoice != null && Invoice.Id != i.Id)
										{
											if(!await AskSave())
												return;
										}
										Invoice.DeleteLocal();
										Invoice = await WebService.Main.GetInvoice(i.Id);
										Invoice.Save(true);
									}
									catch(Exception ex)
									{
										Console.WriteLine(ex);
									}
									finally{
										BigTed.BTProgressHUD.Dismiss();
									}
								},
							}));
							popover.DidDismiss += (sender,  evt) => {
								popover.Dispose();
							};
							popover.PresentFromBarButtonItem(NavigationItem.LeftBarButtonItem, UIPopoverArrowDirection.Any,true);
						}
					},
					{"Payout Buy",() => {
							if(popover != null)
							{
								popover.Dismiss(true);
							}
							popover = new UIPopoverController(new UINavigationController(new LoadBuyPayoutViewController(){
								InvoiceSelected = async (i) =>{
									popover.Dismiss(true);
									try{
										BigTed.BTProgressHUD.ShowContinuousProgress();
										if(Invoice != null && Invoice.Id != i.Id)
										{
											if(!await AskSave())
												return;
										}
										Invoice.DeleteLocal();
										Invoice = await WebService.Main.GetInvoice(i.Id);
										//Setup payments
										Database.Main.Table<PaymentType> ().Where (x => x.IsActive)
											.OrderBy (X => X.SortOrder).ToList ().ForEach (x => Invoice.Payments.Add (new Payment{ PaymentType = x }));
										Invoice.Save(true);
										if((i as BuyInvoice).IsOnAccount)
											Invoice.OnAccountPayment.Amount = Invoice.Total;
										else
											Invoice.CashPayment.Amount = Invoice.Total;
									}
									catch(Exception ex)
									{
										Console.WriteLine(ex);
									}
									finally{
										BigTed.BTProgressHUD.Dismiss();
									}
								},
							}));
							popover.DidDismiss += (sender,  evt) => {
								popover.Dispose();
							};
							popover.PresentFromBarButtonItem(NavigationItem.LeftBarButtonItem, UIPopoverArrowDirection.Any,true);

						}
					},
					{"Settings",() => this.PresentViewControllerAsync (new UINavigationController (new SettingsViewController ()), true)},
				};
				sheet.Dismissed += (object sender, UIButtonEventArgs e2) => {
					sheet.Dispose ();
					sheet = null;
				};
				sheet.ShowFrom (s as UIBarButtonItem, true);
			});
		
			//this.AutomaticallyAdjustsScrollViewInsets = false;
		}
Example #2
0
        public InvoiceViewController()
        {
            SetTitle();
            Settings.Shared.SubscribeToProperty("TestMode", SetTitle);
            var searchBar = new ItemSearchView {
                Frame = new System.Drawing.RectangleF(0, 0, 200, 30)
            };

            searchBar.ItemSelected += (Item obj) => {
                Invoice.AddItem(obj);
            };
            NavigationItem.RightBarButtonItem = new UIBarButtonItem(searchBar);
            NavigationItem.LeftBarButtonItem  = new UIBarButtonItem(UIImage.FromBundle("menu").ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIBarButtonItemStyle.Plain, (s, e) => {
                //Show simple actionsheet
                if (sheet != null)
                {
                    sheet.DismissWithClickedButtonIndex(-1, true);
                    return;
                }
                sheet = new SimpleActionSheet {
                    { "New Invoice", async() => {
                          if (await AskSave())
                          {
                              NewInvoice();
                          }
                      } },
                    { "Load Invoice", () => {
                          if (popover != null)
                          {
                              popover.Dismiss(true);
                          }
                          popover = new UIPopoverController(new UINavigationController(new LoadInvoiceViewController()
                            {
                                InvoiceSelected = async(i) => {
                                    popover.Dismiss(true);
                                    try{
                                        BigTed.BTProgressHUD.ShowContinuousProgress();
                                        if (Invoice != null && Invoice.Id != i.Id)
                                        {
                                            if (!await AskSave())
                                            {
                                                return;
                                            }
                                        }
                                        Invoice.DeleteLocal();
                                        Invoice = await WebService.Main.GetInvoice(i.Id);
                                        Invoice.Save(true);
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex);
                                    }
                                    finally{
                                        BigTed.BTProgressHUD.Dismiss();
                                    }
                                },
                            }));
                          popover.DidDismiss += (sender, evt) => {
                              popover.Dispose();
                          };
                          popover.PresentFromBarButtonItem(NavigationItem.LeftBarButtonItem, UIPopoverArrowDirection.Any, true);
                      } },
                    { "Payout Buy", () => {
                          if (popover != null)
                          {
                              popover.Dismiss(true);
                          }
                          popover = new UIPopoverController(new UINavigationController(new LoadBuyPayoutViewController()
                            {
                                InvoiceSelected = async(i) => {
                                    popover.Dismiss(true);
                                    try{
                                        BigTed.BTProgressHUD.ShowContinuousProgress();
                                        if (Invoice != null && Invoice.Id != i.Id)
                                        {
                                            if (!await AskSave())
                                            {
                                                return;
                                            }
                                        }
                                        Invoice.DeleteLocal();
                                        Invoice = await WebService.Main.GetInvoice(i.Id);
                                        //Setup payments
                                        Database.Main.Table <PaymentType> ().Where(x => x.IsActive)
                                        .OrderBy(X => X.SortOrder).ToList().ForEach(x => Invoice.Payments.Add(new Payment {
                                            PaymentType = x
                                        }));
                                        Invoice.Save(true);
                                        if ((i as BuyInvoice).IsOnAccount)
                                        {
                                            Invoice.OnAccountPayment.Amount = Invoice.Total;
                                        }
                                        else
                                        {
                                            Invoice.CashPayment.Amount = Invoice.Total;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex);
                                    }
                                    finally{
                                        BigTed.BTProgressHUD.Dismiss();
                                    }
                                },
                            }));
                          popover.DidDismiss += (sender, evt) => {
                              popover.Dispose();
                          };
                          popover.PresentFromBarButtonItem(NavigationItem.LeftBarButtonItem, UIPopoverArrowDirection.Any, true);
                      } },
                    { "Settings", () => this.PresentViewControllerAsync(new UINavigationController(new SettingsViewController()), true) },
                };
                sheet.Dismissed += (object sender, UIButtonEventArgs e2) => {
                    sheet.Dispose();
                    sheet = null;
                };
                sheet.ShowFrom(s as UIBarButtonItem, true);
            });

            //this.AutomaticallyAdjustsScrollViewInsets = false;
        }