Tuesday, July 12, 2011

Add & Delete Custom Printer Forms


* AddPrinterForm.prg
DEFINE CLASS AddPrinterForm AS Custom
 
 HIDDEN cUnit, cPrinterName, nFormHeight, nFormWidth, nLeftMargin, ;
              nTopMargin, nRightMargin, nBottomMargin, nInch2mm, nCm2mm, nCoefficient, hHeap
 
 cUnit = "English"  && inches or Metric - cm's
 cPrinterName = ""
 nFormHeight = 0
 nFormWidth = 0
 nLeftMargin = 0
 nTopMargin = 0
 nRightMargin = 0
 nBottomMargin = 0
 
 cApiErrorMessage = ""
 cErrorMessage = ""
 
 nInch2mm = 25.4
 nCm2mm = 10
 nCoefficient = This.nInch2mm * 1000
 
 hHeap = 0
 
 * Win API support class
 oWas = NULL
 
 PROCEDURE Init(tcUnit)
 This.oWas = NEWOBJECT("WinApiSupport", "WinApiSupport.fxp")
 IF PCOUNT() = 1 
  This.cUnit = PROPER(tcUnit)
 ENDIF
 This.LoadApiDlls()
 This.hHeap = HeapCreate(0, 4096, 0)
 * Use Windows default printer
 This.cPrinterName = SET("Printer",2)
 ENDPROC
 
 PROCEDURE cUnit_Assign(tcUnit)
 IF INLIST(tcUnit, "English", "Metric")
  This.cUnit = PROPER(tcUnit)
 ELSE
  RETURN 
 ENDIF
 * Calculate conversion coefficient
 This.nCoefficient = IIF(PROPER(This.cUnit) = "English", ;
      This.nInch2mm, This.nCm2mm) * 1000
 ENDPROC
 
 PROCEDURE Destroy
 IF This.hHeap <> 0
  HeapDestroy(This.hHeap)
 ENDIF
 
 ENDPROC
 
 PROCEDURE SetFormMargins(tnLeft, tnTop, tnRight, tnBottom)
 WITH This
  .nLeftMargin  = tnLeft   * .nCoefficient
  .nTopMargin  = tnTop    * .nCoefficient
  .nRightMargin  = tnRight  * .nCoefficient
  .nBottomMargin  = tnBottom * .nCoefficient
 ENDWITH
 ENDPROC
 
 PROCEDURE AddForm(tcFormName, tnWidth, tnHeight, tcPrinterName)
 LOCAL lhPrinter, llOK, lcForm
 
 This.nFormWidth  = tnWidth  * This.nCoefficient
 This.nFormHeight = tnHeight * This.nCoefficient
 IF PCOUNT() > 3
  This.cPrinterName = tcPrinterName
 ENDIF
 
 This.ClearErrors()
 lhPrinter = 0
 IF OpenPrinter(This.cPrinterName, @lhPrinter, 0) = 0
  This.cErrorMessage = "Unable to get printer handle for " + This.cPrinterName 
  This.cApiErrorMessage = WinApiErrMsg(GetLastError())
  RETURN .F.
 ENDIF
 
 lnFormName = HeapAlloc(This.hHeap, 0, LEN(tcFormName) + 1)
 = SYS(2600, lnFormName, LEN(tcFormName) + 1, tcFormName + CHR(0))
 
 * Build FORM_INFO_1 structure
 WITH This.oWas
  lcForm = .Num2Long(0) + .Num2Long(lnFormName) + ;
   .Num2Long(This.nFormWidth) + .Num2Long(This.nFormHeight) + ;
   .Num2Long(This.nLeftMargin) + .Num2Long(This.nTopMargin) + ;
   .Num2Long(This.nFormWidth - This.nRightMargin) + ;
   .Num2Long(This.nFormHeight - This.nBottomMargin)
 ENDWITH
 
 * Finally, call the API
 IF AddForm(lhPrinter, 1, @lcForm) = 0
  This.cErrorMessage = "Unable to Add Form " + tcFormName 
  This.cApiErrorMessage = STRTRAN(WinApiErrMsg(GetLastError()), "file", "form", -1, -1, 3)
  llOK = .F.
 ELSE
  llOK = .T.
 ENDIF
 = HeapFree(This.hHeap, 0, lnFormName)
 = ClosePrinter(lhPrinter)
 
 RETURN llOK
 
 PROCEDURE ClearErrors
 This.cErrorMessage = ""
 This.cApiErrorMessage = ""
 ENDPROC
 
 PROCEDURE DeleteForm(tcFormName, tcPrinterName)
 LOCAL lhPrinter, llOK
 
 IF PCOUNT() > 1
  This.cPrinterName = tcPrinterName
 ENDIF
 
 This.ClearErrors()
 lhPrinter = 0
 IF OpenPrinter(This.cPrinterName, @lhPrinter, 0) = 0
  This.cErrorMessage = "Unable to get printer handle for " + This.cPrinterName + "."
  This.cApiErrorMessage = WinApiErrMsg(GetLastError())
  RETURN .F.
 ENDIF
 
 * Finally, call the API
 llOK = ( DeleteForm(lhPrinter, tcFormName) <> 0 )
 IF NOT llOK 
  This.cErrorMessage = "Unable to delete Form " + tcFormName 
  This.cApiErrorMessage = STRTRAN(WinApiErrMsg(GetLastError()), "file", "form", -1, -1, 3)
 ENDIF
 = ClosePrinter(lhPrinter)
 RETURN llOK
 
 HIDDEN PROCEDURE LoadApiDlls
  DECLARE Long HeapCreate IN WIN32API Long dwOptions, Long dwInitialSize, Long dwMaxSize
  DECLARE Long HeapAlloc IN WIN32API Long hHeap, Long dwFlags, Long dwBytes
  DECLARE Long HeapFree IN WIN32API Long hHeap, Long dwFlags, Long lpMem
  DECLARE HeapDestroy IN WIN32API Long hHeap
  DECLARE Long GetLastError IN kernel32
 ENDPROC
 
