Details
How do I use Details
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: Equipment.cs
Copy
20 private void button1_Click(object sender, EventArgs e)
21 {
22 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
23 con.Open();
24
25 try
26 {
27 string str = " INSERT INTO equipment(name,description,used,cost) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "'); ";
28
29 SqlCommand cmd = new SqlCommand(str, con);
30 cmd.ExecuteNonQuery();
31
32 string str1 = "select max(eqp_id) from equipment;";
33
34 SqlCommand cmd1 = new SqlCommand(str1, con);
35 SqlDataReader dr = cmd1.ExecuteReader();
36 if (dr.Read())
37 {
38 MessageBox.Show("" + textBox1.Text + "'s Equipment Details is Inserted Successfully.. ");
39 this.Hide();
40
41 }
42 this.Close();
43 }
44 catch (SqlException excep)
45 {
46 MessageBox.Show(excep.Message);
47 }
48 con.Close();
49 }
File name: NewMember.cs
Copy
25 private void button1_Click(object sender, EventArgs e)
26 {
27 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
28 con.Open();
29 string gender = string.Empty;
30 if (radioButton1.Checked)
31 {
32 gender = "Male";
33 }
34 else if (radioButton2.Checked)
35 {
36 gender = "Female";
37 }
38 try
39 {
40 string str = " INSERT INTO members(f_name,l_name,gender,dob,mobile,email,jod,time,address,mem_time) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + gender + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + comboBox1.Text + "','" + textBox7.Text + "','" + comboBox2.Text + "'); ";
41
42 SqlCommand cmd = new SqlCommand(str, con);
43 cmd.ExecuteNonQuery();
44
45 string str1 = "select max(m_id) from members ;";
46
47 SqlCommand cmd1 = new SqlCommand(str1, con);
48 SqlDataReader dr = cmd1.ExecuteReader();
49 if (dr.Read())
50 {
51 MessageBox.Show("" + textBox1.Text + "'s Details is Inserted Successfully.. " + textBox1.Text + "'s Id is " + dr.GetInt32(0) + ".", "Important Message");
52 this.Hide();
53
54 }
55 this.Close();
56 }
57 catch (SqlException excep)
58 {
59 MessageBox.Show(excep.Message);
60 }
61 con.Close();
62 }
File name: NewStaff.cs
Copy
20 private void button1_Click(object sender, EventArgs e)
21 {
22 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
23 con.Open();
24 string gender = string.Empty;
25 if (radioButton1.Checked)
26 {
27 gender = "Male";
28 }
29 else if (radioButton2.Checked)
30 {
31 gender = "Female";
32 }
33 try
34 {
35 string str = " INSERT INTO staff(f_name,l_name,gender,dob,mobile,email,jod,street,city) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + gender + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" +textBox8.Text + "'); ";
36
37 SqlCommand cmd = new SqlCommand(str, con);
38 cmd.ExecuteNonQuery();
39
40 string str1 = "select max(stf_id) from staff;";
41
42 SqlCommand cmd1 = new SqlCommand(str1, con);
43 SqlDataReader dr = cmd1.ExecuteReader();
44 if (dr.Read())
45 {
46 MessageBox.Show("" + textBox1.Text + "'s Details is Inserted Successfully.. " + textBox1.Text + "'s Id is " + dr.GetInt32(0) + ".", "Important Message");
47 this.Hide();
48
49 }
50 this.Close();
51 }
52 catch (SqlException excep)
53 {
54 MessageBox.Show(excep.Message);
55 }
56 con.Close();
57 }
File name: Register.cs
Copy
20 private void button1_Click(object sender, EventArgs e)
21 {
22 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
23 con.Open();
24 string gender = string.Empty;
25 if (radioButton1.Checked)
26 {
27 gender = "Male";
28 }
29 else if (radioButton2.Checked)
30 {
31 gender = "Female";
32 }
33 try
34 {
35 string str = " INSERT INTO employee(emp_username,name,password,gender,email,mobile,address,date) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + gender + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "'); ";
36
37 SqlCommand cmd = new SqlCommand(str, con);
38 cmd.ExecuteNonQuery();
39
40 string str1 = "select max(emp_id) from employee ;";
41
42 SqlCommand cmd1 = new SqlCommand(str1, con);
43 SqlDataReader dr = cmd1.ExecuteReader();
44 if (dr.Read())
45 {
46 MessageBox.Show("" + textBox1.Text + "'s Details is Inserted Successfully.. " + textBox1.Text + "'s Id is " + dr.GetInt32(0) + ".", "Important Message");
47 this.Hide();
48 Home obj1 = new Home();
49 obj1.ShowDialog();
50 }
51 this.Close();
52 }
53 catch (SqlException excep)
54 {
55 MessageBox.Show(excep.Message);
56 }
57 con.Close();
58 }
File name: PatientInformation.cs
Copy
88 private void button2_Click(object sender, EventArgs e)
89 {
90 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True");
91 con.Open();
92 string gen = string.Empty;
93 if (radioButton1.Checked)
94 {
95 gen = "Male";
96 }
97 else
98 {
99 gen = "Female";
100 }
101 try
102 {
103 string str = " Update patient set name='" + textBox2.Text + "',gen='" + gen + "',age='" + textBox3.Text + "',date='" + textBox4.Text + "',cont='" + textBox5.Text + "',addr='" + textBox6.Text + "',disease='" + textBox7.Text + "',status='" + textBox8.Text + "',r_type='" + textBox10.Text + "',building='" + textBox9.Text + "',r_no='" + textBox11.Text + "',price='" + textBox12.Text + "' where id='" + textBox1.Text + "'";
104
105 SqlCommand cmd = new SqlCommand(str, con);
106 cmd.ExecuteNonQuery();
107
108 string str1 = "select max(id) from patient;";
109
110 SqlCommand cmd1 = new SqlCommand(str1, con);
111 SqlDataReader dr = cmd1.ExecuteReader();
112 if (dr.Read())
113 {
114 MessageBox.Show("" + textBox2.Text + "'s Details is Updated Successfully.. ", "Important Message");
115 textBox2.Text = "";
116 textBox4.Text = "";
117 textBox5.Text = "";
118 textBox6.Text = "";
119 textBox7.Text = "";
120 using (SqlConnection con1 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True"))
121 {
122
123 string str2 = "SELECT * FROM patient";
124 SqlCommand cmd2 = new SqlCommand(str2, con1);
125 SqlDataAdapter da = new SqlDataAdapter(cmd2);
126 DataTable dt = new DataTable();
127 da.Fill(dt);
128 dataGridView1.DataSource = new BindingSource(dt, null);
129 }
130 }
131 }
132 catch (SqlException excep)
133 {
134 MessageBox.Show(excep.Message);
135 }
136 con.Close();
137 }
File name: StaffInformation.cs
Copy
155 private void button4_Click(object sender, EventArgs e)
156 {
157 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True");
158 con.Open();
159 string gen = string.Empty;
160 if (radioButton1.Checked)
161 {
162 gen = "Male";
163 }
164 else
165 {
166 gen = "Female";
167 }
168 try
169 {
170 string str = " Update staff set name='" + textBox2.Text + "',gender='" + gen + "',position='" + textBox4.Text + "',salary='" + textBox5.Text + "',contact='" + textBox6.Text + "',address='" + textBox7.Text + "' where id='" + textBox1.Text + "'";
171
172 SqlCommand cmd = new SqlCommand(str, con);
173 cmd.ExecuteNonQuery();
174
175 string str1 = "select max(id) from staff;";
176
177 SqlCommand cmd1 = new SqlCommand(str1, con);
178 SqlDataReader dr = cmd1.ExecuteReader();
179 if (dr.Read())
180 {
181 MessageBox.Show("" + textBox2.Text + "'s Details is Updated Successfully.. ", "Important Message");
182 textBox2.Text = "";
183 textBox4.Text = "";
184 textBox5.Text = "";
185 textBox6.Text = "";
186 textBox7.Text = "";
187 using (SqlConnection con1 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True"))
188 {
189
190 string str2 = "SELECT * FROM staff";
191 SqlCommand cmd2 = new SqlCommand(str2, con1);
192 SqlDataAdapter da = new SqlDataAdapter(cmd2);
193 DataTable dt = new DataTable();
194 da.Fill(dt);
195 dataGridView1.DataSource = new BindingSource(dt, null);
196 }
197 }
198 }
199 catch (SqlException excep)
200 {
201 MessageBox.Show(excep.Message);
202 }
203 con.Close();
204 }
File name: frmCustomerMainMenu.cs
Copy
35 private void btnModifyDetails_Click(object sender, EventArgs e)
36 {
37 frmUpdateCustomerDetails frm = new frmUpdateCustomerDetails();
38 frm.textBox1.Text = lblUser.Text;
39 frm.Getdata();
40 frm.Show();
41 }
File name: frmCustomerMainMenu.cs
Copy
58 private void btnExit_Click(object sender, EventArgs e)
59 {
60 this.Hide();
61 frmCustomerProfileEntry o1 = new frmCustomerProfileEntry();
62 o1.Hide();
63 frmCustomerRegistration o2 = new frmCustomerRegistration();
64 o2.Hide();
65 frmUpdateCustomerDetails o3 = new frmUpdateCustomerDetails();
66 o3.Hide();
67 frmUpdateProfile o4 = new frmUpdateProfile();
68 o4.Hide();
69 frmCustomerOrders o5 = new frmCustomerOrders();
70 o5.Hide();
71 frmLogin frm = new frmLogin();
72 frm.txtUserName.Text = "";
73 frm.txtPassword.Text = "";
74 frm.ProgressBar1.Visible = false;
75 frm.txtUserName.Focus();
76 frm.Show();
77 }
File name: frmCustomerProfileEntry.cs
Copy
24 private void btnSave_Click(object sender, EventArgs e)
25 {
26 if (txtCustomerName.Text == "")
27 {
28 MessageBox.Show("Please enter name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
29 txtCustomerName.Focus();
30 return;
31 }
32
33 if (txtAddress.Text == "")
34 {
35 MessageBox.Show("Please enter address", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
36 txtAddress.Focus();
37 return;
38 }
39 if (txtCity.Text == "")
40 {
41 MessageBox.Show("Please enter city", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
42 txtCity.Focus();
43 return;
44 }
45
46 if (txtContactNo.Text == "")
47 {
48 MessageBox.Show("Please enter contact no.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
49 txtContactNo.Focus();
50 return;
51 }
52
53 try
54 {
55 con = new SqlConnection(cs.DBConn);
56 con.Open();
57 string ct1 = "select CustomerID from Customer where CustomerID='" + txtCustomerID.Text + "'";
58
59 cmd = new SqlCommand(ct1);
60 cmd.Connection = con;
61 rdr = cmd.ExecuteReader();
62
63 if (rdr.Read())
64 {
65 MessageBox.Show("Profile already saved", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
66
67 if ((rdr != null))
68 {
69 rdr.Close();
70 }
71 return;
72 }
73 con = new SqlConnection(cs.DBConn);
74 con.Open();
75
76 string cb = "insert into Customer(CustomerID,Customername,address,City,ContactNo,ContactNo1,Email) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7)";
77
78 cmd = new SqlCommand(cb);
79
80 cmd.Connection = con;
81 cmd.Parameters.AddWithValue("@d1", txtCustomerID.Text);
82 cmd.Parameters.AddWithValue("@d2", txtCustomerName.Text);
83 cmd.Parameters.AddWithValue("@d3", txtAddress.Text);
84 cmd.Parameters.AddWithValue("@d4", txtCity.Text);
85 cmd.Parameters.AddWithValue("@d5", txtContactNo.Text);
86 cmd.Parameters.AddWithValue("@d6", txtContactNo1.Text);
87 cmd.Parameters.AddWithValue("@d7", txtEmail.Text);
88
89
90 cmd.ExecuteReader();
91 MessageBox.Show("Successfully saved", "Customer Details", MessageBoxButtons.OK, MessageBoxIcon.Information);
92 btnSave.Enabled = false;
93 if (con.State == ConnectionState.Open)
94 {
95 con.Close();
96 }
97
98 con.Close();
99
100 }
101 catch (Exception ex)
102 {
103 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
104 }
105 }
File name: frmCustomers.cs
Copy
70 private void btnSave_Click(object sender, EventArgs e)
71 {
72 if (txtCustomerName.Text == "")
73 {
74 MessageBox.Show("Please enter name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
75 txtCustomerName.Focus();
76 return;
77 }
78
79 if (txtAddress.Text == "")
80 {
81 MessageBox.Show("Please enter address", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
82 txtAddress.Focus();
83 return;
84 }
85 if (txtCity.Text == "")
86 {
87 MessageBox.Show("Please enter city", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
88 txtCity.Focus();
89 return;
90 }
91
92 if (txtContactNo.Text == "")
93 {
94 MessageBox.Show("Please enter contact no.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
95 txtContactNo.Focus();
96 return;
97 }
98
99 try
100 {
101 auto();
102
103 con = new SqlConnection(cs.DBConn);
104 con.Open();
105
106 string cb = "insert into Customer(CustomerID,Customername,address,City,ContactNo,ContactNo1,Email,Notes) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8)";
107
108 cmd = new SqlCommand(cb);
109
110 cmd.Connection = con;
111 cmd.Parameters.AddWithValue("@d1", txtCustomerID.Text);
112 cmd.Parameters.AddWithValue("@d2", txtCustomerName.Text);
113 cmd.Parameters.AddWithValue("@d3", txtAddress.Text);
114 cmd.Parameters.AddWithValue("@d4", txtCity.Text);
115 cmd.Parameters.AddWithValue("@d5", txtContactNo.Text);
116 cmd.Parameters.AddWithValue("@d6", txtContactNo1.Text);
117 cmd.Parameters.AddWithValue("@d7", txtEmail.Text);
118 cmd.Parameters.AddWithValue("@d8", txtNotes.Text);
119
120 cmd.ExecuteReader();
121 MessageBox.Show("Successfully saved", "Customer Details", MessageBoxButtons.OK, MessageBoxIcon.Information);
122 btnSave.Enabled = false;
123 if (con.State == ConnectionState.Open)
124 {
125 con.Close();
126 }
127
128 con.Close();
129
130 }
131 catch (Exception ex)
132 {
133 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
134 }
135 }
Download file with original file name:Details
Details 128 lượt xem
Gõ tìm kiếm nhanh...