Sunday, November 29, 2009

ASP.NET WebService Samples

// Calling WebService Function for javascript
WebServiceObj.GetYourFunctionName(param1, param2, ..., onSucceeded, onFailed, userContext);

/**
* WebService onSuccess Callback function for AJAX.
* @param {Object} result               Can be any types return from WebService Function.
* @param {String} userContext      String can be pass into OnSucceeded or OnFailed Callback Function.
* @param {String} methodName    The WebService Name you called.
*/

function OnSucceeded(result, userContext, methodName)
{
    if (methodName == "GetSessionValue")
    {
        displayElement.innerHTML = "Current session state value: " + result;
    }
}
 
/**
* WebService onFailed Callback function for AJAX.
* @param {Object} result              The value retrun from WebService Function.
* @param {String} userContext     Any String you want pass into callback functions.
* @param {String} methodName   The WebService Function name you calling.
*/

function OnFailed(error, userContext, methodName)
{
    var stackTrace = error.get_stackTrace();
    var message = error.get_message();
    var statusCode = error.get_statusCode();
    var exceptionType = error.get_exceptionType();
    var timedout = error.get_timedOut();
    ...
    ...
}
 
 
Related Links:


SQL Server Collation Name

COLLATE  SQL_SortRules[_Pref]_CPCodepage_<ComparisonStyle>
Sample
COLLATE Chinese_Taiwan_Stroke
COLLATE Chinese_Taiwan_Stroke_BIN
COLLATE Chinese_Taiwan_Stroke_CI_AS
COLLATE Chinese_Taiwan_Bopomofo_CS_AI

SortRules
A string identifying the alphabet or language whose sorting rules are applied when dictionary sorting is specified.
Examples are Latin1_General, Polish or
Chinese_Taiwan.
Pref
Specifies uppercase preference.

Codepage
Specifies a one- to four-digit number that identifies the code page used by the collation. CP1 specifies code page 1252, for all other code pages the complete code page number is specified. For example, CP1251 specifies code page 1251 and CP850 specifies code page 850.

CaseSensitivityCI specifies case-insensitive, CS specifies case-sensitive.
AccentSensitivity
AI specifies accent-insensitive, AS specifies accent-sensitive.

BIN
Specifies the binary sort order to be used.

SQL Server Collation Name (Transact-SQL)
SQL Server 2005 Books Online (September 2007) - Collation Settings in Setup

Monday, November 9, 2009

Retrieve Last Inserted Identity of Record

SQL SERVER

March 25, 2007 by pinaldave

SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.
SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.
SELECT IDENT_CURRENT(’tablename’)
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.
To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.
Source: Pinal Dave (http://www.SQLAuthority.com)

MySQL

If you insert a record into a table that contains an AUTO_INCREMENT column, you can obtain the value stored into that column by calling the mysql_insert_id() function or by executing a SELECT LAST_INSERT_ID() statement with mysql_query() and retrieving the value from the result set returned by the statement. .
If you want to use the ID that was generated for one table and insert it into a second table, you can use SQL statements like this:
INSERT INTO foo (auto,text)
    VALUES(NULL,'text');         # generate ID by inserting NULL
INSERT INTO foo2 (id,text)
    VALUES(LAST_INSERT_ID(),'text');  # use ID in second table


You can check from your C applications whether a value was stored in an AUTO_INCREMENT column by executing the following code (which assumes that you've checked that the statement succeeded). It determines whether the query was an INSERT with an AUTO_INCREMENT index:
if ((result = mysql_store_result(&mysql)) == 0 &&
    mysql_field_count(&mysql) == 0 &&
    mysql_insert_id(&mysql) != 0)
{
    used_id = mysql_insert_id(&mysql);
}
Source: http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
 
 

Sunday, October 25, 2009

retrieve the horizontal resolution for a video display, or printer

Device-Independent Bitmaps
A device-independent bitmap (DIB) contains a color table. A color table describes how pixel values correspond to RGB color values, which describe colors that are produced by emitting light. Thus, a DIB can achieve the proper color scheme on any device. A DIB contains the following color and dimension information:
  • The color format of the device on which the rectangular image was created.
  • The resolution of the device on which the rectangular image was created.
  • The palette for the device on which the image was created.
  • An array of bits that maps red, green, blue (RGB) triplets to pixels in the rectangular image.
  • A data-compression identifier that indicates the data compression scheme (if any) used to reduce the size of the array of bits.
The color and dimension information is stored in a BITMAPINFO structure, which consists of a BITMAPINFOHEADER structure followed by two or more RGBQUAD structures. The BITMAPINFOHEADER structure specifies the dimensions of the pixel rectangle, describes the device's color technology, and identifies the compression schemes used to reduce the size of the bitmap. The RGBQUAD structures identify the colors that appear in the pixel rectangle.
There are two varieties of DIBs:
  • A bottom-up DIB, in which the origin lies at the lower-left corner.
  • A top-down DIB, in which the origin lies at the upper-left corner.
If the height of a DIB, as indicated by the Height member of the bitmap information header structure, is a positive value, it is a bottom-up DIB; if the height is a negative value, it is a top-down DIB. Top-down DIBs cannot be compressed.
The color format is specified in terms of a count of color planes and color bits. The count of color planes is always 1; the count of color bits is 1 for monochrome bitmaps, 4 for VGA bitmaps, and 8, 16, 24, or 32 for bitmaps on other color devices. An application retrieves the number of color bits that a particular display (or printer) uses by calling the GetDeviceCaps function, specifying BITSPIXEL as the second argument.
The resolution of a display device is specified in pixels-per-meter. An application can retrieve the horizontal resolution for a video display, or printer, by following this three-step process.
  1. Call the GetDeviceCaps function, specifying HORZRES as the second argument.
  2. Call GetDeviceCaps a second time, specifying HORZSIZE as the second argument.
  3. Divide the first return value by the second return value.
The application can retrieve the vertical resolution by using the same three-step process with different parameters: VERTRES in place of HORZRES, and VERTSIZE in place of HORZSIZE.
The palette is represented by an array of RGBQUAD structures that specify the red, green, and blue intensity components for each color in a display device's color palette. Each color index in the palette array maps to a specific pixel in the rectangular region associated with the bitmap. The size of this array, in bits, is equivalent to the width of the rectangle, in pixels, multiplied by the height of the rectangle, in pixels, multiplied by the count of color bits for the device. An application can retrieve the size of the device's palette by calling the GetDeviceCaps function, specifying NUMCOLORS as the second argument.
Windows supports the compression of the palette array for 8-bpp and 4-bpp bottom-up DIBs. These arrays can be compressed by using the run-length encoding (RLE) scheme. The RLE scheme uses 2-byte values, the first byte specifying the number of consecutive pixels that use a color index and the second byte specifying the index. For more information about bitmap compression, see the description of the BITMAPINFOHEADER, BITMAPFILEHEADER, BITMAPV4HEADER, and BITMAPV5HEADER structures.
An application can create a DIB from a DDB by initializing the required structures and calling the GetDIBits function. To determine whether a device supports this function, call the GetDeviceCaps function, specifying RC_DI_BITMAP as the RASTERCAPS flag.
An application that needs to copy a bitmap can use TransparentBlt to copy all pixels in a source bitmap to a destination bitmap except those pixels that match the transparent color.
An application can use a DIB to set pixels on the display device by calling the SetDIBitsToDevice or the StretchDIBits function. To determine whether a device supports the SetDIBitsToDevice function, call the GetDeviceCaps function, specifying RC_DIBTODEV as the RASTERCAPS flag. Specify RC_STRETCHDIB as the RASTERCAPS flag to determine if the device supports StretchDIBits.
An application that simply needs to display a pre-existing DIB can use the SetDIBitsToDevice function. For example, a spreadsheet application can open existing charts and display them in a window by using the SetDIBitsToDevice function. To repeatedly redraw a bitmap in a window, however, the application should use the BitBlt function. For example, a multimedia application that combines animated graphics with sound would benefit from calling the BitBlt function because it executes faster than SetDIBitsToDevice.

Wednesday, October 21, 2009

How to make auto line break in HTML table td element

CSS can imperfectly solved this issue asa below

.table
{
    table-layout: fixed;
}
.td
{
    word-break: break-all;
    word-wrap:break-word;
}

Friday, October 9, 2009

How to pass parameters to UserControl

  1. Define a constructor method in your UserControl class
    public partial class MyUserControl : System.Web.UI.UserControl
    {
        public MyUserControl()
        {
        }
        public MyUserControl(string param1, int param2, bool param3)
        {
            // Do anything you whant for your parameters here
            textbox1.Text = param1;
            .....

        }
    }
  2. Define our customize LoadControl() method so that the parameters can be pass into the UserControl
    private UserControl LoadUserControl(string controlPath, params object[] parameters)
    {
        List<Type> paramTypes = new List<Type>();
        foreach(object param in parameters)
        {
            paramTypes.Add(param.GetType());
        }
        Page page = new Page();
        UserControl uc = page.LoadControl(controlPath) as UserControl;
        ConstructorInfo ci = uc.GetType().BaseType.GetConstructor(paramTypes.ToArray());
        if(ci == null)
        {
            throw new MemberAccessException(
                "The requested constructor was not found on : "
               
    + uc.GetType().BaseType.ToString());
        }
        else
        {
            ci.Invoke(uc, parameters);
        }
        return uc;
    }
  3. Now you can use the LoadControl as below to pass the parameters to the UserControl
    // Initiallize the UserControl with it parameters .....UserControl myControl = LoadControl(
                                        "MyUserControl.ascx"
                                      , "This is value of param1"
                                      ,  1234, true);
 
 
 
 
 

Friday, September 25, 2009

身份證字號說明

身份證字號 共有十碼, 以下是位置說明,僅供各位參考

N1 N2 N3 N4 N5 N6 N7 N8 N9 N10
戶籍 性別 ~流~~~~~~~~水~~~~~~~~~~~碼~

代表說明

戶籍代表字母
A台北市 B台中市 C基隆市 D台南市 E高雄市 F台北縣
G宜蘭縣 H桃園縣 I嘉義市 J新竹縣 K苗栗縣 L台中縣
M南投縣 N彰化縣 O新竹市 P雲林縣 Q嘉義縣 R台南縣
S高雄縣 T屏東縣 U花蓮縣 V台東縣 W金門縣 X澎湖縣
Y陽明山 Z連江縣

英文字母代表的數字
A=10 B=11 C=12 D=13 E=14 F=15 G=16 H=17 I=34 J=18 K=19 L=20
M=21 N=22 O=35 P=23 Q=24 R=25 S=26 T=27 U=28 V=29 W=32 X=30
Y=31 Z=33

性別代表數字
1:男性
2:女性

步驟

1. 查出英文字所代表的數字

再將所查出的數字 "十位數+個位數x9"
例: 台北市=10
1 + 0x9 =1
台中市=11
1 + 1x9 =10

2. N2x8+N3x7+N4x6+N5x5+N6x4+N7x3+N8x2+N9+N10

將流水碼依序乘8765432
一個個乘.乘完要加起來. (別忘了先乘除後加減)
例: 123456789
1x8+2x7+3x6+4x5+5x4+6x3+7x2+8+9


3.將步驟1 和步驟2 的兩個數加起來除以10.

例:步驟1 台北計算結果 =1
步驟2 1x8+2x7+3x6+4x5+5x4+6x3+7x2+8+9 =129 (1+129)/10

除10後看看是否可以整除.如可以整除即為正確的
身份證字號. 如無法整除即是錯誤的身份證字號

(1+129)/10 = 13 => 可以整除.正確