Skip to content

Commit b9393c8

Browse files
author
angelomiranda
committed
Refactor AddVitamins and update data files
Refactored `AddVitamins` to improve validation logic, added debugging enhancements, and updated font styles across controls. Refactored file path handling in `FilePaths.vb` to use a project-relative directory structure. Added new patient, prescription, receipt, and schedule entries for Marian Rivera. Updated `Vitamins.txt` with new stock entries for Vitamin A and Vitamin K.
1 parent 6984e23 commit b9393c8

File tree

8 files changed

+92
-45
lines changed

8 files changed

+92
-45
lines changed

OB-GYN Clinic/AddVitamins.Designer.vb

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OB-GYN Clinic/AddVitamins.vb

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,42 @@ Public Class AddVitamins
4040
End Sub
4141

4242
Private Sub btnAddVitamin_Click(sender As Object, e As EventArgs) Handles btnAddVitamin.Click
43-
' Only add if all required fields are filled
44-
If Not String.IsNullOrEmpty(txbStocksScientificName.Text) AndAlso
45-
Not String.IsNullOrEmpty(txbManufactureName.Text) AndAlso
46-
Not String.IsNullOrEmpty(txbPricePerPiece.Text) AndAlso
47-
Not String.IsNullOrEmpty(txbStocksQuantity.Text) AndAlso
48-
Not String.IsNullOrEmpty(cbbVitaminType.Text) Then
49-
50-
Dim newEntry As String = $"{cbbVitaminType.Text},{txbStocksScientificName.Text},{txbManufactureName.Text},{txbPricePerPiece.Text},{txbStocksQuantity.Text}"
43+
If grbDrugDetails.Enabled Then
44+
' Only check Drug Details group box fields
45+
If String.IsNullOrWhiteSpace(cbbVitaminType.Text) OrElse
46+
String.IsNullOrWhiteSpace(txbStocksScientificName.Text) OrElse
47+
String.IsNullOrWhiteSpace(txbManufactureName.Text) OrElse
48+
String.IsNullOrWhiteSpace(txbPricePerPiece.Text) OrElse
49+
String.IsNullOrWhiteSpace(txbQuantity.Text) Then
50+
51+
MessageBox.Show("Please fill in all required fields for Drug Details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
52+
Return
53+
End If
54+
55+
Dim newEntry As String = $"{cbbVitaminType.Text},{txbStocksScientificName.Text},{txbManufactureName.Text},{txbPricePerPiece.Text},{txbQuantity.Text}"
5156
Using writer As New StreamWriter(filePathVitamins, True)
5257
writer.WriteLine(newEntry)
5358
End Using
54-
MessageBox.Show("You have successfully added a Vitamin!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
59+
MessageBox.Show("You have successfully added a new Vitamin!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
5560
Me.Close()
56-
Else
57-
MessageBox.Show("Please fill in all required fields.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
61+
62+
ElseIf gpbAddStocks.Enabled Then
63+
' Add Stocks: Require only scientific name and quantity
64+
If String.IsNullOrWhiteSpace(txbStocksScientificName.Text) OrElse
65+
String.IsNullOrWhiteSpace(txbStocksQuantity.Text) Then
66+
67+
MessageBox.Show("Please fill in Scientific Name and Quantity for Add Stocks.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
68+
Return
69+
End If
70+
71+
' Update stock for existing vitamin
72+
Dim stocksToAdd As Integer
73+
If Integer.TryParse(txbStocksQuantity.Text, stocksToAdd) Then
74+
UpdateStockQuantity(txbStocksScientificName.Text, stocksToAdd)
75+
Me.Close()
76+
Else
77+
MessageBox.Show("Quantity must be a valid number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
78+
End If
5879
End If
5980
End Sub
6081

@@ -133,6 +154,9 @@ Public Class AddVitamins
133154
Dim listBoxWidth As Integer = txbStocksScientificName.Width
134155
ltbVitamins.Location = New Point(listBoxX, listBoxY)
135156
ltbVitamins.Width = listBoxWidth
157+
158+
' Show the actual file path being used
159+
MessageBox.Show(filePathVitamins, "Vitamins File Path")
136160
End Sub
137161

138162
Private Sub btnSearch_Click(sender As Object, e As EventArgs)

OB-GYN Clinic/FilePaths.vb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
Imports System.IO
22

33
Public Module FilePaths
4-
' Base path (where your .exe runs)
5-
Public ReadOnly BasePath As String = Application.StartupPath
6-
7-
' Folder for text files
8-
Public ReadOnly TextFolder As String = Path.Combine(BasePath, "Text Files")
4+
' Get the project directory (two levels up from bin\Debug or bin\Release)
5+
Public ReadOnly ProjectPath As String = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\.."))
6+
Public ReadOnly TextFolder As String = Path.Combine(ProjectPath, "Text Files")
97

108
' File paths (directly inside Text Files folder)
119
Public ReadOnly PatientsFile As String = Path.Combine(TextFolder, "Patients.txt")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RL85VPHS,Marian,Rivera,41,Married,12/08/1984 12:00:00 am,Manila,Yes,Caesarean,DingDong,Dantes,Spouse,09876521345,01/09/2025 12:00:00 am,Dr. Manlapaz,26/09/2025 5:33:41 pm
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Marian Rivera,28/10/2025,Vitamin A,3
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
==================================
2+
New OB Master Gyn Clinic
3+
456 Maligaya Street, Tarlac City, Philippines
4+
Contact: (123) 456-7890
5+
Clinic #: 54321 | Doctor #: 5678
6+
Doctor: Dr. Manlapaz | Date: 09/26/2025
7+
Patient: Marian Rivera | First Trimester
8+
Type of Check-Up: Initial Check-Up
9+
-----------------------------------------------------------
10+
Item Price Qty Total
11+
-----------------------------------------------------------
12+
Check-Up Bill: Php. 2000.00
13+
Next Appointment: 28/10/2025
14+
Vitamin A: ₱50.00 x 3 = ₱150.00 |
15+
-----------------------------------------------------------
16+
Total: ₱2,150.00
17+
Payment: ₱3,000.00
18+
Change: ₱850.00
19+
=================================
20+
Thank you for choosing New OB-GYN Clinic!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Marian Rivera,28/10/2025
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Vitamin A,Vitamin A,Zhejiang NHU Co.,50,47
2+
Vitamin K,Vitamin D,Keratin,100,56

0 commit comments

Comments
 (0)