Пример #1
0
 /// <summary>
 ///     Adds the temperature.
 /// </summary>
 /// <param name="item">Item.</param>
 public void AddTemperature(ItemTemperature item)
 {
     lock (Locker)
     {
         Database.Insert(item);
     }
 }
Пример #2
0
 /// <summary>
 ///     Updates the item.
 /// </summary>
 /// <param name="item">Item.</param>
 public void RecordTemperature(ItemTemperature item)
 {
     lock (Locker)
     {
         Database.Update(item);
     }
 }
Пример #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="HACCP.Core.RecordItemCompleteViewModel" /> class.
 /// </summary>
 /// <param name="page">Page.</param>
 /// <param name="item">Item.</param>
 public RecordItemCompleteViewModel(IPage page, object item) : base(page)
 {
     dataStore    = new SQLiteDataStore();
     SelectedItem = item as LocationMenuItem;
     if (SelectedItem != null)
     {
         NoteText         = SelectedItem.Note;
         TemperatureUnit  = SelectedItem.TemperatureUnit;
         TemperatureValue = HACCPUtil.ConvertToDouble(SelectedItem.RecordedTemperature);
         Temperature      = TemperatureValue.ToString("0.0");
         itemTemperature  = dataStore.GetItemTemperature(SelectedItem);
     }
     LoadCorrectiveActions();
 }
Пример #4
0
        /// <summary>
        ///     Builds the upload upload temperatures service method URL.
        /// </summary>
        /// <returns>The upload upload temperatures service method URL.</returns>
        /// <param name="itemTemperature">Item temperature.</param>
        /// <param name="batchId"></param>
        private static StringBuilder BuildUploadUploadTemperaturesServiceMethodUrl(ItemTemperature itemTemperature,
                                                                                   string batchId)
        {
            var temperatureUploadUrl = new StringBuilder();

            var min = GetString(itemTemperature.Min);

            min = min == "0" ? "" : min;

            var max = GetString(itemTemperature.Max);

            max = max == "0" ? "" : max;

            var temperature =
                ((string.IsNullOrEmpty(itemTemperature.Temperature) ? 0 : ConvertToDouble(itemTemperature.Temperature)) *
                 10).ToString();


            temperatureUploadUrl.AppendFormat(
                "/HACCPManagerService/UploadTemperatures?record={0}&item={1}&temp={2}&month={3}&day={4}&year={5}&hour={6}&minute={7}&" +
                "sec={8}&user={9}&cact={10}&min={11}&max={12}&loc={13}&ccp={14}&device={15}&batch={16}&siteId={17}&itemid={18}&" +
                "locationid={19}&ccpid={20}&menuid={21}&isna={22}&tzID={23}&isManual={24}&Blue2ID={25}&Note={26}",

                /*"record:\"{0}\", item:\"{1}\", temp:\"{2}\", month:\"{3}\", day:\"{4}\", year:\"{5}\", hour:\"{6}\", minute:\"{7}\", " +
                 *              "sec:\"{8}\", username:\"{9}\", cact:\"{10}\", min:\"{11}\", max:\"{12}\", loc:\"{13}\", ccp:\"{14}\", device:\"{15}\", " +
                 *              "batch:\"{16}\", siteId:\"{17}\", itemid:\"{18}\", locationid:\"{19}\", ccpid:\"{20}\", menuid:\"{21}\", isna:\"{22}\", " +
                 *              "tzID:\"{23}\", manual:\"{24}\"", */
                GetString(itemTemperature.RecordNo), GetString(itemTemperature.ItemName), temperature,
                GetString(itemTemperature.Month), GetString(itemTemperature.Day), GetString(itemTemperature.Year),
                GetString(itemTemperature.Hour), GetString(itemTemperature.Minute), GetString(itemTemperature.Sec),
                GetString(itemTemperature.UserName), GetString(itemTemperature.CorrAction), min,
                max, GetString(itemTemperature.LocName), GetString(itemTemperature.Ccp),
                GetString(itemTemperature.DeviceId), batchId, GetString(itemTemperature.SiteID),
                GetString(itemTemperature.ItemID),
                GetString(itemTemperature.LocationID), GetString(itemTemperature.CCPID),
                GetString(itemTemperature.MenuID),
                GetString(itemTemperature.IsNA), GetString(itemTemperature.TZID),
                GetString(itemTemperature.IsManualEntry),
                GetString(itemTemperature.Blue2ID), GetString(itemTemperature.Note)
                );

            return(temperatureUploadUrl);
        }
