Friday, September 27, 2013

Abstract Factory Design Pattern

I know there are hundreds of articles available in the web on this topic but this is such an interesting design pattern that I decided to also write about it. It took a lot of search and deep understanding of the concepts of one of the most important design patterns, the Abstract Factory Pattern. I will try to explain it. At first, it may sound quite similar to the Factory Pattern, but they are not the same. The Abstract Factory Pattern is at one level above the Factory Pattern.

When I began to get an idea of this pattern, I persisted and continued to scratch my head for days, with many articles on the internet, but all of them had the same definition as in the following:

"Results in an interface that provides families of related or dependent objects without providing their concrete classes."

I was not able to figure out what exactly does families of related or dependent objects in the definition mean. Finally, I was able to figure out the understanding of this definition, by comparing some of the articles that provided good real-world examples and related their examples with my example from the real world. So the result I developed is explained in the examples below.

What is Abstract Factory Design Pattern?

According to GoF's definition, this pattern "Provides an interface for creating families of related or dependent objects without specifying their concrete classes".

This pattern is generally referred to as a super-set of the Factory Pattern.

Since it is a broader, or a super-set, of the Factory Pattern, we will try to explain this with an example of the Factory Pattern and try to move on to the Abstract factory. So let's start with the Factory Pattern example.

A real-world example for Factory Pattern

Suppose your company gets an assignment in .NET technologies. You have a team of 20 members in .NET, with one team of Silverlight and another of .Net. Your business development team says, provide us the team of members with a required skillset. So your manager receives the required skill set from the BD team, selects a team from the two and gives them the assignment. So here:
  • BD team acts as the client who requests a team to work on a project.
  • Your manager acts on the Factory, who will decide the team to be selected.
  • Silverlight and .Net teams are one of the final outputs/resources received by the client or the BD team to work on the project.
So our factory structure will be something like the following:

image1.gif

And our BD team or client will be sending the request as:

image2.gif

Run the code and see the results.

So this was the Factory Pattern, where you have a single requirement (or a single product to be more precise, in terms of the definition of this pattern).

So now your company needs to receive a new project that requires two different teams, one of .NET and another of mobile technologies (could be Windows or could be Android based), to work on another project.

So here we have more options to do this requirement.

Option One

Add another method to the same factory we created above, to get the team for the mobile technologies. So our code becomes:

image3.gif

But this will not be a good approach. This is because we have added one more functionality; we should be making it more abstract, since we might get another project in the future, that may want to have its own criteria of selecting a team or that may add another requirement like a Java team to be included.

Option Two

We create another factory like the one we created for the .NET and then get the required team from the Mobile technologies team. But this is also not a good approach, since this may result in more and more factories as the requirements of adding more and more teams arises. Also for the same reason above, we may have more projects in the future, that may also need the selection of a mobile and .Net technology team to work on.

The concept that we have discussed until now provides us the following points:
  • We may have more requirements in the future (in other words we may need a third type of team like Java or any other technology team), for other projects. So we may be required to create another factory and may increase in number, as more requirements are added.
  • Right now, we have only one project and based on it we send the requirements and get the required output. But another project, may have different requirements. That project may have its own way of deciding the basic criteria for selecting the required team.
So, these are the two main points, that are addressed by the Abstract Factory Pattern. Let's see, how to do this technically in code and then we will discuss the preceding two points, handled by our code.

So our first job will be to create a Base Factory, that will be encapsulating the definition of the factories (or Team deciding factories).

image4.gif
Now comes the main point of explanation. We will be creating 2 different factories that will implementing the base factory, in their own ways . These factories are nothing but the Projects that we receive. So both of these projects will be deciding their requirements for getting the two different teams, in their own way. This is nothing but point 2 from above.

So our code becomes the following, for the two different projects. For project one:
image5.gif
For project two:

image6.gif

As we can see, we have no specific requirements for selecting the teams for project two. Both of these projects provide their own implementations.

Finally, further class implementations will remain the same like the following
:
image7.gif
Now the BD team will be getting the requirements as:

image8.gif

Now, run the code and see the results.

image9.gif

The following explains how the code above covers the two points that we covered earlier.
  1. For the first point we discussed above, since more technology teams are to be added, we have the same requirements being addressed by the use of a common base interface IBaseFactory. So we can add more teams whenever required, in the base factory (like we added the IMobileTechnologiesTeamFactory team).
  2. The second point we discussed was regarding different requirements of different projects. So class ProjectOne specifies its own requirements for the teams required and class ProjectTwo, does not have any specific requirements. So both have their own definitions.
