private void OnDataEvent(object sender, DataEventArgs dataEventArgs) { CashChanger cashChanger = Session.Instance.CashChanger; if (cashChanger.DepositAmount < Session.Instance.Price) { Dispatcher.BeginInvoke(new Action(() => { TotalPaid.Text = String.Format("Total paid: {0:0.00} €", ((float)cashChanger.DepositAmount) / 100); Remaining.Text = String.Format("Remaining: {0:0.00} €", ((float)(Session.Instance.Price - cashChanger.DepositAmount)) / 100); })); cashChanger.DataEventEnabled = true; return; } Session.Instance.DepositAmount = cashChanger.DepositAmount; cashChanger.EndDeposit(cashChanger.DepositAmount == Session.Instance.Price ? CashDepositAction.NoChange : CashDepositAction.Change); Dispatcher.BeginInvoke(new Action(() => { TotalPaid.Text = String.Format("Total paid: {0:0.00} €", ((float)cashChanger.DepositAmount) / 100); Remaining.Text = String.Format("Remaining: {0:0.00} €", ((float)(Session.Instance.Price - cashChanger.DepositAmount)) / 100); Thread.Sleep(1000); DefaultLinkNavigator dln = new DefaultLinkNavigator(); dln.Navigate(new Uri("/Pages/Print.xaml", UriKind.Relative), this); })); }
public static void Navigate(string url, FrameworkElement source) { DefaultLinkNavigator _navigator = new DefaultLinkNavigator(); _navigator.Navigate(new Uri(url, UriKind.Relative), source, null); }
private void backgroundWorker_Print(object sender, DoWorkEventArgs e) { PosPrinter printer = null; string doneHead = "Finished Printing."; string waitMsg = "Please wait..."; string doneSingleMsg = "Please take your ticket."; string doneMulMsg = "Please take your tickets."; int ticketsToPrint = 1; int price = Session.Instance.Price; string ticket = Session.Instance.Ticket; string testImageFilename = ""; string TicketHeader = ""; switch (Session.Instance.Ticket) { case "Whole Day Ticket": break; } if (Session.Instance.Ticket == "Whole Day Ticket") { TicketHeader = "Whole Day Ticket"; ticketsToPrint = 1; testImageFilename = System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location) + "\\Demo Tickets\\wholeDay.bmp"); } else if (Session.Instance.Ticket == "Ten Tickets") { TicketHeader = "Single Ticket"; ticketsToPrint = 10; testImageFilename = System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location) + "\\Demo Tickets\\singleTicket.bmp"); } else if (Session.Instance.Ticket == "Five Tickets") { TicketHeader = "Single Ticket"; ticketsToPrint = 5; testImageFilename = System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location) + "\\Demo Tickets\\singleTicket.bmp"); } else if (Session.Instance.Ticket == "Single Ticket") { TicketHeader = "Single Ticket"; ticketsToPrint = 1; testImageFilename = System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location) + "\\Demo Tickets\\singleTicket.bmp"); } float singleTicketPrice = ((float)Session.Instance.Price) / ticketsToPrint / 100; string priceString = String.Format("EUR: {0:0.00}", singleTicketPrice); if (Session.Instance.CashChanger != null) { Session.Instance.CashChanger.Close(); Session.Instance.CashChanger = null; } printer = Session.Instance.PosPrinter; if (printer == null) { MessageBox.Show("Printer not activated"); return; } Dispatcher.BeginInvoke(new Action(() => { Subtitle.Text = waitMsg; })); for (int i = 0; i < ticketsToPrint; i++) { Dispatcher.BeginInvoke(new Action(() => { Head.Text = String.Format("Printing Ticket {0} of {1}...", i + 1, ticketsToPrint); })); Bitmap createdBitmap = new System.Drawing.Bitmap(960, 640, PixelFormat.Format24bppRgb); RectangleF rectf = new RectangleF(0, 0, createdBitmap.Width, createdBitmap.Height); Graphics g = Graphics.FromImage(createdBitmap); g.SmoothingMode = SmoothingMode.None; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.FillRectangle(System.Drawing.Brushes.White, 0, 0, rectf.Width, rectf.Height); g.DrawString(TicketHeader + "\r\n" + priceString + "\r\n" + DateTime.Now.ToString("ddd, dd. MMM yyyy H:mm:ss"), new Font("Tahoma", 70), System.Drawing.Brushes.Black, rectf); g.Flush(); createdBitmap.Save("createdBitmap.bmp"); createdBitmap = FloydSteinberg(createdBitmap, createdBitmap.Width, createdBitmap.Height); createdBitmap.Save("createdBitmapFS.bmp"); printer.PrintMemoryBitmap(PrinterStation.Receipt, createdBitmap, -11, -2); printer.CutPaper(100); } printer.DeviceEnabled = false; printer.Release(); printer.Close(); Session.Instance.PosPrinter = null; if (Session.Instance.DepositAmount > Session.Instance.Price) { int change = Session.Instance.DepositAmount - Session.Instance.Price; Dispatcher.BeginInvoke(new Action(() => { Head.Text = String.Format("Returning cash {0:0.00}", ((float)change)/100); })); CashChanger cashChanger = Session.Instance.CashChanger; if (cashChanger != null) { try { cashChanger.DispenseChange(change); } catch (Exception ex) { if (cashChanger.State != ControlState.Closed) cashChanger.Close(); MessageBox.Show("Cash Unit out of order"); } } else { MessageBox.Show("Cash Unit not activated"); } } Dispatcher.BeginInvoke(new Action(() => { Head.Text = doneHead; Subtitle.Text = ticketsToPrint > 1 ? Subtitle.Text = doneMulMsg : doneSingleMsg; })); //PosCommon doorhub = null; //var commonCollection = explorer.GetDevices("PosCommon"); //foreach (DeviceInfo deviceInfo in commonCollection) //{ // if (deviceInfo.ServiceObjectName != "DoorHub") // continue; // doorhub = (PosCommon)explorer.CreateInstance(deviceInfo); // break; //} //if (doorhub == null) //{ // MessageBox.Show("Doorhub not activated"); // return; //} //doorhub.Open(); //doorhub.Claim(1000); //doorhub.DeviceEnabled = true; //DirectIOData data = doorhub.DirectIO(1, 0, new string[] { "HexMaskGPB", "40" }); //doorhub.DeviceEnabled = false; //doorhub.Release(); //doorhub.Close(); Session.Instance.DepositAmount = 0; Session.Instance.Price = 0; Session.Instance.Ticket = ""; Thread.Sleep(5000); Dispatcher.BeginInvoke(new Action(() => { isLeavePageAllowed = true; DefaultLinkNavigator dln = new DefaultLinkNavigator(); dln.Navigate(new Uri("/Pages/Home.xaml", UriKind.Relative), this); })); }
/// <summary> /// Navigates the back. /// </summary> /// <param name="source">The source.</param> public void NavigateBack(FrameworkElement source) { string url = "cmd://browseback"; DefaultLinkNavigator navigator = new DefaultLinkNavigator(); navigator.Navigate(new Uri(url, UriKind.Absolute), source, "_self"); }
public void OnNavigatedTo(NavigationEventArgs e) { if (!NetManager.Instance.IsConnected) { if (ModernDialog.ShowMessage("usmooth is [b]offline[/b], connect to a running game first.", "offline", MessageBoxButton.OK) == MessageBoxResult.OK) { UsLogging.Printf("trying to enter the '[b]realtime[/b]' page when usmooth is [b]offline[/b], back to the main page."); DefaultLinkNavigator dln = new DefaultLinkNavigator(); dln.Navigate(new Uri("/Pages/Home.xaml", UriKind.Relative), this); return; } } NetRequest_FrameData(); }