对于已设置了其位的各个特性,代码会将一条通知添加到将向用户显示的最终报告中。 (下面会讨论代码结束时调用的ReportAvailabilityAtThisTime方法。)
internal: // Check for possible trouble states of a printer using the flags of the QueueStatus property static void SpotTroubleUsingQueueAttributes (System::String^% statusReport, System::Printing::PrintQueue^ pq) { if ((pq->QueueStatus & PrintQueueStatus::PaperProblem) == PrintQueueStatus::PaperProblem) { statusReport = statusReport + "Has a paper problem. "; } if ((pq->QueueStatus & PrintQueueStatus::NoToner) == PrintQueueStatus::NoToner) { statusReport = statusReport + "Is out of toner. "; } if ((pq->QueueStatus & PrintQueueStatus::DoorOpen) == PrintQueueStatus::DoorOpen) { statusReport = statusReport + "Has an open door. "; } if ((pq->QueueStatus & PrintQueueStatus::Error) == PrintQueueStatus::Error) { statusReport = statusReport + "Is in an error state. "; } if ((pq->QueueStatus & PrintQueueStatus::NotAvailable) == PrintQueueStatus::NotAvailable) { statusReport = statusReport + "Is not available. "; } if ((pq->QueueStatus & PrintQueueStatus::Offline) == PrintQueueStatus::Offline) { statusReport = statusReport + "Is off line. "; } if ((pq->QueueStatus & PrintQueueStatus::OutOfMemory) == PrintQueueStatus::OutOfMemory) { statusReport = statusReport + "Is out of memory. "; } if ((pq->QueueStatus & PrintQueueStatus::PaperOut) == PrintQueueStatus::PaperOut) { statusReport = statusReport + "Is out of paper. "; } if ((pq->QueueStatus & PrintQueueStatus::OutputBinFull) == PrintQueueStatus::OutputBinFull) { statusReport = statusReport + "Has a full output bin. "; } if ((pq->QueueStatus & PrintQueueStatus::PaperJam) == PrintQueueStatus::PaperJam) { statusReport = statusReport + "Has a paper jam. "; } if ((pq->QueueStatus & PrintQueueStatus::Paused) == PrintQueueStatus::Paused) { statusReport = statusReport + "Is paused. "; } if ((pq->QueueStatus & PrintQueueStatus::TonerLow) == PrintQueueStatus::TonerLow) { statusReport = statusReport + "Is low on toner. "; } if ((pq->QueueStatus & PrintQueueStatus::UserIntervention) == PrintQueueStatus::UserIntervention) { statusReport = statusReport + "Needs user intervention. "; } // Check if queue is even available at this time of day // The method below is defined in the complete example. ReportAvailabilityAtThisTime(statusReport, pq); };// Check for possible trouble states of a printer using the flags of the QueueStatus property internal static void SpotTroubleUsingQueueAttributes(ref String statusReport, PrintQueue pq) { if ((pq.QueueStatus & PrintQueueStatus.PaperProblem) == PrintQueueStatus.PaperProblem) { statusReport = statusReport + "Has a paper problem. "; } if ((pq.QueueStatus & PrintQueueStatus.NoToner) == PrintQueueStatus.NoToner) { statusReport = statusReport + "Is out of toner. "; } if ((pq.QueueStatus & PrintQueueStatus.DoorOpen) == PrintQueueStatus.DoorOpen) { statusReport = statusReport + "Has an open door. "; } if ((pq.QueueStatus & PrintQueueStatus.Error) == PrintQueueStatus.Error) { statusReport = statusReport + "Is in an error state. "; } if ((pq.QueueStatus & PrintQueueStatus.NotAvailable) == PrintQueueStatus.NotAvailable) { statusReport = statusReport + "Is not available. "; } if ((pq.QueueStatus & PrintQueueStatus.Offline) == PrintQueueStatus.Offline) { statusReport = statusReport + "Is off line. "; } if ((pq.QueueStatus & PrintQueueStatus.OutOfMemory) == PrintQueueStatus.OutOfMemory) { statusReport = statusReport + "Is out of memory. "; } if ((pq.QueueStatus & PrintQueueStatus.PaperOut) == PrintQueueStatus.PaperOut) { statusReport = statusReport + "Is out of paper. "; } if ((pq.QueueStatus & PrintQueueStatus.OutputBinFull) == PrintQueueStatus.OutputBinFull) { statusReport = statusReport + "Has a full output bin. "; } if ((pq.QueueStatus & PrintQueueStatus.PaperJam) == PrintQueueStatus.PaperJam) { statusReport = statusReport + "Has a paper jam. "; } if ((pq.QueueStatus & PrintQueueStatus.Paused) == PrintQueueStatus.Paused) { statusReport = statusReport + "Is paused. "; } if ((pq.QueueStatus & PrintQueueStatus.TonerLow) == PrintQueueStatus.TonerLow) { statusReport = statusReport + "Is low on toner. "; } if ((pq.QueueStatus & PrintQueueStatus.UserIntervention) == PrintQueueStatus.UserIntervention) { statusReport = statusReport + "Needs user intervention. "; } // Check if queue is even available at this time of day // The method below is defined in the complete example. ReportAvailabilityAtThisTime(ref statusReport, pq); }' Check for possible trouble states of a printer using the flags of the QueueStatus property Friend Shared Sub SpotTroubleUsingQueueAttributes(ByRef statusReport As String, ByVal pq As PrintQueue) If (pq.QueueStatus And PrintQueueStatus.PaperProblem) = PrintQueueStatus.PaperProblem Then statusReport = statusReport & "Has a paper problem. " End If If (pq.QueueStatus And PrintQueueStatus.NoToner) = PrintQueueStatus.NoToner Then statusReport = statusReport & "Is out of toner. " End If If (pq.QueueStatus And PrintQueueStatus.DoorOpen) = PrintQueueStatus.DoorOpen Then statusReport = statusReport & "Has an open door. " End If If (pq.QueueStatus And PrintQueueStatus.Error) = PrintQueueStatus.Error Then statusReport = statusReport & "Is in an error state. " End If If (pq.QueueStatus And PrintQueueStatus.NotAvailable) = PrintQueueStatus.NotAvailable Then statusReport = statusReport & "Is not available. " End If If (pq.QueueStatus And PrintQueueStatus.Offline) = PrintQueueStatus.Offline Then statusReport = statusReport & "Is off line. " End If If (pq.QueueStatus And PrintQueueStatus.OutOfMemory) = PrintQueueStatus.OutOfMemory Then statusReport = statusReport & "Is out of memory. " End If If (pq.QueueStatus And PrintQueueStatus.PaperOut) = PrintQueueStatus.PaperOut Then statusReport = statusReport & "Is out of paper. " End If If (pq.QueueStatus And PrintQueueStatus.OutputBinFull) = PrintQueueStatus.OutputBinFull Then statusReport = statusReport & "Has a full output bin. " End If If (pq.QueueStatus And PrintQueueStatus.PaperJam) = PrintQueueStatus.PaperJam Then statusReport = statusReport & "Has a paper jam. " End If If (pq.QueueStatus And PrintQueueStatus.Paused) = PrintQueueStatus.Paused Then statusReport = statusReport & "Is paused. " End If If (pq.QueueStatus And PrintQueueStatus.TonerLow) = PrintQueueStatus.TonerLow Then statusReport = statusReport & "Is low on toner. " End If If (pq.QueueStatus And PrintQueueStatus.UserIntervention) = PrintQueueStatus.UserIntervention Then statusReport = statusReport & "Needs user intervention. " End If ' Check if queue is even available at this time of day ' The method below is defined in the complete example. ReportAvailabilityAtThisTime(statusReport, pq) End Sub
若要使用各个属性检查打印机状态,只需读取各个属性,并将注释添加到最终报告,如果属性为true,将向用户显示最终报告。 (下面会讨论代码结束时调用的ReportAvailabilityAtThisTime方法。)
internal: // Check for possible trouble states of a printer using its properties static void SpotTroubleUsingProperties (System::String^% statusReport, System::Printing::PrintQueue^ pq) { if (pq->HasPaperProblem) { statusReport = statusReport + "Has a paper problem. "; } if (!(pq->HasToner)) { statusReport = statusReport + "Is out of toner. "; } if (pq->IsDoorOpened) { statusReport = statusReport + "Has an open door. "; } if (pq->IsInError) { statusReport = statusReport + "Is in an error state. "; } if (pq->IsNotAvailable) { statusReport = statusReport + "Is not available. "; } if (pq->IsOffline) { statusReport = statusReport + "Is off line. "; } if (pq->IsOutOfMemory) { statusReport = statusReport + "Is out of memory. "; } if (pq->IsOutOfPaper) { statusReport = statusReport + "Is out of paper. "; } if (pq->IsOutputBinFull) { statusReport = statusReport + "Has a full output bin. "; } if (pq->IsPaperJammed) { statusReport = statusReport + "Has a paper jam. "; } if (pq->IsPaused) { statusReport = statusReport + "Is paused. "; } if (pq->IsTonerLow) { statusReport = statusReport + "Is low on toner. "; } if (pq->NeedUserIntervention) { statusReport = statusReport + "Needs user intervention. "; } // Check if queue is even available at this time of day // The following method is defined in the complete example. ReportAvailabilityAtThisTime(statusReport, pq); };// Check for possible trouble states of a printer using its properties internal static void SpotTroubleUsingProperties(ref String statusReport, PrintQueue pq) { if (pq.HasPaperProblem) { statusReport = statusReport + "Has a paper problem. "; } if (!(pq.HasToner)) { statusReport = statusReport + "Is out of toner. "; } if (pq.IsDoorOpened) { statusReport = statusReport + "Has an open door. "; } if (pq.IsInError) { statusReport = statusReport + "Is in an error state. "; } if (pq.IsNotAvailable) { statusReport = statusReport + "Is not available. "; } if (pq.IsOffline) { statusReport = statusReport + "Is off line. "; } if (pq.IsOutOfMemory) { statusReport = statusReport + "Is out of memory. "; } if (pq.IsOutOfPaper) { statusReport = statusReport + "Is out of paper. "; } if (pq.IsOutputBinFull) { statusReport = statusReport + "Has a full output bin. "; } if (pq.IsPaperJammed) { statusReport = statusReport + "Has a paper jam. "; } if (pq.IsPaused) { statusReport = statusReport + "Is paused. "; } if (pq.IsTonerLow) { statusReport = statusReport + "Is low on toner. "; } if (pq.NeedUserIntervention) { statusReport = statusReport + "Needs user intervention. "; } // Check if queue is even available at this time of day // The following method is defined in the complete example. ReportAvailabilityAtThisTime(ref statusReport, pq); }//end SpotTroubleUsingProperties' Check for possible trouble states of a printer using its properties Friend Shared Sub SpotTroubleUsingProperties(ByRef statusReport As String, ByVal pq As PrintQueue) If pq.HasPaperProblem Then statusReport = statusReport & "Has a paper problem. " End If If Not(pq.HasToner) Then statusReport = statusReport & "Is out of toner. " End If If pq.IsDoorOpened Then statusReport = statusReport & "Has an open door. " End If If pq.IsInError Then statusReport = statusReport & "Is in an error state. " End If If pq.IsNotAvailable Then statusReport = statusReport & "Is not available. " End If If pq.IsOffline Then statusReport = statusReport & "Is off line. " End If If pq.IsOutOfMemory Then statusReport = statusReport & "Is out of memory. " End If If pq.IsOutOfPaper Then statusReport = statusReport & "Is out of paper. " End If If pq.IsOutputBinFull Then statusReport = statusReport & "Has a full output bin. " End If If pq.IsPaperJammed Then statusReport = statusReport & "Has a paper jam. " End If If pq.IsPaused Then statusReport = statusReport & "Is paused. " End If If pq.IsTonerLow Then statusReport = statusReport & "Is low on toner. " End If If pq.NeedUserIntervention Then statusReport = statusReport & "Needs user intervention. " End If ' Check if queue is even available at this time of day ' The following method is defined in the complete example. ReportAvailabilityAtThisTime(statusReport, pq) End Sub
创建了ReportAvailabilityAtThisTime方法,以应对需要确定队列在一天的当前时间是否可用的情况。
如果和属性相等,则方法将不执行任何操作StartTimeOfDayUntilTimeOfDay ; 因为在这种情况下,打印机始终可用。 如果它们不同,则方法获取当前时间,该时间之后必须转换为午夜的总分钟数,因为StartTimeOfDay 和UntilTimeOfDay 属性Int32 表示午夜后的分钟数(而不是DateTime 对象)。 最后,该方法会检查当前时间是否介于开始时间和“截至”时间之间。
private: static void ReportAvailabilityAtThisTime (System::String^% statusReport, System::Printing::PrintQueue^ pq) { if (pq->StartTimeOfDay != pq->UntilTimeOfDay) { System::DateTime utcNow = DateTime::UtcNow; System::Int32 utcNowAsMinutesAfterMidnight = (utcNow.TimeOfDay.Hours * 60) + utcNow.TimeOfDay.Minutes; // If now is not within the range of available times . . . if (!((pq->StartTimeOfDay