These are, what I feel, are the reason for the use of this design pattern and what I understand about this pattern from my study. One last point, remember the definition that I mentioned in the start of the article:

"Results in an interface that provides families of related or dependent objects without providing their concrete classes."

This is also in sync with the example we discussed, since we have the interface IBaseFactory, with related groups of functionality in a single unit.
Any more suggestion/points you would like to add to this article are welcome.

Extended Properties Introduction

Extended Properties Introduction

I imagine that most SQL Server database developers and DBAs have used extended properties to add comments to the database objects which they create. However my experience is that this surprisingly useful aspect of the database metadata is often either underused or even avoided. This could be for a variety of reasons, some of which could include:
  • The system stored procedures which manipulate extended properties are initially unintuitive to use.
  • Collections of extended properties once they have been added to a database are not immediately accessible.
  • Adding extended properties is perceived as laborious and not suited to documenting hundreds or thousands of database objects quickly and easily.
  • Updating multiple extended properties in the database metadata can be equally hard work.
  • Exporting extended properties to use in external documentation (which normally means Word or Excel) can be a long-winded process.
So, in order to dispel any negative perceptions which may exist or persist, I intend to take the reader on a tour of extended properties which, I hope, will convince you that they are:
  • Easy to understand
  • Simple to create, modify and delete.
  • Not at all difficult to extract and use in other programs.
Given the amount of information and code to cover, this will be spread over four short articles:
  • An introduction to extended properties.
  • Extracting extended properties, and a macro to generate a Word document of extended properties.
  • Modifying and deleting extended properties.
  • Industrial-strength documentation with extended properties.
