Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11661

how to use Linq groupby and where with date conditions in vb.net

$
0
0

I'm trying to use Linq groupby and where with date conditions in vb.net

Please Guide Me.

PIQ is total purchase quantity

SIQ is total sales quantity

BLC is total purchase quantity minus total sales quantity

Thanks

Public Class Form3    Private Purchase, Sales As New List(Of Invoice)    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load        LoadData()    End Sub    Private PurchaseDetails,SalesDetails As New List(Of Detail)    Private Function CreateConnection() As String        Return ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\TRIAL2.accdb;Persist Security Info=False;")    End FunctionPrivate Sub LoadData()        Using Connection = New OleDbConnection(CreateConnection()) Purchase = CType(Connection.Query(Of Invoice)("SELECT * FROM PURCHASE"), List(Of Invoice))            PurchaseDetails = CType(Connection.Query(Of Detail)("SELECT * FROM PURCHASEDETAILS"), List(Of Detail)) Sales = CType(Connection.Query(Of Invoice)("SELECT * FROM SALES"), List(Of Invoice))            SalesDetails = CType(Connection.Query(Of Detail)("SELECT * FROM SALESDETAILS"), List(Of Detail))End Using        Dim ps = From p In Purchase                 Where p.DATEINVO >= CDate("01/01/2024")                 From pd In PurchaseDetails                 Select             pd.ITEM,             PIQ = pd.QTY,             SIQ = 0,             BLC = pd.QTY                 Order By ITEM        Dim ss = From s In Sales                 Where s.DATEINVO >= CDate("01/01/2024")                 From sd In SalesDetails                 Select            sd.ITEM,            PIQ = 0,            SIQ = sd.QTY,            BLC = -sd.QTY                 Order By ITEM Dim Card_temp = ps.Union(ss).OrderBy(Function(w) w.ITEM) Dim Card As New List(Of ItemCards3)        Dim RunningBalance As Integer = 0        For Each ct In Card_temp            Dim sc As New ItemCards3            With sc                .ITEM = ct.ITEM                .PIQ = ct.PIQ                .SIQ = ct.SIQ                .BLC = RunningBalance + ct.BLC                RunningBalance = .BLC            End With            Card.Add(sc)        Next        DataGridView1.DataSource = Card    End SubEnd ClassPublic Class Invoice    Property INVONO() As String    Property DATEINVO() As Date    Property CUSTCODE() As StringEnd ClassPublic Class Detail    Public Property INVONO() As String    Public Property NOD() As Integer    Public Property ITEM() As String    Public Property QTY() As IntegerEnd ClassPublic Class ItemCards3    Public Property ITEM() As String    Public Property PIQ As Integer    Public Property SIQ As Integer    Public Property BLC As IntegerEnd Class

Table PURCHASE

INVONODATEINVOCUSTCODE
PI100025-Jan-23001
PI100129-Jan-23002
PI100229-Jan-24003
PI000330-Jan-24004

Table PURCHASEDETAILS

INVONONODITEMQTY
PI10001TEST 100010
PI10002TEST 200020
PI10011TEST 300015
PI10021TEST 100020
PI10031TEST 100015

Table SALES

INVONODATEINVOCUSTCODE
SI100025-Jan-23001
SI100129-Jan-23002
SI100229-Jan-24005
SI100330-Jan-24006
SI100429-Jan-24004
SI100530-Jan-24003

Table SALESDETAILS

INVONONODITEMQTY
SI10001TEST 100010
SI10002TEST 200020
SI10011TEST 800035
SI10021TEST 100027
SI10031TEST 100015
SI10041TEST 20002
SI10051TEST 20002

the result of the code above

ITEMPIQSIQBLC
TEST 100015015
TEST 100010025
TEST 100020045
TEST 100001035
TEST 10000278
TEST 1000015-7
TEST 200020013
TEST 2000020-7
TEST 200002-9
TEST 30001506
TEST 8000035-29

Desired result

ITEMPIQSIQBLC
TEST 10003542-7
TEST 20004-4

Viewing all articles
Browse latest Browse all 11661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>