Introduction
In this tip, we will try to understand how to generate code for tiered architecture automatically and generate stored procedures for CRUD operations automatically based on table schema. Through this tool, we will try to understand what are the different classes that are generated and what is the use of those classes and we will try to see how this tool helps us to save time at the time of coding. We will try to understand what kind of logic should go inside this tool.
This is a small tool for all my .NET friends to generate code automatically which saves time for coding, avoids redundant fields, follows similar names and data types, creates stored procedures for CRUD operations with similar fields which is similar to database table columns.
We can create project architecture easily within less time period and we can maintain all projects with unique structure.
Background
I found some issues or problems while creating projects, designing systems, creating stored projects.
- Dissimilarity with field names and datatypes in Tables Columns, Procedures, Data Layers, Presentation Layers, etc.
- No Uniform structure for project architecture, different developers follow different structures for coding within the same project.
- Redundant fields, methods, functions and stored procedures to perform operation because of dissimilar naming conventions.
- Consuming lot of time for coding to perform the same job like creating similar kind of logic and operations.
To solve the above problems, I have created this simple tool for code generation which is helpful and useful to programmers especially.
Using the Code
1. DB Mapping
This is DB Mapping window to select your SQL Servers from local machine or network, select database from that selected server, select tables from the selected database, select various conditions to generate the code based on user choice.
Step 1: The user can enter the server name or load server names from local machine or from network by clicking button S in server details section. Depending on server selection, enter the corresponding user id and password and click button load databases to load all the databases in that server.
Step 2: Select database from database details section, click on button Load Table to load tables.
Step 3: Select required tables for code generation from select table sections click on button Load Selected.
Step 4: Select choose option either Auto or Manually, Other Class either Same or Common, Property Class either Same or Common.
Step 5: Enter Project name without any spaces and click on button Add Class Names to Add/Edit Class information in grid.
Step 6: Based on the user preference, the Grid is loaded, i.e.:
Note
Choose option section: If Auto is selected, all check boxes are selected in Data Grid. If Manually is selected, all check boxes are unselected in Data Grid, then user can select required options from Data Grid.
Other Class section: If Same is selected, the OClassName
will be same as TableName
, i.e., all classes in business layer and data access layer will be generated separately. If Common is selected, all classes in business layer and data access layer will be generated in a single class.
Property Class section: If Same is selected, the Class Name will be same as TableName
, i.e., all property classes in data layer will be generated separately. If Common is selected, all property classes in data layer will be generated in single class.
2. DB Query
This DB Query window will generate stored procedures based on the options selected by user. You can execute these queries from here to generate stored procedure in your selected database.
3. DB Base Classes
This DB Base Classes window will generate base classes for the project with predefined structure. You can add your own logic inside these base classes.
4. DB Classes
This DB Base Classes window will generate base classes for the project with predefined structure. You can add your own logic inside these base classes.
Points of Interest
While creating this tool, I learnt these interesting things:
- How to find database servers from network
- How to handle data grid with controls
- How to create and use user defined components
- How to handle different panels
- How to dock controls in the window
History
- 10th June, 2014: Initial version
I'll keep updates on this tool for any changes or improvements made.