Пример #5
0
        /// <summary>
        ///     Executes the NA command.
        /// </summary>
        /// <returns>The NA command.</returns>
        protected override async Task ExecuteNACommand()
        {
            if (IsBusy)
            {
                return;
            }

            var result =
                await
                Page.ShowConfirmAlert(string.Empty,
                                      HACCPUtil.GetResourceString("SavedNAasthetemperaturerecordingfortheitem"));

            if (result)
            {
                IsBusy = true;
                NACommand.ChangeCanExecute();

                try
                {
                    var  location = dataStore.GetLocationById(SelectedItem.LocationId);
                    var  date     = DateTime.Now;
                    long ccpid;
                    long.TryParse(SelectedItem.Ccpid, out ccpid);
                    var itemTemperature = new ItemTemperature
                    {
                        IsManualEntry = SelectedItem.IsManualEntry ? (short)1 : (short)0,
                        ItemID        = SelectedItem.ItemId,
                        Temperature   = "0",
                        ItemName      = SelectedItem.Name,
                        Max           = SelectedItem.Max,
                        Min           = SelectedItem.Min,
                        CorrAction    = string.Empty,
                        //SelectedCorrectiveAction != null ? SelectedCorrectiveAction.CorrActionName : "None",
                        LocationID = SelectedItem.LocationId,
                        Ccp        = SelectedItem.Ccp,
                        CCPID      = ccpid,
                        IsNA       = 1,
                        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,
                        Blue2ID    = string.Empty
                    };
                    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);

                    await Page.PopPage();

                    if (HaccpAppSettings.SharedInstance.DeviceSettings.AutoAdvance)
                    {
                        MessagingCenter.Send(new AutoAdvanceLocationMessage
                        {
                            CurrentId = SelectedItem.ItemId
                        }, HaccpConstant.AutoadvancelocationMessage);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error on N/A Command {0}", ex.Message);
                }
                finally
                {
                    IsBusy = false;
                    NACommand.ChangeCanExecute();
                }
            }
        }
