Else









How do I use Else
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets

Line Code Ex..
203 else 1
40 else 2
50 else 3
47 else 4
62 else 5
35 else 6
44 else 7
53 else 8
73 else 9
51 else 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: 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: 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: FormHocKy.cs Copy
52         private void btnThem_Click(object sender, EventArgs e)
53         {
54             if (txtMaHocKy.Text!="")
55             {
56                 if (business.Proc_Insert("Insert_HocKy", txtMaHocKy.Text))
57                 {
58                     string sql = "'" + txtMaHocKy.Text + "','" + txtTenHocKy.Text + "','" + txtNamHoc.Text + "','" + dtpBatDau.Text + "','" + dtpKetThuc.Text + "'";
59                     business.Insert("HocKy", sql);
60                     FormHocKy_Load(sender, e);
61                 }
62                 else
63                 {
64                     MessageBox.Show("Mã Học Kỳ đã tồn tại");
65                 }
66             }
67         }
File name: FormHocPhan.cs Copy
25         private void btnThem_Click(object sender, EventArgs e)
26         {
27             if (txtMaHP.Text != "")
28             {
29                 if (business.Proc_Insert("Insert_HocPhan", txtMaHP.Text))
30                 {
31                     string sql = "'" + txtMaHP.Text + "','" + txtTenHP.Text + "'," + Convert.ToInt32(txtSoTC.Text) + "," + Convert.ToInt32(txtSoTietTH.Text) + "," + Convert.ToInt32(txtSoTietLT.Text) + "," + Convert.ToInt32(txtPhanTramDQT.Text) + "," + Convert.ToInt32(txtPhanTramDT.Text) + "";
32                     business.Insert("HocPhan",sql);
33                     FormHocPhan_Load(sender,e);
34                 }
35                 else
36                 {
37                     MessageBox.Show("Mã Học Phần đã tồn tại");
38                 }
39             }
40         }
File name: FormKHGD.cs Copy
34         private void btnThem_Click(object sender, EventArgs e)
35         {
36             if (txtMaKHGD.Text != "")
37             {
38                 if (business.Proc_Insert("Insert_KHGD",txtMaKHGD.Text))
39                 {
40                     string sql = "'"+txtMaKHGD.Text+"','"+cmbMahocKy.SelectedValue.ToString()+"','"+cmbMaKhoiLop.SelectedValue.ToString()+"'";
41                     business.Insert("KeHoachGiangDay",sql);
42                     FormKHGD_Load(sender, e);
43                 }
44                 else
45                 {
46                     MessageBox.Show("Mã KHGD đã tồn tại rồi");
47                 }
48             }
49         }
File name: FormKhoiLop.cs Copy
43         private void btnThem_Click(object sender, EventArgs e)
44         {
45             if(txtMaKhoiLop.Text!="")
46             {
47                 if(business.Proc_Insert("Insert_KhoiLop",txtMaKhoiLop.Text))
48                 {
49                     string sql = "'" + txtMaKhoiLop.Text + "','" + txtTenKhoiLop.Text + "','" + cmbMaHeDT.SelectedValue.ToString() + "','" + cmbMaHeDT.SelectedValue.ToString() + "'";
50                     business.Insert("KhoiLop", sql);
51                     FormKhoiLop_Load(sender, e);
52                 }
53                 else
54                 {
55                     MessageBox.Show("Mã Khối Lớp đã tồn tại rồi");
56                 }
57             }
58         }
File name: FormLop.cs Copy
63         private void btnThem_Click(object sender, EventArgs e)
64         {
65             if (txtMaLop.Text != "")
66             {
67                 if (business.Proc_Insert("Insert_Lop", txtMaLop.Text))
68                 {
69                     string sql = "'"+txtMaLop.Text+"','"+txtTenLop.Text+"','"+cmbMaKhoiLop.SelectedValue.ToString()+"','"+cmbMaGV.SelectedValue.ToString()+"'";
70                     business.Insert("Lop",sql);
71                     FormLop_Load(sender,e);
72                 }
73                 else
74                 {
75                     MessageBox.Show("Mã Lớp đã tồn tại");
76                 }
77             }
78         }
File name: FormNhomHocPhan.cs Copy
41         private void btnThem_Click(object sender, EventArgs e)
42         {
43             if (txtMaNhomHP.Text != "")
44             {
45                 if (business.Proc_Insert("Insert_NhomHocPhan", txtMaNhomHP.Text))
46                 {
47                     string sql = "'"+txtMaNhomHP.Text+"','"+txtTenNhomHP.Text+"','"+cmbMaHP.SelectedValue.ToString()+"','"+cmbMaKHGD.SelectedValue.ToString()+"','"+cmbMaGV.SelectedValue.ToString()+"'";
48                     business.Insert("NhomHocPhan", sql);
49                     FormNhomHocPhan_Load(sender, e);
50                 }
51                 else
52                 {
53                     MessageBox.Show("Mã SV đã tồn tại");
54                 }
55             }
56         }

Else 107 lượt xem

Gõ tìm kiếm nhanh...