Note the use of the code generator soft -

Original link: http://www.cnblogs.com/Spirithero/archive/2011/03/29/1998589.html

Note the use of the code generator soft -

# C 2011-01-17 21:58:39 Read 21 Comments 0   Font Size: Tai Zhong small subscription 

Note the use of the code generator soft -

The factory pattern:

First, the use of soft - build the project, set up top-level namespace.
Second, the resulting open project, checks whether each layer is a separate assembly. In particular interface that does not seem to top-level namespace first step in setting named.

Third, the namespace DBUtility in, not to start the top of the top, but Maticsoft (dynamic soft). And to add a reference LTP.Accounts, under Lib. ? ? ? ? Do not add to try
Third, check whether the data layer DAL implements the interface. (Automatic code has been achieved)
Fourth, check the BLL whether to add a reference to the DAL (SQLServerDAL) project. (Automatic code without addition)
five, Web.config file, add or modify <add key = "DAL" value = "RR.SQLServerDAL" />

The above steps can ensure normal use reflection to create objects.

Five, web folder App_Themes folder, if you want, you can keep, if not, it is necessary to modify the Theme property in web.config, otherwise, could not find BlueTheme theme.

Sixth, to retain web.config web folder for reference.
Seven, maintaining the basic operation of each data table in the web folder (display, modify, add) and .aspx.cs .aspx page, for reference.
Eight, remove all remaining files web folder.

Nine, in the "Solution Manager" to add your own website, "New Site."
Ten, copy the original web.config to a new site, or modify the reference to the new site web.config.

XI to their website add a project reference: Model, BLL, seems to just add the BLL, a generation, it will automatically add the Model, DALFactory, DBUtility, IDAL, OracleDAL, SQLServerDAL reference.

Twelve, use, just start with top-level namespace, you can use.

XIII on sort
GetList (string strWhere) function, by adding: "1 = 1 order by field name DESC" "to be sorted.

Fourth, add your own Common.cs, include enumeration system needed for the operation.
Fifth, add your own Param.cs, extract configuration information in Web.config, for later use, directly extracted from the class. Of course, you need a project reference to System.Configuration (add a reference, and using).
XVI implement paging, soft - code open tab:
. 1, open the BLL
2, IDAL open
. 3, open DAL
wherein: the code Change DAL following code:
        /// <Summary>
        /// Get tab data list
        /// IsCount = 0 returns the total number of records, otherwise, returns the record set
        /// stored paging procedure UP_GetRecordByPage
        /// </ Summary>
        public the DataSet the GetList (IsCount int, int the PageIndex, String strWhere)
        {
            // here, in order not more generated code changes too soft portion,
            // the original first parameter is used as a marker PageSize
            // If PageSize = 0, i.e., = 0 parameter IsCount
            // compared to calculate the total number
            // passed to a stored procedure when, @ IsCount = 1
            // Otherwise, it receives the value of the PageSize

            string tableName = "LWord"; // Sort table ***********
            String colName = "LWordID"; // Sort field ***********

            // get the total number of records, if you save the unity of a PageSize, you can take directly from the global settings.
            IsCount the PageSize = int;
            IF (IsCount == 0) // If then the IsCount = 0, returns the total number of recording
            {
                the SqlParameter [] = {Parameters
                    new new the SqlParameter ( "@ tblName", SqlDbType.VarChar, 255),
                    new new the SqlParameter ( "@ fldName ", SqlDbType.VarChar, 255),
                    new new the SqlParameter (" the PageSize @ ", SqlDbType.Int),
                    new new the SqlParameter (" the PageIndex @ ", SqlDbType.Int),
                    new new the SqlParameter (" @ IsReCount ", SqlDbType.Bit),
                    new new SqlParameter ( "@ OrderType", SqlDbType.Bit),
                    new new SqlParameter ( "@ strWhere"
                };
                Parameters [0] .Value = tableName;
                Parameters [. 1] .Value = colName;
                Parameters [2] .Value = the PageSize;
                Parameters [. 3] .Value = the PageIndex;
                Parameters [. 4] .Value =. 1;      // @ IsReCount . 1 (non) returns the total number, otherwise, it returns the record set
                Parameters [. 5] .Value =. 1;
                Parameters [. 6] .Value = strWhere;

                return DbHelperSQL.RunProcedure("UP_GetRecordByPage", parameters, "ds");
            }
            else
            {
               
                  
                SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };

                parameters[0].Value = tableName;
                parameters[1].Value = colName;
                parameters[2].Value = PageSize;
                parameters[3].Value = PageIndex;
                parameters[4].Value = 0;     //@IsReCount (非)返回总数,返回记录集
                parameters[5].Value = 1;
                parameters[6].Value = strWhere;

                return DbHelperSQL.RunProcedure("UP_GetRecordByPage", parameters, "ds");
            }
        }