Yes, I know that there are plenty of resources about the system view, stored procedures and function which SQL Server uses to manage extended properties, and there are some excellent articles available (not least David Poole's recent article on SQLServerCentral). However, I thought that there was room for a step by step introduction to the subject with lots of practical examples - so here goes.
Let's begin at the start, what exactly are we talking about?
We are talking about ensuring the longevity of your database, by making sure that all your hard work spent creating and modifying a complex system is commented and noted inside the database itself. Nothing can write the documentation for you, but SQL Server can store comments on a specified subset of database objects inside the database metadata. There is no limit (as far as I can see) to the number of separate comments that you can add to a database object, and each one can have a separate heading, or classification. Each comment can be up to 7500 characters (whether you are using Unicode characters or not). Each classification is a sysname data type so has a 128 unicode character limit. Names can also include blank or non-alphanumeric character strings, and binary values - but in practice simple alphanumeric one or two word titles seem to be the most useful.
If you are feeling adventurous, you can use extended properties in many other imaginative ways. How about:
  • Storing data lineage information.
  • Storing versioning information (last modified by, succinct history of change reasons).
  • To store tooltips for user interfaces.
  • To store tooltips in multiple languages, using the name as a linguistic classification.
  • To store column headings for user interfaces.
  • To store column headings in multiple languages, using the name as a linguistic classification.
  • And many, many more!
However, I will presume that most developers and DBAs use extended properties for database documentation, and so this will be the main focus of these articles.

A quick run through extended properties and SSMS

Before we delve into code, and into code tricks and traps, it is worth noting in the interest of completeness, that you can enter extended properties for many (but not all) objects using SSMS. This has the following advantages:
  • Quick for ad-hoc creation and modification of extended properties.
  • Easy to see all the extended properties for a single object.
And the following disadvantages:
  • Very slow if you want to document dozens - or hundreds - of objects.
  • Not all objects are accessible for extended property creations and modification this way.
  • Not easy to get a more holistic view of extended properties, as you are operating only at a detail level.
The objects that you can document using SSMS are:
  • Database
  • Table
  • Table Column
  • Table Index
  • View
  • View Column
  • View Index
  • Stored Procedures
  • User-defined Functions
So, to document an object using SSMS, simply:
  1. Right-click on the object in the object explorer
  2. Select Properties
  3. Select "Extended Properties" in the left pane
  4. Add a new property by entering a name (or classification) and value (or comment).
  5. And, of course, confirm with "OK"
Yes, I know that this is probably too easy and you know it already, but in the interest of thoroughness, I though it best to include it. Besides, it can be really useful to tweak an extended property (and the ellipse button to have a text window to edit in is very useful)!
So, with the GUI approach dealt with, it is time to dig deeper into extended properties using T-SQL. I will begin with the basic database object, the database itself. When you document the database you are including in the database metadata, the following:
Extremely simple Extended Properties
Object type Classification Comment
Database Description This is my database, and I am very proud of it!
Database Description Database Developer Adam
As the metadata is limited to the database itself, you do not need to specify the database - it is a given.
It is fundamental to note that the only things that you can change are the "Classification" and the "Comment". The object is specified by the interface to the metadata (three stored procedures which we will start to look at in a few seconds), and there are only a limited set of objects which allow self-documentation using the extended properties built into SQL Server. However, when we look at all these objects, I am sure that you will agree that nearly everything that you could want to document has been made accessible by the development team.
The entire extended properties paradigm is based very simply on this model. Namely that you add a classification and a comment to any object that supports extended properties. There is no limit to the number of classifications (or property names as SQL Server calls them) that you can create, and nothing enforces their use across objects - it is up to you to apply a coherent naming convention to your extended properties. As you will see later, having a coherent set of classifications will help you create robust and resilient extended properties which can become the core of your database's documentation.
Let's take this one step further, and suppose that you want to add comments to a table. This could be explained schematically as:
Table Extended Properties
Object type Object Name Classification Comment
Table myTable Description This is my table!
Table myTable Developer Adam
And finally, to describe a column:
Column Extended Properties
Object type Object Name Object Sub-Name Classification Comment
Table myTable ID Description This is the ID column
Table myTable ID Developer Adam

As you can see, there is a clear hierarchy to extended properties. As it is this which seems to cause the most confusion amongst the database developers I have spoken to, let's look at it in a little more detail.
Firstly, the good news, there are only four levels.
  1. Database level (as shown in the example above)
  2. Level 0 (the first sub-level, called Level0 by SQL Server)
  3. Level 1 (the second sub-level, called Level1 by SQL Server)
  4. Level 2 (the third sub-level, called Level2 by SQL Server)
These levels correspond to a drill-down hierarchy of database objects, which is extremely coherent once understood, but which can seem a little peculiar at first sight.
So when adding extended properties, it is simply a question of understanding at which level an object is situated (as far as the developers of the extended properties stored procedures are concerned), and how to reference the object.
Rather than start with the system stored procedures which let you add extended properties, I want to take a different tack and start with the hierarchy of objects. Then I will give sample code for nearly every database object which can be documented, to give you reusable code snippets to document your databases.

The extended properties object hierarchy

This is the extended properties object hierarchy, which also covers all the extended properties that I will be covering in this article. Please note that this is not an exhaustive selection, but a subset based on my experience.
Extended Properties Hierarchy
Top Level Database
First Level Schema
Filegroup
Partition Function
Partition Schema
DDL Trigger
Second Level Table
View
Stored Procedure
User Defined Function (Scalar inline and table-valued)
Filegroup Logical file name
Third Level Column (table or view)
Table Constraint (Unique constraint, Default, Primary Key, Foreign Key)
Index (table or view)
Trigger (table or view)
Parameter (Stored Procedure or User Defined Function)

So once you know which object you want to document, all you have to do is find out the appropriate level, and add the comment using the built-in system stored procedure, adding the appropriate reference for the required levels.
The next step, therefore, is actually to do this, using the system stored procedure "sp_addextendedproperty", and seeing how it is used for the objects listed in the table above. I realise that you may not need all the code snippets given below, but preferred to give a reasonable selection so that you will, hopefully, find the one that you need to document your database objects ready to copy and paste.

Documenting the database itself

This is the simplest of all the extended properties to add, because there is no complexity about which level the object is at.
EXECUTE sys.sp_addextendedproperty 
@name = N'Overview' -- The "Classification"
,@value = N'Database comment' -- The "Comment"
;
As there is only one database - and the script has to be using that database for the metadata to be extended, you do not even have to specify the database name, or even the fact that you are referring to a database object. So please note that if you add extended properties without specifying any levels using "sp_addextendedproperty", then you will be adding comments at database-level.
Note:
  • You can, of course, not used named parameters to add extended properties, and merely add the parameter values in the correct order. I will leave the parameters in my examples to clarify the code.
  • If you are not using Unicode characters, then you can forget the "N" before the text that you are adding.

First-level objects

A basic first-level object is a schema, so here s how to add an extended property to an existing database schema:
EXECUTE sys.sp_addextendedproperty 
@level0type = N'SCHEMA' -- The object type
,@level0name = [Sales] -- The object name
,@name = N'Overview' -- The "Classification"
,@value = N'Main Schema' -- The "Comment"
;
The other main objects you can document with this variation on a theme of "sp_addextendedproperty"are:

Filegroup

EXEC sys.sp_addextendedproperty 
@level0type = N'FILEGROUP' 
,@level0name = [PRIMARY] 
,@name = N'Overview' 
,@value = N'Filegroup comment' 
;

Partition Function

EXEC sys.sp_addextendedproperty 
@level0type = N'PARTITION FUNCTION' 
,@level0name = [Partition1] 
,@name = N'Overview' 
,@value = N'Partition Function Comment' 
;

Partition Scheme

EXEC sys.sp_addextendedproperty 
@level0type = N'PARTITION SCHEME' 
,@level0name = [PS2] 
,@name = N'Overview' 
,@value = N'Partition Scheme Comment' 
;

DDL Trigger

EXECUTE sys.sp_addextendedproperty 
@level0type = N'TRIGGER' 
,@level0name = [trg_PreventDDL]
,@name = N'Overview'
,@value = N'Comment on DDL trigger'
;
There are a couple of points worth noting here, that will also apply to the database objects to come in this article:
  • The object type which is specified as "level0type" in the above examples is predefined, and though you may change the case of the object specification (unless your database objects are case-sensitive), you must use the exact object name, including any spaces.
  • You do not have to enclose an object name in square brackets or single quotes - unless the object name contains spaces or other sources of object-naming confusion.

Second-level objects

Probably the most documented object in a database is the table, so let's begin with one of those:
EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' -- The object schema
,@level0name = [Sales] -- The object schema name
,@level1type = N'TABLE' -- The object type
,@level1name = [Stock] -- The object name
,@name = N'Overview' -- The "Classification"
,@value = N'This is a stock table' -- The "Comment" 
;
You need to note here that all objects which are potentially schema-qualified need to have the schema specified, even if they use the default schema. So if an object is in the dbo schema - you need to specify this.
The other main objects you can document with this variation on a theme of "sp_addextendedproperty"are:

View

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales] 
,@level1type = N'VIEW' 
,@level1name = [vw_Invoices]
,@name = N'Overview' 
,@value = N'View Comment' 
;

