Web Application Development / Using LLBL Generated Code

Posts   
 
    
Khuzema
User
Posts: 22
Joined: 24-Jul-2006
# Posted on: 24-Jul-2006 09:43:40   

Hi All,

We are using Demo version of LLBL Gen Pro V2. (Though we have gone thru some other product (Beta/Demo) also and wasted lot of time).

My simple question is -

1) Documentation for LLBLGenProDataSource 2) Example shows (How-To) Add/Edit/Delete 1:n entity i.e. Order (like in Northwind) with OrderDetail using LLBL Gen Pro V2 generated code. 3) Any Reference sample application/ Starter Kit (asking too much - sorry!) like Duwamish/Northwind implemented with LLBL Gen Pro V2.

There are many other similiar product like netTiers (in Beta) they have like petShop and Northwind as sample why such a established product (LLBL Gen Pro) does not have anything similiar reference application to help their customer/user.

Suggestion: There should be seperate forum for ASP.Net/Web Development.

thanks & regards

Khuzema

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39898
Joined: 17-Aug-2003
# Posted on: 24-Jul-2006 10:11:33   

Khuzema wrote:

Hi All,

We are using Demo version of LLBL Gen Pro V2. (Though we have gone thru some other product (Beta/Demo) also and wasted lot of time).

My simple question is -

1) Documentation for LLBLGenProDataSource

It's in the docs: using the generated code -> selfservicing/adapter -> Databinding at design time and runtime -> Databinding with ASP.NET 2.0 And also in the reference manual.

2) Example shows (How-To) Add/Edit/Delete 1:n entity i.e. Order (like in Northwind) with OrderDetail using LLBL Gen Pro V2 generated code.

That hasn't something to do with LLBLGen Pro but with how to setup master-detail in ASP.NET 2.0: it works the same as with ObjectdataSource or SqldataSource -> setup SelectParameter parameters to sync PK value in the master with FK value in the detail. A usage example for master-detail is in the docs I pointed to at 1): master selects orders in detail, which allows you to edit / delete rows in a gridview. To add new rows you should obviously use a Formview, as that's required in ASP.NET: you can't add a new row in a gridview. Though that's more ASP.NET 2.0 knowledge than that it is specific LLBLGen Pro knowledge, simply because it's the same with sqldatasource or objectdatasource.

3) Any Reference sample application/ Starter Kit (asking too much - sorry!) like Duwamish/Northwind implemented with LLBL Gen Pro V2.

We have 2 different examples now, a 3rd (this forum package) is coming soon. There are countless examples in the docs as well. Did you try them all? See Best practises -> How do I? for a list.

LLBLGen Pro is a data-access solution, not an app generator. This means that usage examples are often code snippets doing something with data, not forms or webforms related.

There are many other similiar product like netTiers (in Beta) they have like petShop and Northwind as sample why such a established product (LLBL Gen Pro) does not have anything similiar reference application to help their customer/user.

A petshop implementation is NOT a good reference example. We had a petshop implementation for v1.0.2005.1. However even when we ported a lot of code over to new code because the original petshop was too horrible, its design still wasn't that great simply because the petshop design sucks so much.

Add to that, that a reference implementation is not that valuable: in most situations, the application a developer is working on looks different or has different requirements, and a developer is then better helped with smaller examples and deep explanations about what's going on and why things are done this way and not another way. Our documentation is over 400 printed A4 pages (and that doesn't include the reference manual) which gives the developer a lot of background info so the developer has good understanding what to do when in which situation. Using a sloppy 'example' like the petshop example is then of no help, as the developer might do the wrong things, because the requirements for the petshop example by MS were way different than the requirements of the application the developer is working on.

This forum package for example, which we're currently updating for example purposes, is a good example of this: it won't use the LLBLGenProDataSource controls. Simply because no-where did we use design time databinding or did we need 2-way databinding: either because the code was already written in ASP.NET 1.x or because using a formview would be more work.

Suggestion: There should be seperate forum for ASP.Net/Web Development.

Thanks, but we won't do that. ASP.NET development is not different when it comes to data-access than any other application.

Oh, and I don't consider netTiers as a competitor.

Frans Bouma | Lead developer LLBLGen Pro
Khuzema
User
Posts: 22
Joined: 24-Jul-2006
# Posted on: 24-Jul-2006 10:56:19   

Unbelievably fast response. If this is the speed of response, this one thing is enough to put your money on the software.

Give me some time to go thru. I might be not as quick as you.

warm regards

Khuzema

Khuzema
User
Posts: 22
Joined: 24-Jul-2006
# Posted on: 24-Jul-2006 11:34:47   

Hi,

  1. Sorry about the DataSource documentation, I missed it.

  2. I beg to differ, what you said on Master-Detail example. For the new user s/he might need to know how this generated code can be used (for example if they want to used LLBLGen Datasource control how it can be done and thru coding how it be done). To cut the long story short, if you have a example please provide it (as we are little bit struggling) otherwise its fine with us. (Previously we have used Duwamish as our architecture and used ObjectDataSource)

  3. Which are the two different examples you have, can you provide link to them and waiting for the forum example to be released.

  4. We have nothing to do with Petshop or otherwise, its just a reference application I mentioned, any good reference application will do.

  5. Forum I believe is for user convenience, Web development issues might be different (IMHO).

  6. Competitor or not (I dont know) .netTiers is OR Mapping Tools (Free if you own Codesmith) and generates DAL/BLL and more.

NOTE: .netTiers I didnot mentioned as Competitor product in my previous post, the meaning was having a reference application. I am sorry if I was not clear.

Thats it

warm regards

Khuzema

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 24-Jul-2006 16:32:58   

Did you check the Examples and the Tutorial/Videos sections from www.llblgen.com? You'll find a master/detail example based on Northwind in there.

Also, there is a lot of information about doing ASP.Net with LLBLGen in the following post from Frans's blog: http://weblogs.asp.net/fbouma/archive/2006/06/09/LLBLGen-Pro-v2.0-with-ASP.NET-2.0.aspx

Khuzema
User
Posts: 22
Joined: 24-Jul-2006
# Posted on: 27-Jul-2006 11:30:37   

The example we are looking is for Master-Detail (like order involving Customer-Order-OrderDetail) which include Add/Edit/Delete/Query. The example link does not provide that. The ideal example (for ASP.Net) would a webform shows how to do these functions with LLBL Gen Pro framework & generated code. Anyway, thats not there.

Currently I am working on a example, which once done, I would post it. Then atleast what I would like from the expert is, they review and guide. If this example is Ok then we can make it available for other fellow developers.

thanks & regards

Khuzema

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39898
Joined: 17-Aug-2003
# Posted on: 27-Jul-2006 12:50:42   

There are a couple of examples available, posted on the forum.

For example: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6975

I've some posted below. Grids etc. can be used to delete/edit a row so that's trivial.

Example 1: Add a new order for a customer: Page:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>

