Parsi Coders
تعداد صفحات پرینت شده از طرف هر کلاینت - نسخه قابل چاپ

+- Parsi Coders (http://parsicoders.com)
+-- انجمن: Software Development Programming (http://parsicoders.com/forumdisplay.php?fid=37)
+--- انجمن: C# Programming (http://parsicoders.com/forumdisplay.php?fid=55)
+--- موضوع: تعداد صفحات پرینت شده از طرف هر کلاینت (/showthread.php?tid=2482)



تعداد صفحات پرینت شده از طرف هر کلاینت - atpf - 06-20-2012

درود دوستان عزیز

من دارم یه برنامه مدیریت کافینت می نویسم می خوام تعداد صفحات پرینت شده از طرف هر کلاینت رو بگیرم باید چیکار کنم.
ممنون میشم اگه کسی میدونه و کمک کنه.


RE: تعداد صفحات پرینت شده از طرف هر کلاینت - Amin_Mansouri - 06-21-2012

تعداد صفحات پرینت شده از طرف هر کلاینت دقیقا یعنی چی؟


RE: تعداد صفحات پرینت شده از طرف هر کلاینت - Ghoghnus - 06-21-2012

(06-20-2012، 11:11 PM)atpf نوشته: درود دوستان عزیز

من دارم یه برنامه مدیریت کافینت می نویسم می خوام تعداد صفحات پرینت شده از طرف هر کلاینت رو بگیرم باید چیکار کنم.
ممنون میشم اگه کسی میدونه و کمک کنه.
شما میتونید همون موقع که دستور چاپ زده میشه سمت کلاینت بشمارید بعد نتیجه اخر را به سرور ارسال کنید!


RE: تعداد صفحات پرینت شده از طرف هر کلاینت - atpf - 06-22-2012

(06-21-2012، 08:21 PM)Amin_Mansouri نوشته: تعداد صفحات پرینت شده از طرف هر کلاینت دقیقا یعنی چی؟
درود بر شما دوست عزیز
تعداد صفحات پرینت شده یعنی از طرف هر کلاینت یعنی:
اینکه من به عنوان مدیر کافینت نشستم پشت میز و یکدفعه پرینتر من شروع میکنه به پرینت کردن و چند صفحه میده بیرون.
حالا من می خوام تعداد این صفحات پرینت شده رو توی برنامه سمت سرورم نمایش بده. rose

(06-21-2012، 10:01 PM)Ghoghnus نوشته:
(06-20-2012، 11:11 PM)atpf نوشته: درود دوستان عزیز

من دارم یه برنامه مدیریت کافینت می نویسم می خوام تعداد صفحات پرینت شده از طرف هر کلاینت رو بگیرم باید چیکار کنم.
ممنون میشم اگه کسی میدونه و کمک کنه.
شما میتونید همون موقع که دستور چاپ زده میشه سمت کلاینت بشمارید بعد نتیجه اخر را به سرور ارسال کنید!
درود دوست خوبم
شما درست می فرمایید، اما من نمی دونم چطوری می تونم تعداد صفحات رو بشمرم اگر لطف کنید و کد بذارید بسیار ممنونتون می شم. rose


RE: تعداد صفحات پرینت شده از طرف هر کلاینت - Amin_Mansouri - 06-22-2012

درود
با سورس زیر میتونی تعداد صفحات پرنت شده رو بدست بیاری
چو شبکه داخل هستد یه برنامه تحت سرور بنویس با یه کلاینت کلی سورس مثل چت هست که میتوند ازشون کمک بگیرید نوشتنش ک اری نداره
واسه تعداد صفحات پرینت شده و وضعیت پرینت من 2 تا سورس بهت میدم.
سورس 1:
کد:
Get the number of print jobs in a print queue

The following routine can be used to return the number of print jobs waiting in a queue (for both local and network printers).

Option Explicit

'Constants Definition
Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8

'Types Definition
Private Type DEVMODE
    dmDeviceName As String * CCHDEVICENAME
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * CCHFORMNAME
    dmUnusedPadding As Integer
    dmBitsPerPel As Long
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
End Type

Private Type PRINTER_DEFAULTS
    pDatatype As String
    pDevMode As DEVMODE
    DesiredAccess As Long
End Type

Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Private Type JOB_INFO_1_API
    JobId As Long
    pPrinterName As Long
    pMachineName As Long
    pUserName As Long
    pDocument As Long
    pDatatype As Long
    pStatus As Long
    Status As Long
    Priority As Long
    Position As Long
    TotalPages As Long
    PagesPrinted As Long
    Submitted As SYSTEMTIME
End Type

Private Type JOB_INFO_1
    JobId As Long
    pPrinterName As String
    pMachineName As String
    pUserName As String
    pDocument As String
    pDatatype As String
    pStatus As String
    Status As Long
    Priority As Long
    Position As Long
    TotalPages As Long
    PagesPrinted As Long
    Submitted As SYSTEMTIME
End Type

'API Declarations
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal HPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, ByVal pJob As Long, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long

Private Declare Sub CopyMem Lib "kernel32.dll" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32.dll" (ByVal lpString As Long) As Long

Private Declare Function HeapAlloc Lib "kernel32.dll" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GetProcessHeap Lib "kernel32.dll" () As Long
Private Declare Function HeapFree Lib "kernel32.dll" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long


'Private structure filled by PrinterQueueItems with all the documents data in the selected printer queue
Private JobsDesc(0 To 127) As JOB_INFO_1


'Purpose     :  Returns the number of atJobs in the specified Printer Queue
'Inputs      :  sPrinterName            The name of the printer,
'                                       can be a network path eg. "\\MYSERVER\MYPRINTER"
'Outputs     :  Returns the number of printer atJobs in queue


Function PrinterQueueItems(sPrinterName As String) As Long
    Dim tPrinterStruct As PRINTER_DEFAULTS
    Dim lhwndPrinter As Long
    Dim bRet As Boolean
    Dim atJobs(0 To 127) As JOB_INFO_1_API
    Dim lpcbNeeded As Long
    Dim lpcReturned As Long
    Dim lThisJob As Integer
    Dim lTempBuff As Long

    'Initialize the Printer structure
    tPrinterStruct.pDatatype = vbNullString
    tPrinterStruct.pDevMode.dmSize = Len(tPrinterStruct.pDevMode)
    tPrinterStruct.DesiredAccess = PRINTER_ACCESS_USE
    'Get the printer Handle
    bRet = OpenPrinter(sPrinterName, lhwndPrinter, tPrinterStruct)
    'Get the Printer active atJobs
    bRet = EnumJobs(lhwndPrinter, 0, 127, 1, lTempBuff, 0, lpcbNeeded, lpcReturned)
    If lpcbNeeded = 0 Then
        PrinterQueueItems = 0
    Else
        'Allocate the Buffer
        lTempBuff = HeapAlloc(GetProcessHeap(), 0, lpcbNeeded)
        bRet = EnumJobs(lhwndPrinter, 0, 127, 1, lTempBuff, lpcbNeeded, lpcbNeeded, lpcReturned)
        CopyMem atJobs(0), ByVal lTempBuff, lpcbNeeded
        For lThisJob = 0 To lpcReturned - 1
            JobsDesc(lThisJob).pPrinterName = LPSTRtoSTRING(atJobs(lThisJob).pPrinterName)
            JobsDesc(lThisJob).pMachineName = LPSTRtoSTRING(atJobs(lThisJob).pMachineName)
            JobsDesc(lThisJob).pUserName = LPSTRtoSTRING(atJobs(lThisJob).pUserName)
            JobsDesc(lThisJob).pDocument = LPSTRtoSTRING(atJobs(lThisJob).pDocument)
            JobsDesc(lThisJob).pDatatype = LPSTRtoSTRING(atJobs(lThisJob).pDatatype)
            JobsDesc(lThisJob).pStatus = LPSTRtoSTRING(atJobs(lThisJob).pStatus)
            JobsDesc(lThisJob).JobId = atJobs(lThisJob).JobId
            JobsDesc(lThisJob).Status = atJobs(lThisJob).Status
            JobsDesc(lThisJob).Priority = atJobs(lThisJob).Priority
            JobsDesc(lThisJob).Position = atJobs(lThisJob).Position
            JobsDesc(lThisJob).TotalPages = atJobs(lThisJob).TotalPages
            JobsDesc(lThisJob).PagesPrinted = atJobs(lThisJob).PagesPrinted
            JobsDesc(lThisJob).Submitted = atJobs(lThisJob).Submitted
        Next
        If lTempBuff Then HeapFree GetProcessHeap(), 0, lTempBuff
        PrinterQueueItems = lpcReturned
    End If
    'Close printer
    bRet = ClosePrinter(lhwndPrinter)
End Function

'Removes Null Characters
Private Function TrimStr(strName As String) As String
    'Finds a null then trims the string
    Dim x As Integer

    x = InStr(strName, vbNullChar)
    If x > 0 Then
        TrimStr = Left(strName, x - 1)
    Else
        TrimStr = strName
    End If
End Function


'Returns a string from a pointer
Private Function LPSTRtoSTRING(ByVal lngPointer As Long) As String
    Dim lngLength As Long

    'Get number of characters in string
    lngLength = lstrlenW(lngPointer) * 2
    'Initialize string so we have something to copy the string into
    LPSTRtoSTRING = String(lngLength, 0)
    'Copy the string
    CopyMem ByVal StrPtr(LPSTRtoSTRING), ByVal lngPointer, lngLength
    'Convert to Unicode
    LPSTRtoSTRING = TrimStr(StrConv(LPSTRtoSTRING, vbUnicode))
End Function


'Demonstration routine
Sub Test()
    'Get the Default Printer's Queue
    Debug.Print "Number of Documents in Queue: " & PrinterQueueItems(Printer.DeviceName)
End Sub

سورس 2 که بصورت اموزشی هم هست خیلی کمکت میکنه دوست عزیز
http://support.microsoft.com/kb/202480
بدرود


RE: تعداد صفحات پرینت شده از طرف هر کلاینت - atpf - 06-22-2012

(06-22-2012، 04:44 PM)Amin_Mansouri نوشته: درود
با سورس زیر میتونی تعداد صفحات پرنت شده رو بدست بیاری
چو شبکه داخل هستد یه برنامه تحت سرور بنویس با یه کلاینت کلی سورس مثل چت هست که میتوند ازشون کمک بگیرید نوشتنش ک اری نداره
واسه تعداد صفحات پرینت شده و وضعیت پرینت من 2 تا سورس بهت میدم.
درود دوست خوبم.
بسی سپاسگزارم. rose


RE: تعداد صفحات پرینت شده از طرف هر کلاینت - atpf - 06-22-2012

(06-22-2012، 04:44 PM)Amin_Mansouri نوشته: درود
با سورس زیر میتونی تعداد صفحات پرنت شده رو بدست بیاری
چو شبکه داخل هستد یه برنامه تحت سرور بنویس با یه کلاینت کلی سورس مثل چت هست که میتوند ازشون کمک بگیرید نوشتنش ک اری نداره
واسه تعداد صفحات پرینت شده و وضعیت پرینت من 2 تا سورس بهت میدم.
سورس 1:
کد:
Get the number of print jobs in a print queue

The following routine can be used to return the number of print jobs waiting in a queue (for both local and network printers).

Option Explicit

'Constants Definition
Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8

'Types Definition
Private Type DEVMODE
    dmDeviceName As String * CCHDEVICENAME
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * CCHFORMNAME
    dmUnusedPadding As Integer
    dmBitsPerPel As Long
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
End Type

Private Type PRINTER_DEFAULTS
    pDatatype As String
    pDevMode As DEVMODE
    DesiredAccess As Long
End Type

Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Private Type JOB_INFO_1_API
    JobId As Long
    pPrinterName As Long
    pMachineName As Long
    pUserName As Long
    pDocument As Long
    pDatatype As Long
    pStatus As Long
    Status As Long
    Priority As Long
    Position As Long
    TotalPages As Long
    PagesPrinted As Long
    Submitted As SYSTEMTIME
End Type

Private Type JOB_INFO_1
    JobId As Long
    pPrinterName As String
    pMachineName As String
    pUserName As String
    pDocument As String
    pDatatype As String
    pStatus As String
    Status As Long
    Priority As Long
    Position As Long
    TotalPages As Long
    PagesPrinted As Long
    Submitted As SYSTEMTIME
End Type

'API Declarations
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal HPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, ByVal pJob As Long, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long

Private Declare Sub CopyMem Lib "kernel32.dll" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32.dll" (ByVal lpString As Long) As Long

Private Declare Function HeapAlloc Lib "kernel32.dll" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GetProcessHeap Lib "kernel32.dll" () As Long
Private Declare Function HeapFree Lib "kernel32.dll" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long


'Private structure filled by PrinterQueueItems with all the documents data in the selected printer queue
Private JobsDesc(0 To 127) As JOB_INFO_1


'Purpose     :  Returns the number of atJobs in the specified Printer Queue
'Inputs      :  sPrinterName            The name of the printer,
'                                       can be a network path eg. "\\MYSERVER\MYPRINTER"
'Outputs     :  Returns the number of printer atJobs in queue


Function PrinterQueueItems(sPrinterName As String) As Long
    Dim tPrinterStruct As PRINTER_DEFAULTS
    Dim lhwndPrinter As Long
    Dim bRet As Boolean
    Dim atJobs(0 To 127) As JOB_INFO_1_API
    Dim lpcbNeeded As Long
    Dim lpcReturned As Long
    Dim lThisJob As Integer
    Dim lTempBuff As Long

    'Initialize the Printer structure
    tPrinterStruct.pDatatype = vbNullString
    tPrinterStruct.pDevMode.dmSize = Len(tPrinterStruct.pDevMode)
    tPrinterStruct.DesiredAccess = PRINTER_ACCESS_USE
    'Get the printer Handle
    bRet = OpenPrinter(sPrinterName, lhwndPrinter, tPrinterStruct)
    'Get the Printer active atJobs
    bRet = EnumJobs(lhwndPrinter, 0, 127, 1, lTempBuff, 0, lpcbNeeded, lpcReturned)
    If lpcbNeeded = 0 Then
        PrinterQueueItems = 0
    Else
        'Allocate the Buffer
        lTempBuff = HeapAlloc(GetProcessHeap(), 0, lpcbNeeded)
        bRet = EnumJobs(lhwndPrinter, 0, 127, 1, lTempBuff, lpcbNeeded, lpcbNeeded, lpcReturned)
        CopyMem atJobs(0), ByVal lTempBuff, lpcbNeeded
        For lThisJob = 0 To lpcReturned - 1
            JobsDesc(lThisJob).pPrinterName = LPSTRtoSTRING(atJobs(lThisJob).pPrinterName)
            JobsDesc(lThisJob).pMachineName = LPSTRtoSTRING(atJobs(lThisJob).pMachineName)
            JobsDesc(lThisJob).pUserName = LPSTRtoSTRING(atJobs(lThisJob).pUserName)
            JobsDesc(lThisJob).pDocument = LPSTRtoSTRING(atJobs(lThisJob).pDocument)
            JobsDesc(lThisJob).pDatatype = LPSTRtoSTRING(atJobs(lThisJob).pDatatype)
            JobsDesc(lThisJob).pStatus = LPSTRtoSTRING(atJobs(lThisJob).pStatus)
            JobsDesc(lThisJob).JobId = atJobs(lThisJob).JobId
            JobsDesc(lThisJob).Status = atJobs(lThisJob).Status
            JobsDesc(lThisJob).Priority = atJobs(lThisJob).Priority
            JobsDesc(lThisJob).Position = atJobs(lThisJob).Position
            JobsDesc(lThisJob).TotalPages = atJobs(lThisJob).TotalPages
            JobsDesc(lThisJob).PagesPrinted = atJobs(lThisJob).PagesPrinted
            JobsDesc(lThisJob).Submitted = atJobs(lThisJob).Submitted
        Next
        If lTempBuff Then HeapFree GetProcessHeap(), 0, lTempBuff
        PrinterQueueItems = lpcReturned
    End If
    'Close printer
    bRet = ClosePrinter(lhwndPrinter)
End Function

'Removes Null Characters
Private Function TrimStr(strName As String) As String
    'Finds a null then trims the string
    Dim x As Integer

    x = InStr(strName, vbNullChar)
    If x > 0 Then
        TrimStr = Left(strName, x - 1)
    Else
        TrimStr = strName
    End If
End Function


'Returns a string from a pointer
Private Function LPSTRtoSTRING(ByVal lngPointer As Long) As String
    Dim lngLength As Long

    'Get number of characters in string
    lngLength = lstrlenW(lngPointer) * 2
    'Initialize string so we have something to copy the string into
    LPSTRtoSTRING = String(lngLength, 0)
    'Copy the string
    CopyMem ByVal StrPtr(LPSTRtoSTRING), ByVal lngPointer, lngLength
    'Convert to Unicode
    LPSTRtoSTRING = TrimStr(StrConv(LPSTRtoSTRING, vbUnicode))
End Function


'Demonstration routine
Sub Test()
    'Get the Default Printer's Queue
    Debug.Print "Number of Documents in Queue: " & PrinterQueueItems(Printer.DeviceName)
End Sub

سورس 2 که بصورت اموزشی هم هست خیلی کمکت میکنه دوست عزیز
http://support.microsoft.com/kb/202480
بدرود
درودی دیگر دوست من
غرض از مزاحمت اینکه کدی که شما دادید برا VB هستش اگه لطف کنید برا C# هم بذارید ممنون میشم.
ضمن اینکه اگه درد سر نیست براتون در مورد قسمت های مختلف سورسی که میذارید توضیحاتی بدید تا روشن بشم. آخه تازه کارم من استاد.
باسپاس rose


RE: تعداد صفحات پرینت شده از طرف هر کلاینت - karim_orooji - 08-18-2014

سلام استاد 
اون دو نمونه کدی رو که گذاشتید میتونید با مثال توی یک پروژه کنید
چون من مبتدی  هستم  نمیتونم کد رو استفاده کنم


ممنون میشم