Showing posts from 2015

Print a sales receipt using a thermal printer with C# for POS Application

If you have ever tried to build a POS (Point Of Sales or Point of Services) application, you might have come across the requirement to print a sales receipt like the following. Not just retail stores, but these receipts are produced by banks, hospitality and healthcare too.

Most of the time, such a receipt can be printed using a POS printer, which looks like the one below. The application developer needs to send ESC/POS commands to such a printer  (eg: EPSON) to print the actual receipt. Depending on the manufacturer the capabilities can be vary. However, most of them can handle most of the print commands and print a nicely formatted receipt.

The main advantage of using raw ESC/POS commands for printing is that the printing performance will be faster but this depends on the printer itself.

In this post, I will be using a windows application to send commands to the printer. If you want to do this through a ASP.NET website, the process is a bit more complex and I will try to create anot…

Adding Syntax Highlighting To Blogger

When I was searching for syntax highlighters I found this really cool library and decided to use that instead of piggybacking on SO.

The steps
Don't download hightlight.jsYou need to make changes to your blogger template. Go to your blogger dashboard. ( )Go to Template section on the left side bar.Backup your templateThere is a "Live On Blog" showing a screen of your current blog. under that, there is a "Edit HTML". click that button.hit CTRL+F and type "</b:skin>" and hit enter. Add these lines below "</b:skin>"

<link rel="stylesheet" href=""/> <script src=""></script>
hit CTRL+F and type "</body>" and hit enter. Add this script above "</body>"

Audit SQL Tables with Trigger

Say , you want to audit every record changes in your database tables and also, you need an easier way to query these data whenever needed, I present you, a sample SQL trigger for inserting a new audit record to audit table when an insert, update or delete operation is done on a table row.

First, the audit table: 
CREATE TABLE [dbo].[AuditRecord]( [ID] [int] IDENTITY(1,1) NOT NULL, [AuditType] [char](1) NOT NULL, [TableName] [nvarchar](50) NOT NULL, [OperationTimeStamp] [datetime] NOT NULL CONSTRAINT [DF_AuditRecord_OperationTimeStamp] DEFAULT (getdate()), [UserName] [nvarchar](50) NOT NULL, [Data] [xml] NOT NULL, CONSTRAINT [PK_AuditRecord] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

[AuditType] is either I (Insert), U (Update), or D (Delete)
[Data] is an XML field, which will contain all the IUD operations n…

ASP.NET MVC Fine Grained Identity & Access Control - Part 1

In this series I will explain how I designed a generic claims based access control system ASP.NET MVC 5 with Identity 2.0. Part 2: ASP.NET MVC Fine Grained Identity & Access Control - Part 2

The method I explain here will be useful for applications with moderate complexity, which would require an end user (an admin) to define which resources a particular user has access to. Since I could not find any existing projects with what I want, I bootstrapped my own. I realized that a lot of people want to build something like this, but there are no available resources. Also, please, not that, there is a lot of room for improvement. I will be updating the github repo as I develop the blog post series.

This post targets moderate .NET skill sets. If you have no idea what a claim is, you should first go through that. And see how role based access works. And then come back to claims. Understand the difference and then come back to this post. Also, its nice if you do know what logic gates are. Mo…

Log4Net Logging Output with ReSharper Test Runner - Config

This post assumes you know what Log4Net is and how to configure it and you are using ReSharper and you are unit testing your code. If you don't its time to learn something new..

If you want your log lines to show up in resharper test output window, you need to add  TraceAppender to the appenders list.

<appender name="NetTraceAppender" type="log4net.Appender.TraceAppender, log4net"> <layout type="log4net.Layout.PatternLayout,log4net"> <param name="ConversionPattern" value="%d [%t] %-5p - %m%n" /> </layout> </appender> and the use it under root tag.

<root> <level value="Debug"/> <appender-ref ref="NetTraceAppender" /> <appender-ref ref="RollingFileAppender" /> </root> If using iBatis, and you only want to see the processed SQL query, include following also.

<!-- Print only messages of level DE…

Copy SQL Table With Child Table Relaionships

dbo.RoomOccupancyRate has many dbo.OccupancyChildRate records.

How to copy them?

Following stored procedure takes care of it. It even has the option to copy only the active items.

ALTER PROCEDURE [dbo].[sp_CopyHotelContractRoomOccupancyRate]@NewHotelContractIDint,@SelectedHotelContractIDint,@UserName nvarchar(20),@ActiveItemsOnly bit,@OldDateBandIdint,@NewDateBandIdint,@OldRoomOccupancyIdint,@NewRoomOccupancyIdint AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements. SET NOCOUNT ON; IF (EXISTS(SELECT TOP 1 cr.[RoomOccupancyRateID] FROM [dbo].[RoomOccupancyRate] cr INNER JOIN [dbo].[HotelRoomOccupancy] rc ON cr.[RoomOccupancyID]= rc.[RoomOccupancyID] WHERE rc.[RoomOccupancyID]=@OldRoomOccupancyId)) BEGIN PRINT '----[dbo].[RoomOccupancyRate] table should be copied'

Conditional Filtering in SQL

Assume I need to select a set of data based on the following criteria.

If the @Active-Items-Only flag is set, then select only the active itemsotherwise select all active and non-active items.DECLARE@ActiveOnly bit =1;-- select only activeSELECT[HotelContractID],[RoomTypeID],[TravelStart],[TravelEnd],[ReleaseTypeID],[ReleaseValue],[Active]FROM[dbo].[RoomAllocation]WHERE[HotelContractID]=124AND(CASE-- if active only selected, -- check only active = 1 rows in the table and return 1WHEN@ActiveOnly =1AND(Active =1)THEN1-- if active and inactive both selected, -- check for both active = 1 and active = 0 rows in the table and return 1WHEN<

Random Background & Text Color Generation - Javascript

The Code in JSFiddle:


Extract all MVC / WebApi area/controller/actions

I did some search and created my own based on the answers found in SO.

Extract all MVC / WebApi area/controller/actions - Gist

// // // // // // /// <summary> /// Extract all MVC/WebApi area/controller/actions /// </summary> publicclassResourceHelper { privateconststring NamespacePrefix = "github"; publicstatic List<ApplicationResource> GetResources() { var resources = new List<ApplicationResource>()…