منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : احصاء و تمثيل بيانات بChart
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم ورحمة الله
حاولت ان احصاء و تمثيل البيانات بChart يعمل عند التحميل فقط ثم لا يتغير عند استعمال ComboBox
اليكم الملف
كود :
Imports System.Data.OleDb

Public Class Form1

   Dim DT As New DataTable
   Dim totals() As Integer
   Dim titles() As String = {"ذكر", "أنثى"}

   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       '=========================
       fillcboSubject()
       '=========================
       LoadDataGridView_Subject_Gender()
   End Sub

   Private Sub fillcboSubject()
       'تحميل بيانات المواد في الكومبوبكس
       Subjects_Load()
       '==============================
       ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
       ComboBox1.DataSource = SubjectDT
       ComboBox1.DisplayMember = "Subject"
       ComboBox1.ValueMember = "ID_Subject"
       ComboBox1.SelectedIndex = -1
       'ComboBox1.Text = "المادة"
   End Sub

   Private Sub LoadDataGridView_Subject_Gender()
       Try

           Dim id = ComboBox1.SelectedValue
           DT.Clear()
           Dim DA As New OleDbDataAdapter("SELECT Subjects.Subject, Teachers.Gender AS Gender, Count(Teachers.ID_Teacher) AS total FROM Teachers,Subjects where (Teachers.ID_Subject = Subjects.ID_Subject) and (Teachers.ID_Subject = " & ComboBox1.SelectedValue & ") GROUP BY Subjects.Subject, Teachers.Gender", con)

           DA.Fill(DT)
           DataGridView1.DataSource = DT
           Data_GridView()

           Dim male As Integer = (From x In DT Where x("Gender").Equals("ذكر") Select x("total")).FirstOrDefault
           Dim female As Integer = (From x In DT Where x("Gender").Equals("أنثى") Select x("total")).FirstOrDefault
           totals = {male, female}

       Catch ex As Exception
       End Try
   End Sub

   Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
       LoadDataGridView_Subject_Gender()
       Chart1.Series(0).Points.DataBindXY(titles, totals)
   End Sub


   Private Sub Data_GridView()
       DataGridView1.Columns(0).HeaderText = " المادة"
       DataGridView1.Columns(1).HeaderText = " الجنس"
       DataGridView1.Columns(2).HeaderText = " المجموع"
   End Sub

End Class
شكرا لك اخي 911 على الرد
و لكن النسبة المئوية لم تتحقق
وكذلك اردت لو امكن لماذا لاتتغير في الكود الذي وضعته انا بحيث عند التحميل في المرة الاولى النسبة صحيحىة ثم لاتتغير
كود :
Imports System.Data.OleDb

Public Class Form1

   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       '=========================
       fillcboSubject()
       '=========================
       LoadDataGridView_Subject_Gender()
       '=========================
       Data_GridView()
       '=========================
       ComboBox1.Select()
   End Sub

   Private Sub fillcboSubject()
       'تحميل بيانات المواد في الكومبوبكس
       Subjects_Load()
       '==============================
       ComboBox1.DataSource = SubjectDT
       ComboBox1.DisplayMember = "Subject"
       ComboBox1.ValueMember = "ID_Subject"
       If ComboBox1.Items.Count > 0 Then
           ComboBox1.SelectedIndex = 0
       End If
       'ComboBox1.Text = "المادة"
   End Sub

   Dim DT As New DataTable
   Dim total() As Integer
   Dim titles() As String = {"ذكر", "أنثى"}

   Private Sub LoadDataGridView_Subject_Gender()
       Try

           Dim id = ComboBox1.SelectedValue
           DT.Clear()
           Dim DA As New OleDbDataAdapter("SELECT Subjects.Subject, Teachers.Gender AS Gender, Count(Teachers.ID_Teacher) AS total FROM Teachers,Subjects where (Teachers.ID_Subject = Subjects.ID_Subject) and (Teachers.ID_Subject = " & ComboBox1.SelectedValue & ") GROUP BY Subjects.Subject, Teachers.Gender", con)

           DA.Fill(DT)
           DataGridView1.DataSource = DT

           Dim male As Integer = (From x In DT Where x("Gender").Equals("ذكر") Select x("total")).FirstOrDefault
           Dim female As Integer = (From x In DT Where x("Gender").Equals("أنثى") Select x("total")).FirstOrDefault

           If male > 0 Or female > 0 Then
               total = {(male / (male + female)) * 100, (female / (male + female)) * 100}
           Else
               total = {0, 0}
           End If

           charting()

       Catch ex As Exception

       End Try

   End Sub

   Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
       LoadDataGridView_Subject_Gender()
       charting()
   End Sub

   Private Sub charting()
       Chart1.Series(0).LabelFormat = "#'%'"
       Chart1.Series(0).Points.DataBindXY(titles, total)
       Chart1.Series(0).IsValueShownAsLabel = True
   End Sub

   Private Sub Data_GridView()

       DataGridView1.Columns(0).HeaderText = " المادة"
       DataGridView1.Columns(1).HeaderText = " الجنس"
       DataGridView1.Columns(2).HeaderText = " المجموع"
   End Sub

End Class
شكرا لك اخي 911 على تعبك معنا وبارك الله فيكم