Xinqi Bao's Git

All done
[HospitalManageSys.git] / HospitalManageSys / Form_Registration.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 System.Windows.Forms;
9 using MySql.Data.MySqlClient;
10
11 namespace HospitalManageSys
12 {
13 public partial class Form_Registration : Form
14 {
15 MySqlConnection con;
16 MySqlCommand cmd;
17 DataSet ds;
18 MySqlDataAdapter ada;
19
20 MainForm mf;
21
22
23 public Form_Registration(MySqlConnection connector, MainForm mainform)
24 {
25 InitializeComponent();
26
27 mf = mainform;
28
29 string constr = "server=localhost;database=hospitalmanagesys;uid=huangweiqiang;pwd=hwq123456;";
30 //con = new MySqlConnection(constr);
31 con = connector;
32 con.Open();
33 cmd = new MySqlCommand("select * from administrator", con);
34 ada = new MySqlDataAdapter(cmd);
35 ds = new DataSet();
36 ada.Fill(ds);
37
38 //textBox8.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString();
39
40
41 string strID = getID();
42
43 textBox8.Text = strID;
44
45
46
47 int ds_count = ds.Tables[0].Rows.Count;
48 for (int i = 0; i < ds_count; i++)
49 {
50 comboBox1_doctorID.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
51 }
52 }
53
54
55
56 private void Form1_Load(object sender, EventArgs e)
57 {
58
59 }
60
61 private void label5_Click(object sender, EventArgs e)
62 {
63
64 }
65
66 private string getID()
67 {
68 string str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYZ";
69 int[] iArr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
70 char[] cArr = str.ToCharArray();
71 Random rad =new Random();
72 string date = DateTime.Now.ToString("yyyyMMddHHmmss");
73 int str_i = rad.Next(cArr.Length);
74 int i = rad.Next(iArr.Length);
75 string name = date;//+ " " + cArr[str_i] + iArr[i];
76 return name;
77
78 }
79
80
81 private void textBox8_Click(object sender, EventArgs e)
82 {
83 string strID = getID();
84
85 textBox8.Text = strID;
86 }
87
88 private void button1_Click(object sender, EventArgs e)
89 {
90 cmd.CommandText = "insert into registration (registration_count,patient_name,patient_sex,patient_insurance,doctor_ID,patient_address,patient_fee) value"
91 + "('" + textBox8.Text + "','" + textBox_name.Text + "','" + textBox_patientsex.Text + "','" + textBox_patient_insurance.Text + "','" + comboBox1_doctorID.Text + "','" + textBox4_patientaddress.Text + "','" + textBox_patient_fee.Text + "');";
92 cmd.ExecuteNonQuery();
93 }
94
95
96
97 private void textBox8_TextChanged(object sender, EventArgs e)
98 {
99 string strID=getID();
100
101 textBox8.Text = strID;
102 }
103
104 private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
105 {
106 /* string constr = "server=localhost;database=hospitalmanagesys;uid=huangweiqiang;pwd=hwq123456;";
107 con = new MySqlConnection(constr);
108 con.Open();
109 MySqlCommand cm = new MySqlCommand("select admin_name,admin_ID from administrator", con);
110
111 MySqlDataReader dr = cm.ExecuteReader();
112
113 //绑定
114
115 this.lbxAdministrator.DataSource = dr; //lbxEmp为ListBox对象
116
117 this.lbxadministrator.DataTextField = "admin_name";
118
119 this.lbxadministrator.DataValueField = "admin_ID";
120
121 this.lbxadministrator.DataBind();
122
123 dr.Close();
124
125 con.Close();*/
126 }
127
128
129 private void cBoxTables_SelectedIndexChanged(object sender, EventArgs e)
130 {
131
132 }
133
134
135
136 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
137 {
138 ds.Clear();
139 cmd.CommandText = "select * from administrator where admin_ID='" + comboBox1_doctorID.Text + "';";
140 cmd.ExecuteNonQuery();
141 ada.Fill(ds);
142
143
144 textBox9_doctorname.Text = ds.Tables[0].Rows[0].ItemArray[1].ToString();
145 textBox5_doctordepartment.Text = ds.Tables[0].Rows[0].ItemArray[4].ToString();
146 textBox7_doctorfee.Text = ds.Tables[0].Rows[0].ItemArray[5].ToString();
147 textBox6_doctorcapability.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString();
148
149
150 }
151
152 private void button2_Click(object sender, EventArgs e)
153 {
154 cmd.CommandText = "update registration set patient_name = '" + textBox_name.Text
155 + "',patient_sex = '" + textBox_patientsex.Text
156 + "',patient_insurance = '" + textBox_patient_insurance.Text
157 + "',doctor_ID = '" + comboBox1_doctorID.Text
158 + "',patient_address = '" + textBox4_patientaddress.Text
159 + "',patient_fee = '" + textBox_patient_fee.Text
160 + "' where registration_count = " + textBox1.Text;
161
162 cmd.ExecuteNonQuery();
163
164
165 }
166
167 private void button3_Click(object sender, EventArgs e)
168 {
169 ds.Clear();
170 cmd.CommandText = "select * from registration where registration_count ='" + textBox1.Text + "';";
171 cmd.ExecuteNonQuery();
172 ada.Fill(ds);
173
174 textBox_name.Text = ds.Tables[0].Rows[0].ItemArray[11].ToString();
175 textBox_patient_insurance.Text = ds.Tables[0].Rows[0].ItemArray[12].ToString();
176 textBox_patientsex.Text = ds.Tables[0].Rows[0].ItemArray[13].ToString();
177 textBox4_patientaddress.Text = ds.Tables[0].Rows[0].ItemArray[15].ToString();
178 textBox_patient_fee.Text = ds.Tables[0].Rows[0].ItemArray[16].ToString();
179 comboBox1_doctorID.Text = ds.Tables[0].Rows[0].ItemArray[17].ToString();
180
181
182 }
183
184 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
185 {
186
187 }
188
189
190 }
191
192
193
194 }
195