Thứ Ba, 27 tháng 11, 2012

How to show/hide Grid columns on the fly?

The solution is simple, but quite elaborate to make it work. Here's the complete example using JQuery. You can customize your own way.

First, reference JQuery and create the dynamic list of column names. Then design a checkbox accordingly and hook up onclick event for each:
   <script type="text/javascript" src="JS/jquery-1.3.js"></script>  
   <script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $("#tblExample th").each(function() {
            var iIndex = $(this).closest("th").prevAll("th").length;
            var colName = $(this).html();
                         id:    iIndex
                        ,name:    iIndex
                        ,value:    colName
                        ,type:    'checkbox'
                    .click( function( event )
                        var cbox = $(this)[0];
                        ShowHideColumn(, !cbox.checked);
                    } )
                        'for':    iIndex
                    .text( colName )

        $("#tblExample th").click(function() {
           var iIndex = $(this).closest("th").prevAll("th").length;
           ShowHideColumn(iIndex, true);
        function ShowHideColumn(iIndex, isHide)
               var display = "table-cell";
               if(isHide == true) display = "none";
               $("#tblExample").find("tr").each(function() {
                  $(this).find("td:eq(" + iIndex + ")").css("display", display);
                  $(this).find("th:eq(" + iIndex + ")").css("display", display);
           catch(e) { alert(e);}
        $("#tblExample th").mouseover(function() {

And here is the implementation of HTML markups in body section:
        <div id="divColumns">
        Put a yes/no check on each column name below to show/hide column correspondingly:<br />
        <br />
        Or you can click on header to hide the column at once:<br />
        <table id="tblExample" cellpadding="0" cellspacing="0" border="1" style="border:solid 1px gray;">
                <tr style="background-color:Gray;">
                <tr><td>0002</td><td>Lucky Luke</td><td>33</td></tr>


 Try to uncheck the "Age" checkbox and see how it works. Here's the result:

Happy coding,

Thứ Tư, 21 tháng 11, 2012

6 Key Points for a good IT management job

I've been working with IT management jobs for more than 5 years. I wanna share with you 6 key points which will make your job more fruitful. That is: Job Description, Diversity, Inspiration/Motivation, Rational Schedule, End-to-end Approach and Pecking Order.

1)   Job Description: Clearly-defined Job Description is the key. Develop well-defined standards and clear evaluation criteria in the first place, or as early as possible so employees can gauge their success and we don’t have to remedy the situation at some point in the future.

2)    Diversity: Value diversity in the team. Someone might not smart but work hard, then it has compensations. Think about giving detailed tasks to people who are big-picture oriented or assigned jobs that required toughness to people who are essentially very harmonious in nature. Either way doesn't work. So build on strengths, and to compensate for weaknesses. It’s a trade-off in the team. Remember: “The whole is greater than the sum of its parts”.

3)    Inspiration/Motivation: Inspire team members to grow their skills and develop on the team. Annually, each team member is forced to learn something new and share with others (seminar, forum...). Lack of training kills productivity in the long run.

4)    Rational Schedule: Ensure appropriate schedule for different teams and persons. Tightening schedule kills the creativity and quality in the long run. But loosen schedule causes diminishing focus. Has a balanced development process; are not too gentle or too hasty in software making process. In short, keep in minds 2 important laws:
  • Parkinson's Law: Work expands so as to fill the time available for its completion. (Công việc lúc nào cũng phình ra để lấp đầy thời gian cho phép)
  • Pareto law 80 20 principle.
5)    End-to-end Approach: The work speed, productivity is pretty much same no matter it is just the right begining of project life cycle or going down to the wire (không có giới hạn khoảng cách giữa các điểm khác nhau. Tốc độ làm việc, hiệu quả đều giống nhau cho dù đó là thời điểm bắt đầu hay cuối dự án). The key thing in this approach is "Bring development processes closer to the customers". Have the customer actively participate in the design and offer feedback throughout the development process. This allows both the team and customer to better align their expectations and needs.

6)    Pecking Order: Exercising authority in the team is a indispensable measure to minimize negative conflict and make sure that “running scared” is a good thing to steer the team on the right track.

Thứ Năm, 1 tháng 11, 2012

What is the difference between decodeURIComponent and decodeURI?

Sometimes, we post the request (search for instance) with the value of parameter ("keyword" for instance) passing on the URI, like below:

var uri="ập trình C++&includecomment=true";
If keyword parameter contains the special characters like , / ? : @ & = + $ #..., the URI will be parsed incorrectly. So we have to encode the parameter.

alert(encodeURI('lập trình C++')); ==> Return: l%E1%BA%ADp%20tr%C3%ACnh%20C++

alert(encodeURIComponent('lập trình C++')); ==> Return:l%E1%BA%ADp%20tr%C3%ACnh%20C%2B%2B 

alert(encodeURI('ập trình C++&includecomment=true')); ==> Return:

alert(encodeURIComponent('ập trình C++&includecomment=true')); ==> Return:

From MSDN JScript Reference:
The encodeURI method returns an encoded URI. If you pass the result to decodeURI, the original string is returned. The encodeURI method does not encode the following characters: ":", "/", ";", and "?". Use encodeURIComponent to encode these characters.

, sometimes called fixBrokenURI or produces a "safe" URI by encoding invalid characters such as spaces and some other (e.g. nonprintable), and turns it into a real URI. It has a valid use in fixing up invalid URIs from user input, and it can also be used to turn an IRI (URI with bare Unicode characters in) into a plain URI (using %-escaped UTF-8 to encode the non-ASCII).

encodes the colon and slash and plus characters, and is meant to be used in query strings. The encoding of + and ? and & is of particular importance here, as these are special chars in query strings.

Now you know the real difference between EncodeURI() and EncodeURIComponent().
Converserly, DecodeURI() and DecodeURIComponent() is provided to be an inverse of EncodeURI and EncodeURIComponent.

And here the real Web example:

<input type="text" name="keyword" id="keyword" value="<%=Server.HtmlEncode(Request.QueryString["keyword"]) %>" onkeypress="if(event.keyCode==13) SearchPage()" />

Happy Coding, 

Thứ Tư, 24 tháng 10, 2012

What is a Fact table?

A fact table is the central table in a star schema that contains “facts”. A fact table stores quantitative information for analysis and is often denormalized.

A fact table works with dimension tables. Thus, the fact table consists of two types of columns. The foreign keys column allows joins with dimension tables, and the measures columns contain the data that is being analyzed. The primary key of a fact table is usually a composite key that is made up of all of its foreign keys.

A fact table might contain either detail level facts or facts that have been aggregated (fact tables that contain aggregated facts are often instead called summary tables). A fact table usually contains facts with the same level of aggregation

Types of fact tables:
There are basically three fundamental measurement events, which characterizes all fact tables.[2]
  1. TransactionalA transactional table is the most basic and fundamental. The grain associated with a transactional fact table is usually specified as "one row per line in a transaction", e.g., every line on a receipt. Typically a transactional fact table holds data of the most detailed level, causing it to have a great number of dimensions associated with it.
  2. Periodic snapshots
    The periodic snapshot, as the name implies, takes a "picture of the moment", where the moment could be any defined period of time, e.g. a performance summary of a salesman over the previous month. A periodic snapshot table is dependent on the transactional table, as it needs the detailed data held in the transactional fact table in order to deliver the chosen performance output. 
  3. Accumulating snapshots
    This type of fact table is used to show the activity of a process that has a well-defined beginning and end, e.g., the processing of an order. An order moves through specific steps until it is fully processed. As steps towards fulfilling the order are completed, the associated row in the fact table is updated. An accumulating snapshot table often has multiple date columns, each representing a milestone in the process. Therefore, it's important to have an entry in the associated date dimension that represents an unknown date, as many of the milestone dates are unknown at the time of the creation of the row.

The following diagrams provide an overview of the fact tables in the Team System data warehouse and the dimensions tables they have in common:

Thứ Hai, 16 tháng 1, 2012

Quick Run-through with Bulk Drop Stored Procedures

Why bother with seeking optimized solution which you know that it is just one time deal? Let's use the CURSOR to perform loop and exec SQL one by one. It is long running task but efficient since it's never used again after that. Here is such a simple secret:

declare @name varchar(max)
declare dcursor CURSOR
FOR Select name from sys.procedures Where [type] = 'P' and is_ms_shipped = 0 and [name] not like 'sp[_]%diagram%' and name like 'xxx_%'

open dcursor
fetch next FROM dcursor
    INTO @name

while @@FETCH_STATUS = 0
    fetch next FROM dcursor
    INTO @name

    declare @sql nvarchar(max)
    SET @sql = N'drop procedure ' + @name
    SELECT @sql
CLOSE dcursor