/// <summary> /// bindable_TextChanged /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bindable_TextChanged(object sender, TextChangedEventArgs e) { var decimalChar = Convert.ToString(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator); if (string.IsNullOrEmpty(e.NewTextValue) || e.NewTextValue == decimalChar) { return; } if (!string.IsNullOrEmpty(e.NewTextValue) && e.NewTextValue.Contains(" ")) { ((Entry)sender).Text = e.OldTextValue; return; } if (e.NewTextValue == "-" || e.NewTextValue == string.Format("-{0}", decimalChar)) { ((Entry)sender).Text = string.Empty; return; } try { HACCPUtil.ConvertToDouble(e.NewTextValue); } catch { ((Entry)sender).Text = e.OldTextValue; } }
/// <summary> /// Record Answer screen constructor /// </summary> /// <param name="selectedQuestion"></param> public RecordAnswer(object selectedQuestion) { InitializeComponent(); var question = (Question)selectedQuestion; NavigationPage.SetBackButtonTitle(this, string.Empty); BindingContext = _viewModel = new RecordAnswerViewModel(this); _viewModel.Subtitle = question.QuestionName; _viewModel.RecordResponse = question; switch (question.QuestionType) { case (short)QuestionType.NumericAnswer: _viewModel.IsNumeric = true; _viewModel.IsYesNo = false; break; case (short)QuestionType.YesOrNo: _viewModel.IsYesNo = true; _viewModel.IsNumeric = false; _viewModel.Answer = HACCPUtil.GetResourceString("Yes"); break; } correctiveActionList.ItemSelected += (sender, e) => { if (correctiveActionList.SelectedItem == null) { return; } var correctiveAction = ((CorrectiveAction)e.SelectedItem).CorrActionName; if (!string.IsNullOrEmpty(_viewModel.Answer)) { if ((_viewModel.IsYesNo && _viewModel.Answer == HACCPUtil.GetResourceString("No")) || (!_viewModel.IsYesNo && (HACCPUtil.ConvertToDouble(_viewModel.Answer) < HACCPUtil.ConvertToDouble(_viewModel.RecordResponse.Min) || HACCPUtil.ConvertToDouble(_viewModel.Answer) > HACCPUtil.ConvertToDouble(_viewModel.RecordResponse.Max)))) { if (correctiveAction != HACCPUtil.GetResourceString("None")) { _viewModel.SelectedCorrectiveAction = correctiveAction; _viewModel.IsCorrctiveOptionsVisible = false; } } else { _viewModel.SelectedCorrectiveAction = correctiveAction; _viewModel.IsCorrctiveOptionsVisible = false; } } else { _viewModel.SelectedCorrectiveAction = correctiveAction; _viewModel.IsCorrctiveOptionsVisible = false; } correctiveActionList.SelectedItem = null; }; actionBtn.Clicked += (sender, e) => { numericValueEntry.Unfocus(); }; toggleBtn.Clicked += (sender, e) => { if (_viewModel.IsNumeric) { if (numericValueEntry.IsFocused) { numericValueEntry.Unfocus(); } else { numericValueEntry.Focus(); } } }; if (HaccpAppSettings.SharedInstance.IsWindows) { ToolbarItems.Add(new ToolbarItem { Icon = "logout.png", Order = ToolbarItemOrder.Primary, Command = _viewModel.LogInCommand }); } }
/// <summary> /// Show Popup Data /// </summary> /// <param name="record"></param> public void ShowPopupData(ItemTemperature record) { var list = _viewModel.Items; var item = list.FirstOrDefault(x => x.ItemId == _selectedItem.ItemId); var index = list.IndexOf(item); if (index == 0) { prevImage.Source = "prevDisable.png"; prevButton.IsEnabled = false; } else { prevImage.Source = "prev.png"; prevButton.IsEnabled = true; } if (index == list.Count - 1) { nextImage.Source = "nextDisable.png"; nextButton.IsEnabled = false; } else { nextImage.Source = "next.png"; nextButton.IsEnabled = true; } var tempUnit = HaccpAppSettings.SharedInstance.DeviceSettings.TempScale == 0 ? TemperatureUnit.Fahrenheit : TemperatureUnit.Celcius; var temperature = HACCPUtil.ConvertToDouble(record.Temperature); var min = HACCPUtil.ConvertToDouble(record.Min); var max = HACCPUtil.ConvertToDouble(record.Max); var unit = HACCPUtil.GetResourceString("FahrenheitUnit"); if (tempUnit == TemperatureUnit.Celcius) { temperature = Math.Round(HACCPUtil.ConvertFahrenheitToCelsius(temperature), 1); min = Math.Round(HACCPUtil.ConvertFahrenheitToCelsius(min)); max = Math.Round(HACCPUtil.ConvertFahrenheitToCelsius(max)); unit = HACCPUtil.GetResourceString("CelsciustUnit"); } _viewModel.IsReviewItemVisible = true; questionLabel.Text = record.ItemName; RecordedTemp.Text = string.Format("{0}: {1}{2}", HACCPUtil.GetResourceString("RecordedTemperature"), temperature.ToString("0.0"), unit); CorrectiveAction.IsVisible = true; CorrectiveAction.Text = string.Format("{0}: {1}", HACCPUtil.GetResourceString("CorrectiveAction"), record.CorrAction); if (!string.IsNullOrEmpty(record.Note)) { Notes.Text = string.Format("{0}: {1}", HACCPUtil.GetResourceString("NotesLabel"), record.Note); Notes.IsVisible = true; } else { Notes.IsVisible = false; } TempRange.Text = string.Format("{0}: {1}{2}, {3}: {4}{5}", HACCPUtil.GetResourceString("Min").ToUpper(), min, unit, HACCPUtil.GetResourceString("Max").ToUpper(), max, unit); UserName.Text = string.Format("{0}: {1}", HACCPUtil.GetResourceString("Recordedby"), record.UserName); var date = new DateTime(Convert.ToInt32(record.Year), Convert.ToInt32(record.Month), Convert.ToInt32(record.Day), Convert.ToInt32(record.Hour), Convert.ToInt32(record.Minute), Convert.ToInt32(record.Sec)); var dateString = date.ToString(); TimeStamp.Text = string.Format("{0}: {1}", HACCPUtil.GetResourceString("Time"), HACCPUtil.GetFormattedDate(dateString)); }