Example #1
0
 private void submit_Click(object sender, RoutedEventArgs e)
 {
     orderInfo.Items.Clear();
     guestName.IsReadOnly = false;
     address.IsReadOnly   = false;
     if (menu2.Items.Count == 0)
     {
         MessageBox.Show("你啥都不点,我给你吃啥呀");
         return;
     }
     for (int i = 0; i < menu2.Items.Count; i++)
     {
         menulist   ml       = menu2.Items[i] as menulist;
         StackPanel sp       = ml.FindName("sp") as StackPanel;
         Label      nametext = sp.Children[0] as Label;
         Label      price    = sp.Children[1] as Label;
         counters   cter     = sp.Children[2] as counters;
         TextBlock  num      = cter.FindName("num") as TextBlock;
         menulist   temp     = new menulist();
         temp.name.Content  = nametext.Content;
         temp.price.Content = price.Content;
         TextBlock tempnum = temp.counters.FindName("num") as TextBlock;
         tempnum.Text = num.Text;
         temp.counters.plus.Visibility  = Visibility.Hidden;
         temp.counters.minus.Visibility = Visibility.Hidden;
         this.orderInfo.Items.Add(temp);
     }
     tab.SelectedItem        = tab3;
     confirmOrder.Visibility = Visibility.Visible;
 }
