(11-01-21, 02:04 AM)1nj كتب : المشروع مشتغلش معايا بسبب الديف اكسبرس
لكن شفت ملف الاكسل
الكود دا لمعرفه كم عدد الترو و كم عدد الفولس في العامود ادمن
كود :
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("admin").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
Dim trueCount = 0, falseCount = 0
For Each item In query
If item.Key = "true" Then trueCount = item.Value
If item.Key = "false" Then falseCount = item.Value
Next
MsgBox("true= " & trueCount)
MsgBox("false= " & falseCount)
شكرا اخي ولكن المشكله انه الترو و الفولس دي متغيرين يعني ممكن يكون بدلها اسماء اشخاص
11-01-21, 02:21 AM (آخر تعديل لهذه المشاركة : 11-01-21, 02:28 AM {2} بواسطة اليوم السابع.)
(11-01-21, 02:11 AM)1nj كتب : معناتو حنرجع للكود الاول وبدل name نضع admin وبكده يعرض الاعداد كلها
كود :
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("admin").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
For Each item In query
MsgBox(item.Key & " " & item.Value)
Next
لو فيه true و false و احمد
حيكون مثلا
true = 30
false = 12
احمد = 43
هو نجح الامر تسلم ايدكم جميعا ولكن النقطه هنا في حال استراد البيانات من ملف اكسيل و الكود في بوتن بيشوف ان الداتا تيبل فارغه
ولكن لو اضفت الكود هنا بيشتغل تمام
كود :
Dim filePath As String = OpenFileDialog1.FileName
Dim extension As String = Path.GetExtension(filePath)
Dim header As String = If(rbHeaderYes.Checked, "YES", "NO")
Dim conStr As String, sheetName As String
Case ".xlsx"
'Excel 07
conStr = String.Format(Excel07ConString, filePath, header)
Exit Select
End Select
'Get the name of the First Sheet.
Using con As New OleDbConnection(conStr)
Using cmd As New OleDbCommand()
cmd.Connection = con
con.Open()
Dim dtExcelSchema As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
sheetName = dtExcelSchema.Rows(0)("TABLE_NAME").ToString()
con.Close()
End Using
End Using
'Read Data from the First Sheet.
Using con As New OleDbConnection(conStr)
Using cmd As New OleDbCommand()
Using oda As New OleDbDataAdapter()
Dim dt As New DataTable()
cmd.CommandText = (Convert.ToString("SELECT * From [") & sheetName) + "]"
cmd.Connection = con
con.Open()
oda.SelectCommand = cmd
oda.Fill(dt)
con.Close()
For Each item In query
MsgBox(item.Key & " " & item.Value)
Next
End Using
End Using
End Using
(11-01-21, 02:21 AM)اليوم السابع كتب :
(11-01-21, 02:11 AM)1nj كتب : معناتو حنرجع للكود الاول وبدل name نضع admin وبكده يعرض الاعداد كلها
كود :
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("admin").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
For Each item In query
MsgBox(item.Key & " " & item.Value)
Next
لو فيه true و false و احمد
حيكون مثلا
true = 30
false = 12
احمد = 43
هو نجح الامر تسلم ايدكم جميعا ولكن النقطه هنا في حال استراد البيانات من ملف اكسيل و الكود في بوتن بيشوف ان الداتا تيبل فارغه
ولكن لو اضفت الكود هنا بيشتغل تمام
كود :
Dim filePath As String = OpenFileDialog1.FileName
Dim extension As String = Path.GetExtension(filePath)
Dim header As String = If(rbHeaderYes.Checked, "YES", "NO")
Dim conStr As String, sheetName As String
Case ".xlsx"
'Excel 07
conStr = String.Format(Excel07ConString, filePath, header)
Exit Select
End Select
'Get the name of the First Sheet.
Using con As New OleDbConnection(conStr)
Using cmd As New OleDbCommand()
cmd.Connection = con
con.Open()
Dim dtExcelSchema As DataTable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
sheetName = dtExcelSchema.Rows(0)("TABLE_NAME").ToString()
con.Close()
End Using
End Using
'Read Data from the First Sheet.
Using con As New OleDbConnection(conStr)
Using cmd As New OleDbCommand()
Using oda As New OleDbDataAdapter()
Dim dt As New DataTable()
cmd.CommandText = (Convert.ToString("SELECT * From [") & sheetName) + "]"
cmd.Connection = con
con.Open()
oda.SelectCommand = cmd
oda.Fill(dt)
con.Close()
For Each item In query
Dim k = item.Key
Dim v = item.Value
MsgBox(k & " = " & v)
Next
اصلا query بيعطيك Dictionary وكل سطر فيه له Key و Value
و ال loop بيمر عليهم كلهم
الفكره اخي اني بستخدم شارت المفروض في كل مره يكون التايتل زاي ما موضح في الصورة انا لا اعلمه
ازاي كان ترو او فولس او شئ اخر و العدد ايضا فا كيف اتعامل معاها في هذه الحالة انا بفكر فيها برمجيا بحيث انها تكون احترافيه
مش عارف
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("admin").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
Dim labelPoint1 As System.Func(Of ChartPoint, String) = Function(chartPoint) String.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation)
Dim seriesCollection1 As New SeriesCollection
For Each item In query
seriesCollection1.Add(New PieSeries With {
.Title = item.Key,
.Values = New ChartValues(Of Integer) From {item.Value},
.PushOut = 15,
.DataLabels = True,
.LabelPoint = labelPoint1
}
)
Next
my_chart.Series = seriesCollection1
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("admin").ToString).ToDictionary(Function(x) x.Key, Function(y) y.Count())
Dim labelPoint1 As System.Func(Of ChartPoint, String) = Function(chartPoint) String.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation)
Dim seriesCollection1 As New SeriesCollection
For Each item In query
seriesCollection1.Add(New PieSeries With {
.Title = item.Key,
.Values = New ChartValues(Of Integer) From {item.Value},
.PushOut = 15,
.DataLabels = True,
.LabelPoint = labelPoint1
}
)
Next
my_chart.Series = seriesCollection1
الحل ما كنش فعال فقمت بعمل الاتي
عملت كلاس ليأخذ الخصائص
كود :
Public Class classChartData
Private sliceField As Dictionary(Of String, Double) = New Dictionary(Of String, Double)()
Public Property Slice As Dictionary(Of String, Double)
Get
Return sliceField
End Get
Set(ByVal value As Dictionary(Of String, Double))
sliceField = value
End Set
End Property
Public Sub AddSlice(ByVal slicename As String, ByVal slicevalue As Double)
sliceField.Add(slicename, slicevalue)
End Sub
ثم اضفت الكود في اللوب
كود :
Dim query = dt.Rows.Cast(Of DataRow)().GroupBy(Function(x) x.Item("privacy").ToString).Where(Function(g) g.Count > 1).ToDictionary(Function(x) x.Key, Function(y) y.Count())
Dim labelPoint As Func(Of ChartPoint, String) = Function(chartPoint) String.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation)
Dim cht_y_values As ChartValues(Of Double) = New ChartValues(Of Double)()
Dim series As LiveCharts.SeriesCollection = New LiveCharts.SeriesCollection()
For Each n In query
my_chart.Series.Add(New PieSeries With {
.Title = n.Key,
.DataLabels = True,
.LabelPoint = labelPoint,
.Values = New ChartValues(Of Double) From {
n.Value
}
})
Next
my_chart.LegendLocation = LegendLocation.Left