Exemplo n.º 1
0
        async private void PreviewElement_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            var bi = new BusyIndicator();

            try
            {
                bi.Open("Please wait");
                var imageEncodingProps = ImageEncodingProperties.CreatePng();
                using (var stream = new InMemoryRandomAccessStream())
                {
                    await _mediaCapture.CapturePhotoToStreamAsync(imageEncodingProps, stream);

                    _bytes = new byte[stream.Size];
                    var buffer = await stream.ReadAsync(_bytes.AsBuffer(), (uint)stream.Size, InputStreamOptions.None);

                    _bytes = buffer.ToArray(0, (int)stream.Size);
                    await ByteArrayToBitmapImage(_bytes);

                    var bitmap = new BitmapImage();
                    stream.Seek(0);
                    await bitmap.SetSourceAsync(stream);

                    var model = this.Tag as MaintenanceRepair;
                    if (model == null)
                    {
                        model = new MaintenanceRepair();
                    }
                    if (model.IsMajorPivot)
                    {
                        model.MajorComponentImgList.Add(new ImageCapture
                        {
                            ImageBitmap = bitmap
                        });
                    }
                    else
                    {
                        model.SubComponentImgList.Add(new ImageCapture
                        {
                            ImageBitmap = bitmap
                        });
                    }

                    PreviewElement.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;
                    Img.Visibility                = Windows.UI.Xaml.Visibility.Visible;
                    this.IsSecondaryButtonEnabled = true;
                }
                bi.Close();
            }
            catch (Exception)
            {
                bi.Close();
            }
        }
Exemplo n.º 2
0
 void InitializeFileDiffInfo()
 {
     try {
         BusyIndicator.Show();
         BusyIndicator.UpdateText("Loading file diff info: progress {0} from {1}");
         fileDiffInfo = blameHelper.GetFileDiffInfo(filePath, BusyIndicator.UpdateProgress);
     }
     finally {
         BusyIndicator.Close();
     }
 }
Exemplo n.º 3
0
        async private void PreviewElement_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            var bi = new BusyIndicator();

            try
            {
                bi.Open("Please wait");
                var imageEncodingProps = ImageEncodingProperties.CreatePng();
                using (var stream = new InMemoryRandomAccessStream())
                {
                    await _mediaCapture.CapturePhotoToStreamAsync(imageEncodingProps, stream);

                    _bytes = new byte[stream.Size];
                    var buffer = await stream.ReadAsync(_bytes.AsBuffer(), (uint)stream.Size, InputStreamOptions.None);

                    _bytes = buffer.ToArray(0, (int)stream.Size);
                    var bitmap = new BitmapImage();
                    stream.Seek(0);
                    await bitmap.SetSourceAsync(stream);

                    var model = this.Tag as ServiceSchedulingDetail;
                    if (model.OdoReadingImageCapture == null)
                    {
                        model.OdoReadingImageCapture = new ImageCapture();
                    }
                    model.OdoReadingImageCapture.ImageBitmap = bitmap;
                    model.ODOReadingSnapshot      = Convert.ToBase64String(_bytes);
                    PreviewElement.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;
                    Img.Visibility                = Windows.UI.Xaml.Visibility.Visible;
                    this.IsSecondaryButtonEnabled = true;
                    Img.Source = bitmap;
                }
                bi.Close();
            }
            catch (Exception)
            {
                bi.Close();

                throw;
            }
        }
