Exemplo n.º 1
0
        public SalesAddViewModel(ISalesDatabase isd, ICustomerDatabase icd, ISalesLineDatabase isld, IDialogService ids, IGeoCoder geocoder)
        {
            salesDb       = isd;
            customerDb    = icd;
            salesLineDb   = isld;
            dialog        = ids;
            this.geocoder = geocoder;

            if (!GlobalVars.customerListIsLoaded)
            {
                loadCustomer();
            }
            RaisePropertyChanged(() => CustomerSelection);
            if (SelectedCustomer != null)
            {
                RaisePropertyChanged(() => SelectedCustomer);
            }
            if (InsertSalesItemsList != null)
            {
                if (InsertSalesItemsList.Count() > 0)
                {
                    RaisePropertyChanged(() => InsertSalesItemsList);
                    RaisePropertyChanged(() => TotalDiscountAmount);
                    RaisePropertyChanged(() => Total);
                }
            }
        }
Exemplo n.º 2
0
        public async Task ProceedCommand()
        {
            //check: if location is avalable, then proceed, if cannot get device location, can't proceed
            try
            {
                var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;
                Plugin.Geolocator.Abstractions.Position position;
                string address;
                int    isGpsEnabled;
                if (locator.IsGeolocationEnabled)
                {
                    isGpsEnabled = 1;
                    try
                    {
                        position = await locator.GetPositionAsync(10000);

                        address = await geocoder.GetCityFromLocation(new GeoLocation(position.Latitude, position.Longitude));
                    }
                    catch (Exception ex)
                    {
                        address            = "Unknown";
                        position           = new Plugin.Geolocator.Abstractions.Position();
                        position.Latitude  = 0;
                        position.Longitude = 0;
                    }
                }
                else
                {
                    isGpsEnabled       = 0;
                    address            = "Unknown";
                    position           = new Plugin.Geolocator.Abstractions.Position();
                    position.Latitude  = 0;
                    position.Longitude = 0;
                }
                //insert sales here
                await insertSales(position, address, isGpsEnabled);

                SelectedCustomer = null;
                InsertSalesItemsList.Clear();
                Close(this);
            }
            catch (Exception ex)
            {
            }
        }