السلام عليكم ..
مساء الخير أعزائي الفضلاء ..
هذا تطبيق لما تعلمته في الـ VB.NET ..
وهو يعني بعلاقة : one to one بين كلاسين ..
بين كلاس الـ Department وبين Employee ..
طبعاً المثال بسيط ، وليس الأصل أن العلاقة بن القسم وبين الموظفين علاقة one to one ، لكن كتجربة فقط.. ومن ثم الإنتقال إلى one to many ..
طبعاً المثال فيه خطاً ( نطقي ) عجزت عن كشفه فهو ينفذ وعند الضغط على button لكي يظهر المعلومات تخرج لي رسالة messagebox تحتوي
على كلمة ( False ) ..
للعلم البرنامج يقوم بتعيين قسم وكذلك إضافة موظفين لذلك القسم ..
أرجو مشركتي أيها الأحبة في إيجاد الحل .. وأتوقع أن الحل بسيط لكني لكثرة البحث والتجربة أصاب رأسي ( الشوشرة :) ) ..
تحيات العطرة لكم ..
Public Class employee Private name_e As String Private ssn_e As String Private salary_e As Double Private thedepartment As department Public Sub New(ByVal n As String, ByVal s As String, ByVal sa As Double) setname_e(n) setssn_e(s) setsalary_e(sa) setthedepartment(Nothing) End Sub Public Sub setname_e(ByVal na As String) name_e = na End Sub Public Sub setssn_e(ByVal ss As String) ssn_e = ss End Sub Public Sub setsalary_e(ByVal sl As Double) salary_e = sl End Sub Public Sub setthedepartment(ByVal depp As department) thedepartment = depp End Sub Public Function getname_e() As String Return name_e End Function Public Function getssn_e() As String Return ssn_e End Function Public Function getsalary_e() As Double Return salary_e End Function Public Function getthedepartment() As department Return thedepartment End Function Public Function tellaboutself() As String Dim info As String Return info = "Name : " + getname_e() + " SSN : " + getssn_e() + " Salary : " + Convert.ToString(getsalary_e()) End Function End Class
Public Class department Private depn As String Private theemployee As employee Private manger As employee Public Sub New(ByVal dd As String) setdepn(dd) settheemployee(Nothing) setmanger(Nothing) End Sub Public Sub setdepn(ByVal d As String) depn = d End Sub Public Sub settheemployee(ByVal emp As employee) theemployee = emp End Sub Public Sub setmanger(ByVal man As employee) manger = man End Sub Public Function getdepn() As String Return depn End Function Public Function gettheemployee() As employee Return theemployee End Function Public Function getmanger() As employee Return manger End Function Public Function TellAboutSelf() As String Dim msg As String msg = " Dept Name: " & getdepn() Return msg End Function End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Font = New System.Drawing.Font("Segoe UI", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button1.ForeColor = System.Drawing.Color.Maroon
Me.Button1.Location = New System.Drawing.Point(56, 120)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(184, 32)
Me.Button1.TabIndex = 0
Me.Button1.Text = "one-2-one"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 16)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim e1 As employee = New employee("Ahmad", "1002", 18000878)
Dim e2 As employee = New employee("Ali", "1003", 18000878)
Dim e3 As employee = New employee("Saeed", "1004", 18000878)
Dim d As department = New department("Markting")
e1.setthedepartment(d)
d.settheemployee(e1)
e2.setthedepartment(d)
d.settheemployee(e2)
e3.setthedepartment(d)
d.settheemployee(e3)
MessageBox.Show(d.gettheemployee.tellaboutself())
End Sub
End Class