Friday, July 13, 2012

Crystal Reports,how to use SQL to find first or nth row of every group

If you want to find the first row of every group in Crystal Reports you've got different options. 1 option is using

 If Previous ({table.GroupingField}) = ({table.GroupingField}) Then   
   False  
 Else  
   True  

But another option I like, is using the row_number function of Sql Server. With this function you can number your rows and have the row number reset depending on for example your group condition. Below is an example where I want the row number to reset if the column "SERNR" changes. I've also included the sql results so you can see the row number resetting if the "SERNR" changes. In Crystal Reports you simply check if row_number = 1 or 2 or 3 or which row you want to do something for.

 select row_number() over (Partition by em037.sernr order by em037.datum asc),  
 em037.*, em035.merk, em035.mtype, em035.numpl, em035.numpv, em035.machn, em035.chafn  
 from em037  
 inner join em035 on em035.sernr = em037.sernr  
 where em037.datum between '03/01/2012' and '06/30/2012' and  
 em037.sernr in ('W0L0AHM757G138179', 'WOLGT8EK8A1010638','WVGZZZ1TZ9W085082')  
 and em035.rtype = '002'  



Thursday, June 21, 2012

Combining ImageMagick & VB.Net to print PCX image on TSC/Impuls printer

If you want to print pictures on an TSC printer from .Net you've got different options, the BITMAP command the, PUTBMP and the PUTPCX. But from the TSC .net dll only the downloadPCX command is directly available. The disadvantage is that PCX is a realy old graphic format. So converting a bmp, jpg, png to pcx isn't straightforward in .Net. Luckily you can do this with the ImageMagick commandline tools, the MagickNet .Net port doesn't support the commands needed to convert the image to a halftone image and a pcx file.

These are the commands needed to convert to halftone and then convert this halftone to pcx

 Process.Start("C:\Program Files\ImageMagick-6.7.7-Q16\convert.exe", "sourceFile -colorspace Gray -ordered-dither h4x4a destinationFile")  
 Process.Start("C:\Program Files\ImageMagick-6.7.7-Q16\convert.exe", "destinationFile -colors 2 -depth 1 pcxFile")  

Next you can print an image by using the following commands, the TSC dll should be present in the same directory as the executable

 Private Declare Sub openport Lib "tsclib.dll" (ByVal PrinterName As String)  
 Private Declare Sub closeport Lib "tsclib.dll" ()  
 Private Declare Sub sendcommand Lib "tsclib.dll" (ByVal command_Renamed As String)  
 Private Declare Sub setup Lib "tsclib.dll" (ByVal LabelWidth As String, ByVal LabelHeight As String, ByVal Speed As String, ByVal Density As String, ByVal Sensor As String, ByVal Vertical As String, ByVal Offset As String)  
 Private Declare Sub downloadpcx Lib "tsclib.dll" (ByVal Filename As String, ByVal ImageName As String)  
 Private Declare Sub barcode Lib "tsclib.dll" (ByVal X As String, ByVal Y As String, ByVal CodeType As String, ByVal Height_Renamed As String, ByVal Readable As String, ByVal rotation As String, ByVal Narrow As String, ByVal Wide As String, ByVal Code As String)  
 Private Declare Sub printerfont Lib "tsclib.dll" (ByVal X As String, ByVal Y As String, ByVal FontName As String, ByVal rotation As String, ByVal Xmul As String, ByVal Ymul As String, ByVal Content As String)  
 Private Declare Sub clearbuffer Lib "tsclib.dll" ()  
 Private Declare Sub printlabel Lib "tsclib.dll" (ByVal NumberOfSet As String, ByVal NumberOfCopy As String)  
 Private Declare Sub formfeed Lib "tsclib.dll" ()  
 Private Declare Sub nobackfeed Lib "tsclib.dll" ()  
 Private Declare Sub windowsfont Lib "tsclib.dll" (ByVal X As Short, ByVal Y As Short, ByVal fontheight_Renamed As Short, ByVal rotation As Short, ByVal fontstyle As Short, ByVal fontunderline As Short, ByVal FaceName As String, ByVal TextContent As String)  
 Private Sub Print  
 Call openport(printername)  
 Call setup("44", "80", "4.0", "7", "0", "0", "0")  
 Call clearbuffer()  
 Call sendcommand("DIRECTION 1")  
 Call sendcommand("1") ' Or the number of printout per cut'  
 Call downloadpcx(Application.StartupPath & "\" & pcxFileName, "UL.PCX")  
 Call sendcommand("MOVE")  
 Call sendcommand("PUTPCX 20,20,""UL.PCX""")  
 Call printlabel("1", "1")  
 Call closeport()  
 End Sub  

Wednesday, May 23, 2012

HP Data Protector - Fail job on mount request

If you want a HP Data Protector job to fail on a mount request, you can do this by creating a script abort.bat to replace the default Mount.bat script. The contents if the abort.bat script should be the following:


@echo off
set THIS=%0
set USER=%1
set GROUP=%2
set HOSTNAME=%3
set STARTPID=%4
set DEVNAME=%5
set DEVHOST=%6
set DEVFILE=%7
set DEVCLSS=%8
set DEVCLASSNAME=%9
shift
shift
shift
shift
shift
shift
shift
shift
shift
set MEDID=%1
set MEDLABEL=%2
set MEDLOC=%3
set POOLNAME=%4
set POLICY=%5
set MEDCLASS=%6
set MEDCLASSNAME=%7
set SESSIONKEY=%8

omniabort.exe -session %SESSIONKEY%

Edit 20/07/2012 in DP 6.11 you need to leave out C:\Program Files\OmniBack\bin\ before omniabort.exe -session %SESSIONKEY% otherwise the script will not run.


(You maybe need to change the path of the omniabort.exe but on windows installation it's normally installed in this directory).

To change the script that's run on a mount request you need to go to the Device properties => Settings => Advanced => Other.

Source


Thursday, May 10, 2012

Windows 7 & Cisco, red cross on network shares

Since we started using Windows 7 at work we started noticing that network shares would have a red cross icon after booting. This caused some problems with programs that relied on these network drives. If a user clicked on the mapped drive it would become instantly available. After doing quite a bit of research we found that Win 7 wasn't the only culprit. At the time we started using Win 7 we also updated or network infrastructure from 3com to Cisco. Both 3com and Cisco had spanning tree configured, but with Cisco we had to turn on spanning-tree portfast. Once portfast was turned on, the red cross problem was gone. Spanning-tree portfast allows the port to which the client pc is patched to come up faster. I would advice to also turn on BPDU guard when turning on portfast. 


Windows 7, where are my shortcuts?

One sparkling new feature of Windows 7 is that it feels the urge to delete desktop shortcuts to network folders every now and then.
You can disable this feature by going to control panel => Troubleshooting => Change settings (in the left column) and there turn off Computer Maintenance. Now all your shortcuts should remain on your desktop


Monday, March 5, 2012

Vb.net has the database changed since opening a record (Optimistic Concurrency, ADO.NET)

This is a very interesting MSDN  link for (vb.net) programmers looking for a way to solve a well known problem: How do I know if the data in my database has changed since I got my data from the database, this is also called "concurrency"

For example (from the msdn link)

At 1:00 p.m., User1 reads a row from the database with the following values:

CustID     LastName     FirstName
101          Smith             Bob

At 1:01 p.m., User2 reads the same row.

At 1:03 p.m., User2 changes FirstName from "Bob" to "Robert" and updates the database.
The update succeeds because the values in the database at the time of update match the original values that User2 has.


At 1:05 p.m., User1 changes "Bob"'s first name to "James" and tries to update the row.
At this point, User1 encounters an optimistic concurrency violation because the value in the database ("James") no longer matches the original value that User1 was expecting ("Bob"). 

The concurrency violation simply lets you know that the update failed. The decision now needs to be made whether to overwrite the changes supplied by User2 with the changes supplied by User1, or to cancel the changes by User1.




Here is another link about one of the techniques talked about in the MSDN article

Peter

Tuesday, February 7, 2012

HP Data Protector new notification not triggered

If you've added a new notification in the Data Protector Reporting module, and it seems that your new notification never fires. You have to verify 2 things:


1) Don't forget to do a omnisv -stop / omnisv -start on the command prompt after adding a notifiation.

2) Check your global config file to make sure that the daily check isn't set to 'None'. You can find the global file in ..\omniback\config\server\options and then do a search for 'DailyCheckTime'. Default it runs at 12:30 (24 hour clock notation)


