05-03-18, 07:23 PM
(آخر تعديل لهذه المشاركة : 06-03-18, 01:56 AM {2} بواسطة بيسك لكل العرب.)
(05-03-18, 11:46 AM)Abu Ehab كتب : هذا الكلاس فوورم بالكامل أنسخ والصق فقط
كود :
Imports System.Data.OleDb
Public Class Form1
Dim ConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\db.accdb"
Dim Conn As New OleDbConnection(ConStr)
Dim da As New OleDbDataAdapter
Dim dt As New DataTable
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dt.Clear()
da = New OleDbDataAdapter("Select * from AAA", Conn)
da.Fill(dt)
DataGridView1.DataSource = dt
DataGridView1.Columns(0).Visible = False
Compute(DataGridView1)
End Sub
Private Sub B2DatesFind_Btn_Click(sender As Object, e As EventArgs) Handles B2DatesFind_Btn.Click
Dim dtp1 As Date = DateTimePicker_from.Value
Dim dtp2 As Date = DateTimePicker_to.Value
dt.Clear()
da = New OleDbDataAdapter("Select * from AAA where Date >= #" & dtp1.Year & "/" & dtp1.Month & "/" & dtp1.Day & "# and Date <= #" & dtp2.Year & "/" & dtp2.Month & "/" & dtp2.Day & "# order by Date ", Conn)
da.Fill(dt)
DataGridView1.DataSource = dt
Conn.Close()
TextBox1.Text = (From row In DataGridView1.Rows Select CDbl(row.Cells(2).Value)).Sum()
End Sub
Private Sub Compute(ByVal Dgv As DataGridView)
Dgv.Rows(Dgv.Rows.Count - 1).Cells(1).Value = "Total Is "
Dgv.Rows(Dgv.Rows.Count - 1).Cells(1).Style.BackColor = Color.Black
Dgv.Rows(Dgv.Rows.Count - 1).Cells(1).Style.ForeColor = Color.Gold
Dim rw1 = From theRow As DataGridViewRow In Dgv.Rows
Where theRow.Cells(2).FormattedValue <> String.Empty
Select theRow
Dgv.Rows(Dgv.Rows.Count - 1).Cells(2).Value = rw1.Sum(Function(x As DataGridViewRow) x.Cells(2).Value)
Dim rw2 = From theRow As DataGridViewRow In Dgv.Rows
Where theRow.Cells(3).FormattedValue <> String.Empty
Select theRow
Dgv.Rows(Dgv.Rows.Count - 1).Cells(3).Value = rw2.Sum(Function(x As DataGridViewRow) x.Cells(3).Value)
Dim rw3 = From theRow As DataGridViewRow In Dgv.Rows
Where theRow.Cells(4).FormattedValue <> String.Empty
Select theRow
Dgv.Rows(Dgv.Rows.Count - 1).Cells(4).Value = rw3.Sum(Function(x As DataGridViewRow) x.Cells(4).Value)
End Sub
End Class
السلام عليكم
مشكور أخي ابو ايهاب وجزاك الله الف خير كود الجمع شغال تمام بس ممكن تطويره
ليشمل جميع الاعمدة الموجودة حتي لا يتم تكرار الكود لان يوجد لدي عدة أعمدة
ولك من جزيل الشكر والعرفان
PHP كود :
Dim rw1 = From theRow As DataGridViewRow In Dgv.Rows
Where theRow.Cells(2).FormattedValue <> String.Empty
Select theRow
Dgv.Rows(Dgv.Rows.Count - 1).Cells(2).Value = rw1.Sum(Function(x As DataGridViewRow) x.Cells(2).Value)
