/// <summary>
        /// Webservice call to reorder
        /// </summary>
        private void CallWebserviceReorder()
        {
            string apiUrl = RxConstants.sendOrder;
            App.prescriptionCollection = new PrescriptionCollection();
            Prescription prescription = new Prescription();

            prescription.drugname = App.selectedOrder.drugname;
            prescription.reason = orderDetailsViewModel.ReasonForOrdering;
            prescription.quantity = App.selectedOrder.quantity;
            prescription.amp = App.selectedOrder.amp;
            prescription.ampp = App.selectedOrder.ampp;
            prescription.vmp = App.selectedOrder.vmp;
            prescription.vmpp = App.selectedOrder.vmpp;

            App.prescriptionCollection.Add(prescription);

            SendOrderRequest objInputParam = new SendOrderRequest
            {
                pharmacyid = App.LoginPharId.ToUpper(),
                mail = App.LoginEmailId,

                pin = App.HashPIN,
                prescriptions = App.prescriptionCollection.ToList(),
                system_version = "android",
                app_version = "1.6",
                branding_version = "MLP",
                drugs_hash = ((!string.IsNullOrWhiteSpace(App.DrugDBHash)) && (!string.IsNullOrEmpty(App.DrugDBHash))) ? App.DrugDBHash : string.Empty
            };

            WebClient sendOrderWebserviceCall = new WebClient();
            var uri = new Uri(apiUrl, UriKind.RelativeOrAbsolute);
            var json = JsonHelper.Serialize(objInputParam);
            sendOrderWebserviceCall.Headers["Content-type"] = "application/json";
            sendOrderWebserviceCall.UploadStringCompleted += SendOrderwebservicecall_UploadStringCompleted;
            sendOrderWebserviceCall.UploadStringAsync(uri, "POST", json);
        }
        /// <summary>
        /// Method invoked on cliking update button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            bool _isValid = false;
            if (_isSearchDone == false)
            {
                prescription = new Prescription();

                if (!string.IsNullOrEmpty(tbxDrugSearch.Text) && !string.IsNullOrWhiteSpace(tbxDrugSearch.Text))
                {
                    if (!string.IsNullOrEmpty(tbxQty.Text) || !string.IsNullOrWhiteSpace(tbxQty.Text))
                    {
                        try
                        {

                            QtyValidator = Convert.ToInt16(tbxQty.Text);
                            QtyValidatorToString = Convert.ToString(QtyValidator);
                            if ((QtyValidator <= 0) || (QtyValidator >= 10000))
                            {
                                MessageBox.Show("Please enter a quantity between 1 and 9999 ");

                            }
                            else
                            {
                                prescription.quantity = QtyValidatorToString;
                                _isValid = true;
                                prescription.drugname = tbxDrugSearch.Text;
                                if (!string.IsNullOrEmpty(tbxReason.Text) || !string.IsNullOrWhiteSpace(tbxReason.Text))
                                {
                                    prescription.reason = tbxReason.Text;
                                }
                                else
                                {
                                    prescription.reason = string.Empty;
                                }
                                prescription.amp = string.Empty;
                                prescription.vmp = string.Empty;
                                prescription.vmpp = string.Empty;
                                prescription.ampp = string.Empty;
                            }
                        }
                        catch (OverflowException ex)
                        {
                            MessageBox.Show("Please enter a quantity between 1 and 9999");
                            tbxQty.Text = string.Empty;
                        }
                        catch (FormatException ex)
                        {
                            MessageBox.Show("Enter a number");
                            tbxQty.Text = string.Empty;
                        }
                    }
                    else
                    {
                        _isValid = false;
                        MessageBox.Show("Enter quantity of drug.");
                    }
                }

                else
                {
                    _isValid = false;
                    MessageBox.Show("Enter drug name.");
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(tbxDrugSearch.Text) || !string.IsNullOrWhiteSpace(tbxDrugSearch.Text))
                {
                    if (!string.IsNullOrEmpty(tbxQty.Text) || !string.IsNullOrWhiteSpace(tbxQty.Text))
                    {
                        try
                        {
                            QtyValidator = Convert.ToInt16(tbxQty.Text);
                            QtyValidatorToString = Convert.ToString(QtyValidator);
                            if ((QtyValidator <= 0) || (QtyValidator >= 10000))
                            {
                                MessageBox.Show("Please enter a quantity between 1 and 9999 ");

                            }
                            else
                            {
                                prescription.quantity = QtyValidatorToString;
                                _isValid = true;
                                prescription.drugname = tbxDrugSearch.Text;
                                if (!string.IsNullOrEmpty(tbxReason.Text) || !string.IsNullOrWhiteSpace(tbxReason.Text))
                                {
                                    prescription.reason = tbxReason.Text;
                                }
                                else
                                {
                                    prescription.reason = string.Empty;
                                }
                            }
                        }
                        catch (OverflowException ex)
                        {
                            MessageBox.Show("Please enter a quantity between 1 and 9999");
                            tbxQty.Text = string.Empty;
                        }
                        catch (FormatException ex)
                        {
                            MessageBox.Show("Enter a number");
                            tbxQty.Text = string.Empty;
                        }
                    }

                    else
                    {
                        _isValid = false;
                        MessageBox.Show("Enter quantity of drug.");
                    }
                }

                else
                {
                    _isValid = false;
                    MessageBox.Show("Enter drug name.");
                }

            }

            if (_isValid == true)
            {
                App.autoCompleteEditListDrug.Add(tbxDrugSearch.Text);
                App.prescriptionCollection.ElementAt(App.selectedDrugIndex).amp = prescription.amp;
                App.prescriptionCollection.ElementAt(App.selectedDrugIndex).ampp = prescription.ampp;
                App.prescriptionCollection.ElementAt(App.selectedDrugIndex).drugname = prescription.drugname;
                App.prescriptionCollection.ElementAt(App.selectedDrugIndex).quantity = prescription.quantity;
                App.prescriptionCollection.ElementAt(App.selectedDrugIndex).reason = prescription.reason;
                App.prescriptionCollection.ElementAt(App.selectedDrugIndex).vmp = prescription.vmp;
                App.prescriptionCollection.ElementAt(App.selectedDrugIndex).vmpp = prescription.vmpp;
                NavigationService.Navigate(new Uri(PageURL.navigateToNewRepeatSummaryURL, UriKind.Relative));
            }
        }
        /// <summary>
        /// Drug search
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstDrugSearch_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            selectedData = (sender as ListBox).SelectedItem as DrugDetails;
            _isSearchDone = true;
            if (selectedData != null)
            {
                prescription = new Prescription();

                if (!string.IsNullOrEmpty(selectedData.amp))
                    prescription.amp = selectedData.amp;
                else
                    prescription.amp = string.Empty;
                if (!string.IsNullOrEmpty(selectedData.ampp))
                    prescription.ampp = selectedData.ampp;
                else
                    prescription.ampp = string.Empty;

                tbxDrugSearch.Text = selectedData.drugname;

                if (!string.IsNullOrEmpty(selectedData.vmp))
                    prescription.vmp = selectedData.vmp;
                else
                    prescription.vmp = string.Empty;

                if (!string.IsNullOrEmpty(selectedData.vmpp))
                    prescription.vmpp = selectedData.vmpp;
                else
                    prescription.vmpp = string.Empty;

                PopupSearch.IsOpen = false;
            }
            else
            {
                PopupSearch.IsOpen = true;
            }
        }
        /// <summary>
        /// Event for delete drug click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteDrug_Click(object sender, RoutedEventArgs e)
        {
            selectedDataToDelete = (sender as MenuItem).DataContext as Prescription;
            NewRepeatSummaryViewModel _objNewRepeatSummaryViewModel = this.DataContext as NewRepeatSummaryViewModel;
            _objNewRepeatSummaryViewModel.DrugSearchCollection.Remove(selectedDataToDelete);

            App.prescriptionCollection = _objNewRepeatSummaryViewModel.DrugSearchCollection;

            if (_objNewRepeatSummaryViewModel.DrugSearchCollection.Count == 0)
            {

                tbkNameHeader.Visibility = Visibility.Collapsed;
                tbkQtyHeader.Visibility = Visibility.Collapsed;
                txbNoItems.Visibility = Visibility.Visible;
            }
        }
        /// <summary>
        /// Method invoked on clikking add button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            bool _isValid=false;
            if (_isSearchDone == false)
            {
                prescription = new Prescription();

                if (!string.IsNullOrEmpty(tbxDrugSearch.Text) && !string.IsNullOrWhiteSpace(tbxDrugSearch.Text))
                {
                        if (!string.IsNullOrEmpty(tbxQty.Text) || !string.IsNullOrWhiteSpace(tbxQty.Text))
                        {
                            try
                            {
                                QtyValidator = Convert.ToInt16(tbxQty.Text);
                                QtyValidatorToString = Convert.ToString(QtyValidator);
                                if ((QtyValidator <= 0) || (QtyValidator >= 10000))
                                {
                                    MessageBox.Show("Please enter a quantity between 1 and 9999 ");
                                    tbxQty.Text = string.Empty;
                                }
                                else
                                {
                                    prescription.quantity = QtyValidatorToString;
                                    _isValid = true;
                                    prescription.drugname = tbxDrugSearch.Text;
                                    if (!string.IsNullOrEmpty(tbxReason.Text) || !string.IsNullOrWhiteSpace(tbxReason.Text))
                                    {
                                        prescription.reason = tbxReason.Text;
                                    }
                                    else
                                    {
                                        prescription.reason = string.Empty;
                                    }
                                    prescription.amp = string.Empty;
                                    prescription.vmp = string.Empty;
                                    prescription.vmpp = string.Empty;
                                    prescription.ampp = string.Empty;
                                }
                            }
                            catch (OverflowException ex)
                            {
                                MessageBox.Show("Please enter a quantity between 1 and 9999");
                                tbxQty.Text = string.Empty;
                            }
                            catch (FormatException ex)
                            {
                                MessageBox.Show("Enter a number");
                                tbxQty.Text = string.Empty;
                            }
                        }
                        else
                        {
                            _isValid = false;
                            MessageBox.Show("Enter quantity of drug.");
                        }
                   
                }

                else
                {
                    _isValid = false;
                    MessageBox.Show("Enter drug name.");
                }
            }

            else
            {
                if (!string.IsNullOrEmpty(tbxDrugSearch.Text) || !string.IsNullOrWhiteSpace(tbxDrugSearch.Text))
                {
                    if (!string.IsNullOrEmpty(tbxQty.Text) || !string.IsNullOrWhiteSpace(tbxQty.Text))
                    {
                        try
                        {
                            QtyValidator = Convert.ToInt16(tbxQty.Text);
                            QtyValidatorToString = Convert.ToString(QtyValidator);
                            if ((QtyValidator <= 0) || (QtyValidator >= 10000))
                            {
                                MessageBox.Show("Please enter a quantity between 1 and 9999 ");
                                tbxQty.Text = string.Empty;
                            }
                            else
                            {
                                prescription.quantity = QtyValidatorToString;
                                _isValid = true;
                                prescription.drugname = tbxDrugSearch.Text;
                                if (!string.IsNullOrEmpty(tbxReason.Text) || !string.IsNullOrWhiteSpace(tbxReason.Text))
                                {
                                    prescription.reason = tbxReason.Text;
                                }
                                else
                                {
                                    prescription.reason = string.Empty;
                                }
                            }
                        }
                        catch (OverflowException ex)
                        {
                            MessageBox.Show("Please enter a quantity between 1 and 9999");
                            tbxQty.Text = string.Empty;
                        }
                        catch (FormatException ex)
                        {
                            MessageBox.Show("Enter a number");
                            tbxQty.Text = string.Empty;
                        }
                    }

                    else
                    {
                        _isValid = false;
                        MessageBox.Show("Enter quantity of drug.");
                    }
                }

                else
                {
                    _isValid = false;
                    MessageBox.Show("Enter drug name.");
                }
            }

            if (_isValid == true)
            {
                prescriptionCollection.Add(prescription);

                App.autoCompleteListDrug.Add(tbxDrugSearch.Text);

                tbxDrugSearch.Text = string.Empty;
                tbxQty.Text = string.Empty;
                tbxReason.Text = string.Empty;

                NewRepeatSummaryViewModel _objNewRepeatSummaryViewModel = this.DataContext as NewRepeatSummaryViewModel;
                _objNewRepeatSummaryViewModel.DrugSearchCollection = prescriptionCollection;
                App.prescriptionCollection = prescriptionCollection;

                this.DataContext = _objNewRepeatSummaryViewModel;

                tbkNameHeader.Visibility = Visibility.Visible;
                tbkQtyHeader.Visibility = Visibility.Visible;
                txbNoItems.Visibility = Visibility.Collapsed;
            }

        }