Stored Procedure

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [dbo] 
,@level1type = N'PROCEDURE' 
,@level1name = [pr_ListClients]
,@name = N'Overview' 
,@value = N'Procedure comment' 
;

User-defined Function

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [dbo] 
,@level1type = N'FUNCTION' 
,@level1name = [ufn_GetTownCounty]
,@name = N'Overview' 
,@value = N'Scalar Function' 
;
This code will work for all types of user-defined Function - Scalar, Inline table and Table-Valued parameter.

Filegroup and logical file name

EXEC sys.sp_addextendedproperty 
@level0type = N'FILEGROUP' 
,@level0name = Secondary 
,@level1type = N'LOGICAL FILE NAME' 
,@level1name = [ExtendedProperties_2]
,@name = N'Overview' 
,@value = N'Filegroup and logical file name 2' 
;

Third-level objects

A frequently documented object is a table column, so here is how to add an extended property for a column:
EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' -- The object schema
,@level0name = [Sales] -- The object schema name
,@level1type = N'TABLE' -- The object type
,@level1name = [Stock] -- The object name
,@level2type = N'COLUMN' -- The object attribute
,@level2name = [Make] -- The object attribute name
,@name = N'Overview' -- The "Classification"
,@value = N'Basic column definition' -- The "Comment"
;
Other third-level objects are:

Column View

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales]
,@level1type = N'VIEW'
,@level1name = [vw_Invoices] 
,@level2type = N'COLUMN' 
,@level2name = [ClientName]
,@name = N'Overview' 
,@value = N'Basic column definition' 
;

Table Index

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales] 
,@level1type = N'TABLE' 
,@level1name = [Stock]
,@level2type = N'INDEX' 
,@level2name = [IX_Stock_Registration_Year]
,@name = N'Overview' 
,@value = N'Index comment' 
;