Exemplo n.º 4
0
        private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
        {
            string text = e.Value;

            if (text == "EXPAND")
            {
                ExpandParadigm();
            }

            if (text.Contains("DICTIONARY"))
            {
                string p = text.Split(':').Last();

                Word word = new Word()
                {
                    Pinyin = p
                };
                JWChinese.App.CurrentArticleWords.Add(word);

                Debug.WriteLine(JWChinese.App.CurrentArticleWords.Count());
            }

            if (text.Contains("COMPLETE"))
            {
                if (view.IsChinese)
                {
                    try
                    {
                        busyIndicator.Close();
                    }
                    catch (Exception ex)
                    {
                        JWChinese.App.GemWriteLine("COMPLETE busyIndicator ERROR!!", ex.Message);
                    }
                }

                // Prints the entire page html after all javascript is loaded and executed
                //await ((Windows.UI.Xaml.Controls.WebView)sender).InvokeScriptAsync("eval", new[] { "getHtml()" });
            }

            if (text.Contains("ANNOTATION"))
            {
                string english = text.Split('|')[3];
                string chinese = text.Split('|')[1];
                string pinyin  = text.Split('|')[2];

                Word word = new Word()
                {
                    Chinese = chinese,
                    Pinyin  = pinyin,
                    English = english
                };

                var words = await StorehouseService.Instance.GetWordsAsync();

                string action = (words.Any(w => w.Pinyin == word.Pinyin && w.Chinese == word.Chinese)) ? "Edit" : "Add";

                MessageDialog dialog = new MessageDialog("‌• " + word.English.Replace("/", "\n‌• "), word.Pinyin + " \n" + word.Chinese);
                dialog.Commands.Clear();
                dialog.Commands.Add(new UICommand {
                    Label = action, Id = 0
                });
                if (action == "Edit")
                {
                    // STUPID HACK BECAUSE UWP PHONE DOESNT SUPPORT MORE THAN 2 BUTTONS
                    var deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;
                    if (deviceFamily.Contains("Desktop"))
                    {
                        dialog.Commands.Add(new UICommand {
                            Label = "Delete", Id = 1
                        });
                    }
                }
                dialog.Commands.Add(new UICommand {
                    Label = "Cancel", Id = 2
                });

                var result = await dialog.ShowAsync();

                if ((int)result.Id == 0)
                {
                    if (action == "Add")
                    {
                        TextBox def = new TextBox()
                        {
                            Text = word.English
                        };
                        //def.SelectAll();
                        ContentDialog d = new ContentDialog
                        {
                            Title               = word.Chinese + " \n" + word.Pinyin,
                            Content             = def,
                            PrimaryButtonText   = "OK",
                            SecondaryButtonText = "Cancel"
                        };

                        ContentDialogResult r = await d.ShowAsync();

                        if (r == ContentDialogResult.Primary)
                        {
                            word.English = def.Text;
                            await StorehouseService.Instance.AddWordAsync(word);

                            await((Windows.UI.Xaml.Controls.WebView)sender).InvokeScriptAsync("englishToggle", new string[] { word.English });
                        }
                    }
                    else if (action == "Edit")
                    {
                        var deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;

                        TextBox def = new TextBox()
                        {
                            Text = word.English
                        };
                        //def.SelectAll();
                        ContentDialog d = new ContentDialog
                        {
                            Title               = word.Chinese + " \n" + word.Pinyin,
                            Content             = def,
                            PrimaryButtonText   = "OK",
                            SecondaryButtonText = deviceFamily.Contains("Desktop") ? "Cancel" : "Delete"
                        };

                        ContentDialogResult r = await d.ShowAsync();

                        if (r == ContentDialogResult.Primary)
                        {
                            // Delete and hide old English word
                            word = words.Where(w => w.Pinyin == word.Pinyin && w.Chinese == word.Chinese).SingleOrDefault();
                            await StorehouseService.Instance.DeleteWordAsync(word);

                            await((Windows.UI.Xaml.Controls.WebView)sender).InvokeScriptAsync("englishToggle", new string[] { word.English });

                            // Show and save new edited word
                            await StorehouseService.Instance.AddWordAsync(new Word { Chinese = word.Chinese, English = def.Text, Pinyin = word.Pinyin });

                            await((Windows.UI.Xaml.Controls.WebView)sender).InvokeScriptAsync("englishToggle", new string[] { def.Text });
                        }

                        if (r == ContentDialogResult.Secondary)
                        {
                            if (!deviceFamily.Contains("Desktop"))
                            {
                                word = words.Where(w => w.Pinyin == word.Pinyin && w.Chinese == word.Chinese).SingleOrDefault();
                                await StorehouseService.Instance.DeleteWordAsync(word);

                                await((Windows.UI.Xaml.Controls.WebView)sender).InvokeScriptAsync("englishToggle", new string[] { word.English });
                            }
                        }
                    }
                }
                else if ((int)result.Id == 1)
                {
                    word = words.Where(w => w.Pinyin == word.Pinyin && w.Chinese == word.Chinese).SingleOrDefault();
                    await StorehouseService.Instance.DeleteWordAsync(word);

                    await((Windows.UI.Xaml.Controls.WebView)sender).InvokeScriptAsync("englishToggle", new string[] { word.English });
                }
            }
        }
