LLBLGen Pro feature

Posts   
1  /  2
 
    
rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 10-Apr-2009 11:03:07   

One of the features that i'm interested in this great tool for Ado .net is by not using stored procedures. can someone pls give me an example code without using stored proc by adding , order, orderdetails and updating product entities? The scenario is like a retail application wherein we select several products and temporarily store it in a datagridview with totals updating at the bottom of the grid to be saved later using LLBLGen Pro way without using stored procs.

I have included a visual basic .net app as attachment, can anyone pls modify it using llblgen pro? thank you so much in advance for the help.I'm beginning to like this tool but i'm always stuck coz i'm a newbie.I reallly appreciate the help of anyone.simple_smile

Attachments
Filename File size Added on Approval
Form1.vb 30,737 10-Apr-2009 11:04.56 Approved
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 10-Apr-2009 12:06:51   

The documentation is full of examples.

Also we have posted a lot of example projects on our web site, did you have a look at them?

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 10-Apr-2009 15:35:00   

Thanks so much Walaa, support for llblgen is really great. I tried all the samples and projects but i can't seem to relate on the simple project that i want to create for my own retail store.

here is a sample code of a button save, i can't make it work using LLBLGen way.pls help.

Private Sub bttnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnSave.Click SqlCommand1.Parameters.Clear() SqlCommand1.CommandText = "NewOrder" SqlCommand1.CommandType = CommandType.StoredProcedure Dim sqlParam As New SqlClient.SqlParameter() sqlParam.SqlDbType = SqlDbType.Char sqlParam.Size = 5 sqlParam.ParameterName = "@CustID" sqlParam.Direction = ParameterDirection.Input SqlCommand1.Parameters.Add(sqlParam)

    sqlParam = New SqlClient.SqlParameter()
    sqlParam.ParameterName = "RETURN"
    sqlParam.SqlDbType = SqlDbType.Int
    sqlParam.Direction = ParameterDirection.ReturnValue
    SqlCommand1.Parameters.Add(sqlParam)
    ' Replace this customer ID with the ID of the <retail> customer
    ' or prompt user for the ID of an existing customer
    SqlCommand1.Parameters("@custID").Value = "ALFKI"

    SqlConnection1.Open()
    Dim DetailTrans As SqlClient.SqlTransaction
    DetailTrans = SqlConnection1.BeginTransaction()

    SqlCommand1.Connection = SqlConnection1
    SqlCommand1.Transaction = DetailTrans
    Dim orderID As Integer
    Dim totalItems As Integer
    Dim retValue As Integer
    Try
        SqlCommand1.ExecuteNonQuery()
        orderID = CInt(SqlCommand1.Parameters("RETURN").Value)

        SqlCommand1.CommandText = "NewOrderLine"
        SqlCommand1.CommandType = CommandType.StoredProcedure
        SqlCommand1.Parameters.Clear()
        sqlParam = New SqlClient.SqlParameter()
        sqlParam.SqlDbType = SqlDbType.Int
        sqlParam.ParameterName = "@OrderID"
        sqlParam.Direction = ParameterDirection.Input
        SqlCommand1.Parameters.Add(sqlParam)

        sqlParam = New SqlClient.SqlParameter()
        sqlParam.SqlDbType = SqlDbType.Int
        sqlParam.ParameterName = "@ProductID"
        sqlParam.Direction = ParameterDirection.Input
        SqlCommand1.Parameters.Add(sqlParam)

        sqlParam = New SqlClient.SqlParameter()
        sqlParam.SqlDbType = SqlDbType.Int
        sqlParam.ParameterName = "@quantity"
        sqlParam.Direction = ParameterDirection.Input
        SqlCommand1.Parameters.Add(sqlParam)

        sqlParam = New SqlClient.SqlParameter()
        sqlParam.ParameterName = "RETURN"
        sqlParam.SqlDbType = SqlDbType.Int
        sqlParam.Direction = ParameterDirection.ReturnValue
        SqlCommand1.Parameters.Add(sqlParam)

        Dim row As DataRow
        For Each row In Details1.Tables(0).Rows
            SqlCommand1.Parameters("@OrderID").Value = orderID
            SqlCommand1.Parameters("@ProductID").Value = row.Item(0)
            SqlCommand1.Parameters("@quantity").Value = row.Item(3)
            totalItems = totalItems + CInt(row.Item(3))
            SqlCommand1.ExecuteNonQuery()
        Next
        DetailTrans.Commit()
        retValue = orderID
    Catch exc As Exception
        DetailTrans.Rollback()
        MsgBox(exc.Message)
    Finally
        SqlConnection1.Close()
    End Try
    bttnClear_Click(sender, e)
End Sub
rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 10-Apr-2009 15:39:04   

