Beispiel #1
0
        public void Execute(object parameter)
        {
            if (!CanExecute(parameter))
            {
                return;
            }
            var itemId = (int)parameter;

            if (MessageBox.Show(StringResources.RVPage_Messages_Delete,
                                StringResources.ApplicationName,
                                MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                return;
            }

            try {
                App.ViewModel.IsRvDataChanged = true;
                var deleteCalls = App.Settings.deleteCallsAndRv;
                App.ToastMe(ReturnVisitsInterface.DeleteReturnVisit(itemId, deleteCalls)
                    ? "Deleted."
                    : StringResources.AddTimePage_Messages_TimeDeleteFailed);
            }
            catch {
                App.ToastMe(ReturnVisitsInterface.DeleteReturnVisit(itemId,
                                                                    (MessageBox.Show(StringResources.RVPage_Messages_IncludeAllVisits) == MessageBoxResult.OK))
                    ? "Deleted"
                    : StringResources.AddTimePage_Messages_TimeDeleteFailed);
            }
            finally {
                App.ViewModel.LoadReturnVisitList(SortOrder.DateNewestToOldest);
            }
        }
        public MapCalls()
        {
            this.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentUICulture.Name);
            InitializeComponent();
            ((MapCallsViewModel)DataContext).StartLocationService();

            var bw = new BackgroundWorker();

            bw.RunWorkerCompleted += (o, e) => {
                _rvList = ReturnVisitsInterface.GetReturnVisits(SortOrder.DateNewestToOldest, -1);
                for (_index = 0; _index < _rvList.Length; _index++)
                {
                    if (_rvList[_index].Latitude == 0 || _rvList[_index].Longitude == 0)
                    {
                        MakeGeocodeRequest(GetGeocodeAddress(_rvList[_index]));
                        break;
                    }
                    var p = new Pushpin
                    {
                        Location = new Location
                        {
                            Longitude = _rvList[_index].Longitude,
                            Latitude  = _rvList[_index].Latitude
                        },
                        Content = _rvList[_index]
                    };
                    p.DoubleTap += POnDoubleTap;
                    mRvMaps.Children.Add(p);
                }
            };
            bw.RunWorkerAsync();
        }
Beispiel #3
0
 public bool SaveOrUpdate()
 {
     if (_returnVisitData.DateCreated <= DateTime.MinValue || _returnVisitData.DateCreated >= DateTime.MaxValue)
     {
         _returnVisitData.DateCreated = DateTime.Now;
     }
     App.ViewModel.IsRvDataChanged = true;
     return(ReturnVisitsInterface.AddOrUpdateRV(ref _returnVisitData));
 }