<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        Add an order to the customer:
        <asp:DropDownList ID="_customerComboBox" runat="server" AutoPostBack="True" DataSourceID="_customersDS" DataTextField="CustomerId" DataValueField="CustomerId">
        </asp:DropDownList><br />
        <cc1:LLBLGenProDataSource2 ID="_customersDS" runat="server" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.CustomersEntityFactory, NWTest">
        </cc1:LLBLGenProDataSource2>
        <br />
        Current orders:
        <br />
        <asp:GridView ID="_ordersGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderId" DataSourceID="_ordersDS" OnSelectedIndexChanged="_ordersGrid_SelectedIndexChanged">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="OrderId" HeaderText="OrderId" ReadOnly="True" SortExpression="OrderId" />
                <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" SortExpression="CustomerId" />
                <asp:BoundField DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName" />
                <asp:BoundField DataField="ShipAddress" HeaderText="ShipAddress" SortExpression="ShipAddress" />
                <asp:BoundField DataField="ShipCity" HeaderText="ShipCity" SortExpression="ShipCity" />
                <asp:BoundField DataField="ShipRegion" HeaderText="ShipRegion" SortExpression="ShipRegion" />
                <asp:BoundField DataField="ShipPostalCode" HeaderText="ShipPostalCode" SortExpression="ShipPostalCode" />
                <asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry" SortExpression="ShipCountry" />
                <asp:BoundField DataField="EmployeeId" HeaderText="EmployeeId" SortExpression="EmployeeId" />
                <asp:BoundField DataField="OrderDate" HeaderText="OrderDate" SortExpression="OrderDate" />
                <asp:BoundField DataField="RequiredDate" HeaderText="RequiredDate" SortExpression="RequiredDate" />
                <asp:BoundField DataField="ShippedDate" HeaderText="ShippedDate" SortExpression="ShippedDate" />
                <asp:BoundField DataField="Freight" HeaderText="Freight" SortExpression="Freight" />
                <asp:BoundField DataField="ShipVia" HeaderText="ShipVia" SortExpression="ShipVia" />
            </Columns>
        </asp:GridView>
        <cc1:LLBLGenProDataSource2 ID="_ordersDS" runat="server" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.OrdersEntityFactory, NWTest">
            <SelectParameters>
                <asp:ControlParameter ControlID="_customerComboBox" Name="CustomerId" PropertyName="SelectedValue" />
            </SelectParameters>
            <InsertParameters>
                <asp:ControlParameter ControlID="_customerComboBox" Name="CustomerId" PropertyName="SelectedValue" />
            </InsertParameters>
        </cc1:LLBLGenProDataSource2>
        <br />
        <br />
        New order form<asp:FormView ID="_newOrderFormView" runat="server" DataKeyNames="OrderId" DataSourceID="_ordersDS">
            <EditItemTemplate>
                OrderId:
                <asp:Label ID="OrderIdLabel1" runat="server" Text='<%# Eval("OrderId") %>'></asp:Label><br />
                CustomerId:
                <asp:TextBox ID="CustomerIdTextBox" runat="server" Text='<%# Bind("CustomerId") %>'>
                </asp:TextBox><br />
                EmployeeId:
                <asp:TextBox ID="EmployeeIdTextBox" runat="server" Text='<%# Bind("EmployeeId") %>'>
                </asp:TextBox><br />
                OrderDate:
                <asp:TextBox ID="OrderDateTextBox" runat="server" Text='<%# Bind("OrderDate") %>'>
                </asp:TextBox><br />
                RequiredDate:
                <asp:TextBox ID="RequiredDateTextBox" runat="server" Text='<%# Bind("RequiredDate") %>'>
                </asp:TextBox><br />
                ShippedDate:
                <asp:TextBox ID="ShippedDateTextBox" runat="server" Text='<%# Bind("ShippedDate") %>'>
                </asp:TextBox><br />
                ShipVia:
                <asp:TextBox ID="ShipViaTextBox" runat="server" Text='<%# Bind("ShipVia") %>'>
                </asp:TextBox><br />
                Freight:
                <asp:TextBox ID="FreightTextBox" runat="server" Text='<%# Bind("Freight") %>'>
                </asp:TextBox><br />
                ShipName:
                <asp:TextBox ID="ShipNameTextBox" runat="server" Text='<%# Bind("ShipName") %>'>
                </asp:TextBox><br />
                ShipAddress:
                <asp:TextBox ID="ShipAddressTextBox" runat="server" Text='<%# Bind("ShipAddress") %>'>
                </asp:TextBox><br />
                ShipCity:
                <asp:TextBox ID="ShipCityTextBox" runat="server" Text='<%# Bind("ShipCity") %>'>
                </asp:TextBox><br />
                ShipRegion:
                <asp:TextBox ID="ShipRegionTextBox" runat="server" Text='<%# Bind("ShipRegion") %>'>
                </asp:TextBox><br />
                ShipPostalCode:
                <asp:TextBox ID="ShipPostalCodeTextBox" runat="server" Text='<%# Bind("ShipPostalCode") %>'>
                </asp:TextBox><br />
                ShipCountry:
                <asp:TextBox ID="ShipCountryTextBox" runat="server" Text='<%# Bind("ShipCountry") %>'>
                </asp:TextBox><br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update">
                </asp:LinkButton>
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel">
                </asp:LinkButton>
            </EditItemTemplate>
            <InsertItemTemplate>
                OrderId:
                <asp:TextBox ID="OrderIdTextBox" runat="server" Text='<%# Bind("OrderId") %>'>
                </asp:TextBox><br />
                CustomerId:
                <asp:TextBox ID="CustomerIdTextBox" runat="server" Text='<%# Bind("CustomerId") %>'>
                </asp:TextBox><br />
                EmployeeId:
                <asp:TextBox ID="EmployeeIdTextBox" runat="server" Text='<%# Bind("EmployeeId") %>'>
                </asp:TextBox><br />
                OrderDate:
                <asp:TextBox ID="OrderDateTextBox" runat="server" Text='<%# Bind("OrderDate") %>'>
                </asp:TextBox><br />
                RequiredDate:
                <asp:TextBox ID="RequiredDateTextBox" runat="server" Text='<%# Bind("RequiredDate") %>'>
                </asp:TextBox><br />
                ShippedDate:
                <asp:TextBox ID="ShippedDateTextBox" runat="server" Text='<%# Bind("ShippedDate") %>'>
                </asp:TextBox><br />
                ShipVia:
                <asp:TextBox ID="ShipViaTextBox" runat="server" Text='<%# Bind("ShipVia") %>'>
                </asp:TextBox><br />
                Freight:
                <asp:TextBox ID="FreightTextBox" runat="server" Text='<%# Bind("Freight") %>'>
                </asp:TextBox><br />
                ShipName:
                <asp:TextBox ID="ShipNameTextBox" runat="server" Text='<%# Bind("ShipName") %>'>
                </asp:TextBox><br />
                ShipAddress:
                <asp:TextBox ID="ShipAddressTextBox" runat="server" Text='<%# Bind("ShipAddress") %>'>
                </asp:TextBox><br />
                ShipCity:
                <asp:TextBox ID="ShipCityTextBox" runat="server" Text='<%# Bind("ShipCity") %>'>
                </asp:TextBox><br />
                ShipRegion:
                <asp:TextBox ID="ShipRegionTextBox" runat="server" Text='<%# Bind("ShipRegion") %>'>
                </asp:TextBox><br />
                ShipPostalCode:
                <asp:TextBox ID="ShipPostalCodeTextBox" runat="server" Text='<%# Bind("ShipPostalCode") %>'>
                </asp:TextBox><br />
                ShipCountry:
                <asp:TextBox ID="ShipCountryTextBox" runat="server" Text='<%# Bind("ShipCountry") %>'>
                </asp:TextBox><br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert">
                </asp:LinkButton>
                <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel">
                </asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
                OrderId:
                <asp:Label ID="OrderIdLabel" runat="server" Text='<%# Eval("OrderId") %>'></asp:Label><br />
                CustomerId:
                <asp:Label ID="CustomerIdLabel" runat="server" Text='<%# Bind("CustomerId") %>'></asp:Label><br />
                EmployeeId:
                <asp:Label ID="EmployeeIdLabel" runat="server" Text='<%# Bind("EmployeeId") %>'></asp:Label><br />
                OrderDate:
                <asp:Label ID="OrderDateLabel" runat="server" Text='<%# Bind("OrderDate") %>'></asp:Label><br />
                RequiredDate:
                <asp:Label ID="RequiredDateLabel" runat="server" Text='<%# Bind("RequiredDate") %>'></asp:Label><br />
                ShippedDate:
                <asp:Label ID="ShippedDateLabel" runat="server" Text='<%# Bind("ShippedDate") %>'></asp:Label><br />
                ShipVia:
                <asp:Label ID="ShipViaLabel" runat="server" Text='<%# Bind("ShipVia") %>'></asp:Label><br />
                Freight:
                <asp:Label ID="FreightLabel" runat="server" Text='<%# Bind("Freight") %>'></asp:Label><br />
                ShipName:
                <asp:Label ID="ShipNameLabel" runat="server" Text='<%# Bind("ShipName") %>'></asp:Label><br />
                ShipAddress:
                <asp:Label ID="ShipAddressLabel" runat="server" Text='<%# Bind("ShipAddress") %>'></asp:Label><br />
                ShipCity:
                <asp:Label ID="ShipCityLabel" runat="server" Text='<%# Bind("ShipCity") %>'></asp:Label><br />
                ShipRegion:
                <asp:Label ID="ShipRegionLabel" runat="server" Text='<%# Bind("ShipRegion") %>'></asp:Label><br />
                ShipPostalCode:
                <asp:Label ID="ShipPostalCodeLabel" runat="server" Text='<%# Bind("ShipPostalCode") %>'></asp:Label><br />
                ShipCountry:
                <asp:Label ID="ShipCountryLabel" runat="server" Text='<%# Bind("ShipCountry") %>'></asp:Label><br />
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit">
                </asp:LinkButton>
                <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete">
                </asp:LinkButton>
                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New">
                </asp:LinkButton>
            </ItemTemplate>
        </asp:FormView>
    </form>