View Index

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales] 
,@level1type = N'VIEW' 
,@level1name = [vw_Stock]
,@level2type = N'INDEX' 
,@level2name = [CX_vw_Stock]
,@name = N'Overview' 
,@value = N'Comment on Index of Indexed view' 
;

Table Constraints

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales] 
,@level1type = N'TABLE' 
,@level1name = [Stock]
,@level2type = N'CONSTRAINT' 
,@level2name = [UQ_VehicleRegistration]
,@name = N'Overview' 
,@value = N'Unique constraint' 
;
EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales] 
,@level1type = N'TABLE' 
,@level1name = [Invoice]
,@level2type = N'CONSTRAINT' 
,@level2name = [DF_Invoice_InvoiceDate]
,@name = N'Overview' 
,@value = N'Default constraint' 
;
EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales] 
,@level1type = N'TABLE' 
,@level1name = [Invoice_Lines]
,@level2type = N'CONSTRAINT' 
,@level2name = [PK_Invoice_Lines]
,@name = N'Overview' 
,@value = N'Primary Key' 
;
EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales] 
,@level1type = N'TABLE' 
,@level1name = [Invoice_Lines]
,@level2type = N'CONSTRAINT' 
,@level2name = [FK_Invoice_Lines_Invoice]
,@name = N'Overview' 
,@value = N'Foreign Key' 
;
Although the code is the same for each of the four types of constraint (Unique, Default, Primary Key and Foreign Key) I have given the code for each so you can test them and see that they all work.

Table Trigger

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales] 
,@level1type = N'TABLE' 
,@level1name = [Invoice_Lines]
,@level2type = N'TRIGGER' 
,@level2name = [trg_Invoice_Lines]
,@name = N'Overview' 
,@value = N'Comment on table trigger' 
;

View Trigger

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [Sales] 
,@level1type = N'VIEW' 
,@level1name = [vw_InvoiceLineSalePrice]
,@level2type = N'TRIGGER' 
,@level2name = [NoViewDeletes]
,@name = N'Overview' 
,@value = N'Comment on view trigger' 
;

Stored Procedure Parameter

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [dbo] 
,@level1type = N'PROCEDURE' 
,@level1name = [pr_ListClients]
,@level2type = N'PARAMETER' 
,@level2name = '@ID'
,@name = N'Overview' 
,@value = N'Procedure parameter comment' 
;

User-defined Function parameter

EXEC sys.sp_addextendedproperty 
@level0type = N'SCHEMA' 
,@level0name = [dbo] 
,@level1type = N'FUNCTION' 
,@level1name = [ufn_GetTownCounty]
,@level2type = N'PARAMETER' 
,@level2name = '@ID'
,@name = N'Overview' 
,@value = N'Function Parameter' 
;
Notes:
  • Indexes on views only apply to indexed views - and so you can only add extended properties if you have the Enterprise or Developer versions of SQL server.
  • You need the rights to read the database metadata tables - but I am assuming that as a SQL Server developer, this is a given.
  • Avoid adding extended property names beginning with "MS_" - this is used in views to describe the graphical positioning of query tables, for instance. It is probably best to consider this a kind of reserved term.
  • You need the rights to write to the database metadata tables - but I am assuming that as a SQL Server developer, this is a given.
There are a few more extended properties which can be created, and they apply to the following objects:
  • Aggregate
  • Asymmetric Key
  • Assembly
  • Certificate
  • Service Broker Contract
  • Event Notification
  • Message Type
  • Plan Guide
  • Service Broker Queue
  • Remote Service Binding
  • Service Broker Route
  • Rule
  • Service
  • Symmetric Key
  • Synonym
  • Type
  • XML Schema Collection
The decision to exclude them from this explanation is a purely personal one based on the need not to swamp the reader in code, and to focus on essential database documentation. However, as these objects follow strictly the same logic as those described above, you can easily adapt the code snippets in this article to add extended properties to them also. If you are ever overcome by the need to do this, your first port of call should be: http://msdn.microsoft.com/en-us/library/ms190243.aspx.
The attached script contains all the code given above, grouped slightly differently. It collects the code snippets by object (Table, View etc.) , to help you document all an object's attributes. The next article will deal with Extracting, updating and deleting Extended Properties.
Have fun - and I hope that you found this useful.