Beispiel #4
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Ensure the current culture passed into bindings
            // is the OS culture. By default, WPF uses en-US
            // as the culture, regardless of the system settings.
            LocalizationManager.GlobalStringLoader = new TelerikStringLoader();
            Thread.CurrentThread.CurrentCulture    = CultureInfo.CurrentUICulture;
            Thread.CurrentThread.CurrentUICulture  = CultureInfo.CurrentUICulture;

            var radDiagnostics = new RadDiagnostics();

            radDiagnostics.EmailTo           = "*****@*****.**";
            radDiagnostics.IncludeScreenshot = true;
            radDiagnostics.Init();
            (App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Color.FromArgb(0xFF, 0xD2, 0xDA, 0x86);
            _settingsProvider = new SettingsProvider();
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Show graphics profiling information while debugging.
            if (Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Current.Host.Settings.EnableFrameRateCounter = false;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }
            TimeDataInterface.CheckDatabase();
            ReturnVisitsInterface.CheckDatabase();
            RvPreviousVisitsDataInterface.CheckDatabase();
            RBCTimeDataInterface.CheckDatabase();
            TerritoryCardsInterface.CheckDatabase();
            StreetBuildingInterface.CheckDatabase();
            House2HouseRecordsInterface.CheckDatabase();
        }
        /// <summary>
        /// Creates and adds a few ReturnVisitItemViewModel objects into the lbRvItems collection.
        /// </summary>
        /// <param name="so">The sort order.</param>
        public void LoadReturnVisitList(SortOrder so)
        {
            if (IsRvDataChanged)
            {
                lbRvItems.Clear();
                RvSearchBoxSuggestionsSource.Clear();
            }
            else
            {
                return;
            }



            RvSearchBoxLoaded = false;
            var bw = new BackgroundWorker();

            bw.DoWork += (obt, e) =>
            {
                _rvs = ReturnVisitsInterface.GetReturnVisitsByLastVisitDate(-1) ??
                       new List <ReturnVisitData>();
            };
            bw.RunWorkerCompleted += (obj, e) => {
                foreach (var rv in _rvs)
                {
                    var r = new ReturnVisitSummaryModel
                    {
                        DaysSinceVisit =
                            string.Format(StringResources.MainPage_RV_DaysSince,
                                          DateTime.Today.Subtract(rv.LastVisitDate).Days),
                        FormattedAddress  = rv.FormattedAddress,
                        ImageSource       = rv.Image,
                        ItemId            = rv.ItemId,
                        NameOrDescription = rv.NameOrDescription
                    };

                    if (lbRvItems.Count < 8 && rv.LastVisitDate != SqlCeConstants.DateTimeMinValue)
                    {
                        lbRvItems.Add(r);
                    }

                    RvSearchBoxSuggestionsSource.Add(r);
                }
                IsRvDataChanged   = false;
                RvSearchBoxLoaded = true;
            };
            bw.RunWorkerAsync();
        }
        /// <summary>
        /// Handles the GeocodeCompleted event of the geocodeService control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GeocodeCompletedEventArgs" /> instance containing the event data.</param>
        private void geocodeService_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e)
        {
            if (e.Result == null || e.Result.Results == null || e.Result.Results.Count == 0)
            {
                return;
            }
            var p = new Pushpin
            {
                Location = e.Result.Results[0].Locations[0],
                Content  = _rvList[_index]
            };

            p.DoubleTap += POnDoubleTap;
            mRvMaps.Children.Add(p);
            _rvList[_index].Latitude  = p.Location.Latitude;
            _rvList[_index].Longitude = p.Location.Longitude;
            ReturnVisitsInterface.AddOrUpdateRV(ref _rvList[_index]);
            _index++;
            if (_index < _rvList.Length)
            {
                MakeGeocodeRequest(GetGeocodeAddress(_rvList[_index]));
            }
        }
        /// <summary>
        /// Loads the return visit full list.
        /// </summary>
        public List <Group <ReturnVisitLLItemModel> > LoadReturnVisitFullList()
        {
            IsRvFullListLoading = true;

            var wb = new WriteableBitmap(100, 100);

            for (int i = 0; i < wb.Pixels.Length; i++)
            {
                wb.Pixels[i] = 0xFF3300;
            }
            var bmp = new BitmapImage();

            using (var ms = new MemoryStream()) {
                wb.SaveJpeg(ms, 100, 100, 0, 100);
                bmp.SetSource(ms);
            }

            var rVs = ReturnVisitsInterface.GetReturnVisits(SortOrder.CityAToZ, -1);

            if (rVs == null)
            {
                return(null);
            }
            if (rVs.Length <= 0)
            {
                return(null);
            }
            var rvList = new List <ReturnVisitLLItemModel>();

            foreach (ReturnVisitData r in rVs)
            {
                var bi = new BitmapImage();
                if (r.ImageSrc != null && r.ImageSrc.Length >= 0)
                {
                    var ris = new WriteableBitmap(450, 250);

                    //get image from database
                    for (int i = 0; i < r.ImageSrc.Length; i++)
                    {
                        ris.Pixels[i] = r.ImageSrc[i];
                    }

                    //put the image in a WritableBitmap
                    using (var ms = new MemoryStream()) {
                        ris.SaveJpeg(ms, 450, 250, 0, 100);
                        bi.SetSource(ms);
                    }

                    //crop the image to 100x100 and centered
                    var img = new Image
                    {
                        Source = bi,
                        Width  = 450,
                        Height = 250
                    };
                    var wb2 = new WriteableBitmap(100, 100);
                    var t   = new CompositeTransform
                    {
                        ScaleX     = 0.5,
                        ScaleY     = 0.5,
                        TranslateX = -((450 / 2) / 2 - 50),
                        TranslateY = -((250 / 2) / 2 - 50)
                    };
                    wb2.Render(img, t);
                    wb2.Invalidate();
                    bi = new BitmapImage();
                    using (var ms = new MemoryStream()) {
                        wb2.SaveJpeg(ms, 100, 100, 0, 100);
                        bi.SetSource(ms);
                    }
                    //BitmapImage bi is now cropped
                }
                else
                {
                    bi = bmp;                     //Default image.
                }

                rvList.Add(new ReturnVisitLLItemModel
                {
                    Text         = string.IsNullOrEmpty(r.FullName) ? string.Format("{0} year old {1}", r.Age, r.Gender) : r.FullName,
                    Address1     = string.Format("{0} {1}", r.AddressOne, r.AddressTwo),
                    Address2     = string.Format("{0}, {1} {2}", r.City, r.StateProvince, r.Country),
                    City         = r.City,
                    ImageSource  = bi,
                    ItemId       = r.ItemId,
                    DaysSinceInt = (DateTime.Now - r.LastVisitDate).Days
                });
            }
            IsRvFullListLoading = false;
            return(GetItemGroups(rvList, c => c.City));
        }
Beispiel #8
0
 public bool Delete(bool deleteCalls)
 {
     //throw new System.NotImplementedException();
     App.ViewModel.IsRvDataChanged = true;
     return(ReturnVisitsInterface.DeleteReturnVisit(_returnVisitData.ItemId, deleteCalls));
 }