</body>
</html>

code behind:


using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default6 : System.Web.UI.Page
{
    protected void Page_Load( object sender, EventArgs e )
    {
    }

    protected void _ordersGrid_SelectedIndexChanged( object sender, EventArgs e )
    {
        _newOrderFormView.PageIndex = _ordersGrid.SelectedIndex;
    }
}

Example 2: Master detail with 2 grids, and a combo box to fill the master: page:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        Master detail with 2 grids, 2 datasources and 1 combobox filter for the master set.<br />
        <br />
        Select country:&nbsp;
        <asp:DropDownList ID="_countrySelector" runat="server" AutoPostBack="true">
            <asp:ListItem>Germany</asp:ListItem>
            <asp:ListItem>Brazil</asp:ListItem>
            <asp:ListItem>Canada</asp:ListItem>
            <asp:ListItem>UK</asp:ListItem>
        </asp:DropDownList><br />
        <br />
        Customers:<br />
        <asp:GridView ID="_customersGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerId" DataSourceID="_customersDS" OnSelectedIndexChanged="_customersGrid_SelectedIndexChanged">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" ReadOnly="True" SortExpression="CustomerId" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
                <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" SortExpression="ContactTitle" />
                <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
                <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
                <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
            </Columns>
        </asp:GridView>
        <cc1:LLBLGenProDataSource2 ID="_customersDS" runat="server" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.CustomersEntityFactory, NWTest">
            <SelectParameters>
                <asp:ControlParameter ControlID="_countrySelector" Name="Country" PropertyName="SelectedValue" />
            </SelectParameters>
        </cc1:LLBLGenProDataSource2>
        <br />
        Orders:<br />
        <asp:GridView ID="_ordersGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderId" DataSourceID="_ordersDS">
            <Columns>
                <asp:BoundField DataField="OrderId" HeaderText="OrderId" ReadOnly="True" SortExpression="OrderId" />
                <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" SortExpression="CustomerId" />
                <asp:BoundField DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName" />
                <asp:BoundField DataField="ShipAddress" HeaderText="ShipAddress" SortExpression="ShipAddress" />
                <asp:BoundField DataField="ShipCity" HeaderText="ShipCity" SortExpression="ShipCity" />
                <asp:BoundField DataField="ShipRegion" HeaderText="ShipRegion" SortExpression="ShipRegion" />
                <asp:BoundField DataField="ShipPostalCode" HeaderText="ShipPostalCode" SortExpression="ShipPostalCode" />
                <asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry" SortExpression="ShipCountry" />
            </Columns>
        </asp:GridView>
        <cc1:LLBLGenProDataSource2 ID="_ordersDS" runat="server" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.OrdersEntityFactory, NWTest" LivePersistence="False" OnPerformSelect="_ordersDS_PerformSelect">
            <SelectParameters>
                <asp:ControlParameter ControlID="_customersGrid" Name="CustomerId" PropertyName="SelectedValue" />
            </SelectParameters>
        </cc1:LLBLGenProDataSource2>

    </form>
</body>
</html>

code behind:


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using SD.LLBLGen.Pro.ORMSupportClasses;
using NWTest.DatabaseSpecific;
using NWTest.EntityClasses;
using NWTest.FactoryClasses;
using NWTest.HelperClasses;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load( object sender, EventArgs e )
    {
        if(!Page.IsPostBack)
        {
        }
    }

    protected void _ordersDS_PerformSelect( object sender, PerformSelectEventArgs2 e )
    {
        using( DataAccessAdapter adapter = new DataAccessAdapter() )
        {
            adapter.FetchEntityCollection( e.ContainedCollection, e.Filter, e.MaxNumberOfItemsToReturn, e.Sorter, e.PageNumber, e.PageSize );
        }
    }
    protected void _customersGrid_SelectedIndexChanged( object sender, EventArgs e )
    {
        _ordersDS.Refetch = true;
    }
}

