| Muralidharan 的个人资料Murali@B'lore照片日志列表 | 帮助 |
|
12月29日 Design PatternPast few days, concentrating more on design patterens. here are some of the important notes from what i learn. Design patterns are recurring solutions to software design problems you find again and again in real-world application development. Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges. The Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral. Here you will find information on these important patterns. Creational Patterns Abstract Factory - Creates an instance of several families of classes Builder - Separates object construction from its representation Factory Method - Creates an instance of several derived classes Prototype - A fully initialized instance to be copied or cloned Singleton - A class of which only a single instance can exist Structural Patterns Adapter - Match interfaces of different classes Bridge - Separates an object's interface from its implementation Composite - A tree structure of simple and composite objects Decorator - Add responsibilities to objects dynamically Facade - A single class that represents an entire subsystem Flyweight - A fine-grained instance used for efficient sharing Proxy - An object representing another object Behavioral Patterns Chain of Resp.- A way of passing a request between a chain of objects Command - Encapsulate a command request as an object Interpreter - A way to include language elements in a program Iterator - Sequentially access the elements of a collection Mediator - Defines simplified communication between classes Memento - Capture and restore an object's internal state Observer - A way of notifying change to a number of classes State - Alter an object's behavior when its state changes Strategy - Encapsulates an algorithm inside a class Template Method - Defer the exact steps of an algorithm to a subclass Visitor - Defines a new operation to a class without change Remove Nulls from DatatableThe individual cells in a DataTable can have a null value in the form of System.DbNull.Value. If the DataTable is created by querying a database through ADO.NET, you can write the SQL statement in a way eliminates nulls. It could look like this “SELECT isnull(name, 'n/a') AS name FROM products”. However, there can be scenarios where you don’t have the chance to manipulate the DataTable before you use it. Such a scenario have I recently been involved in and the problem was that the data retrieved from a database could contain nulls in any of the integer type columns. If I then bind the DataTable to a GridView in ASP.NET, I had to do a lot of workarounds to calculate footers and other values based on those columns. Instead of doing the workarounds in a lot of different places in the code, I decided it was a better idea to clean the DataTable for nulls before it is used. That led to the CleanDataTable method below, that replaces null values with zeros for a few integer type columns. /// <summary> /// In the case of null values in a data table, this method /// will turn all nulls into zeros instead. /// </summary> public static DataTable CleanDataTable(DataTable dt) { for (int a = 0; a < dt.Rows.Count; a++) { for (int i = 0; i < dt.Columns.Count; i++) { if (dt.Rows[a][i] == DBNull.Value) { Type type = dt.Columns[i].DataType; if (type == typeof(int) || type == typeof(float) || type == typeof(double)) { dt.Columns[i].ReadOnly = false; dt.Rows[a][i] = 0.0F; } } } }
return dt; }
The point is that you only have to clean it once to avoid any workaround for handling null values. 12月7日 Customize your place holder in Open / Save Dialog boxQ. How can I hide the Places bar in Widows XP's and Windows 2000's Open
and Save common dialog boxes? A. The Open and Save common dialog boxes display a bar along the left- hand side with quick links to the following default locations: * History * My Documents * Desktop * Favorites * My Network Places You can hide this bar by performing the following steps: 1. Start a registry editor (e.g., regedit.exe). 2. Navigate to the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\co mdlg32 subkey. (If this subkey doesn't exist, select New, Key from the Edit menu to create it.) 3. From the Edit menu, select New, DWORD Value. 4. Enter a name of NoPlacesBar and press Enter. 5. Double-click the new value, set it to 1, and click OK. 6. Close the registry editor. The registry change will take effect immediately. To enable the Places bar again, either delete the NoPlacesBar registry value or set it to 0. This change will not affect applications within the Microsoft Office suite but will affect applications, such as Notepad and Microsoft Paint, that use the Open and Save common dialog boxes. -------------------- Q. How can I edit the default Places bar quick links in Windows XP's and Windows 2000's Open and Save common dialog boxes? A. You can modify the five default quick links in the Open and Save common dialog boxes by performing the following steps: 1. Start a registry editor (e.g., regedit.exe). 2. Navigate to the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\co mdlg32 subkey. (If this subkey doesn't exist, select New, Key from the Edit menu to create it.) 3. From the Edit menu, select New, Key. 4. Enter a name of Placesbar and press Enter. 5. Navigate to the new registry subkey. You can create five entries (i.e., Place0, Place1, Place2, Place3, and Place4). Make each entry either a string value (REG_SZ) entry (for a named folder) or a DWORD value (REG_DWORD) entry (for a special folder, such as My Documents or My Network Places). 6. To create a new entry, go to the Edit menu, select New, DWORD Value or New, String Value (as appropriate), enter a name of Placen (e.g., Place0, Place4), and press Enter. 7. Double-click the entry and set its REG_SZ "Value data" to a path and folder name or its REG_DWORD "Value data" to a numeric ID (the table below shows a partial list of these numeric IDs--the shlobj.h file, which is part of the platform software development kit (SDK), defines the full list of special numeric IDs). 8. Close the registry editor. For example, the registry file below sets shortcuts to My Documents, the CD burning folder, and three named folders. Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Policies\comdlg32\Placesbar] "Place0"=dword:00000005 "Place1"=dword:0000003b "Place2"="d:\\temp" "Place3"="d:\\documents" "Place4"="g:\\windows" This change will not affect applications within the Microsoft Office suite but will affect applications, such as Notepad and Microsoft Paint, that use the Open and Save common dialog boxes. Each new entry you add will replace one of the default quick links. ID Pathway 0 Desktop 1 Internet Explorer 2 Start Menu\Programs 3 My Computer\Control Panel 4 My Computer\Printers 5 My Documents 6 <user name>\Favorites 7 Start Menu\Programs\Startup 8 <user name>\Recent 9 <user name>\SendTo a <desktop>\Recycle Bin b <user name>\Start Menu c Logical "My Documents" desktop icon d "My Music" folder e "My Videos" folder 10 <user name>\Desktop 11 My Computer 12 Network Neighborhood (My Network Places) 13 <user name>\Nethood 14 Windows\Fonts 16 All Users\Start Menu 17 All Users\Start Menu\Programs 18 All Users\Startup 19 All Users\Desktop 1a <user name>\Application Data 1b <user name>\PrintHood 1c <user name>\Local Settings\Application Data (nonroaming) 0x001d // nonlocalized startup 1e Nonlocalized common startup 1f Common favorites 20 Internet cache 21 Cookies 22 History 23 All Users\Application Data 24 GetWindowsDirectory() 25 GetSystemDirectory() 26 C:\Program Files 27 C:\Program Files\My Pictures 28 USERPROFILE 29 x86 system directory on RISC 2a x86 C:\Program Files on RISC 2b C:\Program Files\Common 2c x86 Program Files\Common on RISC 2d All Users\Templates 2e All Users\Documents 2f All Users\Start Menu\Programs\Administrative Tools 30 <user name>\Start Menu\Programs\Administrative Tools 31 Network and Dial-up Connections 35 All Users\My Music 36 All Users\My Pictures 37 All Users\My Video 38 Resource Directory 39 Localized Resource Directory 3a All Users OEM-specific applications 3b USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning |
|
|