LLBLGen Pro feature

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

This makes me think you have an issue with your grid implementation.

So to make sure this is not an LLBLGen Pro issue, please check the following code:

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
        Dim productId As Integer
        Dim price As Integer
        Dim qty As Integer

        productId = 0
        price = 0
        qty = 0

        For counter = 0 To 5

                productId = productId + 1
                price = price + 10
                qty = qty + 1

                Dim _orderDetails As New SalesOrderDetailEntity()
                _orderDetails.ProductId = productId
                 _orderDetails.UnitPrice = price
                _orderDetails.OrderQty = qty
                _ordersHeader.SalesOrderDetail.Add(_orderDetails)

                counter = counter + 1
     Next

     _ordersHeader.Save(True)

End Sub

Please make sure price is defined with the appropriate type.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 12:01:24   

your code got only 3 by executing this MessageBox.Show(CStr(_ordersHeader.SalesOrderDetail.Count)) it is suppose to be five right? why is it that the records to be added always fall short?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Apr-2009 12:17:12   

Is this for the last posted code block?

Anyway I think now its time to ask for the LLBLGen ro runtime library version that you are using? And now also its time to ask for your code project? would you please attach a simple repro against Northwind.

Thanks.

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

Yap the one that you posted,

i'm using the LLBLGEN PRO 2.6 Demo

Pls upload a sample project similar to a retail application.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 12:38:22   

pls download the .rar file that i uploaded,thats the project

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

pls download the .rar file that i uploaded,thats the project. http://rapidshare.com/files/221174001/Vb.rar.html

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Apr-2009 12:44:29   

I've got it. I'm ignorant when it comes to VB.NET

The issue is in the For loop and the Counter. Please add the counter to the watch and watch it get incremented by 2 at each iteration.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 12:51:12   

Really, what is the solution to that then? By the way Walla, am i on the right track, am i doing what is best to save a one to many entity, i mean is it acceptable to do that with out using stored procedures or transactions? is that acceptable when it comes to updating 2 or more entities? Thanks again

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 13:16:57   

i brought out the counter outside the loop, after the "Next" statement, problem now is instead of 5 loops it became 6, there is always an extra 1 loop, before i struggle again, am i doing the right thing in savind one to many relationship the LLBLGEN Pro Way and .net best practices? or should i ask, is it a good practice in manipulating in this kind?

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 13:52:49   

i got it Private Sub Button1_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
    Dim counter2 As Integer ' counter2 is the number of rows that a grid has 
    counter2 = OrderLinesDataGridView.Rows.Count
    counter2 = counter2 - 2 ' i subtracted 2 coz i always get a 1 extra number of rows  added to the order
    'details entity

    For counter = 0 To counter2 '(OrderLinesDataGridView.Rows.Count) - 1
        MessageBox.Show(CStr(counter2))
        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
        _ordersHeader.SalesOrderDetail.Add(orderDetails)
        'MessageBox.Show(CStr(_ordersHeader.SalesOrderDetail.Count))
    Next
    counter = counter + 1
    _ordersHeader.Save(True)
    MessageBox.Show(Me, "Save action performed.", "Save result", MessageBoxButtons.OK, MessageBoxIcon.Information)

End Sub

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 13:58:43   

to all database experts out there, is my code acceptable when it comes to database programming best practices? pls. improve it and post the new improvements. thank you, I think this is a great help for newbies like me out there. I'm Beginning to like LLBLGEN Pro, I'l try to buy it if i have enough cash. This is really a great product indeed. More power to the Coders of LLBLGEN pro, im sure u will improve it more.

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

by the way, thanks to walla for being very patient in guiding a newbie sunglasses

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 15:46:16   

The LLBLGEN Pro feature that i like was, its very easy to access the sql tables and I DIDNT USE STORED PROCEDURES, this is one of the many features that i like about this great tool.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 14-Apr-2009 16:04:58   

My next step for this simple project is to be able to subtract all the quantity ordered on the grid to the stock on hand of the Product Entity. I have no idea but i'l try my best.

What i have in mind is to loop again on the datagridview and get the product code and set it as a parameter for my product entity and search the product through its Primary key and manually subtract the quantity column to the product's entity stock on hand. Is there an easier way on how to do this in LLBLGEN?

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

and i came up with this. support team, may i ask for any suggestions on this code to make it better?i don't have any idea whether the database will be slower with this code if it is executed. I added a code inside the loop to subtract the qty ordered on the grid to the product's stock on hand.

Private Sub Button1_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
    Dim counter2 As Integer ' counter2 is the number of rows that a grid has 
    counter2 = OrderLinesDataGridView.Rows.Count
    counter2 = counter2 - 2 ' i subtracted 2 coz i always get an 1 extra number of rows added to the order

    'loop on the grid and add details entity to the database

    For counter = 0 To counter2

        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
        _ordersHeader.SalesOrderDetail.Add(orderDetails)

        'subtract the qty to the product's stock on hand
        Dim products2 As New ProductEntity(OrderLinesDataGridView.Rows(counter).Cells("Code").Value)
        products2.OnHand = products2.OnHand.Value - CInt(OrderLinesDataGridView.Rows(counter).Cells("Qty").Value)
        products2.Save()

    Next
    counter = counter + 1
    _ordersHeader.Save(True)
    MessageBox.Show(Me, "Save action performed.", "Save result", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Apr-2009 21:46:38   

Seems like the two first details aren't new or have no changed fields.

Please post the code you have so far: the relevant code only. If it's too much, please attach a file.

David Elizondo | LLBLGen Support Team
rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 15-Apr-2009 01:13:49   

daelmo wrote:

Seems like the two first details aren't new or have no changed fields.

Please post the code you have so far: the relevant code only. If it's too much, please attach a file.

What the code this was to add a new order then update 1 or more order details on a grid, the fields on the grids are product id, price and qty, then it updates the stock on hand on the product entity.

is there any other better way to do this? the sample application that i'm trying to build is a retail app.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 15-Apr-2009 01:16:50   

daelmo wrote:

Seems like the two first details aren't new or have no changed fields.

Please post the code you have so far: the relevant code only. If it's too much, please attach a file.

What the code this was to add a new order then update 1 or more order details on a grid, the fields on the grids are product id, price and qty, then it updates the stock on hand on the product entity.

is there any other better way to do this? the sample application that i'm trying to build is a retail app. here is the link to the file: http://rapidshare.com/files/221421672/Vb.rar.html

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 15-Apr-2009 05:22:05   

Well the code is working, it saves the new order, the new orderdetails and also updates the product's quantity onhand,.. i don't know if LLBLGEN Pro will always update it as a transaction, that's why i'm asking the support team if the code is okey or not. One thing that i really appreciate is the little code that i used to manipulate 3 entities without knowing ado .net and sql queries and also stored procedures. any improvement or suggestion on the code? thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Apr-2009 11:05:52   

The code is fine and nothing wrong with it.

btw, Saving entities recursively, is done in a transaction. LLBLGen framework does this undeer the scene.

rapido
User
Posts: 45
Joined: 10-Apr-2009
# Posted on: 15-Apr-2009 16:05:27   

Thanks again Walaa! I really appreciate your help. I'm now trying the other tutorials to make myself accustomed with LLBLGen. I hope there will be more improvements after trial period expires, i'm going to buy this .net tool for sure.

1  /  2