private void RevertButton_Click(object sender, RoutedEventArgs e)
        {
            Button  l1 = sender as Button;
            Grid    l2 = l1.Parent as Grid;
            ListBox l3 = l2.Parent as ListBox;

            if (!StatusSteps.Count.Equals(0))
            {
                myItem BackItem = StatusSteps[StatusSteps.Count - 1];
                OrderMenu.Items.Insert(OrderMenu.Items.Count - 1, BackItem);
                StatusSteps.RemoveAt(StatusSteps.Count - 1);

                if (GlobalInfo.isItemSpecial(BackItem.IName))
                {
                    return;
                }

                bool isContain = false;
                foreach (var cg in GlobalInfo.TotalOrderListBox.Items)
                {
                    try
                    {
                        if ((cg as CountGrid).linkItem.IName.Equals(BackItem.IName))
                        {
                            (cg as CountGrid).KindCount += BackItem.Count;
                            isContain = true;
                            break;
                        }
                    }
                    catch
                    {
                    }
                }

                if (!isContain)
                {
                    GlobalInfo.TotalOrderListBox.Items.Add(new CountGrid(BackItem));
                }
            }
            ;
        }
        public OrderMenuForm(OrderMenuList orderMenuList, string TableNumber)
        {
            InitializeComponent();

            ordermenu = orderMenuList;

            var ItemCOL = OrderMenu.Items;

            SolveCoder();

            int CountComboItem = 0;

            foreach (TextBlock tblkcombo in comboBox.Items)
            {
                if (tblkcombo.Text.Contains(TableNumber))
                {
                    break;
                }

                CountComboItem++;
            }

            comboBox.SelectionChanged += ComboBox_SelectionChanged;
            comboBox.SelectedIndex     = CountComboItem;

            ListBox PrintBox = new Printform().Content as ListBox;
            string  Uid      = OrderMenu.Uid = DateTime.Now.ToString("HHmmssMMdd");

            TextBlock tbnbk = new TextBlock();

            tbnbk.FontSize = 16;
            tbnbk.Text     = "桌號 : " + (comboBox.SelectedItem as TextBlock).Text + "  " + Uid + OrderCode.ToString("D2");

            //MessageBox.Show(tbnbk.Text);
            PrintBox.Items.Add(tbnbk);

            int Amount = 0;

            foreach (myItem x in orderMenuList.GetItems())
            {
                x.vblk2text = new Viewbox();
                TextBlock textblk = new TextBlock();

                textblk.FontSize = 18;

                x.ck.Height = 24;
                x.ck.Children.Add(x.vblk2text);
                x.vblk2text.Child = textblk;
                x.vblk2text.PreviewMouseLeftButtonUp += previewMouseLeftButtonUP;

                if (x.Count != 1)
                {
                    textblk.Text = x.IName + "*" + x.Count;
                }
                else
                {
                    textblk.Text = x.IName;
                }

                ItemCOL.Insert(ItemCOL.Count - 1, x);

                Amount += x.Count * x.Price;
                TextBlock tbnlk = new TextBlock();
                tbnlk.Text     = x.IName + "(" + x.Price + ")" + "*" + x.Count;
                tbnlk.FontSize = 20;
                PrintBox.Items.Add(tbnlk);

                if (GlobalInfo.isItemSpecial(x.IName))
                {
                    continue;
                }

                bool isContain = false;
                foreach (var cg in GlobalInfo.TotalOrderListBox.Items)
                {
                    try
                    {
                        if ((cg as CountGrid).linkItem.IName.Equals(x.IName))
                        {
                            isContain = true;
                            (cg as CountGrid).KindCount += x.Count;
                            break;
                        }
                    }
                    catch
                    {
                    }
                }

                if (!isContain)
                {
                    GlobalInfo.TotalOrderListBox.Items.Add(new CountGrid(x));
                }
            }

            TextBlock tbAmount = new TextBlock();

            tbAmount.Text                = "總價 : " + Amount.ToString();
            tbAmount.FontSize            = 24;
            tbAmount.HorizontalAlignment = HorizontalAlignment.Right;
            PrintBox.Items.Add(tbAmount);

            PrintDialog pd = new PrintDialog();

            pd.PrintVisual(PrintBox, OrderMenu.Uid);

            //InitialStatusListBox = SerializeObj.DeepCopy<ListBox>(OrderMenu);

            StatusSteps = new List <myItem>();
        }
Exemple #3
0
        public MainWindow()
        {
            InitializeComponent();

            //MessageBox.Show(DateTime.Now.ToString("MMddHHmmss"));

            if (!Directory.Exists("圖片"))
            {
                Directory.CreateDirectory("圖片");
            }

            if (!File.Exists("coder"))
            {
                using (StreamWriter streamWriter = new StreamWriter("coder", false))
                {
                    streamWriter.WriteLine(1);
                    streamWriter.Close();
                }
            }
            else
            {
                if (!DateTime.Now.ToString("MMdd").Equals(File.GetLastWriteTime("coder").ToString("MMdd")))
                {
                    using (StreamWriter streamWriter = new StreamWriter("coder", false))
                    {
                        streamWriter.WriteLine(1);
                        streamWriter.Close();
                    }
                }
            }

            GlobalInfo.SetTcpListener(9955);

            DispatcherTimer dispatcherTimer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(10)
            };

            dispatcherTimer.Start();
            dispatcherTimer.Tick += (s, e) => {
            };

            var listener = GlobalInfo.GetTcpListener();

            listener.Start();

            new Task(() =>
            {
                while (true)
                {
                    var m_socket = listener.AcceptSocket();

                    Console.WriteLine(IPAddress.Parse(((IPEndPoint)m_socket.LocalEndPoint).Address.ToString()));

                    new Task(() =>
                    {
                        byte[] bytes = new byte[4096];

                        Dispatcher.Invoke(() =>
                        {
                            m_socket.Receive(bytes);

                            string recv = Encoding.UTF8.GetString(bytes);

                            OrderMenuList orderMenuList = new OrderMenuList();

                            recv = recv.Substring(0, recv.IndexOf('\0'));

                            Console.WriteLine(recv);

                            string[] SplitSemi = recv.Split(';');

                            string TableNumber = SplitSemi[SplitSemi.Length - 1];

                            SplitSemi = SplitSemi.Where(w => w != SplitSemi[SplitSemi.Length - 1]).ToArray();

                            foreach (string x in SplitSemi)
                            {
                                string[] SplitComma = x.Split(',');

                                orderMenuList.AddItem(new myItem(SplitComma[0], int.Parse(SplitComma[1]), int.Parse(SplitComma[2])));
                            }

                            AddMenuForm(orderMenuList, TableNumber);

                            GlobalInfo.resort();
                        });

                        m_socket.Close();
                    }).Start();
                }
            }).Start();

            var TotalOrderListBox = GlobalInfo.TotalOrderListBox;

            TotalOrderListBox.Parent.SetValue(ContentPresenter.ContentProperty, null);

            MainGrid.Children.Add(TotalOrderListBox);

            Grid.SetColumn(TotalOrderListBox, 1);
        }