-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddMedicine.cs
More file actions
76 lines (69 loc) · 2.84 KB
/
AddMedicine.cs
File metadata and controls
76 lines (69 loc) · 2.84 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
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 Pharmacy_Management_Sysytem.BusinessLogic;
using Pharmacy_Management_Sysytem.Models;
using Pharmacy_Management_Sysytem.Services;
namespace Pharmacy_Management_Sysytem
{
public partial class AddMedicine : UserControl
{
private readonly IMedicineService _medicineService;
public AddMedicine()
{
InitializeComponent();
_medicineService = Program.Services.MedicineService;
}
void addMedicineToDataBase()
{
if (txtBoxMedicineID.Text == "" || txtBoxMedicineName.Text == "" || txtBoxMedicineNumber.Text == "" || dtbDateOfManufature.Text == "" || dtbExpirationDate.Text == "" || txtBoxQuantity.Text == "" || txtBoxPricePerUnit.Text == "")
{
MessageBox.Show("Enter Correct Information", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
String MedicineID = txtBoxMedicineID.Text;
String MedicineName = txtBoxMedicineName.Text;
String MedicineNumber = txtBoxMedicineNumber.Text;
DateTime ManufactureDate = DateTime.Parse(dtbDateOfManufature.Text);
DateTime ExpirationDate = DateTime.Parse(dtbExpirationDate.Text);
int Quantity = Convert.ToInt32(txtBoxQuantity.Text);
decimal PricePerUnit = Convert.ToDecimal(txtBoxPricePerUnit.Text);
var medicine = new Medicine(MedicineID, MedicineName, MedicineNumber, ManufactureDate, ExpirationDate, Quantity, PricePerUnit);
var result = _medicineService.CreateMedicine(medicine);
if (result.IsSuccess)
{
MessageBox.Show("Medicine Added Successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
clearAll();
}
else
{
MessageBox.Show(result.ErrorMessage ?? "Medicine already existed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void clearAll()
{
txtBoxMedicineID.Clear();
txtBoxMedicineName.Clear();
txtBoxMedicineNumber.Clear();
dtbDateOfManufature.ResetText();
dtbExpirationDate.ResetText();
txtBoxQuantity.Clear();
txtBoxPricePerUnit.Clear();
}
private void btnAdd_Click(object sender, EventArgs e)
{
addMedicineToDataBase();
}
private void btnReset_Click(object sender, EventArgs e)
{
clearAll();
}
}
}