ENDDEFINE
*----------------------------------------------------------------------------------------------
 
FUNCTION OpenPrinter(tcPrinterName, thPrinter, tcDefault)
DECLARE Long OpenPrinter IN WinSpool.Drv ;
 String pPrinterName, Long @ phPrinter, String pDefault
RETURN  OpenPrinter(tcPrinterName, @thPrinter, tcDefault)
 
FUNCTION ClosePrinter (thPrinter)
DECLARE Long ClosePrinter IN WinSpool.Drv Long hPrinter
RETURN ClosePrinter(thPrinter)
 
 
FUNCTION AddForm(thPrinter, tnLevel, tcForm)
DECLARE Long AddForm IN winspool.drv Long hPrinter, Long Level, String @pForm
RETURN AddForm(thPrinter, tnLevel, tcForm)
 
FUNCTION DeleteForm(thPrinter, tcForm)
DECLARE Long DeleteForm IN winspool.drv Long hPrinter, String  pFormName 
RETURN DeleteForm(thPrinter, tcForm)


* Ref : http://www.berezniker.com


Friday, June 24, 2011

Silverlight Isolated Storage Folder / Out of Browser Location

Isolated storage is stored in the OS user's local application data directory, which is different on various operating systems.  For example...


Windows XP Operating System


Isolated File Storage


C:\Documents and Settings\\Local Settings\Application Data\Microsoft\Silverlight\js\


Out of Browser Folder 


C:\Documents and Settings\\Local Settings\Application Data\Microsoft\Silverlight\OutOfBrowser\




Windows 7 or Windows Vista Operating System




Isolated File Storage


C:\Users\username>\AppData\LocalLow\Microsoft\Silverlight\is\



Out of Browser Folder 

C:\Users\username>\AppData\LocalLow\Microsoft\Silverlight\OutOfBrowser\

Thursday, April 28, 2011

Microsoft Community Contributor Award 2011


Just around a week ago, I had blogged about completing one year of active
participation in the Microsoft communities. Today morning, I was pleasantly
surprised to see the following mail in my inbox









I am deeply humbled (and a little worried on where I would place the MCCA logo
on my already overcrowded sidebar Smile) on receiving this and hopefully,
the access to complimentary resources will act as an extra motivational factor for
me to continue my activities. Well, enough of the boring acceptance speech and
 time to flaunt my latest logo





Tuesday, April 26, 2011

Crystal Reports - Passing a current value of grouping field into a subreport as a parameter


  1. Right-click on your subreport. Go to the Change Subreport Links submenu.
  2. Drag your field from the left menu to the right.
  3. Unselect the Select data in subreport based on field: option.
  4. Go into your subreport. Your field will appear in there as a parameter field.
  5. Place Parameter Field on Sub Report
  6. Right Click on Paramter Field in Sub Report and Click Find In Formula 
  7. go into Selection Formulas 
  8. go into Record Selection 
  9. Match Condition as per requirement like {pro_Dtl.Entry_Id} = {?Pm-pro_Hdr.Entry_Id}

Wednesday, April 20, 2011

Get Value from Variable inside Variable.



public class Utils
{
  public static object MyEvaluate(string eval, object source)
  {
    return source.GetType().GetField(eval,
      BindingFlags.IgnoreCase | BindingFlags.NonPublic | 
      BindingFlags.Instance | BindingFlags.Public)
      .GetValue(source);
  }
}
Then you'll have to call it like this instead:
private int A;

// initialize it in the declarations or elsewhere
this.A = 10;
string B = "A";
var C = Utils.MyEvaluate(B, this);