SQL
USE [PrintMonitor]
GO
/****** Object:  StoredProcedure [dbo].[OnPrinterInformationChanged]    Script Date: 10/15/2008 21:19:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[OnPrinterInformationChanged]
(
            @PrinterName varchar(220),
            @Location varchar(1024),
            @Comment varchar(1024),
            @JobCount int,
            @IsReady bit,
            @IsDoorOpen bit,
            @IsInError bit, 
            @IsInitialising bit, 
            @IsAwaitingManualFeed bit, 
            @IsOutOfToner bit,
            @IsUnavailable bit,
            @IsOffline bit, 
            @IsOutOfMemory bit,
            @IsOutputBinFull bit, 
            @IsPaperJammed bit,
            @IsOutOfPaper bit, 
            @IsPaused bit,
            @IsDeletingJob bit, 
            @IsInPowerSave bit,
            @IsPrinting bit,
            @IsWaitingOnUserIntervention bit, 
            @IsWarmingUp bit,
            -- 1.0.8 parameters
            @ServerName varchar(255),
            @ShareName varchar(255),
            @PortName varchar(255), 
            @DriverName varchar(255), 
            @SeperatorFilename varchar(255), 
            @PrintProcessor varchar(255), 
            @DefaultDataType varchar(255),
            @Parameters varchar(1024)
            )
AS
BEGIN

	 DECLARE @PrinterId int
	 
	 SET NOCOUNT ON 

              --If the server name is blank or null, use the HOST name
             IF (ISNULL(@Servername,'') = '')
                  SELECT @ServerName = HOST_NAME()

              IF NOT EXISTS (SELECT 'A' FROM dbo.[Print Servers] WHERE Name = @ServerName) 	 
                      INSERT INTO dbo.[Print Servers]
                                (
                                Name
                                )
                        VALUES
                               (
                               @ServerName
                               )

	 SELECT @PrinterId = Id
	   FROM dbo.Printers
	  WHERE Name = @PrinterName
	 
	 IF @PrinterId IS NOT NULL
	    UPDATE dbo.Printers
	       SET Location = @Location,
	           Comment = @Comment,
	           [Server Name] = @ServerName,
	           [Share Name] = @ShareName,
	           [Port Name] = @PortName,
	           [Driver Name] = @DriverName,
	           [Seperator Filename] = @SeperatorFilename,
	           [Print Processor] = @PrintProcessor,
	           [Default Data Type] = @DefaultDataType,
	           Parameters = @Parameters
	     WHERE Id = @PrinterId 
               ELSE
                    BEGIN
                         SELECT @PrinterId = 1 + (SELECT ISNULL(MAX(Id),0) FROM dbo.Printers)

                         INSERT INTO dbo.Printers
                             (
                             Id,
                             Name,
                             Location,
                             Comment,
                             [Server Name],
                             [Share Name],
                             [Port Name],
                             [Driver Name],
                             [Seperator Filename],
                             [Print Processor],
                             [Default Data Type],
                             Parameters
                             )
                           VALUES
                             (
                             @PrinterId,
                             @PrinterName,
                             @Location,
                             @Comment,
                             @ServerName,
                             @ShareName,
                             @PortName,
                             @DriverName,
                             @SeperatorFilename,
                             @PrintProcessor,
                             @DefaultDataType,
                             @Parameters
                             )
                    END
	 
	RETURN 

END

Last edited Oct 15, 2008 at 8:20 PM by Merrion, version 1

Comments

No comments yet.