Example #2
0
        private void menuRefresh()
        {
            menu1.Items.Clear();
            menu2.Items.Clear();
            string          sql      = "select name,price from menu";
            MySqlDataReader get_menu = getmysqlread(sql);

            while (get_menu.Read())
            {
                try
                {
                    menulist temp = new menulist();
                    temp.name.Content          = get_menu["name"];
                    temp.price.Content         = get_menu["price"];
                    temp.counters.plus.Click  += new RoutedEventHandler(this.menu_Changed);
                    temp.counters.minus.Click += new RoutedEventHandler(this.menu_Changed);
                    this.menu1.Items.Add(temp);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            total.Content = "0.0";
        }
Example #3
0
        public void createOrder(string input, ListBox orderInfo)
        {
            int    state  = 0;
            int    sStart = 0;
            int    sEnd   = 0;
            string dish   = "";
            string num    = "";

            for (int i = 0; i < input.Length; i++)
            {
                if (state == 0)
                {
                    if (input[i] != '|')
                    {
                        continue;
                    }
                    sStart = i + 1;
                    state  = 1;
                }
                if (state == 1)
                {
                    if (input[i] != ',')
                    {
                        continue;
                    }
                    sEnd   = i - 1;
                    state  = 2;
                    dish   = input.Substring(sStart, sEnd - sStart + 1);
                    sStart = i + 1;
                }
                if (state == 2)
                {
                    if (input[i] != '|')
                    {
                        continue;
                    }
                    sEnd  = i - 1;
                    num   = input.Substring(sStart, sEnd - sStart + 1);
                    state = 0;
                    order tmp = new order(dish, num);
                    orders.Add(tmp);
                }
            }
            for (int i = 0; i < orders.Count; i++)
            {
                order    tmp  = orders[i] as order;
                menulist temp = new menulist();
                temp.name.Content  = tmp.getDish();
                temp.price.Content = "";
                TextBlock tempnum = temp.counters.FindName("num") as TextBlock;
                tempnum.Text = tmp.getNum();
                temp.counters.plus.Visibility  = Visibility.Hidden;
                temp.counters.minus.Visibility = Visibility.Hidden;
                orderInfo.Items.Add(temp);
            }
        }
Example #4
0
 private void confirmOrder_Click(object sender, RoutedEventArgs e)
 {
     if (guestName.Text != "" && address.Text != "")
     {
         DateTime now  = DateTime.Now;
         string   time = now.Year.ToString() + "-"
                         + now.Month.ToString() + "-"
                         + now.Day.ToString()
                         + " " + now.Hour.ToString()
                         + ":" + now.Minute.ToString()
                         + ":" + now.Second.ToString();
         string iseathere;
         if ((bool)eatHere_order.IsChecked)
         {
             iseathere = "1";
         }
         else
         {
             iseathere = "0";
         }
         string orderString = "";
         for (int i = 0; i < menu2.Items.Count; i++)
         {
             menulist   ml        = menu2.Items[i] as menulist;
             StackPanel sp        = ml.FindName("sp") as StackPanel;
             Label      nametext  = sp.Children[0] as Label;
             Label      price     = sp.Children[1] as Label;
             counters   cter      = sp.Children[2] as counters;
             TextBlock  num       = cter.FindName("num") as TextBlock;
             order      tempOrder = new order(nametext.Content.ToString(), num.Text);
             orderString += tempOrder.getOrderString();
         }
         string sql = "insert into orders (name,address,orders,price,time,isEatHere) values ('"
                      + guestName.Text
                      + "','" + address.Text
                      + "','" + orderString
                      + "','" + total.Content.ToString()
                      + "','" + time
                      + "','" + iseathere + "')";
         mysqlwrite(sql);
         MessageBox.Show("提交成功!");
         guestName.IsReadOnly = true;
         address.IsReadOnly   = true;
         orderListRefresh();
         guestName.Clear();
         address.Clear();
         orderInfo.Items.Clear();
         confirmOrder.Visibility = Visibility.Hidden;
     }
     else
     {
         MessageBox.Show("输入错误");
     }
     menuRefresh();
 }
Example #5
0
 private void menu2_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         menulist   ml       = menu2.SelectedItems[0] as menulist;
         StackPanel sp       = ml.FindName("sp") as StackPanel;
         Label      nametext = sp.Children[0] as Label;
         image.Source = new BitmapImage(new Uri(GetImagePath(nametext.Content.ToString()), UriKind.RelativeOrAbsolute));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #6
0
        private void menu_Changed(object sender, RoutedEventArgs e)
        {
            try
            {
                for (int i = 0; i < menu1.Items.Count; i++)
                {
                    menulist   ml       = menu1.Items[i] as menulist;
                    StackPanel sp       = ml.FindName("sp") as StackPanel;
                    Label      nametext = sp.Children[0] as Label;
                    Label      price    = sp.Children[1] as Label;
                    counters   cter     = sp.Children[2] as counters;
                    TextBlock  num      = cter.FindName("num") as TextBlock;
                    int        num_temp = -1;
                    int.TryParse(num.Text, out num_temp);
                    bool isInclude = false;
                    for (int j = 0; j < menu2.Items.Count; j++)
                    {
                        menulist   ml_2       = menu2.Items[j] as menulist;
                        StackPanel sp_2       = ml_2.FindName("sp") as StackPanel;
                        Label      nametext_2 = sp_2.Children[0] as Label;
                        if (nametext.Content == nametext_2.Content)
                        {
                            isInclude = true;
                        }
                        if (ml.name.Content.ToString() == ml_2.name.Content.ToString())
                        {
                            if (num_temp == 0)
                            {
                                image.Source = new BitmapImage(new Uri(GetImagePath(nametext.Content.ToString()), UriKind.RelativeOrAbsolute));
                                if (isInclude)
                                {
                                    this.menu2.Items.Remove(menu2.Items[j]);
                                }
                            }
                            else
                            {
                                if (isInclude)
                                {
                                    if (ml_2.counters.num.Text != ml.counters.num.Text)
                                    {
                                        image.Source = new BitmapImage(new Uri(GetImagePath(nametext.Content.ToString()), UriKind.RelativeOrAbsolute));
                                    }
                                    ml_2.counters.num.Text = num_temp.ToString();
                                }
                            }
                        }
                    }
                    if (!isInclude && num_temp != 0)
                    {
                        try
                        {
                            image.Source = new BitmapImage(new Uri(GetImagePath(nametext.Content.ToString()), UriKind.RelativeOrAbsolute));
                        }
                        catch
                        {
                            MessageBox.Show("气死本宝宝了");
                        }
                        menulist temp = new menulist();
                        temp.name.Content  = nametext.Content;
                        temp.price.Content = price.Content;
                        TextBlock tempnum = temp.counters.FindName("num") as TextBlock;
                        tempnum.Text = num.Text;
                        temp.counters.plus.Visibility  = Visibility.Hidden;
                        temp.counters.minus.Visibility = Visibility.Hidden;
                        this.menu2.Items.Add(temp);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            double sum = 0;

            for (int i = 0; i < menu2.Items.Count; i++)
            {
                menulist   ml_2       = menu2.Items[i] as menulist;
                StackPanel sp_2       = ml_2.sp;
                TextBlock  tempnum    = ml_2.counters.num;
                Label      nametext_2 = sp_2.Children[0] as Label;
                int        tempdish;
                double     tempprice;
                int.TryParse(tempnum.Text, out tempdish);
                double.TryParse(ml_2.price.Content.ToString(), out tempprice);
                sum += tempprice * tempdish;
            }
            total.Content = sum.ToString();
        }