-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathucModifyMedicine.cs
More file actions
175 lines (162 loc) · 6.96 KB
/
ucModifyMedicine.cs
File metadata and controls
175 lines (162 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
using Pharmacy_Management_Sysytem.BusinessLogic;
using Pharmacy_Management_Sysytem.Models;
using Pharmacy_Management_Sysytem.Services;
namespace Pharmacy_Management_Sysytem
{
public partial class ucModifyMedicine : UserControl
{
private readonly IMedicineService _medicineService;
public ucModifyMedicine()
{
InitializeComponent();
_medicineService = Program.Services.MedicineService;
}
struct stMedicineInfo
{
public string _MedicineID { get; }
public string _MedicineName { get; }
public string _MedicineNumber { get; }
public string _ManufactureDate { get; }
public string _ExpirationDate { get; }
public int _Quantity { get; }
public int _PricePerUnit { get; }
public stMedicineInfo(string MedicineID ,string MedicineName, string MedicineNumber, string ManufactureDate, string ExpirationDate, int Quantity, int PricePerUnit)
{
_MedicineID = MedicineID;
_MedicineName = MedicineName;
_MedicineNumber = MedicineNumber;
_ManufactureDate = ManufactureDate;
_ExpirationDate = ExpirationDate;
_Quantity = Quantity;
_PricePerUnit = PricePerUnit;
}
}
stMedicineInfo MedicineInfo;
bool IsMedicineFound(string MedicineID)
{
var result = _medicineService.GetMedicineByMedicineId(MedicineID);
return result.IsSuccess;
}
void setAll()
{
txtBoxMedicineID.Enabled = true;
btnSearch.Enabled = true;
txtBoxMedicineID.Clear();
txtBoxMedicineName.Clear();
txtBoxMedicineNumber.Clear();
dtbDateOfManufature.ResetText();
dtbExpirationDate.ResetText();
txtBoxQuantity.Clear();
txtBoxPricePerUnit.Clear();
txtBoxMedicineName.Enabled = false;
txtBoxMedicineNumber.Enabled = false;
dtbDateOfManufature.Enabled = false;
dtbExpirationDate.Enabled = false;
txtBoxQuantity.Enabled = false;
txtBoxPricePerUnit.Enabled = false;
btnUpdate.Enabled = false;
}
void enableBoxes()
{
txtBoxMedicineName.Enabled = true;
txtBoxMedicineNumber.Enabled = true;
dtbDateOfManufature.Enabled = true;
dtbExpirationDate.Enabled = true;
txtBoxQuantity.Enabled = true;
txtBoxPricePerUnit.Enabled = true;
btnUpdate.Enabled = true;
}
void changeBtnUpdataState()
{
if (txtBoxMedicineName.Text != MedicineInfo._MedicineName || txtBoxMedicineNumber.Text != MedicineInfo._MedicineNumber || dtbDateOfManufature.Text != MedicineInfo._ManufactureDate || dtbExpirationDate.Text != MedicineInfo._ExpirationDate || txtBoxQuantity.Text != MedicineInfo._Quantity.ToString() || txtBoxPricePerUnit.Text != MedicineInfo._PricePerUnit.ToString())
{
btnUpdate.Enabled = true;
}
else
{
btnUpdate.Enabled = false;
}
}
void updateMedicine(string MedicineName, string MedicineNumber, string ManufactureDate, string ExpirationDate, int Quantity, int PricePerUnit)
{
// TODO: Implement medicine update using service layer
MessageBox.Show("Medicine update functionality needs to be fully implemented",
"Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void btnSearch_Click(object sender, EventArgs e)
{
if(txtBoxMedicineID.Text.Trim() == "")
{
MessageBox.Show("Enter correct information.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if(IsMedicineFound(txtBoxMedicineID.Text))
{
var result = _medicineService.GetMedicineByMedicineId(txtBoxMedicineID.Text);
if (result.IsSuccess)
{
var medicine = result.Data;
txtBoxMedicineName.Text = medicine.MedicineName;
txtBoxMedicineNumber.Text = medicine.MedicineNumber;
dtbDateOfManufature.Text = medicine.ManufactureDate.ToString();
dtbExpirationDate.Text = medicine.ExpirationDate.ToString();
txtBoxQuantity.Text = medicine.Quantity.ToString();
txtBoxPricePerUnit.Text = medicine.PricePerUnit.ToString();
MedicineInfo = new stMedicineInfo(txtBoxMedicineID.Text, txtBoxMedicineName.Text, txtBoxMedicineNumber.Text, dtbDateOfManufature.Text, dtbExpirationDate.Text, Convert.ToInt32(txtBoxQuantity.Text), Convert.ToInt32(txtBoxPricePerUnit.Text));
txtBoxMedicineID.Enabled = false;
btnSearch.Enabled = false;
enableBoxes();
changeBtnUpdataState();
}
}
else
{
MessageBox.Show("Enter correct information.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnReset_Click(object sender, EventArgs e)
{
setAll();
}
private void txtBoxMedicineName_TextChanged(object sender, EventArgs e)
{
changeBtnUpdataState();
}
private void txtBoxMedicineNumber_TextChanged(object sender, EventArgs e)
{
changeBtnUpdataState();
}
private void dtbDateOfManufature_ValueChanged(object sender, EventArgs e)
{
changeBtnUpdataState();
}
private void dtbExpirationDate_ValueChanged(object sender, EventArgs e)
{
changeBtnUpdataState();
}
private void txtBoxQuantity_TextChanged(object sender, EventArgs e)
{
changeBtnUpdataState();
}
private void txtBoxPricePerUnit_TextChanged(object sender, EventArgs e)
{
changeBtnUpdataState();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
updateMedicine(txtBoxMedicineName.Text, txtBoxMedicineNumber.Text, dtbDateOfManufature.Text, dtbExpirationDate.Text, Convert.ToInt32(txtBoxQuantity.Text), Convert.ToInt32(txtBoxPricePerUnit.Text));
setAll();
}
}
}