Dim objDate As ArrayList
Dim objList As ArrayList
Dim objnumMat As ArrayList
Dim objnumMat_A(,) As String
Dim objWeight As ArrayList
Dim objSumWeight_list As ArrayList
Sub calculateTable()
objDate = New ArrayList
objList = New ArrayList
Dim oRs As DbConn
Dim strQuery As String = "SELECT DISTINCT CONVERT(varchar(10),obj_tbl.input_dt,103) AS input_dt FROM obj_tbl WHERE (( obj_tbl.status != 'delete') AND ('" & ddlSup & "' = obj_tbl.supplier) AND ('" & ddlMaterial & "' = obj_tbl.name_material) AND (obj_tbl.input_dt BETWEEN '" & expenddt & "' AND '" & expenddt2 & "')) ORDER BY input_dt DESC"
oRs = New DbConn(strQuery)
While oRs.ReadData.Read()
objDate.Add(oRs.ReadData("input_dt"))
End While
oRs.ReadData.Close()
'////////////////////
Dim i As Integer = 0
For i = 0 To (objDate.Count - 1)
Response.Write("<br />")
Response.Write(objDate(i))
Next
Dim oRsObj As DbConn
Dim strQueryObj As String = "SELECT DISTINCT obj_listall.obj_All FROM obj_listall WHERE ((obj_listall.status != 'delete') AND ('" & ddlSup & "' = obj_listall.supplier) AND ('" & ddlMaterial & "' = obj_listall.name_material) AND (obj_listall.input_date BETWEEN '" & expenddt & "' AND '" & expenddt2 & "'))"
oRsObj = New DbConn(strQueryObj)
While oRsObj.ReadData.Read()
objList.Add(oRsObj.ReadData("obj_All"))
End While
oRsObj.ReadData.Close()
'////////////////////////////////
Dim j As Integer = 0
For j = 0 To (objList.Count - 1)
Response.Write("<br />")
Response.Write(objList(j))
Next
objSumWeight_list = New ArrayList
Dim w As Integer = 0
For w = 0 To (objDate.Count - 1)
objWeight = New ArrayList
Dim oRsweight As DbConn
Dim wdt As Date = Date.ParseExact(objDate(w), "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
Dim strQueryObjweight As String = "SELECT obj_tbl.weight_t FROM obj_tbl WHERE ((obj_tbl.status != 'delete') AND ('" & ddlSup & "' = obj_tbl.supplier) AND ('" & ddlMaterial & "' = obj_tbl.name_material) AND (obj_tbl.input_dt = '" & wdt & "'))"
oRsweight = New DbConn(strQueryObjweight)
While oRsweight.ReadData.Read()
objWeight.Add(oRsweight.ReadData("weight_t"))
End While
oRsweight.ReadData.Close()
Dim sumw As Double = 0
Dim ww As Integer = 0
For ww = 0 To (objWeight.Count - 1)
sumw = sumw + objWeight(ww)
Next
objSumWeight_list.Add(sumw)
Next
ReDim objnumMat_A((objDate.Count - 1), (objList.Count - 1))
Dim n As Integer = 0
Dim nn As Integer = 0
For n = 0 To (objDate.Count - 1)
For nn = 0 To (objList.Count - 1)
Dim oRsnumMat As DbConn
Dim ndt As Date = Date.ParseExact(objDate(n), "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
Dim strQueryObjnumMat As String = "SELECT obj_listall.obj_num FROM obj_listall WHERE ((obj_listall.status != 'delete') AND ('" & ddlSup & "' = obj_listall.supplier) AND ('" & ddlMaterial & "' = obj_listall.name_material) AND (obj_listall.input_date = '" & ndt & "') AND (obj_listall.obj_All = '" & objList(nn) & "'))"
oRsnumMat = New DbConn(strQueryObjnumMat)
While oRsnumMat.ReadData.Read()
objnumMat_A(n, nn) = CInt(objnumMat_A(n, nn)) + CInt(oRsnumMat.ReadData("obj_num"))
End While
oRsnumMat.ReadData.Close()
Next
Next
Dim sumObjNumList(objList.Count - 1) As String
Dim sInt As Integer = 0
Dim ssInt As Integer = 0
For sInt = 0 To (objList.Count - 1)
For ssInt = 0 To (objDate.Count - 1)
sumObjNumList(sInt) = CInt(sumObjNumList(sInt)) + CInt(objnumMat_A(ssInt, sInt))
Next
Next
'ลองแสดงค่า
Dim k As Integer = 0
Dim l As Integer = 0
For k = 0 To (objDate.Count - 1)
For l = 0 To (objList.Count - 1)
Response.Write("<br />")
Response.Write(objnumMat_A(k, l))
Next
Next
Dim zzz As Integer = 0
For zzz = 0 To sumObjNumList.Count - 1
Response.Write("<br />")
Response.Write(sumObjNumList(zzz))
Next
End Sub
อยากให้ช่วยตรงเรื่อง For อ่าครับ เพราะผมดึงค่ามันมาทีละค่าเลย เนื่องจากเงื่อนไขที่กำหนดมันค่อนข้างเยอะ ประกอบกับการออกแบบ DB ผมยังไม่ค่อยจะดีพอ T^T
ช่วยหน่อยนะครับ
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET
Imports System.Collections.Generic
Public Class Learning_Calculator
Private Delegate Function DelegateFormula(ByVal m As Double, ByVal n As Double) As Double
Private Shared Formula As New Dictionary(Of String, DelegateFormula)() From {{"+", Function(m, n) m + n},
{"-", Function(m, n) m - n},
{"*", Function(m, n) m * n},
{"/", Function(m, n) m / n}
}
''' <summary>
''' Example : Dim ret = Calculate(12.50, 10.00, "-")
''' ret = 2.50
''' </summary>
Public Shared Function Calculate(ByVal a As Double, b As Double, Optional ByVal Oper As String = "+") As Double
Dim retValue As Double = 0.0
If (("+-*/").Contains(Oper)) AndAlso (Not (Oper = "/" AndAlso b = 0)) Then
retValue = Formula(Oper).Invoke(a, b)
End If
Return retValue
End Function
End Class