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; }
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(); }
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); } }
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(); }