Frans Bouma | Lead developer LLBLGen Pro
Khuzema
User
Posts: 22
Joined: 24-Jul-2006
# Posted on: 27-Jul-2006 16:39:28   

thanks for the example. My code will take little bit time. My example approach would be first with code (not with LLBL datasource control,for now).

regards

Khuzema

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39898
Joined: 17-Aug-2003
# Posted on: 27-Jul-2006 17:32:29   

Khuzema wrote:

thanks for the example. My code will take little bit time. My example approach would be first with code (not with LLBL datasource control,for now).

regards

Khuzema

It's fairly straight forward. simple_smile The main thing to look at is the syncing between the grids, which is done the same way as it is done as with ObjectdataSources etc.: 2 datasources, and synced with SelectParameter instances.

Frans Bouma | Lead developer LLBLGen Pro
Khuzema
User
Posts: 22
Joined: 24-Jul-2006
# Posted on: 02-Aug-2006 10:16:37   

Example :: Work in Progress

As I am progressing with example ( with lots of trial and error) I thought let me post it while I continue to work.

This example works in following ways: User select record on a Main grid, base on the primary key a related record is shown for editing. User can click on Add to add new Master detail record and so on.

please review this example and let me know how I can enhance at least in way of using LLBL Gen Pro framework ( For Add/Edit/Delete/Query)


[colorvalue="0011FF"][/color]