i mean, i don't want to use stored procedures anymore, i want to save the related tables using the generated codes of LLBL Gen pro. in adding new orders and many details and updating the product's quantity after a product is sold.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 11-Apr-2009 04:32:00   

Walaa wrote:

The documentation is full of examples.

Also we have posted a lot of example projects on our web site, did you have a look at them?

Thanks Walaa, can you be more specific to what sample was that? thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Apr-2009 04:34:03   

This is a very vague but real example, using Adapter TemplateSet.

// create the order
OrderEntity newOrder = new OrderEntity();
newOrder.CustomerId = "ALFKI";
newOrder.OrderDate = DateTime.Now;
newOrder.ShipVia = 2;

// add the item
OrderDetail item1 = newOrder.OrderDetails.AddNew();
item1.ProductId = 32;

// save the graph
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
     adapter.SaveEntity(newOrder, true, true);
}

You should play with the examples, get familiarized with Adapter or SelfServicing and start your project. It isn't that hard wink

David Elizondo | LLBLGen Support Team
rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 11-Apr-2009 10:21:18   

daelmo wrote:

This is a very vague but real example, using Adapter TemplateSet.

// create the order
OrderEntity newOrder = new OrderEntity();
newOrder.CustomerId = "ALFKI";
newOrder.OrderDate = DateTime.Now;
newOrder.ShipVia = 2;

// add the item
OrderDetail item1 = newOrder.OrderDetails.AddNew();
item1.ProductId = 32;

// save the graph
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
     adapter.SaveEntity(newOrder, true, true);
}

You should play with the examples, get familiarized with Adapter or SelfServicing and start your project. It isn't that hard wink

Thanks so much Daelmo, I'l try to learn it. By the way, I attached the sample visual basic application that i want to convert to the LLBLGEN Pro way, without using stored procedures.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 12-Apr-2009 08:34:20   

has anyone downloaded the invoice app and coverted it yet? pls share the code thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 12-Apr-2009 13:26:57   

rapido wrote:

has anyone downloaded the invoice app and coverted it yet? pls share the code thanks.

I don't think we'll convert it for you, Rapido. The main thing about learning is that you make the conversion and if you run into a problem, ask here for a solution to that problem after you've done some digging through the documentation or searched the forums and looked at the examples we provided. We can convert the app for you but you won't learn anything from that, as the essence of learning is that you make the conversion, see how things work by trying things out, reading about it in the documentation etc.

Frans Bouma | Lead developer LLBLGen Pro
rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 12-Apr-2009 14:49:53   

Otis wrote:

rapido wrote:

has anyone downloaded the invoice app and coverted it yet? pls share the code thanks.

I don't think we'll convert it for you, Rapido. The main thing about learning is that you make the conversion and if you run into a problem, ask here for a solution to that problem after you've done some digging through the documentation or searched the forums and looked at the examples we provided. We can convert the app for you but you won't learn anything from that, as the essence of learning is that you make the conversion, see how things work by trying things out, reading about it in the documentation etc.

simple_smile Challenged at the same Inspired, I'l try to post whatever my mind is capable of doing.By the Way i found a book which is 9$, Titled "Rapid C Sharp Development using C#,SQL2005 and LLBLGEN Pro.. Thanks again support team. More Power!

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 04:26:18   

Otis, pls end my agony, i can't do it the LLLBLGen Pro way. Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Apr-2009 06:48:13   

Rapido, What exactly is what we can do for you? Have you read the book? It's downloadable for free and is a good start, as the Getting started section of the manual as well. Better if you start with little things, to understand the concepts, then you will see that it's easy to get large projects to work in minutes.

David Elizondo | LLBLGen Support Team
rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 08:05:10   

I uploaded my project, pls show me how to save the data in an unbound datagrid. my code for adding a new order is this dim orders as new OrderEntity() orders.OrderDate=Now()

what about the OrderDetails that are on a DataGridView?How do i add it in the orderdetails entity? Can this be done on a transaction? Thanks

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 09:17:41   

pls correct my code for adding a new order and order details

Dim _ordersHeader As New SalesOrderHeaderEntity() _ordersHeader.OrderDate = Now() _ordersHeader.SubTotal = 1000 _ordersHeader.Save()

    'i dont know how to save the order details that are on the grid
    'pls i need your help. thanks

Dim _orderDetails As New SalesOrderDetailEntity() Dim counter As Integer For counter = 0 To (OrderLinesDataGridView.Rows.Count - 1) _orderDetails.ProductId = OrderLinesDataGridView.Rows(counter).Cells("Code").Value _orderDetails.UnitPrice = OrderLinesDataGridView.Rows(counter).Cells("Price").Value _orderDetails.OrderQty = OrderLinesDataGridView.Rows(counter).Cells("Qty").Value counter = counter + 1 Next _ordersHeader.Save()

