private void LvOrders_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ListView clicked = (ListView)sender;

            string[]  words = clicked.Name.Split('_');
            DataRow[] dr    = dSet.Select("RowId = '" + words[1] + "'");



            b.OrderId = dr[0].ItemArray[2].ToString();

            DataTable dt = new DataTable();

            dt = _objbal.getordertransactiondtls(dr[0].ItemArray[2].ToString());
            string  trstatus    = dt.Rows[0]["Transactionstatus"].ToString();
            decimal totalamount = Convert.ToDecimal(dt.Rows[0]["Totalamount"].ToString());

            if (trstatus == "SuccessfulTransaction" || trstatus == "your transaction is successfull")
            {
                b.StatusId    = 4;
                b.totalamount = Convert.ToDecimal(dt.Rows[0]["Totalamount"].ToString());
            }
            else
            {
                b.StatusId    = 2;
                b.totalamount = 0;
            }
            b.EmpCode = dr[0].ItemArray[4].ToString();

            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Order is Done ?", "Order Preparation", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                string result = _objbal.UpdateTickets(b);
                //StackPanel s = new StackPanel();
                stkMain.Children.Clear();
                try
                {
                    string            st = " Order id " + b.OrderId + "Cooking completed";
                    SpeechSynthesizer sp = new SpeechSynthesizer();
                    sp.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult);
                    sp.Volume = 100;
                    sp.Rate   = -3;
                    sp.Speak(st);
                }
                catch (Exception)
                {
                    MessageBox.Show("Switch on the tv in kitchen");
                }
            }
            else if (messageBoxResult == MessageBoxResult.No)
            {
                UCTickets uc1 = new UCTickets();
                uc1.lvOrders.ItemsSource = null;
                stkMain.Children.Clear();
            }
            addUserControl();
        }
        private void addUserControl()
        {
            stkMain.Background = new SolidColorBrush(Colors.Azure);
            if (Application.Current.Properties["restcode"] == null)
            {
                b.RestCode = "BW";
            }
            else

            {
                b.RestCode = Application.Current.Properties["restcode"].ToString();
            }
            //  b.RestCode = "BW";
            dSet = _objbal.GetOrders(b);
            lblCurrentTime.Content = "Current Time :" + DateTime.Now.ToString("hh:mm");
            if (dSet.Rows.Count > 0)
            {
                lblTicketsPending.Content = dSet.Rows.Count.ToString();

                DataColumn ElapsedTime = new System.Data.DataColumn("ElapsedTime", typeof(System.String));
                DataColumn RowId       = new System.Data.DataColumn("RowId", typeof(System.String));
                dSet.Columns.Add(ElapsedTime);
                dSet.Columns.Add(RowId);
                for (int i = 0; i < dSet.Rows.Count; i++)
                {
                    UCTickets  uc = new UCTickets();
                    StackPanel sc = new StackPanel();



                    uc.Name = "UC" + i.ToString();
                    uc.lblOrderID.Content      = dSet.Rows[i]["OrderId"].ToString();
                    uc.lblItemsCount.Content   = "Items : " + dSet.Rows[i][0].ToString();
                    uc.txtUserRequests.Text    = "Customer Request : " + dSet.Rows[i]["CustRequest"].ToString();
                    uc.txtDeliveryTime.Text    = dSet.Rows[i]["ToBeDelivered"].ToString();
                    uc.lblordertype.Content    = dSet.Rows[i]["OrderType"].ToString();
                    uc.lblcustomername.Content = dSet.Rows[i]["CustomerFName"].ToString();
                    uc.lblcustphone.Content    = dSet.Rows[i]["CustPhoneNumber"].ToString();
                    if (uc.lblordertype.Content.ToString() == "Mobile app  order")
                    {
                        uc.stkmn.Background      = Brushes.LightBlue;
                        uc.imgmobicon.Visibility = Visibility.Visible;
                    }
                    if (dSet.Rows[i]["TransactionId"].ToString() == "")
                    {
                        uc.lblosts.Content = "Not Paid";
                    }
                    else if (dSet.Rows[i]["TransactionId"].ToString() == "COD")
                    {
                        uc.lblosts.Content = "Not Paid";
                    }
                    else
                    {
                        uc.lblosts.Content = "Paid";
                    }
                    DateTime dtOrderTime = Convert.ToDateTime(dSet.Rows[i]["OrderTime"].ToString());
                    TimeSpan timespan    = new TimeSpan();
                    DateTime time        = dtOrderTime.Add(timespan);
                    string   displayTime = time.ToString("hh:mm");
                    //Display the order time hh:mm
                    uc.lblOrderTime.Content = "OrderTime : " + String.Format("{0:g}", displayTime);

                    var b1 = DateTime.Parse(DateTime.Now.ToString()) - (DateTime.Parse(dtOrderTime.ToString()));

                    var a1 = b1;
                    if (a1.Hours == 0)
                    {
                        if (a1.Minutes > 10 && a1.Minutes < 19)
                        {
                            uc.lblElapsedTime.Background = Brushes.White;
                        }
                        else if (a1.Minutes > 21 && a1.Minutes < 30)
                        {
                            uc.lblElapsedTime.Background = Brushes.Yellow;
                        }

                        else if (a1.Minutes >= 30)
                        {
                            uc.lblElapsedTime.Background = Brushes.Red;
                        }
                    }
                    else
                    {
                        uc.lblElapsedTime.Background = Brushes.Red;
                    }
                    if (a1.Hours > 0)
                    {
                        dSet.Rows[i]["ElapsedTime"] = a1.Hours + " Hours " + a1.Minutes + " Minutes ";
                    }
                    if (a1.Hours <= 0)
                    {
                        dSet.Rows[i]["ElapsedTime"] = a1.Minutes + " Minutes ";
                    }



                    uc.lblElapsedTime.Content = dSet.Rows[i]["ElapsedTime"];


                    dSet.Rows[i]["RowId"] = i + 1;
                    uc.lvOrders.Name      = "lvOrders" + "_" + dSet.Rows[i]["RowId"];
                    sc.Children.Add(uc);
                    DataTable dSet1 = new DataTable();
                    b.OrderId = dSet.Rows[i]["OrderId"].ToString();
                    dSet1     = _objbal.GetOrdersDetails(b);
                    if (dSet1.Rows.Count > 0)
                    {
                        uc.lvOrders.ItemsSource = dSet1.DefaultView;
                    }
                    stkMain.Children.Add(sc);
                }
            }
            else if (dSet.Rows.Count == 0)
            {
                lblTicketsPending.Content = 0;
            }
        }