Exemplo n.º 5
0
        public InspectionDetailPageViewModel(INavigationService navigationService, ITaskService taskService)
        {
            this._navigationService = navigationService;
            this._taskService       = taskService;
            this.Model = new TIData();

            _busyIndicator  = new BusyIndicator();
            BoundWidth      = Window.Current.Bounds.Width - 60;
            BoundHeight     = (Window.Current.Bounds.Height - 100) / 3;
            CompleteCommand = new DelegateCommand(async() =>
            {
                try
                {
                    _busyIndicator.Open("Please wait, Saving ...");
                    this.SelectedTask.Status = Eqstra.BusinessLogic.Portable.SSModels.DriverTaskStatus.Completed;
                    var imageCaptureList     = await Util.ReadFromDiskAsync <List <Eqstra.BusinessLogic.Portable.TIModels.ImageCapture> >("ImageCaptureList");
                    var resp = await this._taskService.InsertInspectionDataAsync(new List <TIData> {
                        this.Model
                    }, this.SelectedTask, imageCaptureList, UserInfo.CompanyId);

                    if (resp)
                    {
                        PersistentData.RefreshInstance();
                        _navigationService.Navigate("Main", string.Empty);
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    _busyIndicator.Close();
                }
            });
            this.VoiceCommand = new DelegateCommand <string>(async(param) =>
            {
                using (SpeechRecognizer recognizer = new SpeechRecognizer())
                {
                    SpeechRecognitionTopicConstraint topicConstraint
                        = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Development");

                    recognizer.Constraints.Add(topicConstraint);
                    await recognizer.CompileConstraintsAsync();

                    var results = await recognizer.RecognizeWithUIAsync();

                    if (results != null & (results.Confidence != SpeechRecognitionConfidence.Rejected))
                    {
                        if (param == "Remedy")
                        {
                            this.Model.Remedy = results.Text;
                        }
                        if (param == "Recommendation")
                        {
                            this.Model.Recommendation = results.Text;
                        }
                        if (param == "CauseOfDamage")
                        {
                            this.Model.CauseOfDamage = results.Text;
                        }
                    }

                    else
                    {
                        await new MessageDialog("Sorry, I did not get that.").ShowAsync();
                    }
                }
            });
        }
Exemplo n.º 6
0
        public ServiceSchedulingPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator, ILocationService locationService, IServiceDetailService serviceDetailService, ISupplierService supplierService, ITaskService taskService)
        {
            this._navigationService    = navigationService;
            this._serviceDetailService = serviceDetailService;
            this._taskService          = taskService;
            this._eventAggregator      = eventAggregator;
            this._locationService      = locationService;
            this._supplierService      = supplierService;
            this.Model            = new ServiceSchedulingDetail();
            _busyIndicator        = new BusyIndicator();
            IsEnabledDesType      = true;
            this.Address          = new BusinessLogic.Portable.SSModels.Address();
            this.applicationTheme = Application.Current.RequestedTheme;
            this.SpBorderBrush    = this.applicationTheme == ApplicationTheme.Dark ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black);
            this.LtBorderBrush    = this.applicationTheme == ApplicationTheme.Dark ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black);
            this.DtBorderBrush    = this.applicationTheme == ApplicationTheme.Dark ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black);
            this.StBorderBrush    = this.applicationTheme == ApplicationTheme.Dark ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black);
            this.IsLiftRequired   = false;
            this.AddVisibility    = Visibility.Collapsed;
            BoundWidth            = Window.Current.Bounds.Width - 30;
            BoundMinWidth         = Window.Current.Bounds.Width - 80;

            this.NextPageCommand = DelegateCommand.FromAsyncHandler(
                async() =>
            {
                try
                {
                    if (this.Validate())
                    {
                        _busyIndicator.Open("Please wait, Saving ...");

                        this.Model.ServiceDateOption1 = this.Model.ServiceDateOpt1.ToString("MM/dd/yyyy HH:mm");
                        this.Model.ServiceDateOption2 = this.Model.ServiceDateOpt2.ToString("MM/dd/yyyy HH:mm");
                        this.Model.ODOReadingDate     = this.Model.ODOReadingDt.ToString("MM/dd/yyyy HH:mm");
                        bool response = await _serviceDetailService.InsertServiceDetailsAsync(this.Model, this.Address, this.UserInfo);
                        if (response)
                        {
                            var caseStatus = await this._taskService.UpdateStatusListAsync(this.SelectedTask, this.UserInfo);
                            var supplier   = new SupplierSelection()
                            {
                                CaseNumber = this.SelectedTask.CaseNumber, CaseServiceRecID = this.SelectedTask.CaseServiceRecID, SelectedSupplier = this.SelectedSupplier
                            };
                            var res = await this._supplierService.InsertSelectedSupplierAsync(supplier, this.UserInfo);
                            if (res)
                            {
                                this.SelectedTask.Status = caseStatus.Status;
                                await this._taskService.UpdateStatusListAsync(this.SelectedTask, this.UserInfo);
                                PersistentData.RefreshInstance();
                                navigationService.Navigate("Main", string.Empty);
                            }
                        }
                        _busyIndicator.Close();
                    }
                }
                catch (Exception ex)
                {
                    _busyIndicator.Close();
                }
                finally
                {
                }
            },

                () => { return(this.Model != null); });


            this.TakePictureCommand = DelegateCommand <ImageCapture> .FromAsyncHandler(async (param) =>
            {
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode       = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
                openPicker.FileTypeFilter.Add(".bmp");
                openPicker.FileTypeFilter.Add(".png");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".jpg");
                PersistentData.Instance.ServiceSchedulingDetail = this.Model;

                openPicker.PickSingleFileAndContinue();

                this._eventAggregator.GetEvent <ServiceSchedulingDetailEvent>().Subscribe(model =>
                {
                    this.Model = model;
                });
                this._eventAggregator.GetEvent <ImageCaptureEvent>().Subscribe(imageCapture =>
                {
                    this.Model.OdoReadingImageCapture = imageCapture;
                });
            });

            this.OpenImageViewerCommand = new DelegateCommand(
                async() =>
            {
                if (_imageViewer == null)
                {
                    _imageViewer = new ImageViewerPopup(this._eventAggregator, this.Model);
                }
                else
                {
                    _imageViewer      = null;
                    this._imageViewer = new ImageViewerPopup(this._eventAggregator, this.Model);
                }

                _imageViewer.DataContext = this.Model.OdoReadingImageCapture;
                await _imageViewer.ShowAsync();
            });


            this.VoiceCommand = new DelegateCommand(async() =>
            {
                try
                {
                    SpeechRecognizer recognizer = new SpeechRecognizer();

                    SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Development");

                    recognizer.Constraints.Add(topicConstraint);
                    await recognizer.CompileConstraintsAsync();

                    var results = await recognizer.RecognizeWithUIAsync();
                    if (results != null & (results.Confidence != SpeechRecognitionConfidence.Rejected))
                    {
                        this.Model.AdditionalWork = results.Text;
                    }
                    else
                    {
                        await new MessageDialog("Sorry, I did not get that.").ShowAsync();
                    }
                }
                catch (Exception)
                {
                }
            });


            this.AddCommand = new DelegateCommand(async() =>
            {
                _addressDialog = new AddressDialog(this._locationService, this._eventAggregator, this.Address);
                this.Model.SelectedDestinationType = new DestinationType();
                await _addressDialog.ShowAsync();
            });

            this.DetailCommand = new DelegateCommand(async() =>
            {
                moreInfo             = new DetailsDialog();
                moreInfo.DataContext = this.SelectedTask;
                await moreInfo.ShowAsync();
            });

            this.SupplierFilterCommand = new DelegateCommand(async() =>
            {
                sp = new SearchSupplierDialog(this._locationService, this._eventAggregator, this._supplierService);
                await sp.ShowAsync();
            });

            this._eventAggregator.GetEvent <AddressFilterEvent>().Subscribe((address) =>
            {
                if (address != null)
                {
                    this.Address     = address;
                    StringBuilder sb = new StringBuilder();

                    sb.Append(address.Street).Append(",").Append(Environment.NewLine);

                    if ((address.SelectedSuburb != null) && !String.IsNullOrEmpty(address.SelectedSuburb.Name))
                    {
                        sb.Append(address.SelectedSuburb.Name).Append(",").Append(Environment.NewLine);
                    }
                    if (address.SelectedRegion != null)
                    {
                        sb.Append(address.SelectedRegion.Name).Append(",").Append(Environment.NewLine);
                    }
                    if ((address.SelectedCity != null) && !String.IsNullOrEmpty(address.SelectedCity.Name))
                    {
                        sb.Append(address.SelectedCity.Name).Append(",").Append(Environment.NewLine);
                    }
                    if ((address.Selectedprovince != null) && !String.IsNullOrEmpty(address.Selectedprovince.Name))
                    {
                        sb.Append(address.Selectedprovince.Name).Append(",").Append(Environment.NewLine);
                    }

                    if ((address.SelectedCountry != null) && !String.IsNullOrEmpty(address.SelectedCountry.Name))
                    {
                        sb.Append(address.SelectedCountry.Name).Append(",").Append(Environment.NewLine);
                    }

                    sb.Append(address.SelectedZip);


                    this.Model.Address = sb.ToString();
                }
            });

            _eventAggregator.GetEvent <SupplierFilterEvent>().Subscribe(poolofSupplier =>
            {
                this.PoolofSupplier = poolofSupplier;
            });
        }
