/// <summary>
        /// Method to bind the autocomplete list
        /// </summary>
        /// <param name="pillsReminderModelCol"></param>
        private void BindPillsinAutoCompleteList(PillsReminderModelCol pillsReminderModelCol)
        {
            List <string> autoCompleteLst = new List <string>();

            PillsReminderModel objPillsPillsReminderModel;

            foreach (var item in pillsReminderModelCol)
            {
                objPillsPillsReminderModel = new PillsReminderModel {
                    PillName = item.PillName, NumberOfPills = item.NumberOfPills
                };
                autoCompleteLst.Add(objPillsPillsReminderModel.PillName);
            }
            acbDrugSearch.ItemsSource = autoCompleteLst;
        }
        /// <summary>
        /// Method to bind the autocomplete list
        /// </summary>
        /// <param name="pillsReminderModelCol"></param>
        private void BindPillsinAutoCompleteList(PillsReminderModelCol pillsReminderModelCol)
        {
            List<string> autoCompleteLst = new List<string>();

            PillsReminderModel objPillsPillsReminderModel;

            foreach (var item in pillsReminderModelCol)
            {
                objPillsPillsReminderModel = new PillsReminderModel { PillName = item.PillName, NumberOfPills = item.NumberOfPills };
                autoCompleteLst.Add(objPillsPillsReminderModel.PillName);
            }
            acbDrugSearch.ItemsSource = autoCompleteLst;
        }
        /// <summary>
        /// Method for back key
        /// </summary>
        /// <param name="e"></param>
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            PillsReminderModelCol objReminderCollection = new PillsReminderModelCol();
            DateTime DateSet=new DateTime();
            DateTime TimeSet = new DateTime();
          

            if (App.HeaderPillsReminder.Equals("daily morning"))
            {
                objReminderCollection = App.DailyMorningPillsCollection;
                DateSet = App.DailyMorningReminderDate;
                TimeSet=App.DailyMorningReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("daily afternoon"))
            {
                objReminderCollection = App.DailyAfternoonPillsCollection;
                DateSet = App.DailyAfternoonReminderDate;
                TimeSet=App.DailyAfternoonReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("daily evening"))
            {
                objReminderCollection = App.DailyEveningPillsCollection;
                DateSet = App.DailyEveningReminderDate;
                TimeSet=App.DailyEveningReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("daily night"))
            {
                objReminderCollection = App.DailyNightPillsCollection;
                DateSet = App.DailyNightReminderDate;
                TimeSet=App.DailyNightReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("weekly"))
            {
                objReminderCollection = App.WeeklyPillsCollection;
                DateSet = App.WeeklyReminderDate;
                TimeSet=App.WeeklyReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("monthly"))
            {
                objReminderCollection = App.MonthlyPillsCollection;
                DateSet = App.MonthlyReminderDate;
                TimeSet=App.MonthlyReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("every 28 days"))
            {
                objReminderCollection = App.Every28DaysPillsCollection;
                DateSet = App.Every28DaysReminderDate;
                TimeSet = App.Every28DaysReminderTime;
            }

            if (PopupSearch.IsOpen)
            {
                PopupSearch.IsOpen = false;
                ApplicationBar.IsVisible = true;
                ((ApplicationBarIconButton)this.ApplicationBar.Buttons[0]).IsEnabled = true;
                LayoutRoot.IsHitTestVisible = true;
                e.Cancel = true;
            }
            else if (popupConfirmLeavePage.IsOpen)
            {
                popupConfirmLeavePage.IsOpen = false;
                LayoutRoot.IsHitTestVisible = true;
                e.Cancel = true;
            }
            else   if (objReminderCollection != null)
            {
                if (App.IsCheckedTempStore != App.IsChecked || App.ReminderDateTemp != DateSet || App.ReminderTimeTemp != TimeSet || (App.PillsReminderModelColLocalStorage.Count != objReminderCollection.ToList().Count && objReminderCollection != null) || App.IsPillUpdated == true)
                {
                    App.IsPillUpdated = false;
                    popupConfirmLeavePage.IsOpen = true;
                    LayoutRoot.IsHitTestVisible = false;
                    e.Cancel = true;
                }
                else
                {
                    NavigationService.Navigate(new Uri(PageURL.navigateToHomePanoramaURL + "?goto=3", UriKind.RelativeOrAbsolute));

                }
            }
            else if (objReminderCollection==null)
            {
                if (App.IsCheckedTempStore != App.IsChecked || App.ReminderDateTemp != DateSet || App.ReminderTimeTemp != TimeSet || App.IsPillUpdated == true)
                {
                    App.IsPillUpdated = false;
                    popupConfirmLeavePage.IsOpen = true;
                    LayoutRoot.IsHitTestVisible = false;
                    e.Cancel = true;
                }
                else
                {
                    NavigationService.Navigate(new Uri(PageURL.navigateToHomePanoramaURL + "?goto=3", UriKind.RelativeOrAbsolute));

                }
            }

           
        }
        /// <summary>
        /// Method for back key
        /// </summary>
        /// <param name="e"></param>
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            PillsReminderModelCol objReminderCollection = new PillsReminderModelCol();
            DateTime DateSet = new DateTime();
            DateTime TimeSet = new DateTime();


            if (App.HeaderPillsReminder.Equals("daily morning"))
            {
                objReminderCollection = App.DailyMorningPillsCollection;
                DateSet = App.DailyMorningReminderDate;
                TimeSet = App.DailyMorningReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("daily afternoon"))
            {
                objReminderCollection = App.DailyAfternoonPillsCollection;
                DateSet = App.DailyAfternoonReminderDate;
                TimeSet = App.DailyAfternoonReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("daily evening"))
            {
                objReminderCollection = App.DailyEveningPillsCollection;
                DateSet = App.DailyEveningReminderDate;
                TimeSet = App.DailyEveningReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("daily night"))
            {
                objReminderCollection = App.DailyNightPillsCollection;
                DateSet = App.DailyNightReminderDate;
                TimeSet = App.DailyNightReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("weekly"))
            {
                objReminderCollection = App.WeeklyPillsCollection;
                DateSet = App.WeeklyReminderDate;
                TimeSet = App.WeeklyReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("monthly"))
            {
                objReminderCollection = App.MonthlyPillsCollection;
                DateSet = App.MonthlyReminderDate;
                TimeSet = App.MonthlyReminderTime;
            }
            else if (App.HeaderPillsReminder.Equals("every 28 days"))
            {
                objReminderCollection = App.Every28DaysPillsCollection;
                DateSet = App.Every28DaysReminderDate;
                TimeSet = App.Every28DaysReminderTime;
            }

            if (PopupSearch.IsOpen)
            {
                PopupSearch.IsOpen       = false;
                ApplicationBar.IsVisible = true;
                ((ApplicationBarIconButton)this.ApplicationBar.Buttons[0]).IsEnabled = true;
                LayoutRoot.IsHitTestVisible = true;
                e.Cancel = true;
            }
            else if (popupConfirmLeavePage.IsOpen)
            {
                popupConfirmLeavePage.IsOpen = false;
                LayoutRoot.IsHitTestVisible  = true;
                e.Cancel = true;
            }
            else if (objReminderCollection != null)
            {
                if (App.IsCheckedTempStore != App.IsChecked || App.ReminderDateTemp != DateSet || App.ReminderTimeTemp != TimeSet || (App.PillsReminderModelColLocalStorage.Count != objReminderCollection.ToList().Count&& objReminderCollection != null) || App.IsPillUpdated == true)
                {
                    App.IsPillUpdated            = false;
                    popupConfirmLeavePage.IsOpen = true;
                    LayoutRoot.IsHitTestVisible  = false;
                    e.Cancel = true;
                }
                else
                {
                    NavigationService.Navigate(new Uri(PageURL.navigateToHomePanoramaURL + "?goto=3", UriKind.RelativeOrAbsolute));
                }
            }
            else if (objReminderCollection == null)
            {
                if (App.IsCheckedTempStore != App.IsChecked || App.ReminderDateTemp != DateSet || App.ReminderTimeTemp != TimeSet || App.IsPillUpdated == true)
                {
                    App.IsPillUpdated            = false;
                    popupConfirmLeavePage.IsOpen = true;
                    LayoutRoot.IsHitTestVisible  = false;
                    e.Cancel = true;
                }
                else
                {
                    NavigationService.Navigate(new Uri(PageURL.navigateToHomePanoramaURL + "?goto=3", UriKind.RelativeOrAbsolute));
                }
            }
        }
        /// <summary>
        /// Show Pills
        /// </summary>
        /// <param name="pillsCol"></param>
        /// <returns></returns>
        private string ShowPills(PillsReminderModelCol pillsCol)
        {
            string pillNames = string.Empty;
            foreach (var item in pillsCol)
            {
                if (string.IsNullOrEmpty(pillNames) || (string.IsNullOrWhiteSpace(pillNames)))
                {
                    if (item.NumberOfPills.Contains("x"))
                        pillNames = string.Join(", ", string.Concat(item.NumberOfPills.Substring(3), " ", item.PillName));
                    else
                    {
                        item.NumberOfPills = string.Concat(" x ", item.NumberOfPills);
                        pillNames = string.Join(", ", string.Concat(item.NumberOfPills.Substring(3), " ", item.PillName));
                    }
                }

                else
                {
                    if (item.NumberOfPills.Contains("x"))
                        pillNames = string.Join(", ", pillNames, string.Concat(item.NumberOfPills.Substring(3), " ", item.PillName));
                    else
                    {
                        item.NumberOfPills = string.Concat(" x ", item.NumberOfPills);
                        pillNames = string.Join(", ", pillNames, string.Concat(item.NumberOfPills.Substring(3), " ", item.PillName));
                    }
                }

            }
            return pillNames;
        }
        /// <summary>
        /// Method to add pills to list
        /// </summary>
        private void AddingToList()
        {
            if (!string.IsNullOrEmpty(PillNames) && !string.IsNullOrWhiteSpace(PillNames))
            {
               
                if (!string.IsNullOrEmpty(Qty) && !string.IsNullOrWhiteSpace(Qty))
                {
                    try
                    {
                       int QtyToInt = Convert.ToInt16(Qty);

                       
                        string appendQty = String.Concat(" x ", Qty);
                            var pillCol = new PillsReminderModel { PillName = PillNames, NumberOfPills = appendQty };
                            
                            if (PillsReminderCollection == null)
                            {
                                PillsReminderCollection = new PillsReminderModelCol();
                                PillsReminderCollection.Add(pillCol);
                            }
                                 
                            else
                            {
                                PillsReminderCollection.Add(pillCol);
                            }
                            
                            if (HeaderPillsReminder.Equals("daily morning"))
                           
                                App.DailyMorningPillsCollection = PillsReminderCollection;
                                
                          
                            else if (HeaderPillsReminder.Equals("daily afternoon"))
                                App.DailyAfternoonPillsCollection = PillsReminderCollection;
                            else if (HeaderPillsReminder.Equals("daily evening"))
                                App.DailyEveningPillsCollection = PillsReminderCollection;
                            else if (HeaderPillsReminder.Equals("daily night"))
                                App.DailyNightPillsCollection = PillsReminderCollection;
                            else if (HeaderPillsReminder.Equals("weekly"))
                                App.WeeklyPillsCollection = PillsReminderCollection;
                            else if (HeaderPillsReminder.Equals("monthly"))
                                App.MonthlyPillsCollection = PillsReminderCollection;
                            else if (HeaderPillsReminder.Equals("every 28 days"))
                                App.Every28DaysPillsCollection = PillsReminderCollection;
                            
                            Qty = string.Empty;
                            PillNames = string.Empty;
                          
                    }
                    catch (OverflowException ex)
                    {
                        MessageBox.Show("Please enter a quantity between 1 and 9999");
                        Qty = string.Empty;
                    }
                    catch (FormatException ex)
                    {
                        MessageBox.Show("Enter a number");
                        Qty = string.Empty;
                    }
                }
                else
                    MessageBox.Show("Please enter quantity.");
           
            }
            else
            {
                MessageBox.Show("Please enter pill name.");
            }
        }
 /// <summary>
 /// Method to append special characters
 /// </summary>
 /// <param name="PillsReminderCollection"></param>
 /// <returns></returns>
 private PillsReminderModelCol AppendSpecialCharacter(PillsReminderModelCol PillsReminderCollection)
 {
     PillsReminderModelCol obj = new PillsReminderModelCol();
     foreach (var item in PillsReminderCollection)
     {
         if (item.NumberOfPills.Contains("x"))
         { }
         else
         {
             item.NumberOfPills = string.Concat(" x ", item.NumberOfPills);
         }
         obj.Add(item);
     }
     return obj;
 }
        /// <summary>
        /// Display saved values
        /// </summary>
        private void DisplayValues()
        {
            if (HeaderPillsReminder.Equals("daily morning"))
            {
                PillsReminderCollection = App.DailyMorningPillsCollection != null ? App.DailyMorningPillsCollection : null;

                if (PillsReminderCollection != null)
                {
                    
                    objPillsReminderModelCol = AppendSpecialCharacter(PillsReminderCollection);
                    if (App.PillsReminderModelColLocalStorage.Count == 0 && !App.IsReminderToombstoned)
                    {
                       
                      if(!App.IsEditCancelled)
                            App.PillsReminderModelColLocalStorage = App.DailyMorningPillsCollection.ToList(); 
                       
                      
                    }
                }
                else
                    objPillsReminderModelCol = PillsReminderCollection;
                App.ReminderToDisplay = "daily morning reminder";
                ReminderDate = App.DailyMorningReminderDate;
                ReminderTime = App.DailyMorningReminderTime;
                ReminderStatus = App.DailyMorningReminderOnOff;
                if (ReminderStatus.Equals("Off") || ReminderStatus.Equals(string.Empty))
                {
                    IsChecked = false;
                    App.IsChecked = IsChecked;
                   
                    Bgcolor = "#1cc183";
                    App.Bgcolor = Bgcolor;
                }
               
                else if (ReminderStatus.Equals("On"))
                {
                    IsChecked = true;
                    App.IsChecked = IsChecked;
                   
                    Bgcolor = "#00FF00";
                    App.Bgcolor = Bgcolor;
                }
            }
            else if (HeaderPillsReminder.Equals("daily afternoon"))
            {
                PillsReminderCollection = App.DailyAfternoonPillsCollection != null ? App.DailyAfternoonPillsCollection : null;

                if (PillsReminderCollection != null)
                {
                    objPillsReminderModelCol = AppendSpecialCharacter(PillsReminderCollection);
                    if (App.PillsReminderModelColLocalStorage.Count == 0 && !App.IsReminderToombstoned)
                    {
                        if (!App.IsEditCancelled)
                        App.PillsReminderModelColLocalStorage = App.DailyAfternoonPillsCollection.ToList();
                    }
                }
                else
                    objPillsReminderModelCol = PillsReminderCollection;
                App.ReminderToDisplay = "daily afternoon reminder";
                ReminderDate = App.DailyAfternoonReminderDate;
                ReminderTime = App.DailyAfternoonReminderTime;
                ReminderStatus = App.DailyAfternoonReminderOnOff;
                if (ReminderStatus.Equals("Off") )
                {
                    IsChecked = false;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#1cc183";
                    App.Bgcolor = Bgcolor;
                }
                else
                {
                    IsChecked = true;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#00FF00";
                    App.Bgcolor = Bgcolor;
                }
            }
            else if (HeaderPillsReminder.Equals("daily evening"))
            {
                PillsReminderCollection = App.DailyEveningPillsCollection != null ? App.DailyEveningPillsCollection : null;

                if (PillsReminderCollection != null)
                {
                    objPillsReminderModelCol = AppendSpecialCharacter(PillsReminderCollection);
                    if (App.PillsReminderModelColLocalStorage.Count == 0 && !App.IsReminderToombstoned)
                    {
                        if (!App.IsEditCancelled)
                        App.PillsReminderModelColLocalStorage = App.DailyEveningPillsCollection.ToList();
                    }
                }
                else
                    objPillsReminderModelCol = PillsReminderCollection;

                App.ReminderToDisplay = "daily evening reminder";
                ReminderDate = App.DailyEveningReminderDate;
                ReminderTime = App.DailyEveningReminderTime;
                ReminderStatus = App.DailyEveningReminderOnOff;
                if (ReminderStatus.Equals("Off"))
                {
                    IsChecked = false;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#1cc183";
                    App.Bgcolor = Bgcolor;
                }
                else
                {
                    IsChecked = true;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#00FF00";
                    App.Bgcolor = Bgcolor;
                }
            }
            else if (HeaderPillsReminder.Equals("daily night"))
            {
                PillsReminderCollection = App.DailyNightPillsCollection != null ? App.DailyNightPillsCollection : null;

                if (PillsReminderCollection != null)
                {
                    objPillsReminderModelCol = AppendSpecialCharacter(PillsReminderCollection);
                    if (App.PillsReminderModelColLocalStorage.Count == 0 && !App.IsReminderToombstoned)
                    {
                        if (!App.IsEditCancelled)
                        App.PillsReminderModelColLocalStorage = App.DailyNightPillsCollection.ToList();
                    }
                }
                else
                    objPillsReminderModelCol = PillsReminderCollection;
                App.ReminderToDisplay = "daily night reminder";
                ReminderDate = App.DailyNightReminderDate;
                ReminderTime = App.DailyNightReminderTime;
                ReminderStatus = App.DailyNightReminderOnOff;
                if (ReminderStatus.Equals("Off"))
                {
                    IsChecked = false;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#1cc183";
                    App.Bgcolor = Bgcolor;
                }
                else
                {
                    IsChecked = true;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#00FF00";
                    App.Bgcolor = Bgcolor;
                }
            }
            else if (HeaderPillsReminder.Equals("weekly"))
            {
                PillsReminderCollection = App.WeeklyPillsCollection != null ? App.WeeklyPillsCollection : null;

                if (PillsReminderCollection != null)
                {
                    objPillsReminderModelCol = AppendSpecialCharacter(PillsReminderCollection);
                    if (App.PillsReminderModelColLocalStorage.Count == 0 && !App.IsReminderToombstoned)
                    {
                        if (!App.IsEditCancelled)
                        App.PillsReminderModelColLocalStorage = App.WeeklyPillsCollection.ToList();
                    }
                }
                else
                    objPillsReminderModelCol = PillsReminderCollection;
                App.ReminderToDisplay = "weekly reminder";
                ReminderDate = App.WeeklyReminderDate;
                ReminderTime = App.WeeklyReminderTime;
                ReminderStatus = App.WeeklyReminderOnOff;
                if (ReminderStatus.Equals("Off"))
                {
                    IsChecked = false;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#1cc183";
                    App.Bgcolor = Bgcolor;
                }
                else
                {
                    IsChecked = true;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#00FF00";
                    App.Bgcolor = Bgcolor;
                }
            }
            else if (HeaderPillsReminder.Equals("monthly"))
            {
                PillsReminderCollection = App.MonthlyPillsCollection != null ? App.MonthlyPillsCollection : null;

                if (PillsReminderCollection != null)
                {
                    objPillsReminderModelCol = AppendSpecialCharacter(PillsReminderCollection);
                    if (App.PillsReminderModelColLocalStorage.Count == 0 && !App.IsReminderToombstoned)
                    {
                        if (!App.IsEditCancelled)
                        App.PillsReminderModelColLocalStorage = App.MonthlyPillsCollection.ToList();
                    }
                }
                else
                    objPillsReminderModelCol = PillsReminderCollection;
                App.ReminderToDisplay = "monthly reminder";
                ReminderDate = App.MonthlyReminderDate;
                ReminderTime = App.MonthlyReminderTime;
                ReminderStatus = App.MonthlyReminderOnOff;
                if (ReminderStatus.Equals("Off"))
                {
                    IsChecked = false;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#1cc183";
                    App.Bgcolor = Bgcolor;
                }
                else
                {
                    IsChecked = true;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#00FF00";
                    App.Bgcolor = Bgcolor;
                }
            }
            else if (HeaderPillsReminder.Equals("every 28 days"))
            {
                PillsReminderCollection = App.Every28DaysPillsCollection != null ? App.Every28DaysPillsCollection : null;

                if (PillsReminderCollection != null)
                {
                    objPillsReminderModelCol = AppendSpecialCharacter(PillsReminderCollection);
                    if (App.PillsReminderModelColLocalStorage.Count == 0 && !App.IsReminderToombstoned)
                    {
                        if (!App.IsEditCancelled)
                        App.PillsReminderModelColLocalStorage = App.Every28DaysPillsCollection.ToList();
                    }
                }
                else
                    objPillsReminderModelCol = PillsReminderCollection;
                App.ReminderToDisplay = "every 28 days reminder";
                ReminderDate = App.Every28DaysReminderDate;
                ReminderTime = App.Every28DaysReminderTime;
                ReminderStatus = App.Every28DaysReminderOnOff;
                if (ReminderStatus.Equals("Off"))
                {
                    IsChecked = false;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#1cc183";
                    App.Bgcolor = Bgcolor;
                }
                else
                {
                    IsChecked = true;
                    App.IsChecked = IsChecked;
                    Bgcolor = "#00FF00";
                    App.Bgcolor = Bgcolor;
                }
            }
        }