If
How do I use If
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
197 | if (dr.Read()) | 1 |
283 | if (dr.Read()) | 2 |
110 | if (!frm.Name.Equals(form_hienthoi)) | 3 |
26 | if (e.KeyChar == ' ') | 4 |
33 | if (quyen != -1) | 5 |
42 | if (txtMaGV.Text!="") | 6 |
61 | if (result == DialogResult.Yes) | 7 |
78 | if (e.KeyChar == ' ') | 8 |
39 | if(txtMaHeDT.Text!="") | 9 |
58 | if (result == DialogResult.Yes) | 10 |
File name: ClassBLL.cs
Copy
191 public int CheckLogin(string name, string pass)
192 {
193 SqlConnection con = da.GetConnect();
194 SqlCommand cmd = new SqlCommand("select *from Users Where Username='"+name+"' and Password='"+pass+"'",con);
195 con.Open();
196 SqlDataReader dr = cmd.ExecuteReader();
197 if (dr.Read())
198 {
199 if (dr[2].ToString() == "admin")
200 {
201 return 1;
202 }
203 else
204 {
205 return 2;
206 }
207 }
208 else
209 {
210 return -1;
211 }
212 }
File name: ClassBLL.cs
Copy
275 public bool Proc_Insert(string proc,string test)
276 {
277 SqlConnection con = da.GetConnect();
278 con.Open();
279 SqlCommand cmd = new SqlCommand(proc, con);
280 cmd.CommandType = CommandType.StoredProcedure;
281 cmd.Parameters.Add("@test", SqlDbType.NVarChar).Value = test;
282 SqlDataReader dr = cmd.ExecuteReader();
283 if (dr.Read())
284 {
285 return false;
286 }
287 return true;
288 }
File name: Form9.cs
Copy
104 public void CloseForm(string form_hienthoi)
105 {
106 // duyet qua tung form con dang mo
107 foreach (Form frm in this.MdiChildren)
108 {
109 // neu hok phai form dang mo thi dong lai
110 if (!frm.Name.Equals(form_hienthoi))
111 frm.Close();
112 }
113 }
File name: FormDangNhap.cs
Copy
24 private void txtTenDangNhap_KeyPress(object sender, KeyPressEventArgs e)
25 {
26 if (e.KeyChar == ' ')
27 e.Handled = true;
28 }
File name: FormDangNhap.cs
Copy
30 private void btnDangNhap_Click(object sender, EventArgs e)
31 {
32 int quyen=business.CheckLogin(txtTenDangNhap.Text, txtMatKhau.Text);
33 if (quyen != -1)
34 {
35 Form9.quyen = quyen;
36 Form9 f = (Form9)this.MdiParent;
37 f.PhanQuyenMenu();
38 this.Close();
39 }
40 else
41 {
42 MessageBox.Show("Sai Tên Đăng Nhập Hoặc Mật Khẩu !!");
43 }
44 }
File name: FormGiangVien.cs
Copy
40 private void btnThem_Click(object sender, EventArgs e)
41 {
42 if (txtMaGV.Text!="")
43 {
44 if(business.Proc_Insert("Insert_GiangVien",txtMaGV.Text))
45 {
46 string sql = "'"+txtMaGV.Text+"','"+txtTenGV.Text+"','"+dtpNamSinh.Text+"','"+txtDiaChi.Text+"'";
47 business.Insert("GiangVien",sql);
48 FormGiangVien_Load(sender,e);
49 }
50 else
51 {
52 MessageBox.Show("Mã GV đã tồn tại");
53 }
54 }
55 }
File name: FormGiangVien.cs
Copy
57 private void btnXoa_Click(object sender, EventArgs e)
58 {
59 DialogResult result;
60 result = MessageBox.Show("Bạn có chắc chắn muốn xóa không ?","Hệ Thống", MessageBoxButtons.YesNo);
61 if (result == DialogResult.Yes)
62 {
63 string sql = "MaGV='" + txtMaGV.Text + "'";
64 business.Delete("GiangVien", sql);
65 FormGiangVien_Load(sender, e);
66 }
67 }
File name: FormGiangVien.cs
Copy
76 private void txtMaGV_KeyPress(object sender, KeyPressEventArgs e)
77 {
78 if (e.KeyChar == ' ')
79 e.Handled = true;
80 }
File name: FormHeDaoTao.cs
Copy
37 private void btnThem_Click(object sender, EventArgs e)
38 {
39 if(txtMaHeDT.Text!="")
40 {
41 if (business.Proc_Insert("Insert_HeDaoTao", txtMaHeDT.Text))
42 {
43 string sql = "'" + txtMaHeDT.Text + "','" + txtTenHeDT.Text + "'";
44 business.Insert("HeDaoTao", sql);
45 FormHeDaoTao_Load(sender, e);
46 }
47 else
48 {
49 MessageBox.Show("Mã Hệ Đào Tạo đã tồn tại");
50 }
51 }
52 }
File name: FormHeDaoTao.cs
Copy
54 private void btnXoa_Click(object sender, EventArgs e)
55 {
56 DialogResult result;
57 result = MessageBox.Show("Bạn có chắc chắn muốn xóa không ?","Hệ Thống", MessageBoxButtons.YesNo);
58 if (result == DialogResult.Yes)
59 {
60 string sql = "MaHeDT = '" + txtMaHeDT.Text + "'";
61 business.Delete("HeDaoTao", sql);
62 FormHeDaoTao_Load(sender, e);
63 }
64 }
Download file with original file name:If
If 150 lượt xem
Gõ tìm kiếm nhanh...