4, write stored procedures in the database as follows: (. Use this name because DAL are used is this) UP_GetRecordByPage

------------------------------------
- Purpose: to support any sort of paging stored procedures
- Description :
------------------------------------
the CREATE PROCEDURE [dbo] [UP_GetRecordByPageOrder].

@tblName varchar (255), - the table name
@fldName varchar (255), - display field name
@OrderfldName varchar (255), - the sort field names
@StatfldName varchar (255), - the statistical field name
@PageSize int = 10 - page size
@PageIndex int = 1, - p
@IsReCount bit = 0, - returns the total number of recorded non-zero value
@OrderType bit = 0, - set the sort type, a non-zero value in descending order
: - @strWhere varchar (1000) = '' query (do not add where attention)
AS
DECLARE @strSQL VARCHAR (6000) - the main statements
may temporary variables (long query - declare @strTmp varchar (100) be wrong, 100 can be modified to 1000)
DECLARE @strOrder VARCHAR (400) - sort type
! = 0 IF @OrderType
the begin
SET @strTmp = '<(SELECT min'
SET @strOrder = 'Order by [' + + @OrderfldName '] desc'
End
the else
the begin
set @strTmp = '>(select max'
set @strOrder = ' order by [' + @OrderfldName +'] asc'
end
set @strSQL = 'select top ' + str(@PageSize) + ' ' + @fldName + ' from ['
+ @tblName + '] where [' + @OrderfldName + ']' + @strTmp + '(['
+ @OrderfldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @OrderfldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
+ @strOrder
if @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) + ' ' + @fldName + ' from ['
+ @tblName + '] where [' + @OrderfldName + ']' + @strTmp + '(['
+ @OrderfldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @OrderfldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder
if @PageIndex = 1
begin
set @strTmp = ''
if @strWhere != ''
set @strTmp = ' where ' + @strWhere
set @strSQL = 'select top ' + str(@PageSize) + ' ' + @fldName + ' from ['
+ @tblName + ']' + @strTmp + ' ' + @strOrder
end

if @IsReCount != 0
set @strSQL = @strSQL+' select count(1) as Total from [' + @tblName + ']'
if @strWhere!=''
set @strSQL = @strSQL+' where ' + @strWhere
exec (@strSQL)


2,
------------------------------------
- Uses: paging store procedure (there is a primary key of table high efficiency)
- Description:
------------------------------------
the CREATE PROCEDURE [the dbo] . [UP_GetRecordByPage]
@tblName VARCHAR (255), - table
@fldName varchar (255), - the primary key field name
@PageSize int = 10, - page size
@PageIndex int = 1, - p
@IsReCount bit = 0, - returns the total number of recorded non-zero value
@OrderType bit = 0, - set the sort type, a non-zero value in descending
@strWhere varchar (1000) = '' - query (Note: do not add where)
aS
DECLARE @strSQL VARCHAR (6000) - the main statement
declare @strTmp varchar (100) - temporary variables (query too long may be wrong, it can be modified 100 to 1000)
DECLARE @strOrder VARCHAR (400) - sort type
@OrderType IF! = 0
the begin
SET @strTmp = '<(SELECT min'
set @strOrder = ' order by [' + @fldName +'] desc'
end
else
begin
set @strTmp = '>(select max'
set @strOrder = ' order by [' + @fldName +'] asc'
end
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
+ @strOrder
if @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder
if @PageIndex = 1
begin
set @strTmp =''
if @strWhere != ''
set @strTmp = ' where ' + @strWhere
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + ']' + @strTmp + ' ' + @strOrder
end
if @IsReCount != 0
set @strSQL = 'select count(*) as Total from [' + @tblName + ']'+' where ' + @strWhere
exec (@strSQL)

 

Quote from http://blog.163.com/jian-zou/blog/static/34866055201101795839687/

Reproduced in: https: //www.cnblogs.com/Spirithero/archive/2011/03/29/1998589.html

Guess you like

Origin blog.csdn.net/weixin_30672019/article/details/95051932