Esempio n. 1
0
        /// <summary>
        /// Save the chosen value whenever a value is chosen from a picker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DidSelectFromChoices(object sender, EventArgs e)
        {
            var choice = sender as CustomPicker;

            using (SQLiteConnection conn = new SQLiteConnection(Preferences.Get("databaseLocation", "")))
            {
                var text         = conn.Table <TextData>().Select(t => t).Where(TextData => TextData.Id == choice.ValueId).FirstOrDefault();
                var choiceString = choice.SelectedItem.ToString();
                text.value = choiceString;
                var chosen = conn.Table <FieldChoice>().Select(t => t).Where(mychoice => mychoice.formField_fk == choice.TypeId).Where(mychoice => mychoice.text == choiceString).FirstOrDefault();

                if (chosen != null)
                {
                    text.fieldChoiceId = chosen.choiceId;
                    //conn.Update(text);
                }
                try
                {
                    if (choice.Mandatory)
                    {
                        var empty = String.IsNullOrEmpty(choiceString);
                        Validation[(int)choice.ValueId] = !empty;
                        SaveCommand.ChangeCanExecute();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
 void EditReportViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (!string.IsNullOrEmpty(e.PropertyName))
     {
         SaveCommand.ChangeCanExecute();
     }
 }
Esempio n. 3
0
        /// <summary>
        /// When date field entries change, we can trigger a reevaluation of the page here
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DateFieldChanged(object sender, EventArgs e)
        {
            var      dateField = (CustomDatePicker)sender;
            DateTime?date      = (DateTime?)dateField.NullableDate;
            int      valueId   = (int)dateField.ValueId;

            if (dateField.Mandatory)
            {
                var empty = (date == null);
                Validation[valueId] = !empty;
                SaveCommand.ChangeCanExecute();
            }

            if (date != null)
            {
                CustomStackLayout stack = (CustomStackLayout)dateField.Parent;
                foreach (var el in stack.Children)
                {
                    if (el is CustomTimePicker)
                    {
                        CustomTimePicker tp = (CustomTimePicker)el;
                        if (tp.NullableDate == null)
                        {
                            tp.NullableDate = new TimeSpan(0);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// When time field entries change, we can trigger a reevaluation of the page here
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TimeFieldChanged(object sender, EventArgs e)
        {
            var      timeField = (CustomTimePicker)sender;
            TimeSpan?time      = (TimeSpan?)timeField.NullableDate;
            int      valueId   = (int)timeField.ValueId;

            if (timeField.Mandatory)
            {
                var empty = (time == null);
                Validation[valueId] = !empty;
                SaveCommand.ChangeCanExecute();
            }
            if (time != null)
            {
                CustomStackLayout stack = (CustomStackLayout)timeField.Parent;
                foreach (var el in stack.Children)
                {
                    if (el is CustomDatePicker)
                    {
                        CustomDatePicker dp = (CustomDatePicker)el;
                        if (dp.NullableDate == null)
                        {
                            dp.NullableDate = DateTime.Now;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Clears the date field
        /// </summary>
        private void ClearDate(object parameter)
        {
            var dic = (Dictionary <String, Object>)parameter;

            dic.TryGetValue("text", out var textData);
            TextData text = (TextData)textData;

            dic.TryGetValue("date", out var dateObj);
            CustomDatePicker dateField = (CustomDatePicker)dateObj;

            dic.TryGetValue("time", out var timeObj);
            CustomTimePicker timeField = (CustomTimePicker)timeObj;

            dateField.NullableDate = null;
            timeField.NullableDate = null;
            DateTime?date    = (DateTime?)dateField.NullableDate;
            int      valueId = (int)dateField.ValueId;

            if (dateField.Mandatory)
            {
                var empty = (date == null);
                Validation[valueId] = !empty;
                SaveCommand.ChangeCanExecute();
            }

            using (SQLiteConnection conn = new SQLiteConnection(Preferences.Get("databaseLocation", "")))
            {
                text.value = String.Empty;
                //conn.Update(text);
                Record.UpdateRecord(text.record_fk);
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Saves the answer.
        /// </summary>
        private async void SaveAnswer()
        {
            var date     = DateTime.Now;
            var response = new CheckListResponse
            {
                CategoryId = RecordResponse.CategoryId,
                Question   = RecordResponse.QuestionName,
                Answer     = Answer,
                CorrAction =
                    SelectedCorrectiveAction != string.Empty
                        ? SelectedCorrectiveAction
                        : HACCPUtil.GetResourceString("None"),
                QuestionType = RecordResponse.QuestionType.ToString(),
                UserName     = HaccpAppSettings.SharedInstance.UserName,
                DeviceId     = HaccpAppSettings.SharedInstance.DeviceId,
                SiteId       = HaccpAppSettings.SharedInstance.SiteSettings.SiteId,
                IsNa         = 0,
                Hour         = date.Hour.ToString(),
                Day          = date.Day.ToString(),
                Minute       = date.Minute.ToString(),
                Month        = date.Month.ToString(),
                Sec          = date.Second.ToString(),
                Year         = date.Year.ToString(),
                Tzid         = HaccpAppSettings.SharedInstance.SiteSettings.TimeZoneId,
                Min          = RecordResponse.Min,
                Max          = RecordResponse.Max,
                QuestionId   = RecordResponse.QuestionId,
                Catname      = RecordResponse.CategoryName,
                ChecklistId  = HaccpAppSettings.SharedInstance.SiteSettings.CheckListId
            };

            Debug.WriteLine("++++++++++++++++++++++++++++++");
            Debug.WriteLine("***Category Name= {0}***", response.Catname);
            Debug.WriteLine("++++++++++++++++++++++++++++++");
            dataStore.SaveCheckListResponse(response);
            RecordResponse.RecordStatus = 1;
            dataStore.UpdateQuestionRecordStatus(RecordResponse);
            MessagingCenter.Send(RecordResponse, HaccpConstant.QuestionMessage);
            dataStore.UpdateCategoryRecordStatus(RecordResponse.CategoryId);
            MessagingCenter.Send(new CategoryStatus {
                CategoryId = RecordResponse.CategoryId
            },
                                 HaccpConstant.CategoryMessage);
            IsBusy = false;
            SaveCommand.ChangeCanExecute();
            await Page.PopPage();

            if (HaccpAppSettings.SharedInstance.DeviceSettings.AutoAdvance)
            {
                MessagingCenter.Send(new AutoAdvanceCheckListMessage {
                    CurrentId = RecordResponse.QuestionId
                },
                                     HaccpConstant.AutoadvancechecklistMessage);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// When numeric field entries change, we can trigger a reevaluation of the page here
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NumericFieldChanged(object sender, EventArgs e)
        {
            var textField = (CustomEntry)sender;
            int valueId   = (int)textField.ValueId;

            if (textField.Mandatory)
            {
                var empty = String.IsNullOrEmpty(textField.Text);
                Validation[valueId] = !empty;
                SaveCommand.ChangeCanExecute();
            }
        }
Esempio n. 8
0
        public EmployeeViewModel()
        {
            this.SaveCommand      = new Command(OnSave, ValidateSave);
            this.CancelCommand    = new Command(OnCancel);
            this.TakePhotoCommand = new Command(async() => await OnTakePhotoAsync());

            this.photoPath  = "DetailsPlaceholder.jpg";
            this.employeeId = Guid.NewGuid();

            // everytime check if we can save
            this.PropertyChanged += (_, __) => SaveCommand.ChangeCanExecute();
        }
Esempio n. 9
0
 private void SalesOrderViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     SaveCommand.ChangeCanExecute();
 }
Esempio n. 10
0
 void EditRuleViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     SaveCommand.ChangeCanExecute();
 }
Esempio n. 11
0
        /// <summary>
        ///     Executes the save command.
        /// </summary>
        /// <returns>The save command.</returns>
        protected override async Task ExecuteSaveCommand()
        {
            try
            {
                IsBusy = true;
                SaveCommand.ChangeCanExecute();

                HACCPUtil.ConvertToDouble(SelectedItem.Min);
                HACCPUtil.ConvertToDouble(SelectedItem.Max);

                var temp = TemperatureValue;
                if (TemperatureUnit == TemperatureUnit.Celcius)
                {
                    temp = HACCPUtil.ConvertCelsiusToFahrenheit(TemperatureValue);
                }


                if (
                    await
                    Page.ShowConfirmAlert(HACCPUtil.GetResourceString("SaveRecord"),
                                          string.Format(
                                              HACCPUtil.GetResourceString("RecordedTemperature0Correctiveactiontaken1User2"),
                                              Temperature + HaccpConstant.NewlineCharacter,
                                              SelectedCorrectiveAction != null
                                    ? SelectedCorrectiveAction.CorrActionName + HaccpConstant.NewlineCharacter
                                    : HACCPUtil.GetResourceString("None") + HaccpConstant.NewlineCharacter,
                                              HaccpAppSettings.SharedInstance.UserName)))
                {
                    //if (itemTemperature == null) {
                    var  date = DateTime.Now;
                    long ccpid;
                    long.TryParse(SelectedItem.Ccpid, out ccpid);
                    var location = dataStore.GetLocationById(SelectedItem.LocationId);

                    itemTemperature = new ItemTemperature
                    {
                        IsManualEntry = SelectedItem.IsManualEntry ? (short)1 : (short)0,
                        ItemID        = SelectedItem.ItemId,
                        Temperature   = temp.ToString("0.0"),
                        ItemName      = SelectedItem.Name,
                        Max           = SelectedItem.Max,
                        Min           = SelectedItem.Min,
                        CorrAction    =
                            SelectedCorrectiveAction != null
                                ? SelectedCorrectiveAction.CorrActionName
                                : HACCPUtil.GetResourceString("None"),
                        LocationID = SelectedItem.LocationId,
                        Ccp        = SelectedItem.Ccp,
                        CCPID      = ccpid,
                        IsNA       = 0,
                        Hour       = date.Hour.ToString(),
                        Day        = date.Day.ToString(),
                        Minute     = date.Minute.ToString(),
                        Month      = date.Month.ToString(),
                        Sec        = date.Second.ToString(),
                        Year       = date.Year.ToString(),
                        SiteID     = HaccpAppSettings.SharedInstance.SiteSettings.SiteId,
                        UserName   = HaccpAppSettings.SharedInstance.UserName,
                        DeviceId   = HaccpAppSettings.SharedInstance.DeviceId,
                        MenuID     = HaccpAppSettings.SharedInstance.SiteSettings.MenuId,
                        TZID       = HaccpAppSettings.SharedInstance.SiteSettings.TimeZoneId,
                        //BatchId = HACCPAppSettings.SharedInstance.SiteSettings.LastBatchNumber,
                        LocName = location.Name,
                        Note    =
                            !string.IsNullOrEmpty(NoteText) && !string.IsNullOrWhiteSpace(NoteText)
                                ? NoteText.Trim()
                                : string.Empty,
                        Blue2ID = SelectedItem.Blue2Id
                    };
                    dataStore.AddTemperature(itemTemperature);

                    SelectedItem.RecordStatus = 1;
                    dataStore.RecordLocationItem(SelectedItem);

                    MessagingCenter.Send(SelectedItem, HaccpConstant.RecorditemMessage);
                    dataStore.UpdateLocationItemRecordStatus(SelectedItem.LocationId);
                    MessagingCenter.Send(new MenuLocationId
                    {
                        LocationId = SelectedItem.LocationId
                    }, HaccpConstant.MenulocationMessage);

                    if (HaccpAppSettings.SharedInstance.IsWindows)
                    {
                        await Page.PopPages(2);
                    }
                    else
                    {
                        Page.RemoveRecordItemPage();
                        await Page.PopPage();
                    }

                    if (HaccpAppSettings.SharedInstance.DeviceSettings.AutoAdvance)
                    {
                        MessagingCenter.Send(new AutoAdvanceLocationMessage
                        {
                            CurrentId = SelectedItem.ItemId
                        }, HaccpConstant.AutoadvancelocationMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error occured while saving temperature {0}", ex.Message);
            }
            finally
            {
                IsBusy = false;
                SaveCommand.ChangeCanExecute();
            }
        }
Esempio n. 12
0
        /// <summary>
        ///     Executes the save command.
        /// </summary>
        /// <returns>The save command.</returns>
        private async Task ExecuteSaveCommand()
        {
            var saved = false;

            if (IsBusy)
            {
                return;
            }

            if (ServerAddress.Trim() == null || ServerAddress.Trim().Length < 1)
            {
                Page.DisplayAlertMessage("", HACCPUtil.GetResourceString("EnterServerIPAddressorDomainName"));
                return;
            }
            var isDataExists = false;

            Page.EndEditing();
            IsBusy = true;
            SaveCommand.ChangeCanExecute();
            Page.ShowProgressIndicator();
            var currentServerAddressStatus = IsServerAddressExist;

            try
            {
                var isConnected = await TestConnection(false);

                if (isConnected)
                {
                    if (currentServerAddressStatus)
                    {
                        isDataExists = dataStore.CheckTemperaturesExists() || dataStore.CheckCheckListsExists();
                    }

                    if (isDataExists == false)
                    {
                        HaccpAppSettings.SharedInstance.SiteSettings.ServerAddress   = ServerAddress.Trim();
                        HaccpAppSettings.SharedInstance.SiteSettings.ServerPort      = Port.Trim();
                        HaccpAppSettings.SharedInstance.SiteSettings.ServerDirectory = ServerDirectory.Trim();

                        dataStore.SaveSiteSettings(HaccpAppSettings.SharedInstance.SiteSettings);

                        saved = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Ooops! Something went wrong while save connection. Exception: {0}", ex);
            }
            finally
            {
                IsBusy = false;
                SaveCommand.ChangeCanExecute();
                Page.DismissPopup();
            }
            if (saved)
            {
                await Page.ShowAlert("", HACCPUtil.GetResourceString("ServerSettingsupdatedsuccessfully"));

                if (currentServerAddressStatus)
                {
                    await Page.PopPage();
                }
                else
                {
                    //if (HaccpAppSettings.SharedInstance.IsWindows)
                    //{
                    //    var style = Application.Current.Resources["WindowsListScrollHelpGridStyle"] as Style;
                    //    if (style != null)
                    //    {
                    //        style.Setters.RemoveAt(0);
                    //        style.Setters.Insert(0, new Setter {Property = VisualElement.HeightRequestProperty, Value = 90});
                    //    }

                    //    var recordstyle = Application.Current.Resources["WindowsScrollHelpGridStyle"] as Style;
                    //    if (recordstyle != null)
                    //    {
                    //        recordstyle.Setters.RemoveAt(0);
                    //        recordstyle.Setters.Insert(0,
                    //            new Setter {Property = VisualElement.HeightRequestProperty, Value = 85});
                    //    }
                    //    // related to scroll issue fix after changing language
                    //}
                    Page.LoadHomePage();
                }
            }
            else if (isDataExists)
            {
                var siteSettings = new SiteSettings
                {
                    ServerAddress   = ServerAddress.Trim(),
                    ServerPort      = Port.Trim(),
                    ServerDirectory = ServerDirectory.Trim()
                };
                await Page.NavigateToWithSelectedObject(PageEnum.ServerSettingsConfirmation, true, siteSettings);
            }
        }
Esempio n. 13
0
        /// <summary>
        ///     Executes the save command.
        /// </summary>
        /// <returns>The save command.</returns>
        protected override async Task ExecuteSaveCommand()
        {
            if (IsBusy)
            {
                return;
            }
            try
            {
                IsBusy = true;
                SaveCommand.ChangeCanExecute();

                if (string.IsNullOrEmpty(Answer) && !IsYesNo)
                {
                    Answer = string.Empty;
                    Page.DisplayAlertMessage(HACCPUtil.GetResourceString("RecordAnswer"),
                                             HACCPUtil.GetResourceString("Specifyanumericvalue"));
                }
                else if (SelectedCorrectiveAction == HACCPUtil.GetResourceString("None"))
                {
                    if ((IsYesNo && Answer != HACCPUtil.GetResourceString("Yes")) ||
                        (!IsYesNo &&
                         (HACCPUtil.ConvertToDouble(Answer) < HACCPUtil.ConvertToDouble(RecordResponse.Min) ||
                          HACCPUtil.ConvertToDouble(Answer) > HACCPUtil.ConvertToDouble(RecordResponse.Max))))
                    {
                        CorrectiveActions =
                            new ObservableCollection <CorrectiveAction>(
                                dataStore.GetCorrectiveActionForQuestion(RecordResponse.QuestionId));
                        if (CorrectiveActions != null && CorrectiveActions.Count > 0)
                        {
                            IsCorrctiveOptionsVisible = true;
                        }
                        else if (
                            await
                            Page.ShowConfirmAlert(HACCPUtil.GetResourceString("RecordAnswer"),
                                                  string.Format(
                                                      HACCPUtil.GetResourceString("RecordedAnswer01CorrectiveActiontaken2"),
                                                      Answer, Environment.NewLine,
                                                      SelectedCorrectiveAction == string.Empty
                                            ? HACCPUtil.GetResourceString("None")
                                            : SelectedCorrectiveAction)))
                        {
                            SaveAnswer();
                        }
                    }
                    else
                    {
                        if (RecordResponse.QuestionType == (short)QuestionType.NumericAnswer)
                        {
                            try
                            {
                                var answerVal = HACCPUtil.ConvertToDouble(Answer);
                                Answer = answerVal.ToString();
                            }
                            catch
                            {
                                Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("Specifyavalidanswer"));
                                return;
                            }
                        }

                        if (
                            await
                            Page.ShowConfirmAlert(HACCPUtil.GetResourceString("RecordAnswer"),
                                                  string.Format(
                                                      HACCPUtil.GetResourceString("RecordedAnswer01CorrectiveActiontaken2"), Answer,
                                                      Environment.NewLine,
                                                      SelectedCorrectiveAction == string.Empty
                                            ? HACCPUtil.GetResourceString("None")
                                            : SelectedCorrectiveAction)))
                        {
                            SaveAnswer();
                        }
                    }
                }
                else
                {
                    if (RecordResponse.QuestionType == (short)QuestionType.NumericAnswer)
                    {
                        try
                        {
                            var answerVal = HACCPUtil.ConvertToDouble(Answer);
                            Answer = answerVal.ToString();
                        }
                        catch
                        {
                            Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("Specifyavalidanswer"));
                            return;
                        }
                    }
                    if (
                        await
                        Page.ShowConfirmAlert(HACCPUtil.GetResourceString("RecordAnswer"),
                                              string.Format(HACCPUtil.GetResourceString("RecordedAnswer01CorrectiveActiontaken2"),
                                                            Answer, Environment.NewLine,
                                                            SelectedCorrectiveAction == string.Empty
                                        ? HACCPUtil.GetResourceString("None")
                                        : SelectedCorrectiveAction)))
                    {
                        SaveAnswer();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Ooops! Something went wrong. Exception: {0}", ex);
            }
            finally
            {
                IsBusy = false;
                SaveCommand.ChangeCanExecute();
            }
        }
Esempio n. 14
0
 public NewItemViewModel()
 {
     CancelCommand         = new Command(OnCancel);
     this.PropertyChanged +=
         (_, __) => SaveCommand.ChangeCanExecute();
 }