Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();

            textBoxIP.Text = Config.HistoryIPAddress;

            if (!Config.IsIPPrinter)
            {
                buttonConnectPrinter.Visibility  = Visibility.Collapsed;
                buttonConnectPrinters.Visibility = Visibility.Collapsed;

                Grid.SetRowSpan(listViewLog, 2);
                listViewIpPrinter.Visibility        = Visibility.Collapsed;
                textBlockIpPrinter.Visibility       = Visibility.Collapsed;
                listViewIpPrinterStatus.Visibility  = Visibility.Collapsed;
                textBlockIpPrinterStatus.Visibility = Visibility.Collapsed;

                textBlockIP.Visibility = Visibility.Collapsed;
                textBoxIP.Visibility   = Visibility.Collapsed;
                comboBox.Visibility    = Visibility.Visible;

                List <string> printers = BasePrinter.GetPritners();
                printers.ForEach(p => {
                    comboBox.Items.Add(p);
                });
                comboBox.SelectedIndex = 0;
            }

            IPPrinter.GetInstance().OnLog += (ip, bmp, message, style) => {
                ipPrinterLog(ip, bmp?.GetHashCode(), message, style);
            };
        }
Esempio n. 2
0
        public async Task Print(ShiftForPrinting protocol)
        {
            handleIPPrinterFormat(protocol.PrinterFormat);

            IPAddress ip  = IPAddress.Parse(protocol.Printer.IpAddress);
            Bitmap    bmp = generateShiftBmp(protocol);
            await IPPrinter.GetInstance().Print(ip, bmp, protocol.PrinterFormat.ColorDepth);
        }
Esempio n. 3
0
        private async void buttonConnectPrinters_Click(object sender, RoutedEventArgs e)
        {
            var protocol = await getPrintersForPrinting();

            if (protocol == null)
            {
                serverLog("获取打印机信息失败,请检查网络设置", LogLevel.Error);
                return;
            }

            foreach (var ip in protocol.Printers.Select(p => p.IpAddress).Distinct())
            {
                await IPPrinter.GetInstance().Connect(IPAddress.Parse(ip));
            }
        }
Esempio n. 4
0
        void ipPrinterLog(IPAddress ip, int?hashCode, string message, LogLevel level)
        {
            if (message != null)
            {
                listViewIpPrinter.Dispatcher.Invoke(() => {
                    listViewIpPrinter.Items.Add(new IPPrinterLog {
                        DateTime = DateTime.Now,
                        IP       = ip,
                        Message  = message,
                        HashCode = hashCode,
                        Level    = level
                    });

                    listViewIpPrinter.SelectedIndex = listViewIpPrinter.Items.Count - 1;
                    listViewIpPrinter.ScrollIntoView(listViewIpPrinter.SelectedItem);
                });
            }

            listViewIpPrinterStatus.Dispatcher.Invoke(() => {
                listViewIpPrinterStatus.Items.Clear();
                var map = IPPrinter.GetInstance().IPClientBmpMap;
                foreach (IPAddress ipKey in map.Keys)
                {
                    string status         = "已断开";
                    LogLevel printerLevel = LogLevel.Error;
                    if (map[ipKey].IsConnecting)
                    {
                        status       = "正在连接";
                        printerLevel = LogLevel.Info;
                    }
                    else if (map[ipKey].TcpClientInfo != null)
                    {
                        status       = "已连接";
                        printerLevel = LogLevel.Success;
                    }
                    listViewIpPrinterStatus.Items.Add(new IPPrinterStatus {
                        IP          = ipKey,
                        Message     = status,
                        WaitedCount = map[ipKey].Queue.Count,
                        IdleTime    = map[ipKey].TcpClientInfo?.IdleTime ?? 0,
                        Level       = printerLevel
                    });
                }
            });
        }
Esempio n. 5
0
        public async Task Print(DineForPrinting protocol, List <PrintType> printTypes, bool isFullDineMenus)
        {
            handleIPPrinterFormat(protocol.PrinterFormat);

            List <Task> allTasks = new List <Task>();

            foreach (PrintType type in printTypes)
            {
                if (type == PrintType.Recipt)
                {
                    if (protocol.Dine.Desk.ReciptPrinter == null)
                    {
                        continue;
                    }

                    IPAddress ip  = IPAddress.Parse(protocol.Dine.Desk.ReciptPrinter.IpAddress);
                    Bitmap    bmp = generateReciptBmp(protocol, isFullDineMenus);
                    allTasks.Add(IPPrinter.GetInstance().Print(ip, bmp, protocol.PrinterFormat.ColorDepth));
                }
                else if (type == PrintType.ServeOrder)
                {
                    if (protocol.Dine.Desk.ServePrinter == null)
                    {
                        continue;
                    }

                    IPAddress ip  = IPAddress.Parse(protocol.Dine.Desk.ServePrinter.IpAddress);
                    Bitmap    bmp = generateServeOrderBmp(protocol);
                    allTasks.Add(IPPrinter.GetInstance().Print(ip, bmp, protocol.PrinterFormat.ColorDepth));
                }
                else if (type == PrintType.KitchenOrder)
                {
                    foreach (DineMenu dineMenu in protocol.Dine.DineMenus.Where(p => p.Status != HotelDAO.Models.DineMenuStatus.Returned))
                    {
                        if (dineMenu.Menu.Printer == null)
                        {
                            continue;
                        }

                        if (!dineMenu.Menu.IsSetMeal)
                        {
                            IPAddress ip  = IPAddress.Parse(dineMenu.Menu.Printer.IpAddress);
                            Bitmap    bmp = generateKitchenOrderBmp(protocol, dineMenu, null);
                            allTasks.Add(IPPrinter.GetInstance().Print(ip, bmp, protocol.PrinterFormat.ColorDepth));
                        }
                        else
                        {
                            foreach (SetMealMenu setMealMenu in dineMenu.Menu.SetMealMenus)
                            {
                                IPAddress ip  = IPAddress.Parse(dineMenu.Menu.Printer.IpAddress);
                                Bitmap    bmp = generateKitchenOrderBmp(protocol, dineMenu, setMealMenu);
                                allTasks.Add(IPPrinter.GetInstance().Print(ip, bmp, protocol.PrinterFormat.ColorDepth));
                            }
                        }
                    }
                }
            }

            foreach (var t in allTasks)
            {
                await t;
            }
        }
Esempio n. 6
0
 private async void buttonConnectPrinter_Click(object sender, RoutedEventArgs e)
 {
     await IPPrinter.GetInstance().Connect(IPAddress.Parse(textBoxIP.Text));
 }