Code Smith Templates to create web application

Posts   
1  /  2  /  3
 
    
bertcord avatar
bertcord
User
Posts: 206
Joined: 01-Dec-2003
# Posted on: 30-Jul-2004 07:34:39   

I have been using LLBLGen for about 7 months. I bought LLBLGen to help me write some internal web applications to manage lookup data. I needed a fast way to edit and update simple data. I really liked the whole code generation thing and decide to see if I could extend the concept to build both my Business Layer and my presentation layer. I have emailed Frans the set of templates I have created to do this. I have been working on an off with this for about 4 months. When I started writing them LLBLGen did not support extended properties and I was already familiar with Codesmith so I decide to use it as my template engine. The download will include the following pieces

  1. BC.LLBLGen.Pro.LGPLoader.dll – When placed in the code smith directory it will allow you to load you LGP file into codesmith. See the LGPSample.cst as an simple example of how you can use it.
  2. BC.LLBLGen.Pro.CSTemplates.dll – Custom code behind for use in codesmith
  3. BC.LLBLGen.zip – contains the actually code smith templates

The templates were designed to work with the C# version of the adapter templates….and yes I wrote the codes smith templates in VB.NET and they output C#....don't ask me why I guess I wanted to learn both languages

Running the templates produces the following Projects

  1. BL – project contains a controller class for each entity
  2. Web Controls – Contains dropdown lists repeaters and ASPxGrid (component form DevExpress)
  3. WebApplicaiton – Contains the data entry forms.

I guess I would consider this a beta version as I only consider them about 80% done. Something I am working on now

  1. Concurrency
  2. Logging
  3. Option to create Bat files to compile instead of projects. This will include strongly signing the assemblies
  4. Business Layer- Add Unique constraint fetch
  5. Create typed views for display.
  6. Mulit column Primary Keys support
  7. Regular datagrid control – If anyone wants to help with this it would be great
  8. Navigation from Grid View to form edit
  9. Instead of creating aspx pages create server controls

Here is a sample screen shot of the Orders From from the northwind Project

Bert

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39741
Joined: 17-Aug-2003
# Posted on: 30-Jul-2004 09:52:33   

That looks really incredible, Bert! simple_smile

I'll upload the template zip a.s.a.p.

(edit: uploaded!)

Frans Bouma | Lead developer LLBLGen Pro
free4all
User
Posts: 35
Joined: 12-Sep-2003
# Posted on: 30-Jul-2004 16:15:44   

Hi Bert,

Screen shot looks really good! I do something very similar with llblgen templates which generate my manager objects and asp.net pages.

I've downloaded your codesmith templates to take a look and maybe steal some ideas or scrap my system and start using yours...

Just wondering what version of Codesmith you use? I have downloaded the latest one from the web today (ver 2.5.14) and tried opening your Master.cst template but I receive the following error:


Error loading assembly CodeSmith.Engine.  Please make sure that you re-compile any custom assemblies against the current version of CodeSmith.

System.IO.FileLoadException: The located assembly's manifest definition with name 'CodeSmith.Engine' does not match the assembly reference.
File name: "CodeSmith.Engine"
   at CodeSmith.Engine.CodeTemplateCompiler.CreateInstance()
   at CodeSmith.Gui.CodeTemplateGenerator.a(String , String , String , Boolean )

=== Pre-bind state information ===
LOG: DisplayName = CodeSmith.Engine, Version=2.5.17.0, Culture=neutral, PublicKeyToken=9fd61cdb91609a7a
 (Fully-specified)
LOG: Appbase = C:\Program Files\CodeSmith\v2.5\
LOG: Initial PrivatePath = NULL
Calling assembly : BC.LLBLGen.Pro.CSTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===

LOG: Publisher policy file is not found.
LOG: Host configuration file not found.
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\config\machine.config.
LOG: Post-policy reference: CodeSmith.Engine, Version=2.5.17.0, Culture=neutral, PublicKeyToken=9fd61cdb91609a7a
LOG: Attempting download of new URL file:///C:/Program Files/CodeSmith/v2.5/CodeSmith.Engine.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 01-Aug-2004 04:29:01   

I also get the same results as above.

I tried to recompile your CS Assembly Projects, but when I add the reference to SD.LLBLGen.Pro.ApplicationCore, I receive precompile errors stating that CustomProperties is not a member of SD.LLBLGen.Pro.ApplicationCore.Entities.EntityDefinition.

My version of the ApplicationCore is 1.0.2003.1 built on 5-5-2004

Any thougts?

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 01-Aug-2004 05:23:40   

Ok, after downloading and installing the latest version of LLBLGen I was able to recompile the source provided by bert.

I also updated the reference in the source provided by bert, to use my version of CodeSmith, and the templates work fine.