Wednesday, February 1, 2012

Visual Studio 2010 SP1 install hangs, VS2010-KB983509, Warning 1909.Could not create Shortcut

Last week I was upgrading the Visual Studio 2010 on multiple workstations to SP1. On one workstation the update kept running and running for more than an hour and got stuck on installing "VS2010-KB983509" . Cancelling and reapplying the update didn't help. After some googling I tried to remove and reinstall the Microsoft Visual C++ 2010 redist and runtime. This also didn't help. 


After doing some more research I found you can monitor the log file of the SP1 install in %TEMP% folder
look for a file with the following pattern  HFI*.tmp.html and a recent date.


In my case this log file kept growing and growing so I opened it and pretty soon it was obvious that the installer was stuck in a loop trying to create a .lnk file


This was the exact error: "Warning 1909.Could not create Shortcut Visual Studio Itanium Cross Tools Command Prompt (2010).lnk. Verify that the destination folder exists and that you can access it.  Are you sure you want to cancel?"


If you read this error you would expect to see a popup window asking to cancel the install but no popup was displayed. So by doing some more research I decided to look at the %comspec% environment variable. You can do this by running the set command in a cmd window or win + r and run sysdm.cpl and go to the advanced tab and click on the button "Environment Variables" 


The %comspec% variable should like %SystemRoot%\system32\cmd.exe but in my case, some previous installer left /blabla/blaa.bat after the cmd.exe part. So after changing the variable back to %SystemRoot%\system32\cmd.exe the SP1 installer finished his job in about 20 minutes 

HP Data Protector - omnisnmp - Cannot configure the SNMP service...

When trying to start omnisnmp on your HP Data Protector cell manager you may receive the following error:


"Cannot configure the SNMP service, it is not installed on the system. Install the SNMP service from the Control Panel's Network icon."






First of all, make sure the SNMP service is installed and running. But this is usually the case when you want to start omnisnmp :-)


The problem is that omnisnmp can't run when other HP Insight utilities are running, so open your services.msc and stop all HP Insight xxxxx agents which are running. 



After stopping the services execute the omnisnmp command again and it should run fine and don't forget to restart the services you stopped

Extra info from HP