0% found this document useful (0 votes)
11 views4 pages

Abdu Hamus Assign

DBMS assignment

Uploaded by

daninazu512
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Abdu Hamus Assign

DBMS assignment

Uploaded by

daninazu512
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Structure Definition
vb
Copy code
Structure student
Dim department As String
Dim division As String
Dim id As String
End Structure

 Defines a student structure with three fields:


o department: The department the student belongs to.
o division: The division within the department.
o id: A unique identifier for the student.

2. Class Initialization
vb
Copy code
Public Class department
Dim newstudent As student
Private stdcount As Integer = 0

 Declares a variable newstudent of type student to hold student information.


 Initializes stdcount to 0, which keeps track of the total number of students.

3. Form Load Event


vb
Copy code
Private Sub department_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cmbdepartment.SelectedIndex = 0
End Sub

 Purpose: Sets the default selected item of the department dropdown (cmbdepartment) to
the first option (index 0) when the form loads.

4. Handle Department Selection Change


vb
Copy code
Private Sub cmbdepartment_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbdepartment.SelectedIndexChanged
Dim depcode As String
depcode = getdepcode(cmbdepartment.Text.Trim())
End Sub

 Triggered when the user selects a different department in cmbdepartment.


 Calls the getdepcode function to retrieve a department code (like "CS" for "Computer
Science") for later use.

5. Handle Division Selection Change


vb
Copy code
Private Sub clbdivision_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles clbdivision.SelectedIndexChanged
Dim divcode As String
divcode = clbdivision.Text.Trim().Substring(0, 1)
End Sub

 Triggered when the user selects a division from the division list (clbdivision).
 Retrieves the first character of the selected division text (e.g., "M" for "Marketing") and
stores it for ID generation.

6. Retrieve Department Code


vb
Copy code
Private Function getdepcode(ByVal dept As String) As String
Select Case dept
Case "Computer Science"
Return "CS"
Case "Accounting"
Return "AC"
Case "Managment"
Return "MG"
Case "Buisness Administration"
Return "BA"
Case "Marketing"
Return "MK"
Case Else
Return "xx"
End Select
End Function

 A utility function that takes a department name as input and returns a short code for the
department.
 Returns "xx" if the department name does not match any predefined case.
7. Generate and Display Student ID
vb
Copy code
Private Sub btnid_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnid.Click
stdcount += 1
newstudent.department = cmbdepartment.Text.Trim()
newstudent.division = clbdivision.Text.Trim()

1. Increments stdcount to reflect a new student.


2. Fetches selected values for department and division from the user interface.

ID Generation Process:

vb
Copy code
Dim departmentnu As String = getdepcode(newstudent.department)
Dim divisionnu As String = newstudent.division.Trim().Substring(0, 1)
Dim str As String = stdcount.ToString("0000")
Dim year As String = (DateTime.Now.Year Mod 2000).ToString()
newstudent.id = departmentnu & divisionnu & "/" & str & "/" & year

 departmentnu: Department code from getdepcode.


 divisionnu: First character of the division.
 str: Formats stdcount as a 4-digit string (e.g., 1 → 0001).
 year: Extracts the last two digits of the current year.
 Combines these components to generate an ID like CSM/0001/24.

Store and Display the ID:

vb
Copy code
depdictionary.Add(newstudent.id, newstudent)
btnid.Text = newstudent.id

 Adds the new student to a dictionary (depdictionary) for later use.


 Displays the generated ID on the btnid button.

8. Button Hover Behavior


vb
Copy code
Private Sub btnid_MouseEnter(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnid.MouseEnter
btnid.Text = newstudent.id
End Sub

Private Sub btnid_MouseLeave(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnid.MouseLeave
btnid.Text = "/////////////////////////"
End Sub

 When hovering over the btnid button, it shows the generated ID.
 When the mouse leaves the button, it resets the text to "/////////////////////////".

9. Registration and Exit


vb
Copy code
Private Sub btnregister_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnregister.Click
Form1.ShowDialog()
End Sub

 Opens another form (Form1) when the Register button is clicked.

vb
Copy code
Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnexit.Click
Me.Close()
End Sub

 Closes the application when the Exit button is clicked.

Summary

1. The user selects a department and division.


2. A unique student ID is generated based on:
o Department code.
o Division code.
o Student count.
o Year.
3. The ID is displayed and stored in a dictionary for later use.
4. Additional buttons allow for registration (opening a new form) and exiting

You might also like