-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmMedicineAndDetail.cs
190 lines (177 loc) · 8.69 KB
/
FrmMedicineAndDetail.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PharmacyAutomation
{
public partial class FrmMedicineAndDetail : Form
{
public FrmMedicineAndDetail()
{
InitializeComponent();
}
public string personID;
public string username;
SqlConnection connection = new SqlConnection("Data Source=DESKTOP-2H5V0KB\\SQLEXPRESS;Initial Catalog=DbPharmacy;Integrated Security=True");
public void CategoryList()
{
SqlCommand command = new SqlCommand("Select * From TblMedicineCategory", connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
cmbCategory.DisplayMember = "CategoryName";
cmbCategory.ValueMember = "CategoryID";
cmbCategory.DataSource = dataTable;
}
public void MedicineList()
{
SqlCommand command = new SqlCommand("Select MedicineID,MedicineName,Quantity,Stock,ConsumptionDate,Country,PurchasePrice,SalePrice,CategoryName,TblMedicine.Situation from TblMedicine inner join TblMedicineCategory on TblMedicine.CategoryID=TblMedicineCategory.CategoryID where TblMedicine.Situation=1", connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
dataGridView1.DataSource = dataTable;
}
private void FrmSeller_Load(object sender, EventArgs e)
{
MedicineList();
CategoryList();
}
private void btnAdd_Click(object sender, EventArgs e)
{
connection.Open();
SqlCommand command = new SqlCommand("insert into TblMedicine (MedicineName,Quantity,Stock,ConsumptionDate,Country,PurchasePrice,SalePrice,Situation,CategoryID) values (@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9)", connection);
command.Parameters.AddWithValue("@p1", txtMedicineName.Text);
command.Parameters.AddWithValue("@p2", txtQuantity.Text);
command.Parameters.AddWithValue("@p3", txtMedicineStock.Text);
command.Parameters.AddWithValue("@p4", DateTime.Parse(dtpConsumptionDate.Text));
command.Parameters.AddWithValue("@p5", txtCountry.Text);
command.Parameters.AddWithValue("@p6", txtPurchasePrice.Text);
command.Parameters.AddWithValue("@p7", txtSalePrice.Text);
command.Parameters.AddWithValue("@p9", cmbCategory.SelectedValue);
if (rdbActive.Checked == true)
{
command.Parameters.AddWithValue("@p8", "True");
}
if (rdbPassive.Checked == true)
{
command.Parameters.AddWithValue("@p8", "False");
}
command.ExecuteNonQuery();
MessageBox.Show("İlaç başarılı bir şekilde sisteme kaydedildi");
connection.Close();
MedicineList();
}
private void btnDelete_Click(object sender, EventArgs e)
{
connection.Open();
SqlCommand command = new SqlCommand("Update TblMedicine set Situation=0 where MedicineID=@p1", connection);
command.Parameters.AddWithValue("@p1", txtMedicineID.Text);
command.ExecuteNonQuery();
MessageBox.Show("Ürün sistemden başarılı bir şekilde silindi", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
connection.Close();
MedicineList();
}
private void btnBack_Click(object sender, EventArgs e)
{
Close();
FrmAdminDashboard frmAdminDashboard = new FrmAdminDashboard();
frmAdminDashboard.personID = personID;
frmAdminDashboard.username = username;
frmAdminDashboard.Show();
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int secilen = dataGridView1.SelectedCells[0].RowIndex;
txtMedicineID.Text = dataGridView1.Rows[secilen].Cells[0].Value.ToString();
txtMedicineName.Text = dataGridView1.Rows[secilen].Cells[1].Value.ToString();
txtQuantity.Text = dataGridView1.Rows[secilen].Cells[2].Value.ToString();
txtMedicineStock.Text = dataGridView1.Rows[secilen].Cells[3].Value.ToString();
dtpConsumptionDate.Text = dataGridView1.Rows[secilen].Cells[4].Value.ToString();
txtCountry.Text = dataGridView1.Rows[secilen].Cells[5].Value.ToString();
txtPurchasePrice.Text = dataGridView1.Rows[secilen].Cells[6].Value.ToString();
txtSalePrice.Text = dataGridView1.Rows[secilen].Cells[7].Value.ToString();
if (Convert.ToBoolean(dataGridView1.Rows[secilen].Cells[9].Value.ToString()))
{
rdbActive.Checked = true;
}
else
{
rdbPassive.Checked = true;
}
connection.Open();
SqlCommand command =
new SqlCommand("select * from TblMedicineCategory where CategoryID=(Select CategoryID From TblMedicine Where MedicineID=@p1)", connection);
command.Parameters.AddWithValue("@p1", dataGridView1.Rows[secilen].Cells[0].Value.ToString());
SqlDataReader dataReader2 = command.ExecuteReader();
while (dataReader2.Read())
{
cmbCategory.SelectedValue = Int32.Parse(dataReader2["CategoryID"].ToString());
}
connection.Close();
}
private void txtSearchMedicine_TextChanged(object sender, EventArgs e)
{
if (txtSearchMedicine.Text != "" && txtSearchMedicine.Text != "İlaç ismi giriniz...")
{
SqlCommand command =
new SqlCommand(
"Select MedicineID,MedicineName,Quantity,Stock,ConsumptionDate,Country,PurchasePrice,SalePrice,CategoryName,TblMedicine.Situation from TblMedicine inner join TblMedicineCategory on TblMedicine.CategoryID=TblMedicineCategory.CategoryID where TblMedicine.Situation=1 and MedicineName Like '" + txtSearchMedicine.Text + "%'",
connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
dataGridView1.DataSource = dataTable;
}
else
{
MedicineList();
}
}
private void txtSearchMedicine_Enter(object sender, EventArgs e)
{
if (txtSearchMedicine.Text == "İlaç ismi giriniz...")
{
txtSearchMedicine.Text = "";
}
}
private void txtSearchMedicine_Leave(object sender, EventArgs e)
{
if (txtSearchMedicine.Text == "")
{
txtSearchMedicine.Text = "İlaç ismi giriniz...";
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
connection.Open();
SqlCommand command = new SqlCommand("update TblMedicine set MedicineName=@p1,Quantity=@p2,Stock=@p3,ConsumptionDate=@p4,Country=@p5,PurchasePrice=@p6,SalePrice=@p7,Situation=@p8,CategoryID=@p9 where MedicineID=@p10", connection);
command.Parameters.AddWithValue("@p1", txtMedicineName.Text);
command.Parameters.AddWithValue("@p2", txtQuantity.Text);
command.Parameters.AddWithValue("@p3", Convert.ToInt32(txtMedicineStock.Text));
command.Parameters.AddWithValue("@p4", DateTime.Parse(dtpConsumptionDate.Text));
command.Parameters.AddWithValue("@p5", txtCountry.Text);
command.Parameters.AddWithValue("@p6", Convert.ToDecimal(txtPurchasePrice.Text));
command.Parameters.AddWithValue("@p7", Convert.ToDecimal(txtSalePrice.Text));
command.Parameters.AddWithValue("@p9", cmbCategory.SelectedValue);
command.Parameters.AddWithValue("@p10", txtMedicineID.Text);
if (rdbActive.Checked == true)
{
command.Parameters.AddWithValue("@p8", "True");
}
if (rdbPassive.Checked == true)
{
command.Parameters.AddWithValue("@p8", "False");
}
command.ExecuteNonQuery();
MessageBox.Show("İlaç başarılı bir şekilde güncellendi", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
connection.Close();
MedicineList();
}
}
}