Xinqi Bao's Git

All done
[HospitalManageSys.git] / HospitalManageSys / Form_DrugIm.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using MySql.Data.MySqlClient;
9 using System.Windows.Forms;
10
11 namespace HospitalManageSys
12 {
13 public partial class Form_DrugIm : Form
14 {
15 MySqlConnection conn;
16 MainForm mf;
17
18 public Form_DrugIm(MySqlConnection connector, MainForm mainform)
19 {
20 InitializeComponent();
21
22 conn = connector;
23 mf = mainform;
24 }
25 private void Form1_Load(object sender, EventArgs e)
26 {
27 textBox1.MaxLength = 20;
28 CreateHeaderandFillListView();
29
30 }
31
32
33 private void CreateHeaderandFillListView()
34 {
35 ColumnHeader colHead = new ColumnHeader();
36 colHead.Text = "Pid";
37 colHead.Width = 50;
38 lvitem.Columns.Add(colHead);
39 ColumnHeader col2 = new ColumnHeader();
40 col2.Text = "Pname";
41 col2.Width = 100;
42 lvitem.Columns.Add(col2);
43 ColumnHeader col3 = new ColumnHeader();
44 col3.Text = "Pprize";
45 col3.Width = 100;
46 lvitem.Columns.Add(col3);
47 ColumnHeader col4 = new ColumnHeader();
48 col4.Text = "Pdetile";
49 col4.Width = 100;
50 lvitem.Columns.Add(col4);
51 ColumnHeader col5 = new ColumnHeader();
52 col5.Text = "Pamount";
53 col5.Width = 100;
54 lvitem.Columns.Add(col5);
55 }
56 private static DataSet SelectRows(DataSet dataset, string connectionString, string queryString)
57 {
58 using (MySqlConnection connection = new MySqlConnection (connectionString))
59 {
60 MySqlDataAdapter adapter = new MySqlDataAdapter();
61 adapter.SelectCommand = new MySqlCommand(queryString,connection);
62 adapter.Fill(dataset);
63 return dataset;
64 }
65 }
66
67 private void CreateItemView()
68 {
69 string a;
70 a = textBox5.Text;
71 ListViewItem lvi = new ListViewItem(textBox1.Text);
72 lvi.SubItems.Add(textBox2.Text);
73 lvi.SubItems.Add(textBox3.Text);
74 lvi.SubItems.Add(textBox4.Text);
75 lvi.SubItems.Add(textBox5.Text);
76 lvitem.Items.Add(lvi);
77 }
78 private void checkBox1_CheckedChanged(object sender, EventArgs e)
79 {
80
81 }
82
83 private void button1_Click(object sender, EventArgs e)
84 {
85 if (textBox1.Text == "") MessageBox.Show("please fill up the entering box");
86 else if (textBox2.Text == "") MessageBox.Show("please fill up the entering box");
87 else if (textBox3.Text == "") MessageBox.Show("please fill up the entering box");
88 else if (textBox4.Text == "") MessageBox.Show("please fill up the entering box");
89 else if (textBox5.Text == "") MessageBox.Show("please fill up the entering box");
90 else
91 {
92 CreateItemView();
93 MessageBox.Show("药品编号输入有误");
94 textBox1.Text = "";
95 textBox2.Text = "";
96 textBox3.Text = "";
97 textBox4.Text = "";
98 textBox5.Text = "";
99 textBox6.Text = "";
100 textBox7.Text = "";
101
102 }
103 }
104
105 private void textBox1_TextChanged(object sender, EventArgs e)
106 {
107
108 }
109
110 private void toolTip1_Popup(object sender, PopupEventArgs e)
111 {
112
113 }
114
115 private void button2_Click(object sender, EventArgs e)
116 {
117 MessageBox.Show("clear");
118 textBox1.Text = "";
119 textBox2.Text = "";
120 textBox3.Text = "";
121 textBox4.Text = "";
122 textBox5.Text = "";
123 lvitem.Columns.Clear();
124 }
125
126 private void label1_Click(object sender, EventArgs e)
127 {
128
129 }
130
131 private void button3_Click(object sender, EventArgs e)
132 {
133
134 DataSet ds = new DataSet();
135 string ConnectionString = HospitalManageSys.SqlCmd.strcon;
136 //MySqlConnection conn = new MySqlConnection(ConnectionString);
137 conn.Open();
138 string a = "select*from dru"+"g";
139 string sql = string.Format(a);
140 MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn);
141 sda.Fill(ds);
142 DataView dv = ds.Tables[0].DefaultView;
143 listBox1.DataSource = ds.Tables[0];
144 if (radioButton1.Checked)
145 listBox1.DisplayMember = "Drug_name";
146 else if (radioButton2.Checked)
147 listBox1.DisplayMember = "Drug_supplier";
148 else if (radioButton3.Checked)
149 listBox1.DisplayMember = "Drug_id";
150 conn.Close();
151 ttt();
152 }
153 private void ttt()
154 {
155
156 string ConnectionString = HospitalManageSys.SqlCmd.strcon;
157 //MySqlConnection conn = new MySqlConnection(ConnectionString);
158 try
159 {
160 conn.Open();
161 label7.Text = "服务器名称:" + conn.DataSource + ";要使用的数据库:" + conn.Database;
162 string strcmd = "select*from drug";
163 MySqlCommand cmd = new MySqlCommand(strcmd, conn);
164 MySqlDataAdapter ada = new MySqlDataAdapter(cmd);
165 DataSet ds = new DataSet();
166 ada.Fill(ds);//查询结果填充数据集
167 dataGridView1.DataSource = ds.Tables[0];
168 conn.Dispose();
169 conn.Close();
170 }
171 catch (Exception)
172 {
173 label7.Text = "failed";
174 }
175
176 }
177
178 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
179 {
180
181 }
182
183 private void button4_Click(object sender, EventArgs e)
184 {
185 if (textBox1.Text == "") MessageBox.Show("please fill up the entering box");
186 else if (textBox2.Text == "") MessageBox.Show("please fill up the entering box");
187 else if (textBox3.Text == "") MessageBox.Show("please fill up the entering box");
188 else if (textBox4.Text == "") MessageBox.Show("please fill up the entering box");
189 else if (textBox5.Text == "") MessageBox.Show("please fill up the entering box");
190 else
191 {
192 DataSet ds = new DataSet();
193 string connectionString = HospitalManageSys.SqlCmd.strcon;//"Data Source=localhost;Initial Catalog=hospitalmanagesys;User ID=root;Password=nnnbc4318";
194 string t1, t2, t3, t4, t5, t6, t7;
195 t1 = textBox1.Text;
196 t2 = textBox2.Text;
197 t3 = textBox3.Text; t4 = textBox4.Text; t5 = textBox5.Text; t6 = textBox6.Text; t7 = textBox7.Text;
198 string query = "insert into hospitalmanagesys.drug value('" + t1 + "','" + t2 + "','" + t3 + "','" + t4 + "','" + t7 + "','" + t6 + "','" + t5 + "');";
199 ds = SelectRows(ds, connectionString, query);
200 MessageBox.Show("添加成功");
201 }
202
203 }
204
205 private void textBox2_TextChanged(object sender, EventArgs e)
206 {
207
208 }
209
210 private void textBox3_TextChanged(object sender, EventArgs e)
211 {
212
213 }
214
215 private void textBox4_TextChanged(object sender, EventArgs e)
216 {
217
218 }
219
220 private void textBox7_TextChanged(object sender, EventArgs e)
221 {
222
223 }
224
225 private void textBox6_TextChanged(object sender, EventArgs e)
226 {
227
228 }
229
230 private void textBox5_TextChanged(object sender, EventArgs e)
231 {
232
233 }
234
235 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
236 {
237
238 }
239
240 private void label8_Click(object sender, EventArgs e)
241 {
242
243 }
244
245 private void radioButton3_CheckedChanged(object sender, EventArgs e)
246 {
247
248 }
249
250 private void radioButton2_CheckedChanged(object sender, EventArgs e)
251 {
252
253 }
254
255
256 }
257 }