Пример #6
0
        /// <summary>
        ///     Executes the record command.
        /// </summary>
        private async void ExecuteRecordCommand()
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                bool connected;
                bool gotTemperartureReading;
                if (HaccpAppSettings.SharedInstance.IsWindows)
                {
                    gotTemperartureReading = WindowsBLEManager.SharedInstance.GotTemperartureReading;
                    connected = WindowsBLEManager.SharedInstance.HasAnyPairedDevice;
                }
                else
                {
                    connected = BLEManager.SharedInstance.IsConnected;
                    gotTemperartureReading = BLEManager.SharedInstance.GotTemperartureReading;
                }

                if (!IsManualEntryOn && !connected)
                {
                    if (HaccpAppSettings.SharedInstance.IsWindows)
                    {
                        return;
                    }
                    if (!BLEManager.SharedInstance.Adapter.IsBluetoothEnabled)
                    {
                        await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("TurnONBluetoothonyourdevice"));

                        return;
                    }
                    await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("Blue2TurnOnMessage"));

                    return;
                }


                if (!IsManualEntryOn && !gotTemperartureReading)
                {
                    return;
                }

                if (IsManualEntryOn && string.IsNullOrEmpty(ManualTemperature))
                {
                    await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("SpecifyTemperature"));

                    return;
                }
                if (IsManualEntryOn)
                {
                    try
                    {
                        double.Parse(ManualTemperature);
                    }
                    catch
                    {
                        Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("Specifyavalidtemperaturevalue"));
                        return;
                    }
                }
                else if (DisplayBlue2Temperature == HACCPUtil.GetResourceString("ConnectBlue2Label") ||
                         DisplayBlue2Temperature == HACCPUtil.GetResourceString("Blue2SleepString") ||
                         DisplayBlue2Temperature == HACCPUtil.GetResourceString("Blue2LowString") ||
                         DisplayBlue2Temperature == HACCPUtil.GetResourceString("Blue2HighString") &&
                         DisplayBlue2Temperature == HACCPUtil.GetResourceString("Blue2BatteryString"))
                {
                    await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("InvalidTemperatureAlert"));

                    return;
                }

                var allowedMax = HaccpAppSettings.SharedInstance.DeviceSettings.TempScale == 0 ? 9999.9 : 5537.7;
                var allowedMin = HaccpAppSettings.SharedInstance.DeviceSettings.TempScale == 0 ? -9999.9 : -5537.7;

                if (IsManualEntryOn)
                {
                    if (ManualEntryTemperature > allowedMax || ManualEntryTemperature < allowedMin)
                    {
                        await Page.ShowAlert(string.Empty, HACCPUtil.GetResourceString("InvalidTemperatureAlert"));

                        return;
                    }
                }
                else
                {
                    var lastReading = HaccpAppSettings.SharedInstance.IsWindows
                        ? WindowsBLEManager.SharedInstance.LastReading
                        : BLEManager.SharedInstance.LastReading;
                    var lastunit = HaccpAppSettings.SharedInstance.IsWindows
                        ? WindowsBLEManager.SharedInstance.LastUnit
                        : BLEManager.SharedInstance.LastUnit;

                    if (TemperatureUnit == TemperatureUnit.Celcius && lastunit != TemperatureUnit.Celcius)
                    {
                        lastReading = HACCPUtil.ConvertFahrenheitToCelsius(lastReading);
                    }
                    else if (TemperatureUnit == TemperatureUnit.Fahrenheit && lastunit != TemperatureUnit.Fahrenheit)
                    {
                        lastReading = HACCPUtil.ConvertCelsiusToFahrenheit(lastReading);
                    }

                    Blue2Temperature = lastReading;
                }

                IsBusy = true;
                RecordCommand.ChangeCanExecute();


                var temp = IsManualEntryOn ? ManualEntryTemperature : Blue2Temperature;

                var minTemp = HACCPUtil.ConvertToDouble(SelectedItem.Min);
                var maxTemp = HACCPUtil.ConvertToDouble(SelectedItem.Max);

                var convertedTemp = temp;
                if (TemperatureUnit == TemperatureUnit.Celcius)
                {
                    minTemp = Math.Round(HACCPUtil.ConvertFahrenheitToCelsius(minTemp));
                    maxTemp = Math.Round(HACCPUtil.ConvertFahrenheitToCelsius(maxTemp));
                    //convertedTemp = HACCPUtil.ConvertFahrenheitToCelsius (temp);
                }


                if (convertedTemp >= minTemp && convertedTemp <= maxTemp &&
                    HaccpAppSettings.SharedInstance.DeviceSettings.SkipRecordPreview)
                {
                    var  date = DateTime.Now;
                    long ccpid;
                    long.TryParse(SelectedItem.Ccpid, out ccpid);
                    var location = dataStore.GetLocationById(SelectedItem.LocationId);

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

                    var itemTemperature = new ItemTemperature
                    {
                        IsManualEntry = IsManualEntryOn ? (short)1 : (short)0,
                        ItemID        = SelectedItem.ItemId,
                        Temperature   = convertedTemp.ToString("0.0"),
                        ItemName      = SelectedItem.Name,
                        Max           = SelectedItem.Max,
                        Min           = SelectedItem.Min,
                        CorrAction    = 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,
                        LocName       = location.Name,
                        Note          = NoteText,
                        Blue2ID       = SelectedItem.Blue2Id
                    };
                    dataStore.AddTemperature(itemTemperature);

                    SelectedItem.RecordStatus = 1;
                    dataStore.RecordLocationItem(SelectedItem);
                    if (HaccpAppSettings.SharedInstance.IsWindows)
                    {
                        WindowsBLEManager.SharedInstance.ResetBlue2AutoOff();
                    }
                    else
                    {
                        BLEManager.SharedInstance.ResetBlue2AutoOff();
                    }

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

                    MessagingCenter.Send(new RecordSaveCompleteToast(), HaccpConstant.ToastMessage);
                }
                else
                {
                    SelectedItem.IsManualEntry       = IsManualEntryOn;
                    SelectedItem.RecordedTemperature = temp.ToString("0.0");
                    SelectedItem.TemperatureUnit     = TemperatureUnit;
                    SelectedItem.Blue2Id             = IsManualEntryOn ? string.Empty : Blue2Id;
                    SelectedItem.Note = NoteText;
                    if (HaccpAppSettings.SharedInstance.IsWindows)
                    {
                        WindowsBLEManager.SharedInstance.ResetBlue2AutoOff();
                    }
                    else
                    {
                        BLEManager.SharedInstance.ResetBlue2AutoOff();
                    }


                    await Page.NavigateToWithSelectedObject(PageEnum.RecordComplete, true, SelectedItem);

                    IsBusy = false;
                    RecordCommand.ChangeCanExecute();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error on recording {0}", ex.Message);
            }
        }
Пример #7
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();
            }
        }