USE [Payroll]
GO
/****** Object:  Table [dbo].[CFG_ApprovalTypeHead] Script Date: 08/02/2006 10:55:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CFG_ApprovalTypeHead](
    [CompanyID] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [ApprovalID] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [App_EDesc] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [App_ADesc] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [App_SDesc] [nvarchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [Comment] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [App_Exececutive] [nvarchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [InsertedOn] [datetime] NULL,
    [InsertUser] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [UpdatedOn] [datetime] NULL,
    [UpdateUser] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_CFG_ApprovalTypeHead] PRIMARY KEY CLUSTERED 
(
    [CompanyID] ASC,
    [ApprovalID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
USE [WzPayroll]
GO
/****** Object:  Table [dbo].[CFG_ApprovalTypeDetail]   Script Date: 08/02/2006 10:55:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CFG_ApprovalTypeDetail](
    [CompanyID] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [ApprovalID] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [ApprovalSNo] [int] NOT NULL,
    [AppEmpID] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [AppEmp_Name] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [AppEmp_Rank] [int] NULL,
    [InsertedOn] [datetime] NULL,
    [InsertUser] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [UpdatedOn] [datetime] NULL,
    [UpdateUser] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_CFG_ApprovalTypeDetail] PRIMARY KEY CLUSTERED 
(
    [CompanyID] ASC,
    [ApprovalID] ASC,
    [ApprovalSNo] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
USE [Payroll]
GO
ALTER TABLE [dbo].[CFG_ApprovalTypeDetail]  WITH CHECK ADD  CONSTRAINT [ApprovalMasterDetail] FOREIGN KEY([CompanyID], [ApprovalID])
REFERENCES [dbo].[CFG_ApprovalTypeHead] ([CompanyID], [ApprovalID])
ON UPDATE CASCADE
ON DELETE CASCADE


Below is my User Control code.



[colorvalue="0000AA"][/color]

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ApprovalType.ascx.cs" Inherits="WISDOM.Payroll.HR.UserControls.ApprovalType" EnableTheming="true"%>
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses"
  TagPrefix="cc1" %>
<div id="Cover" class="DivCover">
          <div id="DivSearch" class="DivSearch">
          <asp:Table runat="server" ID="tblFilter" SkinID="FilterTable">
    <asp:TableRow ID="TableRow1" runat="server">
        <asp:TableCell ID="TableCell1" runat="server" SkinID="TitleCell">
            <asp:label id="lblTitle" runat="server" SkinID="TitleLabel" >Approval Type Configuration</asp:label>
        </asp:TableCell>
    </asp:TableRow>
  <asp:TableRow ID="TableRow16" runat="server">
    <asp:TableCell ID="TableCell23" runat="server" SkinID="SearchCell">
      <asp:Label ID="Label1" runat="server" SkinID="SearchLabel">Search...</asp:Label>&nbsp;
    </asp:TableCell>
  </asp:TableRow>
  <asp:TableRow ID="TableRow2" runat="server">
          <asp:TableCell ID="TableCell2" runat="server" SkinID="FilterCell">
              <asp:Table ID="Table1" runat="server" SkinID="FilterTableInner">
                  <asp:TableRow ID="TableRow3" runat="server">
                      <asp:TableCell ID="TableCell3" runat="server">&nbsp;Filter: 
                          <asp:dropdownlist id="ddlFilterColumn" runat="server" SkinID="FilterColumn">
                              <asp:ListItem Value="CompanyID" Text="CompanyID"></asp:ListItem>
                              <asp:ListItem Value="ApprovalID" Text="ApprovalID"></asp:ListItem>
                              <asp:ListItem Value="App_EDesc" Text="App_EDesc"></asp:ListItem>
                              <asp:ListItem Value="App_ADesc" Text="App_ADesc"></asp:ListItem>
                              <asp:ListItem Value="App_SDesc" Text="App_SDesc"></asp:ListItem>
                              <asp:ListItem Value="Comment" Text="Comment"></asp:ListItem>
                              <asp:ListItem Value="App_Exececutive" Text="App_Exececutive"></asp:ListItem>
                              <asp:ListItem Value="InsertedOn" Text="InsertedOn"></asp:ListItem>
                              <asp:ListItem Value="InsertUser" Text="InsertUser"></asp:ListItem>
                              <asp:ListItem Value="UpdatedOn" Text="UpdatedOn"></asp:ListItem>
                              <asp:ListItem Value="UpdateUser" Text="UpdateUser"></asp:ListItem>
                          </asp:dropdownlist>
                          <asp:dropdownlist id="ddlFilterOperator" runat="server" SkinID="FilterOperator">
                              <asp:ListItem Value="LIKE">Starts with</asp:ListItem>
                              <asp:ListItem Value="=">Is Exactly</asp:ListItem>
                              <asp:ListItem Value="&gt;">Greater Than</asp:ListItem>
                              <asp:ListItem Value="&lt;">Less Than</asp:ListItem>
                          </asp:dropdownlist>
                          <asp:textbox id="txtFilterCriteria" runat="server" SkinID="FilterCriteria"></asp:textbox>
                        
                          <!--Foreign Key Filter Lists-->
                        
                      </asp:TableCell>
                      <asp:TableCell>
<%--                          <asp:Button id="btnFilter" runat="server" Text="Filter" SkinID="GridFilterButton" OnClick="btnFilter_Click"></asp:Button>&nbsp;
                          <asp:Button id="btnClearFilter" runat="server" Text="Clear" SkinID="GridFilterClearButton" OnClick="btnClearFilter_Click"></asp:Button>
--%>                      </asp:TableCell>
                  </asp:TableRow>
              </asp:Table>
          </asp:TableCell>
      </asp:TableRow>           
</asp:Table>

</div>
  <div id="GrdView" class="DivMid">
      <asp:GridView SkinID="AdminList" ID="gvList" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="CompanyId,ApprovalId" OnRowCommand="gvList_RowCommand" OnSelectedIndexChanged="gvList_SelectedIndexChanged" OnRowDeleting="gvList_RowDeleting">
        <Columns>
                    <asp:TemplateField ShowHeader="False">
                        <HeaderTemplate>
                            <asp:Button ID="cmdAdd" runat="server" CommandName="New" CausesValidation="False" Text="Add" SkinID="GridAddButton" ToolTip="Add new Approval record" />
                        </HeaderTemplate>
                        <ItemTemplate>                      
                            <asp:ImageButton ID="btnEdit" runat="server" SkinID="GridEditButton" CausesValidation="False" CommandName="Select" ></asp:ImageButton>
                            <asp:ImageButton ID="btnDelete" runat="server" CausesValidation="False" CommandName="Delete"
                                OnClientClick="return confirm('Are you sure you want to delete this record?');" SkinID="GridDeleteButton"></asp:ImageButton>
                        </ItemTemplate>
                    </asp:TemplateField>
          <asp:BoundField DataField="AppEdesc" HeaderText="AppEdesc" SortExpression="AppEdesc" />
          <asp:BoundField DataField="AppAdesc" HeaderText="AppAdesc" SortExpression="AppAdesc" />
          <asp:BoundField DataField="AppSdesc" HeaderText="AppSdesc" SortExpression="AppSdesc" />
          <asp:BoundField DataField="Comment" HeaderText="Comment" SortExpression="Comment" />
          <asp:BoundField DataField="AppExececutive" HeaderText="AppExececutive" SortExpression="AppExececutive" />
        </Columns>
      </asp:GridView>
    </div>
</div>
<div id="FrmView" class="DivRight">&nbsp;
  <asp:FormView ID="fvEditor" runat="server" OnItemInserting="fvEditor_ItemInserting">
    <EditItemTemplate>
      <table>
        <tr>
          <td>ApprovalID:</td>
          <td><asp:TextBox ID="txtApprovalID" runat="server" Text='<%# Bind("ApprovalId") %>'></asp:TextBox></td>
        </tr>
        <tr>
          <td colspan="4">
            <table>
              <tr>
                <td>Description</td>
              </tr>
              <tr>
                <td>English:</td>
                <td><asp:TextBox ID="txtApprovalEngDescE" runat="server" Text='<%# Bind("AppEdesc") %>'></asp:TextBox></td>
              </tr>
              <tr>
                <td>Arabic:</td>
                <td><asp:TextBox ID="txtApprovalArbDescE" runat="server" Text='<%# Bind("AppAdesc") %>'></asp:TextBox></td>
              </tr>
              <tr>
                <td>Short:</td>
                <td><asp:TextBox ID="txtShortDescE" runat="server" Text='<%# Bind("AppSdesc") %>'></asp:TextBox></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td>Comments</td>
          <td><asp:TextBox ID="txtAppCommentsE" runat="server" Text='<%# Bind("Comment") %>'></asp:TextBox></td>
          <td>Executive</td>
          <td><asp:TextBox ID="txtAppExecutiveE" runat="server" Text='<%# Bind("AppExececutive") %>'></asp:TextBox></td>
        </tr>
      </table>
      <br />
      <asp:GridView ID="gvApprovalDtlListE" runat="server" AutoGenerateColumns="False" DataKeyNames="CompanyId,ApprovalId,ApprovalSno">
        <Columns>
          <asp:TemplateField HeaderText="SerialNo" SortExpression="SerialNo">
            <ItemTemplate>
              <asp:TextBox ID="ApprovalSNoEditE" runat="server" Text='<%# Bind("ApprovalSNo") %>'></asp:TextBox>
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="EmployeeID" SortExpression="AppEmpId">
            <ItemTemplate>
              <asp:TextBox ID="txtAppEmpIdEditE" runat="server" Text='<%# Bind("AppEmpId") %>'></asp:TextBox>
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="AppEmpName" SortExpression="EmployeeName">
            <ItemTemplate>
              <asp:TextBox ID="txtAppEmpNameEditE" runat="server" Text='<%# Bind("AppEmpName") %>'></asp:TextBox>
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="AppEmpRank" SortExpression="Designation">
            <ItemTemplate>
              <asp:TextBox ID="txtAppEmpRankEditE" runat="server" Text='<%# Bind("AppEmpRank") %>'></asp:TextBox>
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>
      </asp:GridView>
      Add new record:
      <asp:FormView ID="fvEditorDtlE" runat="server" DataKeyNames="CompanyId,ApprovalId,ApprovalSno"
        OnItemInserting="fvEditorDtlE_ItemInserting" DefaultMode="Insert">
        <InsertItemTemplate>
          <table>
            <tr>
              <td>
                <asp:TextBox ID="AppSNoTextBoxE" runat="server" Text='<%# Bind("AppEmpId") %>'></asp:TextBox><br />
              </td>
              <td>
                <asp:TextBox ID="AppEmpIdTextBoxE" runat="server" Text='<%# Bind("AppEmpId") %>'></asp:TextBox><br />
              </td>
              <td>
                <asp:TextBox ID="AppEmpNameTextBoxE" runat="server" Text='<%# Bind("AppEmpName") %>'></asp:TextBox><br />
              </td>
              <td>
                <asp:TextBox ID="AppEmpRankTextBoxE" runat="server" Text='<%# Bind("AppEmpRank") %>'></asp:TextBox><br />
              </td>
            </tr>
          </table>
        </InsertItemTemplate>
        <FooterTemplate>
          <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
            Text="Insert"></asp:LinkButton>
          <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
            Text="Cancel"></asp:LinkButton>
        </FooterTemplate>
      </asp:FormView>
    </EditItemTemplate>
    <InsertItemTemplate>
      <table>
        <tr>
          <td>
            ApprovalID:</td>
          <td>
            <asp:TextBox ID="txtApprovalID" runat="server" Text='<%# Bind("ApprovalId") %>'></asp:TextBox></td>
        </tr>
        <tr>
          <td colspan="4">
            <table>
              <tr>
                <td>
                  Description</td>
              </tr>
              <tr>
                <td>
                  English:</td>
                <td>
                  <asp:TextBox ID="txtApprovalEngDesc" runat="server" Text='<%# Bind("AppEdesc") %>'></asp:TextBox></td>
              </tr>
              <tr>
                <td>
                  Arabic:</td>
                <td>
                  <asp:TextBox ID="txtApprovalArbDesc" runat="server" Text='<%# Bind("AppAdesc") %>'></asp:TextBox></td>
              </tr>
              <tr>
                <td>
                  Short:</td>
                <td>
                  <asp:TextBox ID="txtShortDesc" runat="server" Text='<%# Bind("AppSdesc") %>'></asp:TextBox></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td>
            Comments</td>
          <td>
            <asp:TextBox ID="txtAppComments" runat="server" Text='<%# Bind("Comment") %>'></asp:TextBox></td>
          <td>
            Executive</td>
          <td>
            <asp:TextBox ID="txtAppExecutive" runat="server" Text='<%# Bind("AppExececutive") %>'></asp:TextBox></td>
        </tr>
      </table>
      <br />
      <asp:GridView ID="gvApprovalDtlList" runat="server" AutoGenerateColumns="False" DataKeyNames="CompanyId,ApprovalId,ApprovalSno">
        <Columns>
          <asp:TemplateField HeaderText="SerialNo" SortExpression="SerialNo">
            <ItemTemplate>
              <asp:TextBox ID="ApprovalSNoEdit" runat="server" Text='<%# Bind("ApprovalSNo") %>'></asp:TextBox>
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="EmployeeID" SortExpression="AppEmpId">
            <ItemTemplate>
              <asp:TextBox ID="txtAppEmpIdEdit" runat="server" Text='<%# Bind("AppEmpId") %>'></asp:TextBox>
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="AppEmpName" SortExpression="EmployeeName">
            <ItemTemplate>
              <asp:TextBox ID="txtAppEmpNameEdit" runat="server" Text='<%# Bind("AppEmpName") %>'></asp:TextBox>
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="AppEmpRank" SortExpression="Designation">
            <ItemTemplate>
              <asp:TextBox ID="txtAppEmpRankEdit" runat="server" Text='<%# Bind("AppEmpRank") %>'></asp:TextBox>
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>
      </asp:GridView>
      Add new record:
      <asp:FormView ID="fvEditorDtl" runat="server" DataKeyNames="CompanyId,ApprovalId,ApprovalSno"
        OnItemInserting="fvEditorDtl_ItemInserting" DefaultMode="Insert">
        <InsertItemTemplate>
          <table>
            <tr>
              <td>
                <asp:TextBox ID="AppSNoTextBox" runat="server" Text='<%# Bind("AppEmpId") %>'></asp:TextBox><br />
              </td>
              <td>
                <asp:TextBox ID="AppEmpIdTextBox" runat="server" Text='<%# Bind("AppEmpId") %>'></asp:TextBox><br />
              </td>
              <td>
                <asp:TextBox ID="AppEmpNameTextBox" runat="server" Text='<%# Bind("AppEmpName") %>'></asp:TextBox><br />
              </td>
              <td>
                <asp:TextBox ID="AppEmpRankTextBox" runat="server" Text='<%# Bind("AppEmpRank") %>'></asp:TextBox><br />
              </td>
            </tr>
          </table>
        </InsertItemTemplate>
        <FooterTemplate>
          <asp:LinkButton ID="InsertButtonE" runat="server" CausesValidation="True" CommandName="Insert"
            Text="Insert"></asp:LinkButton>
          <asp:LinkButton ID="InsertCancelButtonE" runat="server" CausesValidation="False" CommandName="Cancel"
            Text="Cancel"></asp:LinkButton>
        </FooterTemplate>
      </asp:FormView>   
    </InsertItemTemplate>
    <FooterTemplate>
  <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
    Text="Insert"></asp:LinkButton>
  <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
    Text="Cancel"></asp:LinkButton>
</FooterTemplate>

  </asp:FormView>
</div>

Here is code behind :: code


[colorvalue="0000AA"][/color]
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using WISDOM.Payroll.DatabaseSpecific;
using WISDOM.Payroll.EntityClasses;
using WISDOM.Payroll.FactoryClasses;
using WISDOM.Payroll.RelationClasses;
using WISDOM.Payroll.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;


namespace WISDOM.Payroll.HR.UserControls
{
  public partial class ApprovalType : System.Web.UI.UserControl
  {

    #region Private Properties

    ///<summary>
    ///Private property to hold the last filter criteria
    ///</summary>
    private string Filter
    {
      get
      {
        if (ViewState["Filter"] == null)
        {
          return String.Empty;
        }
        else
          return ViewState["Filter"].ToString();
      }
      set
      {
        ViewState["Filter"] = value;
      }
    }

    private EntityCollection ApprovalHead
    {
      get
      {
        if (ViewState["ApprovalHead"] == null)
        { return new EntityCollection(); }
        else
          return (EntityCollection)ViewState["ApprovalHead"];
      }
      set { ViewState["ApprovalHead"] = value; }
    }

    private CfgApprovalTypeHeadEntity ApprovalHeadEnt
    {
      get
      {
        if (ViewState["ApprovalHeadEnt"] == null)
        { return new CfgApprovalTypeHeadEntity(); }
        else
          return (CfgApprovalTypeHeadEntity)ViewState["ApprovalHeadEnt"];
      }
      set { ViewState["ApprovalHeadEnt"] = value; }
    }

    private EntityCollection ApprovalDetails
    {
      get
      {
        if (ViewState["ApprovalDetails"] == null)
        { return new EntityCollection(); }
        else
          return (EntityCollection)ViewState["ApprovalDetails"];
      }
      set { ViewState["ApprovalDetails"] = value; }
    }



    //= new EntityCollection(new CfgApprovalTypeHeadEntityFactory());

    #endregion


    protected void Page_Load(object sender, EventArgs e)
    {
      gvListBind();
    }

    protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      switch (e.CommandName.ToUpper())
      {
        case "NEW":

          fvEditor.ChangeMode(FormViewMode.Insert);

          EntityCollection approvalHead = new EntityCollection(new CfgApprovalTypeHeadEntityFactory());
          ApprovalHead.Clear();
          approvalHead.Add(new CfgApprovalTypeHeadEntity());
          ApprovalHead = (EntityCollection)approvalHead;
          CfgApprovalTypeHeadEntity appHeadEntity = (CfgApprovalTypeHeadEntity)approvalHead[0];
          ApprovalHeadEnt = appHeadEntity;
          fvEditor.DataSource = approvalHead;
          fvEditor.DataBind();

          EntityCollection appDtl = new EntityCollection(new CfgApprovalTypeDetailEntityFactory());
          CfgApprovalTypeDetailEntity appDtls = new CfgApprovalTypeDetailEntity();
          //appDtls.CompanyId = "1";
          appDtl.Add(appDtls);
          FormView fvDtl = (FormView)fvEditor.FindControl("fvEditorDtl");
          fvDtl.ChangeMode(FormViewMode.Insert);
          if (fvDtl != null)
          {
            fvDtl.DataSource = appDtl;
            fvDtl.DataBind();
          }
          break;
        case "SELECT":
          if (gvList.SelectedValue != null)
          {
          }
          break;
        default:
          return;
      }
    }

    protected void gvList_SelectedIndexChanged(object sender, EventArgs e)
    {
      fvEditor.ChangeMode(FormViewMode.Edit);
      EntityCollection approvalHead = new EntityCollection(new CfgApprovalTypeHeadEntityFactory());
      DataAccessAdapter adapter = new DataAccessAdapter();

      RelationPredicateBucket appRelBucket = new RelationPredicateBucket();
      IPredicateExpression preX = new PredicateExpression();
      preX.Add(CfgApprovalTypeHeadFields.CompanyId == gvList.SelectedDataKey[0].ToString());
      preX.AddWithAnd(CfgApprovalTypeHeadFields.ApprovalId == gvList.SelectedDataKey[1].ToString());
      appRelBucket.PredicateExpression.Add(preX);


      adapter.FetchEntityCollection(approvalHead, appRelBucket);
      ApprovalHead.Clear();
      ApprovalHead = (EntityCollection)approvalHead;

      fvEditor.DataSource = ApprovalHead;
      fvEditor.DataBind();

      CfgApprovalTypeHeadEntity appHeadEntity = (CfgApprovalTypeHeadEntity)approvalHead[0];
      ApprovalHeadEnt = appHeadEntity;
      EntityCollection appDetails =new EntityCollection(new CfgApprovalTypeDetailEntityFactory());
      adapter.FetchEntityCollection(appDetails, appHeadEntity.GetRelationInfoCfgApprovalTypeDetail());

      ApprovalDetails = appDetails;
      int j = 0;
      foreach (EntityBase2 c in appDetails)
      {
        ApprovalHeadEnt.CfgApprovalTypeDetail.Add((CfgApprovalTypeDetailEntity)appDetails[j]);
        j++;
      }
      try //NOTE: First time there will be no selection as a result appDetails will be null and give error.
      {
        GridView gvAppDetail = (GridView)fvEditor.FindControl("gvApprovalDtlListE");
        gvAppDetail.DataSource = appDetails;
        gvAppDetail.DataBind();
        FormView fvDtl = (FormView)fvEditor.FindControl("fvEditorDtlE");
        fvDtl.DataSource = appDetails;
        fvDtl.DataBind();
        fvDtl.ChangeMode(FormViewMode.Insert);
      }
      catch { }
    }

    protected void fvEditorDtl_ItemInserting(object sender, FormViewInsertEventArgs e)
    {

      // fvEditor Formview variables
      TextBox txtApprovalID = (TextBox)fvEditor.FindControl("txtApprovalID");
      TextBox txtEngDesc = (TextBox)fvEditor.FindControl("txtApprovalEngDesc");
      TextBox txtArbDesc = (TextBox)fvEditor.FindControl("txtApprovalArbDesc");
      TextBox txtShtDesc = (TextBox)fvEditor.FindControl("txtShortDesc");
      TextBox txtComments = (TextBox)fvEditor.FindControl("txtAppComments");
      TextBox txtExecutive = (TextBox)fvEditor.FindControl("txtAppExecutive");

      ApprovalHeadEnt.CompanyId = "1";
      ApprovalHeadEnt.ApprovalId = txtApprovalID.Text;
      ApprovalHeadEnt.AppEdesc = txtEngDesc.Text;
      ApprovalHeadEnt.AppAdesc = txtArbDesc.Text;
      ApprovalHeadEnt.AppSdesc = txtShtDesc.Text;
      ApprovalHeadEnt.Comment = txtComments.Text;
      ApprovalHeadEnt.AppExececutive = txtExecutive.Text;


      //fvEditorDtl::Formview Detail
      FormView fvDtl = (FormView)fvEditor.FindControl("fvEditorDtl");
      TextBox txtAppSNo = (TextBox)fvDtl.FindControl("AppSNoTextBox");

      if (txtAppSNo.Text != null && txtAppSNo.Text.Length != 0) // Check for new record
      {
        TextBox txtAppEmpID = (TextBox)fvDtl.FindControl("AppEmpIdTextBox");
        TextBox txtAppEmpName = (TextBox)fvDtl.FindControl("AppEmpNameTextBox");
        TextBox txtAppEmpRank = (TextBox)fvDtl.FindControl("AppEmpRankTextBox");
        CfgApprovalTypeDetailEntity dtlEntity = new CfgApprovalTypeDetailEntity();
        dtlEntity.CompanyId = "1";
        dtlEntity.ApprovalId = "1";
        dtlEntity.ApprovalSno = Convert.ToInt32(txtAppSNo.Text);
        dtlEntity.AppEmpId = txtAppEmpID.Text;
        dtlEntity.AppEmpName = txtAppEmpName.Text;
        dtlEntity.AppEmpRank = Convert.ToInt32(txtAppEmpRank.Text);
        dtlEntity.InsertedOn = DateTime.Now;
        dtlEntity.InsertUser = "Admin";
        ApprovalHeadEnt.CfgApprovalTypeDetail.Add(dtlEntity);

        txtAppSNo.Text = string.Empty;
        txtAppEmpID.Text = string.Empty;
        txtAppEmpName.Text = string.Empty;
        txtAppEmpRank.Text = string.Empty;
        ////Gridview variables
        GridView gvDtl = (GridView)fvEditor.FindControl("gvApprovalDtlList");
        gvDtl.DataSource = ApprovalHeadEnt.CfgApprovalTypeDetail;
        gvDtl.DataBind();
      }
    }

    protected void fvEditor_ItemInserting(object sender, FormViewInsertEventArgs e)
    {

      TextBox txtEngDesc = (TextBox)fvEditor.FindControl("txtApprovalEngDesc");
      TextBox txtArbDesc = (TextBox)fvEditor.FindControl("txtApprovalArbDesc");
      TextBox txtShtDesc = (TextBox)fvEditor.FindControl("txtShortDesc");
      TextBox txtComments = (TextBox)fvEditor.FindControl("txtAppComments");
      TextBox txtExecutive = (TextBox)fvEditor.FindControl("txtAppExecutive");

      ApprovalHeadEnt.AppEdesc = txtEngDesc.Text;
      ApprovalHeadEnt.AppAdesc = txtArbDesc.Text;
      ApprovalHeadEnt.AppSdesc = txtShtDesc.Text;
      ApprovalHeadEnt.Comment = txtComments.Text;
      ApprovalHeadEnt.AppExececutive = txtExecutive.Text;

      DataAccessAdapter adap = new DataAccessAdapter();
      adap.SaveEntity(ApprovalHeadEnt, true, true);
      //gvDtl.DataSource = ApprovalHeadEnt.CfgApprovalTypeDetail;
      //gvDtl.DataBind();
      gvListBind();


    }
    protected void fvEditorDtlE_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
      //Gridview variables
      GridView gvDtl = (GridView)fvEditor.FindControl("gvApprovalDtlListE");
      //

      //Get all the rows in the grid and place it inside a GridViewRowCollection
      GridViewRowCollection rowCollection = gvDtl.Rows;

      //loop thru all the rows
      for (int i = 0; i < gvDtl.Rows.Count; i++)
      {

        GridViewRow row = gvDtl.Rows[i];
        //find the control

        string txtAppSno = ((TextBox)row.Cells[0].FindControl("ApprovalSNoEditE")).Text;
        string txtAppEID = ((TextBox)row.Cells[0].FindControl("txtAppEmpIdEditE")).Text;
        string txtAppNam = ((TextBox)row.Cells[0].FindControl("txtAppEmpNameEditE")).Text;
        string txtAppRnk = ((TextBox)row.Cells[0].FindControl("txtAppEmpRankEditE")).Text;

        ApprovalHeadEnt.CfgApprovalTypeDetail[i].ApprovalSno = Convert.ToInt32(txtAppSno);
        ApprovalHeadEnt.CfgApprovalTypeDetail[i].AppEmpId = txtAppEID;
        ApprovalHeadEnt.CfgApprovalTypeDetail[i].AppEmpName = txtAppNam;
        ApprovalHeadEnt.CfgApprovalTypeDetail[i].AppEmpRank = Convert.ToInt32(txtAppRnk);
      }


      // fvEditor Formview variables

      TextBox txtEngDesc = (TextBox)fvEditor.FindControl("txtApprovalEngDescE");
      TextBox txtArbDesc = (TextBox)fvEditor.FindControl("txtApprovalArbDescE");
      TextBox txtShtDesc = (TextBox)fvEditor.FindControl("txtShortDescE");
      TextBox txtComments = (TextBox)fvEditor.FindControl("txtAppCommentsE");
      TextBox txtExecutive = (TextBox)fvEditor.FindControl("txtAppExecutiveE");

      ApprovalHeadEnt.AppEdesc = txtEngDesc.Text;
      ApprovalHeadEnt.AppAdesc = txtArbDesc.Text;
      ApprovalHeadEnt.AppSdesc = txtShtDesc.Text;
      ApprovalHeadEnt.Comment = txtComments.Text;
      ApprovalHeadEnt.AppExececutive = txtExecutive.Text;

      //fvEditorDtl::Formview Detail
      FormView fvDtl = (FormView)fvEditor.FindControl("fvEditorDtlE");
      TextBox txtAppSNo = (TextBox)fvDtl.FindControl("AppSNoTextBoxE");

      if (txtAppSNo.Text != null && txtAppSNo.Text.Length != 0) // Check for new record
      {
        TextBox txtAppEmpID = (TextBox)fvDtl.FindControl("AppEmpIdTextBoxE");
        TextBox txtAppEmpName = (TextBox)fvDtl.FindControl("AppEmpNameTextBoxE");
        TextBox txtAppEmpRank = (TextBox)fvDtl.FindControl("AppEmpRankTextBoxE");
        CfgApprovalTypeDetailEntity dtlEntity = new CfgApprovalTypeDetailEntity();
        dtlEntity.CompanyId = "1";
        dtlEntity.ApprovalId = "1";
        dtlEntity.ApprovalSno = Convert.ToInt32(txtAppSNo.Text);
        dtlEntity.AppEmpId = txtAppEmpID.Text;
        dtlEntity.AppEmpName = txtAppEmpName.Text;
        dtlEntity.AppEmpRank = Convert.ToInt32(txtAppEmpRank.Text);
        dtlEntity.InsertedOn = DateTime.Now;
        dtlEntity.InsertUser = "Admin";
        ApprovalHeadEnt.CfgApprovalTypeDetail.Add(dtlEntity);

        txtAppSNo.Text = string.Empty;
        txtAppEmpID.Text = string.Empty;
        txtAppEmpName.Text = string.Empty;
        txtAppEmpRank.Text = string.Empty;
      }

      DataAccessAdapter adap = new DataAccessAdapter();
      adap.SaveEntity(ApprovalHeadEnt, true, true);
      gvDtl.DataSource = ApprovalHeadEnt.CfgApprovalTypeDetail;
      gvDtl.DataBind();
    }

    protected void gvListBind()
    {
      EntityCollection approvalHead = new EntityCollection(new CfgApprovalTypeHeadEntityFactory());
      DataAccessAdapter adapter = new DataAccessAdapter();
      adapter.FetchEntityCollection(approvalHead, null);
      gvList.DataSource = approvalHead;
      gvList.DataBind();

    }
    protected void gvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
      gvList.SelectedIndex=e.RowIndex;
    
      EntityCollection approvalHead = new EntityCollection(new CfgApprovalTypeHeadEntityFactory());
      DataAccessAdapter adapter = new DataAccessAdapter();

      RelationPredicateBucket appRelBucket = new RelationPredicateBucket();
      IPredicateExpression preX = new PredicateExpression();
      preX.Add(CfgApprovalTypeHeadFields.CompanyId == gvList.SelectedDataKey[0].ToString());
      preX.AddWithAnd(CfgApprovalTypeHeadFields.ApprovalId == gvList.SelectedDataKey[1].ToString());
      appRelBucket.PredicateExpression.Add(preX);

      adapter.FetchEntityCollection(approvalHead, appRelBucket);
      adapter.DeleteEntityCollection(approvalHead);
      gvList.SelectedIndex = -1;
      gvListBind();
    }
}
}



I am looking for ways to fine tune the above example. Once its done in proper way I prefer to post it as a new message with appropriate subject so it will be easy for other to search.

thanks & regards

Khuzema

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39898
Joined: 17-Aug-2003
# Posted on: 02-Aug-2006 11:04:19   

With all due respect, we can't check a lengthy piece of code for every detail if it's correct.

What would have been better is that you described what you want to accomplish. A long list of code isn't helpful, as the reader then first has to reverse engineer the code into a 'design', which likely won't match your design.

What I also find strange is the 'trial and error' remark. Is that with the ASP.NET aspect of things or with the LLBLGen Pro features? LLBLGen Pro with ASP.NET 2.0 is straight forward, the trial-and-error approach is not needed, simply because you either use the property grid in vs.net to setup a datasource control, or let the datasourcecontrol do the work for you. I have no idea what your form has to do, but looking at the long code-behind I think you re-coded a lot of logic which is automatic with the datasourcecontrols of LLBLGen Pro.

Frans Bouma | Lead developer LLBLGen Pro
Khuzema
User
Posts: 22
Joined: 24-Jul-2006
# Posted on: 08-Aug-2006 14:21:32   

Sorry for the long posting ( I shall edit it out), these days I am going thru the LLBL gen pro documentation to get more understanding of the framework. Let see if I can come up with more neat code. I am also writing my requirement, so as to communicate easily.

thanks for the patience, regards

Khuzema