I made one change to the template: I commented out line 50 and 51, and replace with 52 and 53 here is the change:


    '_LLBLGenProjectGUID = GetProjectFileGUID(RootDestinationFolder + LLBLGenProject.DestinationFolder.Substring(LLBLGenProject.DestinationFolder.LastIndexOf("\")) + "\" + LLBLGenProject.RootNameSpace +".csproj")
    '_LLBLGenDBSpecificProjectGUID = GetProjectFileGUID(RootDestinationFolder + LLBLGenProject.DestinationFolder.Substring(LLBLGenProject.DestinationFolder.LastIndexOf("\")) + "\" + LLBLGenProject.RootNameSpace +"DBSpecific.csproj")
    _LLBLGenProjectGUID = GetProjectFileGUID(LLBLGenProject.DestinationFolder + "\" +LLBLGenProject.RootNameSpace +".csproj")
    _LLBLGenDBSpecificProjectGUID = GetProjectFileGUID(LLBLGenProject.DestinationFolder + "\" + LLBLGenProject.RootNameSpace +"DBSpecific.csproj")


This gets around the .\DL path requirement. I did this because my code generated output is never close to the .lgp file.

Bert, would you be willing to share your DNN templates if they are done yet? Please please please?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39741
Joined: 17-Aug-2003
# Posted on: 01-Aug-2004 11:19:07   

Devildog74 wrote:

I also get the same results as above.

I tried to recompile your CS Assembly Projects, but when I add the reference to SD.LLBLGen.Pro.ApplicationCore, I receive precompile errors stating that CustomProperties is not a member of SD.LLBLGen.Pro.ApplicationCore.Entities.EntityDefinition.

My version of the ApplicationCore is 1.0.2003.1 built on 5-5-2004

Any thougts?

Good point. I'll update the entry on the website with this info.

Frans Bouma | Lead developer LLBLGen Pro
bertcord avatar
bertcord
User
Posts: 206
Joined: 01-Dec-2003
# Posted on: 02-Aug-2004 17:51:16   

free4all wrote:

Screen shot looks really good! I do something very similar with llblgen templates which generate my manager objects and asp.net pages.
I've downloaded your codesmith templates to take a look and maybe steal some ideas or scrap my system and start using yours...

I am interested in hearing feeback you may have on my manager objects..let me know if it is missing anythign you need.

free4all wrote:

Just wondering what version of Codesmith you use?

I am using the most recent Beta Build of codesmith. This might only be valid for a liscensed customer. You can recompile the project with the version you are using.

Devildog74 wrote:

I made one change to the template: I commented out line 50 and 51, and replace with 52 and 53 here is the change:

I will make this change in the next version I send in thanks

Devildog74 wrote:

Bert, would you be willing to share your DNN templates if they are done yet? Please please please?

Yes I plan on making them available soon. It will have much more features such as the ability to assign portal rules to different actiosn such as update and delete. I am sidetracked this week trying to get SQL reporting services working in my portal. MAybe next week I will have time to finsih up.

If anyone wants to help they could create a custom datagrid class for the orders entity. I could take this class and convert it into a template. This way peope can have some working grids.

Bert

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 03-Aug-2004 10:34:21   

Bert, I can help you out with this.

I have modified the master.cst and the masterwebcontrols.cst to use a GridTypeEnum value.

The MsterWebControls.cst GO method has been modified to only create the devEx directory and files when the enum is set accordingly and the csproj text now has the If Then statement in the references section and files section.

I can have the datagrid class to you in a day or so.

Do you want to see my cst changes? If so, you can reach me via the email in my profile. We dont need to blow up Fran's forum with CodeSmith templates smile

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 03-Aug-2004 10:36:44   

If you need any pointers with SQL Reporting Services, let me know. Ive been around and around with that beast many times.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39741
Joined: 17-Aug-2003
# Posted on: 03-Aug-2004 10:56:37   

Devildog74 wrote:

Do you want to see my cst changes? If so, you can reach me via the email in my profile. We dont need to blow up Fran's forum with CodeSmith templates smile

That's ok simple_smile If it gets the job done, why not use that tool? simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 03-Aug-2004 13:44:34   

Thanks for lettings us use your forum Frans,

Here is the Master.cst


<%@ CodeTemplate Language="VB" Inherits="LLBLBaseCodeTemplate"  TargetLanguage="HTML" Description="" Debug="true" %>
<%@ Property Name="GenerateDocumentation" Type="System.Boolean" Default="false" Category="Options" Description="" %>
<%@ Property Name="GenerateWebApplication" Type="System.Boolean" Default="true" Category="Options" Description="" %>
<%@ Property Name="GenerateDotNetNukeModule" Type="System.Boolean" Default="false" Category="Options" Description="" %>
<%@ Property Name="GridControlType" Type="GridTypeEnum" Category="Options" Description="Type of grid control to use in the GRID pages for the asp.net web app" %>

<%@ Assembly Name="BC.LLBLGen.Pro.LGPLoader" %>
<%@ Import NameSpace="BC.LLBLGen.Pro" %>
<%@ Assembly Name="BC.LLBLGen.Pro.CSTemplates" %>
<%@ Import NameSpace="BC.LLBLGen.Pro.CSTemplates" %>
<%@ Assembly Name="SD.LLBLGen.Pro.ApplicationCore" %>
<%@ Assembly Name="SD.LLBLGen.Pro.DBDriverCore" %>
<%@ Import Namespace="SD.LLBLGen.Pro.ApplicationCore.Entities" %>
<%@ Import Namespace="SD.LLBLGen.Pro.DBDriverCore" %>
<%@ Import Namespace="SD.LLBLGen.Pro.ApplicationCore" %>

<%@ Assembly Name="SD.LLBLGen.Pro.ApplicationCore" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="System.Design" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import NameSpace="System.IO" %>


<script runat="template">
public enum GridTypeEnum
  StandardGrid=0
  DevExGrid=1
end enum

Private _MasterWebControls as New codetemplate 
Private _MasterWebApplication as New codetemplate
Private _MasterDNNModule as New codetemplate
Private _MasterBLL as New codetemplate
Private _Documentation as New codetemplate
Private _VSSolutionFile as New codetemplate
Private _VBSCreateVirtualDirectory as new codetemplate
Private _VBSRemoveVirtualDirectory as new codetemplate


Private _WebApplicationProjectGuid as String
Private _WebControlsProjectGuid as String
Private _DNNModuleProjectGUID as String
Private _LLBLGenProjectGUID as String
Private _LLBLGenDBSpecificProjectGUID as String
Private _BLProjectGuidProjectGUID as String


Public  Sub Go()

    'Create GUIDS for project files.  This is required to build the solution File
    'Pull Guids out of the LLBLGen PRoject Files
    _WebApplicationProjectGuid =Guid.NewGuid().ToString().ToUpper()
    _WebControlsProjectGuid =Guid.NewGuid().ToString().ToUpper()
    _DNNModuleProjectGUID =Guid.NewGuid().ToString().ToUpper()
    _BLProjectGuidProjectGUID =Guid.NewGuid().ToString().ToUpper()
    '_LLBLGenProjectGUID = GetProjectFileGUID(RootDestinationFolder + LLBLGenProject.DestinationFolder.Substring(LLBLGenProject.DestinationFolder.LastIndexOf("\")) + "\" + LLBLGenProject.RootNameSpace +".csproj")
    '_LLBLGenDBSpecificProjectGUID = GetProjectFileGUID(RootDestinationFolder + LLBLGenProject.DestinationFolder.Substring(LLBLGenProject.DestinationFolder.LastIndexOf("\")) + "\" + LLBLGenProject.RootNameSpace +"DBSpecific.csproj")
    _LLBLGenProjectGUID = GetProjectFileGUID(LLBLGenProject.DestinationFolder + "\" +LLBLGenProject.RootNameSpace +".csproj")
    _LLBLGenDBSpecificProjectGUID = GetProjectFileGUID(LLBLGenProject.DestinationFolder + "\" + LLBLGenProject.RootNameSpace +"DBSpecific.csproj")

    
    
    Dim startTime As DateTime =  DateTime.Now 
    Response.WriteLine("Starting Code Gen")
    
    
    'Copy Resource DLL's
    Me.CopyFolder(Me.CodeTemplateInfo.DirectoryName + "Resources", RootDestinationFolder)
    'Me.CopyFile(Me.CodeTemplateInfo.DirectoryName + "Resources\DevExpress.Web.ASPxGrid.dll", RootDestinationFolder + "\Resources")
    'Me.CopyFile(Me.CodeTemplateInfo.DirectoryName + "Resources\SolpartWebControls.dll", RootDestinationFolder + "\Resources")
        
    
    'Create Web Controls
    
    Response.WriteLine("Start Creating Web Controls " + DateTime.Now)
    CreateDirectory("WebControls")
    _MasterWebControls = Me.CompileTemplate(Me.CodeTemplateInfo.DirectoryName + "MasterWebControls.cst") 
    _MasterWebControls.SetProperty("LLBLGenProjectFileToLoad", LLBLGenProject)
    _MasterWebControls.SetProperty("WebControlsProjectGuid", _WebControlsProjectGuid)
    _MasterWebControls.SetProperty("LLBLGenDBSpecificProjectGUID", _LLBLGenDBSpecificProjectGUID)
    _MasterWebControls.SetProperty("LLBLGenProjectGUID", _LLBLGenProjectGUID)
    _MasterWebControls.SetProperty("BLProjectGuid", _BLProjectGuidProjectGUID)
    _MasterWebControls.SetProperty("GridControlType", Me.GridControlType)
    _MasterWebControls.RenderToFile(RootDestinationFolder + "\WebControls\" + LLBLGenProject.RootNameSpace + "WebControls.csproj", True)
    
    Response.WriteLine("End Creating Web Controls " + DateTime.Now)
    
    Response.WriteLine("Start Creating BL " + DateTime.Now)
    CreateDirectory("BL")
    _MasterBLL = Me.CompileTemplate(Me.CodeTemplateInfo.DirectoryName + "MasterBL.cst") 
    _MasterBLL.SetProperty("LLBLGenProjectFileToLoad", LLBLGenProject)
    _MasterBLL.SetProperty("BLProjectGuid", _BLProjectGuidProjectGUID)
    _MasterBLL.SetProperty("LLBLGenDBSpecificProjectGUID", _LLBLGenDBSpecificProjectGUID)
    _MasterBLL.SetProperty("LLBLGenProjectGUID", _LLBLGenProjectGUID)
    _MasterBLL.RenderToFile(RootDestinationFolder + "\BL\" + LLBLGenProject.RootNameSpace + ".BL.csproj", True)
    Response.WriteLine("Start Creating BL " + DateTime.Now)
    
    
    
    
    IF GenerateDocumentation then
        Response.WriteLine("Start Creating Documentation " + DateTime.Now)
        CreateDirectory("Documentation")
        'Copy Resource Files
        Me.CopyFolder("C:\Program Files\CodeSmith\v2.5\Samples\DBDocumenter\output\images", RootDestinationFolder + "\Documentation")
        Me.CopyFile("C:\Program Files\CodeSmith\v2.5\Samples\DBDocumenter\output\dbdocs.css", RootDestinationFolder + "\Documentation")
        
        _Documentation = Me.CompileTemplate("C:\Program Files\CodeSmith\v2.5\Samples\DBDocumenter\master.cst")
        '_Documentation.SetProperty("SourceDatabase", CodeSmithSchema)
        _Documentation.SetProperty("ServerName", RootDestinationFolder + "Documentation")
        _Documentation.SetProperty("DocumentationTitle", LLBLGenProject.ProjectName + " Project Documentation")
        _Documentation.SetProperty("OutputDirectory", RootDestinationFolder + "\Documentation")
        _Documentation.RenderToFile(RootDestinationFolder + "\Documentation\results.txt", True)
        Me.CopyFolder(RootDestinationFolder + "\Documentation", RootDestinationFolder + "\WebApplication")
        Response.WriteLine("End Creating Documentation " + DateTime.Now)
    Else
        Response.writeLine("Documentation skiped")
    End IF
    
    IF GenerateWebApplication then
    
        Response.WriteLine("Start Creating WebApplication " + DateTime.Now)
        
        Me.CopyFolder(Me.CodeTemplateInfo.DirectoryName + "WebApplication\Images", RootDestinationFolder + "\WebApplication")
        
        _MasterWebApplication = Me.CompileTemplate(Me.CodeTemplateInfo.DirectoryName + "MasterWebApplication.cst") 
        _MasterWebApplication.SetProperty("LLBLGenDBSpecificProjectGUID", _LLBLGenDBSpecificProjectGUID)
        _MasterWebApplication.SetProperty("LLBLGenProjectGUID", _LLBLGenProjectGUID)
        _MasterWebApplication.SetProperty("LLBLGenProjectFileToLoad", LLBLGenProject)
        _MasterWebApplication.SetProperty("WebControlsProjectGuid", _WebControlsProjectGuid)
        _MasterWebApplication.SetProperty("WebApplicationProjectGuid", _WebApplicationProjectGuid)
        _MasterWebApplication.SetProperty("BLProjectGuid", _BLProjectGuidProjectGUID)
        
        _MasterWebApplication.RenderToFile(RootDestinationFolder + "\WebApplication\" + LLBLGenProject.RootNameSpace + "WebApplication.csproj", True)
        Response.WriteLine("End Creating WebApplication " + DateTime.Now)
    Else
        Response.writeLine("WebApplication skiped")
    End IF
    
    IF GenerateDotNetNukeModule then
        Me.CopyFolder(Me.CodeTemplateInfo.DirectoryName + "DNNModule\Resources", RootDestinationFolder)
        Me.CopyFolder(Me.CodeTemplateInfo.DirectoryName + "WebApplication\Images", RootDestinationFolder + "\DotNetNukeModule")
        Response.WriteLine("Start Creating DotNetNukeModule" + DateTime.Now)

        _MasterDNNModule = Me.CompileTemplate(Me.CodeTemplateInfo.DirectoryName + "MasterDNNModule.cst") 
        _MasterDNNModule.SetProperty("LLBLGenDBSpecificProjectGUID", _LLBLGenDBSpecificProjectGUID)
        _MasterDNNModule.SetProperty("LLBLGenProjectGUID", _LLBLGenProjectGUID)
        _MasterDNNModule.SetProperty("LLBLGenProjectFileToLoad", LLBLGenProject)
        _MasterDNNModule.SetProperty("WebControlsProjectGuid", _WebControlsProjectGuid)
        _MasterDNNModule.SetProperty("DNNModuleProjectGUID", _DNNModuleProjectGUID)
        _MasterDNNModule.SetProperty("BLProjectGuid", _BLProjectGuidProjectGUID)
        _MasterDNNModule.RenderToFile(RootDestinationFolder + "\DotNetNukeModule\DNN.Modules." + LLBLGenProject.RootNameSpace + "WebNavigator.csproj", True)        
        Response.WriteLine("End Creating DotNetNukeModule " + DateTime.Now)
    Else
        Response.writeLine("DotNetNukeModule skiped")
    End If
    
    'Create Solution file

    _VSSolutionFile = Me.CompileTemplate(Me.CodeTemplateInfo.DirectoryName + "Shared\VSSolutionFile.cst") 
    _VSSolutionFile.SetProperty("LLBLGenProjectFileToLoad", LLBLGenProject)
    _VSSolutionFile.SetProperty("LLBLGenProjectGUID", _LLBLGenProjectGUID)
    _VSSolutionFile.SetProperty("LLBLGenDBSpecificProjectGUID", _LLBLGenDBSpecificProjectGUID)
    _VSSolutionFile.SetProperty("WebControlsProjectGuid", _WebControlsProjectGuid)
    _VSSolutionFile.SetProperty("BLProjectGuid", _BLProjectGuidProjectGUID)
    
    IF GenerateWebApplication then
        _VSSolutionFile.SetProperty("WebApplicationProjectGuid", _WebApplicationProjectGuid)
    End IF
    IF GenerateDotNetNukeModule then
        _VSSolutionFile.SetProperty("DNNModuleProjectGUID", _DNNModuleProjectGUID)
    End If
    _VSSolutionFile.RenderToFile(RootDestinationFolder + "\" + LLBLGenProject.RootNameSpace + ".sln", True)     
        
        

    
    
    
    Response.WriteLine("CODE Gen Complete")
    Response.WriteLine(DateTime.Now)
End Sub


</script>


<%

me.Go()

%>

Here is the MasterWebControls.cst:


<%@ CodeTemplate  Inherits="LLBLBaseCodeTemplate" Debug="False" Language="VB" TargetLanguage="c#" Description="Generates the project file for teh WebControls Project layer.  Executes the Web Controls templates." %>
<%@ Property Name="WebControlsProjectGuid" Type="System.String" Default="WebControlsProjectGuid" Category="Options" Description="Project GUID to use" %>
<%@ Property Name="LLBLGenDBSpecificProjectGUID" Type="System.String" Default="LLBLGenDBSpecificProjectGUID" Category="Options" Description="This is a sample string property." %>
<%@ Property Name="LLBLGenProjectGUID" Type="System.String" Default="LLBLGenProjectGUID" Category="Options" Description="This is a sample string property." %>
<%@ Property Name="BLProjectGuid" Type="System.String" Default="BLProjectGuid" Category="Options" Description="Project GUID to use" %>
<%@ Property Name="GridControlType" Type="CurrentControlTypeEnum" Options="Options" Description="Type of grid control to use in the GRID pages for the asp.net web app" %>

<%@ Assembly Name="BC.LLBLGen.Pro.LGPLoader" %>
<%@ Import NameSpace="BC.LLBLGen.Pro" %>
<%@ Assembly Name="BC.LLBLGen.Pro.CSTemplates" %>
<%@ Import NameSpace="BC.LLBLGen.Pro.CSTemplates" %>
<%@ Assembly Name="SD.LLBLGen.Pro.ApplicationCore" %>
<%@ Assembly Name="SD.LLBLGen.Pro.DBDriverCore" %>
<%@ Import Namespace="SD.LLBLGen.Pro.ApplicationCore.Entities" %>
<%@ Import Namespace="SD.LLBLGen.Pro.DBDriverCore" %>
<%@ Import Namespace="SD.LLBLGen.Pro.ApplicationCore" %>

<script runat="template">
public enum CurrentControlTypeEnum
    StandardGrid = 0
    DevExGrid = 1
end enum
Public  Sub Go()


    
    'Create Directory for webcontrols, delete if exists
    CreateDirectory("WebControls\DropDownLists",false,false)
    CreateDirectory("WebControls\Repeaters",false,false)
    
    'Generate a Repeater for each Entity
    me.RenderToFileForEachSingleKeyEntity("WebControls\Repeater.cst","WebControls\Repeaters",CodeGenObject.WebRepeater,"cs")
    
    'Generate a DropDownLists for each Entity
    me.RenderToFileForEachSingleKeyEntity("WebControls\DropDownList.cst","WebControls\DropDownLists",CodeGenObject.WebDropDownList,"cs")
    
    if me.GridControlType = CurrentControlTypeEnum.DevExGrid then
        CreateDirectory("WebControls\DevExpressGrids",false,false)  
        
        'Generate a DevEx Grid for each Entity
        me.RenderToFileForEachEntity("WebControls\DevExpressGrids.cst","WebControls\DevExpressGrids",CodeGenObject.WebDevExGrid,"cs",nothing)
        
        'Generate a DevEx Grid for each typed View
        me.RenderToFileForEachTypedView("WebControls\DevExpressGrids2.cst","WebControls\DevExpressGrids",CodeGenObject.WebDevExGrid,"cs")
    
        'Generate Base Grid
         me.RenderToFile("WebControls\BaseDevExGrid.cst","WebControls\DevExpressGrids\BaseDevExGrid.cs")    
    end if 
        
    'Generate Assemblyinfo
     me.RenderToFile("Shared\AssemblyInfo.cst","WebControls\AssemblyInfo.cs")
        
    
End Sub

</script> 

<VisualStudioProject>
    <CSHARP 
        ProjectType = "Local"
        ProductVersion = "7.10.3077"
        SchemaVersion = "2.0"
        ProjectGuid = "{<%=WebControlsProjectGuid%>}"
    >
        <Build>
            <Settings
                ApplicationIcon = ""
                AssemblyKeyContainerName = ""
                AssemblyName = "<%= LLBLGenProject.RootNamespace %>WebControls"
                AssemblyOriginatorKeyFile = ""
                DefaultClientScript = "JScript"
                DefaultHTMLPageLayout = "Grid"
                DefaultTargetSchema = "IE50"
                DelaySign = "false"
                OutputType = "Library"
                PreBuildEvent = ""
                PostBuildEvent = ""
                RootNamespace = "WebControls"
                RunPostBuildEvent = "OnBuildSuccess"
                StartupObject = ""
            >
                <Config
                    Name = "Debug"
                    AllowUnsafeBlocks = "false"
                    BaseAddress = "285212672"
                    CheckForOverflowUnderflow = "false"
                    ConfigurationOverrideFile = ""
                    DefineConstants = "DEBUG;TRACE"
                    DocumentationFile = ""
                    DebugSymbols = "true"
                    FileAlignment = "4096"
                    IncrementalBuild = "false"
                    NoStdLib = "false"
                    NoWarn = ""
                    Optimize = "false"
                    OutputPath = "bin\Debug\"
                    RegisterForComInterop = "false"
                    RemoveIntegerChecks = "false"
                    TreatWarningsAsErrors = "false"
                    WarningLevel = "4"
                />
                <Config
                    Name = "Release"
                    AllowUnsafeBlocks = "false"
                    BaseAddress = "285212672"
                    CheckForOverflowUnderflow = "false"
                    ConfigurationOverrideFile = ""
                    DefineConstants = "TRACE"
                    DocumentationFile = ""
                    DebugSymbols = "false"
                    FileAlignment = "4096"
                    IncrementalBuild = "false"
                    NoStdLib = "false"
                    NoWarn = ""
                    Optimize = "true"
                    OutputPath = "bin\Release\"
                    RegisterForComInterop = "false"
                    RemoveIntegerChecks = "false"
                    TreatWarningsAsErrors = "false"
                    WarningLevel = "4"
                />
            </Settings>
            <References>
                <Reference
                    Name = "System"
                    AssemblyName = "System"
                    HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll"
                />
                <Reference
                    Name = "System.Data"
                    AssemblyName = "System.Data"
                    HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
                />
                <Reference
                    Name = "System.XML"
                    AssemblyName = "System.Xml"
                    HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
                />
                <Reference
                    Name = "SD.LLBLGen.Pro.ORMSupportClasses.NET11"
                    AssemblyName = "SD.LLBLGen.Pro.ORMSupportClasses.NET11"
                    HintPath = "..\bin\SD.LLBLGen.Pro.ORMSupportClasses.NET11.dll"
                />
                <Reference
                    Name = "SD.LLBLGen.Pro.DQE.SqlServer.NET11"
                    AssemblyName = "SD.LLBLGen.Pro.DQE.SqlServer.NET11"
                    HintPath = "..\bin\SD.LLBLGen.Pro.DQE.SqlServer.NET11.dll"
                />
                 <Reference
                    Name = "<%= LLBLGenProject.ProjectName %>"
                    Project = "{<%=LLBLGenProjectGUID%>}"
                    Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
                />
                <Reference
                    Name = "<%= LLBLGenProject.ProjectName %>DBSpecific"
                    Project = "{<%=LLBLGenDBSpecificProjectGUID%>}"
                    Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
                />
                <Reference
                    Name = "<%= LLBLGenProject.ProjectName %>.BL"
                    Project = "{<%=BLProjectGuid%>}"
                    Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
                />
                <Reference
                    Name = "System.Drawing"
                    AssemblyName = "System.Drawing"
                    HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll"
                />
                <Reference
                    Name = "System.Web"
                    AssemblyName = "System.Web"
                    HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Web.dll"
                />
                
                <% If Me.GridControlType =  CurrentControlTypeEnum.DevExGrid then %>
                <Reference
                    Name = "DevExpress.Web.ASPxGrid"
                    AssemblyName = "DevExpress.Web.ASPxGrid"
                    HintPath = "..\Resources\DevExpress.Web.ASPxGrid.dll"
                />
                <% End if %>
            </References>
        </Build>
        <Files>
            <Include>
                <File
                    RelPath = "AssemblyInfo.cs"
                    SubType = "Code"
                    BuildAction = "Compile"
                />
                <File
                    RelPath = "DevExpressGrids\BaseDevExGrid.cs"
                    SubType = "Code"
                    BuildAction = "Compile"
                />
        <% Dim i As Integer
            For i = 0 To LLBLGenProject.Entities.Count - 1
                IF LLBLGenProject.Entities(i).PrimaryKeyFields.Count = 1 then%>
            <File
                    RelPath = "DropDownLists\<%=GetCodeGenObjectName(LLBLGenProject.Entities(i).Name,CodeGenObject.WebDropDownList, False)%>.cs"
                    SubType = "Code"
                    BuildAction = "Compile"
                />
                <%
                end if
                next%>
        <%  
            For i = 0 To LLBLGenProject.Entities.Count - 1
                IF LLBLGenProject.Entities(i).PrimaryKeyFields.Count = 1 then%>
            <File
                    RelPath = "Repeaters\<%=GetCodeGenObjectName(LLBLGenProject.Entities(i).Name,CodeGenObject.WebRepeater, False)%>.cs"
                    SubType = "Code"
                    BuildAction = "Compile"
                />
                <%
                end if
                next%>
          <%  
            For i = 0 To LLBLGenProject.Entities.Count - 1
                'IF LLBLGenProject.Entities(i).PrimaryKeyFields.Count = 1 then%>
            <File
                    RelPath = "DevExpressGrids\<%=GetCodeGenObjectName(LLBLGenProject.Entities(i).Name,CodeGenObject.WebDevExGrid, False)%>.cs"
                    SubType = "Code"
                    BuildAction = "Compile"
                />
                <%
                'end if
                next%>
            <%
            If GridControlType =  CurrentControlTypeEnum.DevExGrid then
                For i = 0 To LLBLGenProject.TypedViews.Count - 1%>
            <File 
                    RelPath = "DevExpressGrids\<%=GetCodeGenObjectName(LLBLGenProject.TypedViews(i).Name,CodeGenObject.WebDevExGrid, False)%>.cs"
                    SubType = "Code"
                    BuildAction = "Compile"
                />
            <%  next
            End If
            %>
            </Include>
        </Files>
    </CSHARP>
</VisualStudioProject>
<%me.Go()%>

bertcord avatar
bertcord
User
Posts: 206
Joined: 01-Dec-2003
# Posted on: 03-Aug-2004 15:07:58   

cool thanks. Email me the datagrid example when you get it done. I will then create a template from it and add your changes above.

Bert

free4all
User
Posts: 35
Joined: 12-Sep-2003
# Posted on: 03-Aug-2004 17:35:44   

Hi All,

Managed to get the Codesmith templates to run after recompiling Bert’s source (didn’t realise Bert had included the DLL source in the zip flushed ) . Then using the updated templates kindly supplied by Devildog74 I tried CodeSmith on one of my projects and eventually got it to compile. I had to remove a couple of northwind references from:

Controller.cst:

Line 83:


EntityCollection <%=Entity.Name%>Collection = new EntityCollection(new Northwind.FactoryClasses.<%=Entity.Name%>EntityFactory());

Which I assume should be:

EntityCollection <%=Entity.Name%>Collection = new EntityCollection(new <%=LLBLGenProject.RootNamespace%>.FactoryClasses.<%=Entity.Name%>EntityFactory());

And..

ActionsProceduresController.cst:

Lines 19, 20:

using Northwind.DatabaseSpecific;
using Northwind.EntityClasses;

Which I simply commented out.

I’ve not got any grid support as yet as I don’t have the required custom control so I look forward to seeing Bert/Devildog74’s update.

In the mean time I’ve got lots to play with. Thanks guys! smile

bertcord avatar
bertcord
User
Posts: 206
Joined: 01-Dec-2003
# Posted on: 03-Aug-2004 17:41:06   

free4all wrote:

I had to remove a couple of northwind references from:

Controller.cst:

Line 83:


EntityCollection <%=Entity.Name%>Collection = new EntityCollection(new Northwind.FactoryClasses.<%=Entity.Name%>EntityFactory());

thanks....as you can see I have only used these in testing so far thanks for pointed that out

bert

alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 04-Aug-2004 16:18:22   

Perhaps I am missing the value of these templates. Once LLBLGen does its thing and generates the DAL, it is not at all difficult to create these types of pages by hand. Additionally, the result is generally much more fine tuned if you create the pages manually.

bertcord avatar
bertcord
User
Posts: 206
Joined: 01-Dec-2003
# Posted on: 04-Aug-2004 17:09:55   

alexdresko wrote:

Perhaps I am missing the value of these templates. Once LLBLGen does its thing and generates the DAL, it is not at all difficult to create these types of pages by hand.

Faster than 30 seconds stuck_out_tongue_winking_eye ?

OF course you can write them by hand just like many people write dataaccess code by hand.

It is also not just the GUI that my templates create. I creates a class library of web controls. I am currently working on a template that will create a VBscript that will add these objects to your visual studio toolbox. So for example if you are working on the Northwind project and you need a drop down list of customers you can just drag and drop the Customer drop down control form you toolbox. I woudl like to create custom controls for each control that can hold data.

It also creates a BL library also which for me makes things easier.

I also think this adds value to LLBLGen. Hopefully when Frans adds the ability to run code blocks in his templates I will convert them to use his template generator.

Bert

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 05-Aug-2004 01:49:27   

I havent tested the code yet, but it looks right.

Ok, here is the Generic ASP.NET Data grid Base:


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;

namespace Northwind.Adapter.Web.Controls
{

    /// <summary>
    /// This class defines the BaseDataGrid which is a custom server control that derives from DataGrid
    /// </summary>
    public class BaseDataGrid : System.Web.UI.WebControls.DataGrid
    {
        #region constructors...
        /// <summary>
        /// The default public constructor
        /// </summary>
        public BaseDataGrid()
        {
        }       
        #endregion

        #region protected methods
        /// <summary>
        /// Allows us to override the base controls OnInti method. We override the 
        /// base classes method in order to provide our own custom implementation
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.AutoGenerateColumns = false;
            this.AllowPaging = true;
            this.AllowSorting = true;

            //header
            this.ShowHeader = true;
            this.BorderColor = Color.FromArgb(255, 201, 32); //DARK Orange;
            this.HeaderStyle.BackColor = Color.FromArgb(255, 201, 32); //DARK Orange;
            this.HeaderStyle.Font.Name = "helvetica,arial,sanserif";
            this.HeaderStyle.Font.Bold = true;
            this.HeaderStyle.Font.Size = new FontUnit("8pt");
            this.HeaderStyle.ForeColor = Color.FromArgb(0, 0, 0);
            this.HeaderStyle.Wrap = false;
            this.HeaderStyle.BorderColor = Color.Black;

            //Items / Rows
            //this.ItemStyle.BackColor = Color.FromArgb(255, 255, 228); //Pale Yellow;
            this.AlternatingItemStyle.BackColor = Color.FromArgb(255, 255, 255); //Pale Yellow
            this.ItemStyle.BackColor = Color.FromArgb(255, 255, 228); //Pale Yellow
            this.ItemStyle.Font.Name = "helvetica,arial,sanserif";
            this.ItemStyle.Font.Size = new FontUnit("8pt");

            this.SelectedItemStyle.BackColor = Color.FromArgb(255,255,153);
            this.SelectedItemStyle.ForeColor = System.Drawing.Color.Black;

            //Pager
            this.PagerStyle.HorizontalAlign = HorizontalAlign.Left;
            this.PagerStyle.Font.Size = FontUnit.Parse("8pt");
            this.PagerStyle.Font.Name = "helvetica,arial,sanserif";
            this.PagerStyle.BackColor = Color.FromArgb(102, 102, 102);
            this.PageSize = 20;
            this.PagerStyle.Width = new Unit(20);
            this.PagerStyle.Height= new Unit(20);



        }       
        #endregion  
    }
}



And here is the concrete class:


using System;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;

using Northwind.Adapter.EntityClasses;
using Northwind.Adapter.DatabaseSpecific;
using Northwind.Adapter;
using Northwind.Adapter.HelperClasses;
using Northwind.Adapter.FactoryClasses;
using Northwind.Adapter.BL;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace Northwind.Adapter.Web.Controls
{
    /// <summary>
    /// Summary description for OrderDataGrid.
    /// </summary>
    [DefaultProperty("Text"), 
        ToolboxData("<{0}:OrderDataGrid runat=server></{0}:OrderDataGrid>")]
    public class OrderDataGrid : BaseDataGrid
    {
        private EntityCollection _orders;

        #region constructors...
        /// <summary>
        /// This is the default new constructor
        /// </summary>
        public OrderDataGrid() : base()
        {
            
        }

        
        #endregion

        #region properties...

        /// <summary>
        /// Gets/Sets the EmployeeId in the viewstate
        /// </summary>
        public int FilterByFkEmployeeId
        {
            get 
            {
                string s = (string)ViewState["FilterByFkEmployeeId"];
                return ((s == null) ? Null.NullInteger : Convert.ToInt32(s));
            }
            set 
            {
                ViewState["FilterByFkEmployeeId"] = value.ToString();
            }
        }


        /// <summary>
        /// Gets/Sets the customer id from the viewstate
        /// </summary>
        public string FilterByFkCustomerId
        {
            get 
            {
                string s = (string)ViewState["FilterByFkCustomerId"];
                return ((s == null) ? Null.NullString : Convert.ToString(s));
            }
            set 
            {
                ViewState["FilterByFkCustomerId"] = value.ToString();
            }
        }


        /// <summary>
        /// Gets/Sets the Ship Via value in the viewstate
        /// </summary>
        public int FilterByFkShipVia
        {
            get 
            {
                string s = (string)ViewState["FliterByFkSipVia"];
                return ((s == null) ? Null.NullInteger : Convert.ToInt32(s));
            }
            set 
            {
                ViewState["FilterByFkShipVia"] = value.ToString();
            }
        }
        #endregion

        #region protected members
        /// <summary>
        /// This method is fired as part of the control lifecycle
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }       
        #endregion

        #region private methods

        /// <summary>
        /// This event handler fetches the data from the controoler and binds the data
        /// </summary>
        /// <param name="sender">Source of the event</param>
        /// <param name="e">Custom data passed from the caller of the event</param>
        private void OnDataBinding(object sender, EventArgs e)
        {
            _orders = OrdersController.FetchOrdersCollection(
                this.FilterByFkCustomerId, this.FilterByFkEmployeeId, this.FilterByFkShipVia);  

            this.DataSource = _orders;
        }

        /// <summary>
        /// Hooks up the OnDataBinding event handler
        /// </summary>
        private void InitializeComponent()
        {
            this.DataBinding += new System.EventHandler( 
                this.OnDataBinding);
        }   

        /// <summary>
        /// This is a helper method that creates the columns in the internal columns collection
        /// </summary>
        /// <param name="fieldName">Specify the name of the database column</param>
        /// <param name="wrapText">A boolean value that sets the Wrap property of the header 
        /// and the data item</param>
        /// <param name="formatExpression">A string value that will set the DataFormatString 
        /// of the data column</param>
        /// <remarks>
        /// When setting the formatExpression, if you dont want to set the value, pass null 
        /// or string.empty
        /// </remarks>
        private void CreateColumn(string fieldName, bool wrapText, string formatExpression)
        {
            BoundColumn col = new BoundColumn();

            col.ItemStyle.Wrap = wrapText;
            col.HeaderStyle.Wrap = wrapText;
            col.DataField = fieldName;

            if ((formatExpression != null) && (formatExpression != string.Empty))
            {
                col.DataFormatString = formatExpression;
            }

            col.HeaderText = fieldName;

            this.Columns.Add(col);
        }


        #endregion

        #region public methods

        /// <summary>
        /// Sets the inital properties of the grid
        /// </summary>
        /// <param name="customerId">Primary key of the customer that this order relates to</param>
        /// <param name="employeeId">Primary key of the employee that this employee relates to</param>
        /// <param name="shipVia">Primary Key of the Shipping Method</param>
        public void Initialize(string customerId, int employeeId, int shipVia)
        {
            this.FilterByFkCustomerId = customerId;
            this.FilterByFkShipVia=shipVia;
            this.FilterByFkEmployeeId = employeeId;
        }


        /// <summary>
        /// Forces the grid to create its columns
        /// </summary>
        public void CreateColumns()
        {
            this.Columns.Clear();
            
            this.CreateColumn("OderID", false, null);
            this.CreateColumn("CustomerId", false, null);
            this.CreateColumn("EmployeeId", false,null);
            this.CreateColumn("CustomerId", false,null);
            this.CreateColumn("OrderDate", false, "{0:MM/dd/yyyy}");
            this.CreateColumn("RequiredDate", false, "{0:MM/dd/yyyy}");
            this.CreateColumn("ShippedDate", false, "{0:MM/dd/yyyy}"  );
            this.CreateColumn("ShipVia", false,null);
            this.CreateColumn("Freight", false,null);
            this.CreateColumn("ShipName", false,null);
            this.CreateColumn("ShipAddress", false,null);
            this.CreateColumn("ShipCity", false,null);
            this.CreateColumn("ShipRegion", false,null);
            this.CreateColumn("ShipPostalCode", false,null);
            this.CreateColumn("ShipCountry", false,null);

        }       
        #endregion
    
    
    }
}



Bert, is the email in your profile a valid email? It looks like a no-spam email?

bertcord avatar
bertcord
User
Posts: 206
Joined: 01-Dec-2003
# Posted on: 05-Aug-2004 03:16:34   

Yep that is my email. I create a email address for every forum I am on. You can send code files to that address if ya want.

Looks good thanks. I do have one question. I have not worked much with the standard datagrid but I was under the impression that you have to do more than

this.AllowSorting = true;

to enable sorting. I think this just enables the column headers but you still need to handle the event and create the sort predicate.

Bert

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 05-Aug-2004 05:43:39   

bertcord wrote:

I think this just enables the column headers but you still need to handle the event and create the sort predicate.

Actually, yes, you are correct. I will be visiting this code again tomorrow. Its on my office PC. I will have a rev. for you tomorrow.

bertcord avatar
bertcord
User
Posts: 206
Joined: 01-Dec-2003
# Posted on: 05-Aug-2004 08:37:23   

Devildog74 wrote:

Actually, yes, you are correct. I will be visiting this code again tomorrow. Its on my office PC. I will have a rev. for you tomorrow.

thanks...you can just send it to my email address and I will have frans add it to the 3rd party section

bert

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 06-Aug-2004 20:03:10   

I am having a real bear of a time triyng to get the item command and sort commands to fire on the derived grid that I am working on.

Bert, do you have any pointers? Should I be doing anything with IPostBackDataHandler? The grid loads data but no trappable events seem to be firing during the item command event or the page changed event.

bertcord avatar
bertcord
User
Posts: 206
Joined: 01-Dec-2003
# Posted on: 09-Aug-2004 15:59:42   

[quotenick="Devildog74"]I am having a real bear of a time triyng to get the item command and sort commands to fire on the derived grid that I am working on.

Bert, do you have any pointers? [quote]

What issues are you having? InStead of wireing up event handles in your derived controls you shold override the method and call the base method.

bert

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 09-Aug-2004 18:59:34   

Actually, I did get it figured out. I was initializing the grid in the click event of a button on an asp.net web page, so, when I clicked the pager, the data wasnt initialized, and it did not have any data in it, so the:


        protected override void OnPageIndexChanged(DataGridPageChangedEventArgs e)
        {
            base.OnPageIndexChanged(e);
            this.Page.Response.Write("OnPageIndexChanged fired");
        }


was not firing. Now, the next question is, what would be the proper approach to avoid a database refetch after each page index click?

On another note, I made a lot of changes to the Controller.cst to make them more compliant with respect to FxCop.

bertcord avatar
bertcord
User
Posts: 206
Joined: 01-Dec-2003
# Posted on: 09-Aug-2004 21:38:11   

Devildog74 wrote:

Now, the next question is, what would be the proper approach to avoid a database refetch after each page index click?

I would not worry about it now. Once the new adapter template set is out that supports paging we can work that in.

Devildog74 wrote:

On another note, I made a lot of changes to the Controller.cst to make them more compliant with respect to FxCop.

Sounds good I woudl love to check it out. Like I have said before I have no formal traning writing code, only a few books I have read and this forum. I am always looking for some positive feedback. Can you send me your Controll.cst? Did you change the interace at all?

On another note...the next verison of this is going to be cool. I added some vbscripts that add the webcontrols into the VS toolbox. This way you can just drag and drop your controls. I hope to start next week on composite server controls for each entity next week

Bert

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 10-Aug-2004 01:32:24   

bert, there's mail on the way to you.

1  /  2  /  3