public static List <CurrentSemester> GetCurrentSemesterStudents(string Faculty, string Session, int Semester)
        {
            int batchId    = Convert.ToInt32(Session.Substring(2, 2)); //startIndex, Length
            int startRange = batchId * 100000;
            int endRange   = ((batchId + 1) * 100000) - 1;

            List <CurrentSemester> AllStudents = new List <CurrentSemester>();
            SqlConnection          con         = new SqlConnectionGenerator().FromFaculty(Faculty);

            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT * FROM CurrentSemester WHERE StudentId BETWEEN " + startRange + " AND " + endRange + " AND Semester=" + Semester + ";", con);

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        CurrentSemester CS = new CurrentSemester();
                        CS.StudentId = Convert.ToInt32(reader.GetValue(1));
                        CS.Semester  = Convert.ToInt32(reader.GetValue(2));
                        AllStudents.Add(CS);
                    }
                    reader.Close();
                }
                else
                {
                    return(null);
                }
            }
            con.Close();

            return(AllStudents);
        }
Esempio n. 2
0
        public Boolean InsertEnrollment(IDictionary <string, object> dict)
        {
            CurrentSemester currentSemester = CheckIsudentIsPresentOrNot(dict);


            if (currentSemester == null)
            {
                InsertCurrentSemester(dict);

                String sql = "";
                if (Convert.ToInt32(dict["Semester"]) % 2 == 0)
                {
                    sql = "Insert Into JulEnrollment (";
                }
                else
                {
                    sql = "Insert Into JanEnrollment (";
                }
                String value = " VALUES (";
                foreach (KeyValuePair <string, object> item in dict)
                {
                    sql   += item.Key + ", ";
                    value += "'" + item.Value + "' , ";
                }
                sql   = sql.Substring(0, sql.Length - 2);
                value = value.Substring(0, value.Length - 2);
                sql   = sql + ") " + value + ")";

                SqlCommand myCommand = new SqlCommand(sql, myConn);
                try
                {
                    myConn.Open();
                    myCommand.ExecuteNonQuery();
                }
                catch (System.Exception ex)
                {
                    return(false);
                }
                finally
                {
                    if (myConn.State == ConnectionState.Open)
                    {
                        myConn.Close();
                    }
                }
            }
            else
            {
                UpdateEnrollment(dict);
            }

            return(true);
        }
Esempio n. 3
0
        private CurrentSemester CheckIsudentIsPresentOrNot(IDictionary <string, object> dict)
        {
            CurrentSemester currentSemester = new CurrentSemester();

            String str;

            str = "SELECT * FROM CurrentSemester  WHERE StudentId ='" + dict["StudentId"] + "'";

            SqlCommand myCommand = new SqlCommand(str, myConn);

            try
            {
                myConn.Open();
                SqlDataReader oReader = myCommand.ExecuteReader();
                if (oReader.Read())
                {
                    currentSemester.StudentId = Convert.ToInt32(oReader["StudentId"]);
                    currentSemester.Semester  = Convert.ToInt32(oReader["Semester"]);
                }
                else
                {
                    currentSemester = null;
                }
            }
            catch (System.Exception ex)
            {
                return(currentSemester);
            }
            finally
            {
                if (myConn.State == ConnectionState.Open)
                {
                    myConn.Close();
                }
            }

            return(currentSemester);
        }