Add Virtual Keyboard Using jQuery Plugin

Introduction

This article describes how to show a virtual keyboard in ASP.Net using a jQuery plugin.
Description
You will often see in some banking sites use of a virtual keypad in their site to enter a username and password.
That type of Virtual Keypad we can implement using the Mottie keyboard plugin of jQuery.
To create this application you need the jQuery files listed below.
  • jquery.min.js
  • jquery-ui.min.js
  • jquery-ui.css
Plugin files:
  • jquery.keyboard.js
  • jquery.keyboard.extension-typing.js
  • keyboard.css
You can download them from the source code attached in this page.
Refer to this link Mottie keyboard plugin
Design Add a TextBox to a page of which you want to show a keyboard when the focus is on it.
Now design your screen as in the following screen:

Or you can copy the following source code:

<body>
   <form id="form1" runat="server">

   
<div>

       
Textbox with virtual key pad

       
<asp:TextBox ID="keyboard" runat="server" MaxLength="4"></asp:TextBox>

   
</div>

   
</form>

</
body>
Next add the following JavaScript and CSSstyle in the head tag of an aspx file.

<
head runat="server">
   
<title></title>

   
<link href="jquery-ui.css" rel="stylesheet" type="text/css" />

   
<script src="jquery.min.js" type="text/javascript"></script>

   
<script src="jquery-ui.min.js" type="text/javascript"></script>

   
<link href="keyboard.css" rel="stylesheet" type="text/css" />

   
<script src="jquery.keyboard.js" type="text/javascript"></script>

   
<script src="jquery.keyboard.extension-typing.js" type="text/javascript"></script>

   
<script type="text/javascript">

       
$(document).ready(function () {

           
$('#keyboard').keyboard({

               
preventPaste: true,

               
autoAccept: true

           
})

           
.addTyping();

       
});

   
</script>

</
head>

In the code above just check this line:

preventPaste: true
It prevents a copy and paste on the TextBox.

Now build your application and put the focus on the TextBox. It will show the Virtual KeyBoard.


Virtual Key Board with Lock/Unlock button

You can provide an option for the user to use either the System keyboard or the Virtual Key Board by providing a Lock/unlock button.
To do that add the following JavaScript and CSSstyle in the head tag of an aspx file.

<
head id="Head1" runat="server">
   
<title></title>

   
<link href="http://code.jquery.com/ui/1.9.2/themes/ui-darkness/jquery-ui.css" rel="stylesheet">

   
<script src="jquery.min.js" type="text/javascript"></script>

   
<script src="jquery-ui.min.js" type="text/javascript"></script>

   
<link href="keyboard.css" rel="stylesheet" type="text/css" />

   
<script src="jquery.keyboard.js" type="text/javascript"></script>

   
<script src="jquery.keyboard.extension-typing.js" type="text/javascript"></script>

   
<script type="text/javascript">

       
$(document).ready(function () {

           
$('#keyboard').keyboard({

               
// Prevents direct input in the preview window when true

               
lockInput: true,

               
preventPaste: true,

               
autoAccept: true,

               
visible: function (e, kb, el) {

                   
if (!kb.$keyboard.find('.ui-keyboard-lock').length) {

                       
kb.$keyboard.append('<button class="ui-keyboard-button ui-keyboard-lock ui-state-default ui-corner-all"><span class="ui-icon-locked ui-icon"></span></button>');

                       
kb.$keyboard.find('.ui-keyboard-lock').click(function () {

                           
var locked = !kb.options.lockInput;

                           
kb.options.lockInput = locked;

                           
kb.$preview

                   
.toggleClass('ui-keyboard-lockedinput', locked)

                   
.prop('readonly', locked);

                           
$(this).find('span')

                   
.toggleClass('ui-icon-locked', locked)

                   
.toggleClass('ui-icon-unlocked', !locked);

                       
});

                   
}

               
}

           
})

.addTyping();

       
});

   
</script>

</
head>
In the code above just check this line:

lockInput: true
It used to prevent System keyboard input in the TextBox.

Now build your application and put the focus on the TextBox. It will show the Virtual KeyBoard with a Lock Symbol.
If the Symbol is Lock then that means you are unable to input from the system keyboard.
If it's unlocked then you will able to input from the system keyboard.