can't save, i think its on the new generated orderid which i can't save on the details entity, pls show me a best practice for this, i tried transactions but my mind isnt capable.pls help thanks!

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 09:22:48   

correction to the code.

to save the order details it is suppose to be _orderDetails.Save() but still i can't save it,

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 10:02:41   

improved code but it only saves the last row entered into the grid

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 'save the order header Dim _ordersHeader As New SalesOrderHeaderEntity() _ordersHeader.OrderDate = Now() _ordersHeader.SubTotal = 1000

    'i dont know how to save the order details that are on the grid
    'pls i need your help. thanks

    Dim _orderDetails As New SalesOrderDetailEntity()
    Dim counter As Integer
    For counter = 0 To (OrderLinesDataGridView.Rows.Count - 1)
   _orderDetails.ProductId =     OrderLinesDataGridView.Rows(counter).Cells("Code").Value
        _orderDetails.UnitPrice = OrderLinesDataGridView.Rows(counter).Cells("Price").Value

_orderDetails.OrderQty = OrderLinesDataGridView.Rows(counter).Cells("Qty").Value counter = counter + 1 _ordersHeader.SalesOrderDetail.Add(_orderDetails) _ordersHeader.Save(True)

   Next

End Sub
rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 10:10:14   

rapido wrote:

improved code but it only saves the last row entered into the grid

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 'save the order header Dim _ordersHeader As New SalesOrderHeaderEntity() _ordersHeader.OrderDate = Now() _ordersHeader.SubTotal = 1000

    'i dont know how to save the order details that are on the grid
    'pls i need your help. thanks

    Dim _orderDetails As New SalesOrderDetailEntity()
    Dim counter As Integer
    For counter = 0 To (OrderLinesDataGridView.Rows.Count - 1)
   _orderDetails.ProductId =     OrderLinesDataGridView.Rows(counter).Cells("Code").Value
        _orderDetails.UnitPrice = OrderLinesDataGridView.Rows(counter).Cells("Price").Value

_orderDetails.OrderQty = OrderLinesDataGridView.Rows(counter).Cells("Qty").Value counter = counter + 1 _ordersHeader.SalesOrderDetail.Add(_orderDetails) _ordersHeader.Save(True)

   Next

End Sub

This code only saves one order header and 1 order detail on the grid even if the grid contains several rows.what happened was, the last row that is added on the grid is the one that is only saved.Can someone pls help?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Apr-2009 10:47:15   

What about this?

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        'save the order header
        Dim _ordersHeader As New SalesOrderHeaderEntity()
        _ordersHeader.OrderDate = Now()
        _ordersHeader.SubTotal = 1000

        Dim counter As Integer
        For counter = 0 To (OrderLinesDataGridView.Rows.Count - 1)

                Dim _orderDetails As New SalesOrderDetailEntity()
                _orderDetails.ProductId =    OrderLinesDataGridView.Rows(counter).Cells("Code").Value
                 _orderDetails.UnitPrice = OrderLinesDataGridView.Rows(counter).Cells("Price").Value
                _orderDetails.OrderQty = OrderLinesDataGridView.Rows(counter).Cells("Qty").Value

                counter = counter + 1
                _ordersHeader.SalesOrderDetail.Add(_orderDetails)
     Next

     _ordersHeader.Save(True)

End Sub
rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 10:53:09   

It saves just one order and one order detail, but in the datagrid view it has 3 details for example but the problem is that only the third row in grid is saved. the first and second was not, in other words, whether i have many rows in the grid, only the last one is saved in the order details entity.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Apr-2009 11:04:54   

Did you try the exact code I've posted?

Did you place

Dim _orderDetails As New SalesOrderDetailEntity()

inside the loop?

And the Save call outside the loop?

If so then please debug the code to see if the loop was iterated 3 times, and that before the Save call, _ordersHeader.SalesOrderDetail.Count == 3

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 11:19:35   

I got puzzled now, i tried to add 3 orderdetail lines but only 2 are saved, i tried to enter 5 orderdetail lines but only 3 are saved.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 11:33:44   

i tried the same entries but still the record that i want to add is lacking and some of the fields are left blank on the last record, strange confused

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Apr-2009 11:40:22   

And what about the value of **_ordersHeader.SalesOrderDetail.Count ** prior to each save?

Is it lacking also, or it's not?

It could be that the fields of an entity are not set to new values (not changed), therefore the entity will be skipped when inserting.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 11:46:09   

simple_smile It's driving me crazy, i tried to add 6 orderdetails on the grid, 4 was saved but the 4th row contains empty fields. eg the qty and product id columns are emplty but on the previous 3 records that were added are not. cry

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 11:53:04   

i added this code, and tried to add 6 orderdetail lines

MessageBox.Show(CStr(_ordersHeader.SalesOrderDetail.Count))

the count is just 4, what seems to be the problem Walaa? Pls don't give up helping me, thanks

1  /  2