Exemplo n.º 7
0
        public async override void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, Dictionary <string, object> viewModelState)
        {
            try
            {
                _busyIndicator.Open("Please wait, loading ...");
                if (ApplicationData.Current.RoamingSettings.Values.ContainsKey(Constants.USERINFO))
                {
                    this.UserInfo = JsonConvert.DeserializeObject <UserInfo>(ApplicationData.Current.RoamingSettings.Values[Constants.USERINFO].ToString());
                }

                if (ApplicationData.Current.RoamingSettings.Values.ContainsKey(Constants.SELECTEDTASK))
                {
                    this.SelectedTask = JsonConvert.DeserializeObject <Pithline.FMS.BusinessLogic.Portable.SSModels.Task>(ApplicationData.Current.RoamingSettings.Values[Constants.SELECTEDTASK].ToString());
                }

                this.Model = await _serviceDetailService.GetServiceDetailAsync(SelectedTask.CaseNumber, SelectedTask.CaseServiceRecID, SelectedTask.ServiceRecID, this.UserInfo);

                this.PoolofSupplier = await this._supplierService.GetSuppliersByClassAsync(SelectedTask.VehicleClassId, this.UserInfo);

                if (string.IsNullOrEmpty(this.Model.ODOReadingSnapshot))
                {
                    this.Model.OdoReadingImageCapture = new ImageCapture()
                    {
                        ImageBitmap = new BitmapImage(new Uri("ms-appx:///Assets/odo_meter.png"))
                    };
                }
                else
                {
                    var bitmap = new BitmapImage();
                    await bitmap.SetSourceAsync(await this.ConvertToRandomAccessStreamAsync(Convert.FromBase64String(this.Model.ODOReadingSnapshot)));

                    this.Model.OdoReadingImageCapture = new ImageCapture()
                    {
                        ImageBitmap = bitmap
                    };
                }


                if (this.Model == null)
                {
                    this.Model = navigationParameter as ServiceSchedulingDetail;
                }
                if (!String.IsNullOrEmpty(this.Model.ServiceDateOption1))
                {
                    this.Model.ServiceDateOpt1 = DateTime.Parse(this.Model.ServiceDateOption1);
                }
                if (!String.IsNullOrEmpty(this.Model.ServiceDateOption2))
                {
                    this.Model.ServiceDateOpt2 = DateTime.Parse(this.Model.ServiceDateOption2);
                }

                if (!String.IsNullOrEmpty(this.Model.ODOReadingDate))
                {
                    this.Model.ODOReadingDt = DateTime.Parse(this.Model.ODOReadingDate);
                }

                if (this.Model != null)
                {
                    this.IsLiftRequired = this.Model.IsLiftRequired;
                }
                this.Model.CaseNumber = this.SelectedTask.CaseNumber;
                _busyIndicator.Close();
            }
            catch (Exception)
            {
                _busyIndicator.Close();
            }
        }