-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoctorForm.cs
231 lines (194 loc) · 8.24 KB
/
DoctorForm.cs
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using System;
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 System.Data.SqlClient;
namespace HCPApp
{
public partial class DoctorForm : Form
{
Functions Con;
public DoctorForm()
{
InitializeComponent();
Con = new Functions();
ShowDoctors();
}
private void ShowDoctors()
{
try
{
string Query = "Select * from DoctorTbl";
DoctorList.DataSource = Con.GetData(Query);
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
private void pictureBox10_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
if (txtFirstName.Text == "" || txtLastName.Text == "" || ComboSpec.SelectedIndex == -1 || ComboDay.SelectedIndex == -1 || ComboTime.SelectedIndex == -1 || txtQualification.Text == "" || txtContact.Text == "")
{
MessageBox.Show("Missing Some of Some or All of The data!");
}
else
{
string FName = txtFirstName.Text;
string LName = txtLastName.Text;
string Specification = ComboSpec.SelectedItem.ToString();
string AvailableDay = ComboDay.SelectedItem.ToString();
string AvailableTime = ComboTime.SelectedItem.ToString();
string Qualify = txtQualification.Text;
string Conta = txtContact.Text;
string Query = "INSERT INTO DoctorTbl ( FirstName, LastName, Specification, AvailableDay, AvailableTime, Qualification, Contact) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')";
Query = string.Format(Query, FName, LName, Specification, AvailableDay, AvailableTime, Qualify, Conta);
Con.SetData(Query);
ShowDoctors();
MessageBox.Show("Doctor Added.");
txtFirstName.Text = "";
txtLastName.Text = "";
ComboSpec.SelectedIndex = -1;
ComboDay.SelectedIndex = -1;
ComboTime.SelectedIndex = -1;
txtQualification.Text = "";
txtContact.Text = "";
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
private void DoctorList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow selectedRow = DoctorList.Rows[e.RowIndex];
txtFirstName.Text = selectedRow.Cells[1].Value.ToString();
txtLastName.Text = selectedRow.Cells[2].Value.ToString();
ComboSpec.SelectedItem = selectedRow.Cells[3].Value.ToString();
ComboDay.SelectedItem = selectedRow.Cells[4].Value.ToString();
ComboTime.SelectedItem = selectedRow.Cells[5].Value.ToString();
txtQualification.Text = selectedRow.Cells[6].Value.ToString();
txtContact.Text = selectedRow.Cells[7].Value.ToString();
int doctorId = Convert.ToInt32(selectedRow.Cells[0].Value);
Updatebtn.Tag = doctorId.ToString();
}
}
private void Updatebtn_Click(object sender, EventArgs e)
{
try
{
if (txtFirstName.Text == "" || txtLastName.Text == "" || ComboSpec.SelectedIndex == -1 || ComboDay.SelectedIndex == -1 || ComboTime.SelectedIndex == -1 || txtQualification.Text == "" || txtContact.Text == "")
{
MessageBox.Show("Missing Some or All of the Data!");
}
else
{
int doctorId = Convert.ToInt32(Updatebtn.Tag); // Assuming the doctor ID is stored in the Tag property
string connectionString = @"Data Source=LAPTOP-A9K7TF0H\SQLEXPRESS;Initial Catalog=HCPAppDB;Integrated Security=True";
int rowsAffected = Con.UpdateDoctorInfo(doctorId, txtFirstName.Text, txtLastName.Text, ComboSpec.SelectedItem.ToString(), ComboDay.SelectedItem.ToString(), ComboTime.SelectedItem.ToString(), txtQualification.Text, txtContact.Text, connectionString);
if (rowsAffected > 0)
{
ShowDoctors();
MessageBox.Show("Doctor Updated.");
}
else
{
MessageBox.Show("Failed to update doctor information.");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Deletebtn_Click(object sender, EventArgs e)
{
try
{
if (MessageBox.Show("Are you sure you want to delete this doctor?", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int doctorId = Convert.ToInt32(Updatebtn.Tag);
string connectionString = @"Data Source=LAPTOP-A9K7TF0H\SQLEXPRESS;Initial Catalog=HCPAppDB;Integrated Security=True";
int rowsAffected = Con.DeleteDoctor(doctorId, connectionString);
if (rowsAffected > 0)
{
ShowDoctors();
MessageBox.Show("Doctor Deleted.");
}
else
{
MessageBox.Show("Failed to delete doctor.");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void DoctorForm_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'hCPAppDBDataSet2.DoctorTbl' table. You can move, or remove it, as needed.
this.doctorTblTableAdapter.Fill(this.hCPAppDBDataSet2.DoctorTbl);
}
private void label3_Click(object sender, EventArgs e)
{
}
private void guna2Button1_Click(object sender, EventArgs e)
{
AdminDashboard dashboard = new AdminDashboard();
dashboard.Show();
this.Hide();
}
private void guna2Button6_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void guna2Button3_Click(object sender, EventArgs e)
{
PatientForm patientForm = new PatientForm();
patientForm.Show();
this.Hide();
}
private void panel4_Paint(object sender, PaintEventArgs e)
{
}
private void DoctorList_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow selectedRow = DoctorList.Rows[e.RowIndex];
txtFirstName.Text = selectedRow.Cells[1].Value.ToString();
txtLastName.Text = selectedRow.Cells[2].Value.ToString();
ComboSpec.SelectedItem = selectedRow.Cells[3].Value.ToString();
ComboDay.SelectedItem = selectedRow.Cells[4].Value.ToString();
ComboTime.SelectedItem = selectedRow.Cells[5].Value.ToString();
txtQualification.Text = selectedRow.Cells[6].Value.ToString();
txtContact.Text = selectedRow.Cells[7].Value.ToString();
int doctorId = Convert.ToInt32(selectedRow.Cells[0].Value);
Updatebtn.Tag = doctorId.ToString();
}
}
private void guna2Button4_Click(object sender, EventArgs e)
{
Appointment appointment = new Appointment();
appointment.Show();
this.Hide();
}
}
}