コード例 #1
0
        public Subject[] List_Subject()
        {
            Subject sub;
            List<Subject> lstSub = new List<Subject>();
            SqlDataReader sdr = null;
            string query = "Select * From tbl_MonHoc";
            try
            {
                connect.Open_Connect();
                SqlCommand cmd = new SqlCommand(query, connect.con);
                sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    sub = new Subject();
                    sub.Code_sub = sdr[0].ToString();
                    sub.Name_sub = sdr[1].ToString();
                    lstSub.Add(sub);
                }
            }
            catch
            {
                lstSub = null;
            }
            finally
            {
                if (sdr != null)
                {
                    sdr.Close();
                }
                if (connect.con != null)
                {
                    connect.Close_Connect();
                }

            }
            return lstSub.ToArray();
        }
コード例 #2
0
        public Subject[] Search_Subject(string keyword)
        {
            List<Subject> lst_sub = new List<Subject>();
            SqlDataReader sdr = null;
            Subject sub;
            string query1 = "Select MH.* From tbl_KetQua KQ,tbl_MonHoc MH Where MSSV ='070707' And KQ.MaMonHoc = MH.MaMonHoc And MH.MaMonHoc = '"+keyword+"'";
            string query2 = "Select MH.* From tbl_KetQua KQ,tbl_MonHoc MH Where MSSV ='070707' And KQ.MaMonHoc = MH.MaMonHoc And TenMonHoc like N'%"+keyword+"%'";
            try
            {
                connect.Open_Connect();
                SqlCommand cmd1 = new SqlCommand(query1, connect.con);
                sdr = cmd1.ExecuteReader();
                if (sdr.HasRows == true)
                {
                    while (sdr.Read())
                    {
                        sub = new Subject();
                        sub.Semester = "HK";
                        sub.Code_sub = sdr[0].ToString();
                        sub.Name_sub = sdr[1].ToString();
                        sub.SoTC = (int)sdr[2];
                        sub.Sotiet = (int)sdr[3];
                        lst_sub.Add(sub);
                    }
                }
                else
                {
                    connect.Open_Connect();
                    SqlCommand cmd2 = new SqlCommand(query2, connect.con);
                    SqlDataReader sdr2 = null;
                    sdr2 = cmd2.ExecuteReader();
                    while (sdr2.Read())
                    {
                        sub = new Subject();
                        sub.Semester = "HK";
                        sub.Code_sub = sdr2[0].ToString();
                        sub.Name_sub = sdr2[1].ToString();
                        sub.SoTC = (int)sdr2[2];
                        sub.Sotiet = (int)sdr2[3];
                        lst_sub.Add(sub);
                    }
                }

            }
            catch
            {
                lst_sub = null;
            }
            finally
            {
                if (sdr != null)
                {
                    sdr.Close();
                }
                if (connect.con != null)
                {
                    connect.Close_Connect();
                }

            }
            return lst_sub.ToArray();
        }
コード例 #3
0
        public Subject[] Lec_Sub(string code_lecturer, string semester)
        {
            List<Subject> lst_sub = new List<Subject>();
            SqlDataReader sdr = null;
            Subject sub;
            string query = "Select Distinct KQ.HocKy,  MH.* From tbl_KetQua KQ, tbl_MonHoc MH Where MSGV = '" + code_lecturer + "' And KQ.HocKy = '" + semester + "' And KQ.MaMonHoc = MH.MaMonHoc";
            try
            {
                connect.Open_Connect();
                SqlCommand cmd = new SqlCommand(query, connect.con);
                sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    sub = new Subject();
                    sub.Semester = sdr[0].ToString();
                    sub.Code_sub = sdr[1].ToString();
                    sub.Name_sub = sdr[2].ToString();
                    sub.SoTC = (int)sdr[3];
                    sub.Sotiet = (int)sdr[4];
                    lst_sub.Add(sub);
                }
            }
            catch
            {
                lst_sub = null;
            }
            finally
            {
                if (sdr != null)
                {
                    sdr.Close();
                }
                if (connect.con != null)
                {
                    connect.Close_Connect();
                }

            }
            return lst_sub.ToArray();
        }