private void InkEmptyFunc(object sender, PrinterEventArgs e)//event handler for ink { if (e.IsCritic) { MessageBox.Show("at:" + e.ErrorTime + "\nMessage from printer: " + e.Message, e.PrinterName + " Ink Missing!!!!!!", MessageBoxButton.OK, MessageBoxImage.Error); CurrentPrinter.addInk(); queue.Enqueue(CurrentPrinter); CurrentPrinter = queue.Dequeue(); } else { MessageBox.Show("at:" + e.ErrorTime + "\nMessage from printer: " + e.Message, e.PrinterName + " Ink Missing!!!!!!", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void PageMissingFunc(object sender, PrinterEventArgs e) { MessageBox.Show("at:" + e.ErrorTime + "\nMessage from printer: " + e.Message, e.PrinterName + " Page Missing!!!!!!", MessageBoxButton.OK, MessageBoxImage.Error); CurrentPrinter.addPages(); if (CurrentPrinter.InkCount <= 0)//in case the ink is also missing the program activate the second event { return; } else { queue.Enqueue(CurrentPrinter); CurrentPrinter = queue.Dequeue(); } }
public void Print() { // 1. roll the random numbers to use for print double inkUse = rnd.Next((int)MIN_ADD_INK, (int)MAX_PRINT_INK); int pageUse = rnd.Next(MIN_ADD_PAGES, MAX_PRINT_PAGES); Thread.Sleep(500); // 2. reduce the ink and pages from printer values and visual bars PageCount -= pageUse; howPageMissing = PageCount; this.pageCountSlider.Value = PageCount; InkCount -= inkUse; this.inkCountProgressBar.Value = InkCount; // 3. activate events and error messages if needed if (PageCount <= 0) { pageLabel.Foreground = Brushes.Red; PrinterEventArgs noPages = new PrinterEventArgs(true, "Missing " + howPageMissing * (-1) + " Pages", PrinterName); PageMissing(this, noPages); } if (InkCount <= 15 && InkCount > 10) { inkLabel.Foreground = Brushes.Yellow; PrinterEventArgs lowInk = new PrinterEventArgs(false, "Low ink, only " + Convert.ToString(InkCount) + "% ink remain.", printerName); InkEmpty(this, lowInk); } else if (InkCount <= 10 && InkCount > 0) { inkLabel.Foreground = Brushes.Orange; PrinterEventArgs veryLowInk = new PrinterEventArgs(false, "Very low ink, only " + Convert.ToString(InkCount) + "% ink remain.", printerName); InkEmpty(this, veryLowInk); } else if (inkCount <= 0) { inkLabel.Foreground = Brushes.Red; PrinterEventArgs criticInk = new PrinterEventArgs(true, "No ink left. Please add ink", printerName); InkEmpty(this, criticInk); } }