private void EnterStudentClassInfo(string clas, string section)
        {
            SqlConnection conn = null;

            try
            {
                conn = RegisterStudentToDB.ConnectDB();

                conn.Open();
                string     checkDuplicate = "select ClassId from Class where ClassName='" + clas + "'";
                SqlCommand cmd            = new SqlCommand(checkDuplicate, conn);



                /*string enterClassInfo = "insert into Class values('" + section + "','" + clas + "',null,null,null);SELECT @@IDENTITY ";
                 * cmd = new SqlCommand(enterClassInfo, conn);*/
                ident = cmd.ExecuteScalar();

                clsIndentity = long.Parse(ident.ToString());

                conn.Close();
            }
            catch (Exception e)
            {
            }
        }
        private static long insertCountry(string country)
        {
            long          identity = 0;
            object        ident    = null;
            SqlConnection conn     = null;

            conn = RegisterStudentToDB.ConnectDB();
            string enterCountry = "insert into Country values('" + country + "'); SELECT @@IDENTITY ";

            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(enterCountry, conn);
                ident = cmd.ExecuteScalar();

                identity = long.Parse(ident.ToString());

                conn.Close();

                return(identity);
            }
            catch (Exception e)
            {
                throw;
            }
        }
        public string DataToDB(int userid, string clas, string clsroom, string section, int vac, int normal, int deb, int hep)
        {
            enterMedicalInfo(vac, normal, deb, hep);
            EnterStudentClassInfo(clas, section);
            SqlConnection conn = null;

            try
            {
                stdRollNo = clas + section + userid;
                conn      = RegisterStudentToDB.ConnectDB();

                conn.Open();

                string     enterClassInfo = "insert into Student values('" + stdRollNo + "','" + clsIndentity + "','" + userid + "','" + medIdentity + "','" + Convert.ToString(System.DateTime.Now) + "','" + clas + "');SELECT @@IDENTITY ";
                SqlCommand cmd            = new SqlCommand(enterClassInfo, conn);
                ident = cmd.ExecuteScalar();

                clsIndentity = long.Parse(ident.ToString());

                conn.Close();
                return(stdRollNo);
            }
            catch (Exception e)
            {
            }
            return(null);
        }
        public bool makeIncharge(string cls, string teacher)
        {
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();

            int uid = 0;

            try
            {
                conn.Open();
                string         getcourseid = "select UserId from Userz where (FName='" + teacher + "' and User_Type='teacher')";
                DataSet        ds          = new DataSet();
                SqlDataAdapter dabt        = new SqlDataAdapter(getcourseid, conn);
                dabt.Fill(ds, "Userz");
                DataTable dt   = ds.Tables["Userz"];
                string    cid1 = ds.Tables[0].Rows[0][0].ToString();
                uid = Int32.Parse(cid1);
                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }
            try
            {
                int cid = 0;
                conn.Open();
                string         getclsid = "select ClassId from Class where ClassName='" + cls + "'";
                DataSet        ds       = new DataSet();
                SqlDataAdapter dabt     = new SqlDataAdapter(getclsid, conn);
                dabt.Fill(ds, "Class");
                DataTable dt   = ds.Tables["Class"];
                string    cid1 = ds.Tables[0].Rows[0][0].ToString();
                cid = Int32.Parse(cid1);
                if (cid != 0)
                {
                    SqlCommand    cmd       = null;
                    SqlDataReader dr        = null;
                    string        updateCmd = "UPDATE Teacher SET ClassIncharge='" + cid + "' WHERE User_Id='" + uid + "'";
                    cmd = new SqlCommand(updateCmd, conn);
                    dr  = cmd.ExecuteReader();
                    bool i = dr.HasRows;
                    if (i)
                    {
                        return(false);
                    }
                    dr.Close();

                    conn.Close();
                    return(true);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(false);
        }
        public String changePasswordDLL(string txtUsername, string txtPassword, string txtNewPassword, string ConfirmNewPassword, int flag)
        {
            SqlConnection conn = RegisterStudentToDB.ConnectDB();
            //string type = null;

            string verifyCmd = "select UserName, Password from Login where UserName= '******' AND Password='******'";

            string updateCmd = "UPDATE Login SET Password='******' WHERE UserName='******'";

            try
            {
                conn.Open();
                SqlCommand    cmd;
                SqlDataReader dr;
                bool          i;

                if (flag == 0)
                {
                    cmd = new SqlCommand(verifyCmd, conn);
                    dr  = cmd.ExecuteReader();
                    i   = dr.HasRows;
                    if (!i)
                    {
                        return(" Old Password that you provided is Incorrect, Enter Again.");
                    }
                    dr.Close();
                }
                else if (flag == 1)
                {
                    verifyCmd = "select UserName from Login where UserName= '******'";
                    cmd       = new SqlCommand(verifyCmd, conn);
                    dr        = cmd.ExecuteReader();
                    i         = dr.HasRows;
                    if (!i)
                    {
                        return(" User does not exist, Enter Again.");
                    }
                    dr.Close();
                }

                cmd = new SqlCommand(updateCmd, conn);
                dr  = cmd.ExecuteReader();
                i   = dr.HasRows;
                if (i)
                {
                    return("password updation failed.");
                }
                dr.Close();
                conn.Close();
            }
            catch
            {
                throw;
            }

            return("Password Updated Successfully. Use your New Password now.");
        }
        public string display4UpdateStudentsDLL(string rollNo, string date)
        {
            string        sid  = null;
            DateTime      d    = DateTime.Parse(date);
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();
            try
            {
                conn.Open();
                string         getStudentID = "select StudentId from Student where StudentRollNo='" + rollNo + "'";
                DataSet        ds           = new DataSet();
                SqlDataAdapter dabt         = new SqlDataAdapter(getStudentID, conn);
                dabt.Fill(ds, "Student");
                DataTable dt = ds.Tables["Student"];
                sid = ds.Tables[0].Rows[0][0].ToString();
                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }
            try
            {
                conn.Open();

                string         getStudents = "select  isPresent from Attandance where (StudentId='" + sid + "' and date='" + d + "')";
                DataSet        dsStudents  = new DataSet();
                SqlDataAdapter dast        = new SqlDataAdapter(getStudents, conn);
                dast.Fill(dsStudents, "present");
                DataTable dtStudents = dsStudents.Tables["present"];
                string    isP;
                if (dsStudents.Tables[0].Rows.Count == 0)
                {
                    return("false");
                }
                isP = dsStudents.Tables[0].Rows[0][0].ToString();


                conn.Close();
                if (isP == "A")
                {
                    return(rollNo);
                }
                else
                {
                    return("P");
                }
                //return absentRollNo;
            }
            catch (Exception)
            {
                throw;
            }
        }
        public string getTeacherDetailsDLL(string tName)
        {
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();
            try
            {
                conn.Open();

                string         getUserID = "select UserId from Userz where (FName='" + tName + "' and User_Type='teacher')";
                DataSet        ds        = new DataSet();
                SqlDataAdapter dabt      = new SqlDataAdapter(getUserID, conn);
                dabt.Fill(ds, "Userz");
                DataTable dt  = ds.Tables["Userz"];
                string    uid = ds.Tables[0].Rows[0][0].ToString();

                string  getClassIncharge = "select ClassIncharge from Teacher where User_Id='" + uid + "'";
                DataSet ds1 = new DataSet();
                dabt = new SqlDataAdapter(getClassIncharge, conn);
                dabt.Fill(ds1, "class");
                DataTable dt1           = ds1.Tables["class"];
                string    classIncharge = null;
                if (ds1.Tables[0].Rows.Count == 0)
                {
                    classIncharge = "0";
                    return(classIncharge);
                }
                else
                {
                    classIncharge = ds1.Tables[0].Rows[0][0].ToString();
                }

                string getClassName = "select ClassName from Class where ClassId='" + classIncharge + "'";
                ds   = new DataSet();
                dabt = new SqlDataAdapter(getClassName, conn);
                dabt.Fill(ds, "C");
                DataTable dt2 = ds.Tables["C"];
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return("0");
                }
                string name = ds.Tables[0].Rows[0][0].ToString();
                conn.Close();

                return(name);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public DataSet getMarks4StudentsDLL(string rollNo)
        {
            DataSet       s    = new DataSet();
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();
            long   sid          = 0;
            string getStudentId = "select StudentId from Student where  StudentRollNo= '" + rollNo + "'";

            try
            {
                conn.Open();

                SqlDataAdapter CourseDetails = new SqlDataAdapter(getStudentId, conn);
                DataSet        ds            = new DataSet();
                CourseDetails.Fill(ds, "std");
                //conn.Close();
                DataTable dt = ds.Tables["std"];
                sid = long.Parse(ds.Tables[0].Rows[0][0].ToString());

                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }

            string getMarks = "select SubjectName,SubjectType,TotalMarks,ObtainedMarks,Test1Marks,Test2Marks,Test3Marks,Test4Marks,Test5Marks,Assignment1Marks,Assignment2Marks,Assignment3Marks,Assignment4Marks,Assignment5Marks,weightage from Subject s,Tests_Assignments a where  (s.StudentId= '" + sid + "' and a.TestId=s.Test_Id)";

            try
            {
                conn.Open();

                SqlDataAdapter CourseDetails = new SqlDataAdapter(getMarks, conn);
                s = new DataSet();
                CourseDetails.Fill(s, "marks");
                //conn.Close();
                DataTable dt = s.Tables["marks"];

                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            return(s);
        }
예제 #9
0
        public DataSet getclassinfo(string clsname)
        {
            int clsnam = Int32.Parse(clsname);
            int cid    = 0;

            //int crid = 0;
            try
            {
                SqlConnection conn = null;
                //int clsIdentity = 0;
                //object ident = null;
                //int cid = 0;

                conn = RegisterStudentToDB.ConnectDB();
                conn.Open();
                string         getclassid = "select ClassRoom_Id from Class where ClassName='" + clsnam + "'";
                DataSet        ds         = new DataSet();
                SqlDataAdapter dabt       = new SqlDataAdapter(getclassid, conn);
                dabt.Fill(ds, "Class");
                DataTable dt = ds.Tables["Class"];
                if (ds.Tables[0].Rows.Count != 0)
                {
                    string cid1 = ds.Tables[0].Rows[0][0].ToString();

                    cid = Int32.Parse(cid1);
                }
                //return ds;
                if (cid != 0)
                {
                    string getinfo = "select * from ClassRooms where (ClassRoomId='" + cid + "')";
                    obj = new SqlDataAdapter(getinfo, conn);
                    DataSet ds1 = new DataSet();
                    obj.Fill(ds1, "classinfo");
                    if (ds1.Tables[0].Rows.Count != 0)
                    {
                        return(ds1);
                    }
                }
                conn.Close();
                return(ds);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public String login(string txtUsername, string txtPassword)
        {
            SqlConnection conn      = RegisterStudentToDB.ConnectDB();
            string        type      = null;
            string        verifyCmd = "select UserName, Password from Login where UserName= '******' AND Password='******'";
            string        loginCmd  = "select LoginId from Login where UserName= '******' AND Password='******'";

            try
            {
                conn.Open();

                SqlCommand    cmd = new SqlCommand(verifyCmd, conn);
                SqlDataReader dr  = cmd.ExecuteReader();
                bool          i   = dr.HasRows;
                if (!i)
                {
                    return(null);        // case: user name and password is incorrect.
                }
                dr.Close();
                SqlDataAdapter userType = new SqlDataAdapter(loginCmd, conn);
                DataSet        ds       = new DataSet();
                userType.Fill(ds, "Login");
                conn.Close();
                DataTable dt  = ds.Tables["Login"];
                string    LID = ds.Tables[0].Rows[0][0].ToString();
                //conn.Close();
                //return LID;
                //conn.Open();
                string chkUserTypeCmd = "select * from Userz where Login_Id= '" + LID + "' ";
                userType = new SqlDataAdapter(chkUserTypeCmd, conn);
                DataSet ds1 = new DataSet();
                userType.Fill(ds1, "Userz");
                conn.Close();
                DataTable dt1 = ds1.Tables["Userz"];
                type = ds1.Tables[0].Rows[0][8].ToString();

                conn.Close();
            }
            catch
            {
                throw;
            }

            return(type);
        }
예제 #11
0
        public bool editUserdetail(DataSet Ds, string userName)
        {
            string fname   = Ds.Tables[0].Rows[0][0].ToString();
            string lname   = Ds.Tables[0].Rows[0][1].ToString();
            string phoneNo = Ds.Tables[0].Rows[0][2].ToString();
            string Mob     = Ds.Tables[0].Rows[0][3].ToString();
            string email   = Ds.Tables[0].Rows[0][4].ToString();
            string homeadd = Ds.Tables[0].Rows[0][5].ToString();



            try
            {
                conn = RegisterStudentToDB.ConnectDB();
                conn.Open();
                string         getLoginId  = "select LoginId from Login where username = '******'";
                SqlDataAdapter userLoginId = new SqlDataAdapter(getLoginId, conn);
                DataSet        ds1         = new DataSet();
                userLoginId.Fill(ds1);

                //DataTable dt = ds1.Tables["Login"];
                string lid = ds1.Tables[0].Rows[0][0].ToString();
                loginid = Int32.Parse(lid);

                string updateuserdetail = "UPDATE Userz set FName='" + fname + "', LName ='" + lname + "',PhoneNo='" + phoneNo + "', MobNo ='" + Mob + "',EmailAdress='" + email + "',Address='" + homeadd + "'"
                                          + "where Login_Id='" + loginid + "'";
                SqlCommand cmd = null;
                //SqlDataReader dr = null;
                int dr = 0;
                cmd = new SqlCommand(updateuserdetail, conn);
                dr  = cmd.ExecuteNonQuery();

                if (dr > 0)
                {
                    return(true);
                }
                conn.Close();

                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public string Add_Course_DLL(string course, string type)
        {
            course = course.ToLower();
            type   = type.ToLower();
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();
            string checkDuplicatonCmd = "select * from Courses where CourseName = '" + course + "'";

            try
            {
                conn.Open();
                SqlCommand    cmd = new SqlCommand(checkDuplicatonCmd, conn);
                SqlDataReader dr  = cmd.ExecuteReader();
                bool          i   = dr.HasRows;
                if (i)
                {
                    return("Course Already Exist");
                }

                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }

            string AddCourseCommand = "insert into Courses values('" + course + "', '" + type + "')";

            //string AddCourseCommand = "insert into Sujects values('" + course + "', '" + type + "')";
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(AddCourseCommand, conn);
                cmd.ExecuteScalar();
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }

            return("Course Added Successfully");
        }
예제 #13
0
        public DataSet getUserDetail(string userName)
        {
            try
            {
                conn = RegisterStudentToDB.ConnectDB();
                conn.Open();
                string         getLoginId  = "select LoginId from Login where username = '******'";
                SqlDataAdapter userLoginId = new SqlDataAdapter(getLoginId, conn);
                DataSet        ds1         = new DataSet();
                userLoginId.Fill(ds1);

                //DataTable dt = ds1.Tables["Login"];
                string lid = ds1.Tables[0].Rows[0][0].ToString();
                loginid = Int32.Parse(lid);
                conn.Close();
                //return ds1;
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                //DataSet ds2 = new DataSet();
                //conn = RegisterStudentToDB.ConnectDB();
                conn.Open();
                ds = new DataSet();
                string getuserdetail = "select FName as 'First Name', LName as 'Last Name',PhoneNo as 'Phone No', MobNo as 'Mobile No',EmailAdress as 'Email Address',Address as 'Home Address'"
                                       + " from Userz where Login_Id='" + loginid + "'";

                SqlDataAdapter dapt2 = new SqlDataAdapter(getuserdetail, conn);
                dapt2.Fill(ds);
                //if (ds.Tables[0].Rows.Count>0)
                //{
                return(ds);
                // }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public DataSet displayStudentsDLL(string className)
        {
            string        cid  = null;
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();
            try
            {
                conn.Open();
                string         getClassID = "select ClassId from Class where ClassName='" + className + "'";
                DataSet        ds         = new DataSet();
                SqlDataAdapter dabt       = new SqlDataAdapter(getClassID, conn);
                dabt.Fill(ds, "Class");
                DataTable dt = ds.Tables["Class"];
                cid = ds.Tables[0].Rows[0][0].ToString();
                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }
            try
            {
                conn.Open();

                string         getStudents = "select StudentRollNo from Student where Class_id='" + cid + "'";
                DataSet        dsStudents  = new DataSet();
                SqlDataAdapter dast        = new SqlDataAdapter(getStudents, conn);
                dast.Fill(dsStudents, "student");
                DataTable dtStudents = dsStudents.Tables["student"];
                //string rollNo = dsStudents.Tables[0].Rows[0][0].ToString();

                conn.Close();
                return(dsStudents);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public DataSet getAttendanceDLL(string rollNo)
        {
            string        sid;
            string        lid;
            string        aid;
            SqlConnection conn = RegisterStudentToDB.ConnectDB();

            try
            {
                conn.Open();
                string         getStudentID = "select StudentId from Student where StudentRollNo='" + rollNo + "'";
                DataSet        ds           = new DataSet();
                SqlDataAdapter dabt         = new SqlDataAdapter(getStudentID, conn);
                dabt.Fill(ds, "Student");
                DataTable dt = ds.Tables["Student"];
                sid = ds.Tables[0].Rows[0][0].ToString();
                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                conn.Open();
                string         getAttendance = "select date,isPresent from Attandance where StudentId='" + sid + "'";
                DataSet        ds            = new DataSet();
                SqlDataAdapter dabt          = new SqlDataAdapter(getAttendance, conn);
                dabt.Fill(ds, "Student");
                DataTable dt = ds.Tables["Student"];
                //aid = ds.Tables[0].Rows[0][1].ToString();
                conn.Close();
                return(ds);
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void enterMedicalInfo(int vac, int normal, int deb, int hep)
        {
            SqlConnection conn = null;

            try
            {
                conn = RegisterStudentToDB.ConnectDB();

                conn.Open();

                string     enterMedicalInfo = "insert into MedicalInfo values('" + vac + "','" + deb + "','" + hep + "','" + normal + "');SELECT @@IDENTITY ";
                SqlCommand cmd = new SqlCommand(enterMedicalInfo, conn);
                ident = cmd.ExecuteScalar();

                medIdentity = long.Parse(ident.ToString());

                conn.Close();
            }
            catch (Exception e)
            {
            }
        }
        public string Delete_Course_DLL(String course)
        {
            SqlConnection conn      = RegisterStudentToDB.ConnectDB();
            string        verifyCmd = "select CourseName from Courses where CourseName= '" + course + "'";

            //string loginCmd = "select LoginId from Login where UserName= '******' AND Password='******'";
            try
            {
                conn.Open();

                SqlCommand    cmd = new SqlCommand(verifyCmd, conn);
                SqlDataReader dr  = cmd.ExecuteReader();
                bool          i   = dr.HasRows;
                if (!i)
                {
                    return("No Such Course Exist.");
                }

                dr.Close();
                string deleteCmd = "DELETE FROM Courses WHERE CourseName='" + course + "'";
                cmd = new SqlCommand(deleteCmd, conn);
                dr  = cmd.ExecuteReader();
                i   = dr.HasRows;
                if (i)
                {
                    return("Course deletion error, try again.");
                }

                dr.Close();
                conn.Close();
            }
            catch
            {
                throw;
            }

            return("Course Deleted Successfully.");
        }
예제 #18
0
        public bool updateclass(DataSet a)
        {
            //    obj.Update(ds1);
            // return true;
            SqlConnection conn = null;

            try
            {
                int capacity = Int32.Parse(a.Tables[0].Rows[0][1].ToString());
                int roomno   = Int32.Parse(a.Tables[0].Rows[0][2].ToString());
                int roomid   = Int32.Parse(a.Tables[0].Rows[0][0].ToString());
                conn = RegisterStudentToDB.ConnectDB();

                string update = "UPDATE ClassRooms SET ClassCapacity='" + capacity + "'"
                                + ",ClassROomNumber='" + roomno + "'"
                                + ",ClassRoomStatus='" + a.Tables[0].Rows[0][3].ToString() + "' "
                                + "WHERE (ClassRoomId='" + roomid + "')";
                conn.Open();
                SqlCommand    cmd = null;
                SqlDataReader dr  = null;
                bool          i   = false;
                cmd = new SqlCommand(update, conn);
                dr  = cmd.ExecuteReader();
                i   = dr.HasRows;
                if (i)
                {
                    return(true);
                }
                dr.Close();
                conn.Close();
                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void searchStudents(DataSet stdInfo)
        {
            SetInfo(stdInfo);
            makeQuery();
            SqlConnection  conn  = null;
            SqlDataAdapter stdDA = null;

            //DataSet stdDS = new DataSet(); ;, Country.CountryName AS Country, City.CityName AS City " +



            /*string cmd = " SELECT Registration.RegistraionDate, Registration.RegisteredInClass,Userz.FName AS 'Frist Name', Userz.LName AS 'Last Name', " +
             *  "Userz.PhoneNo AS 'Ph No', Userz.MobNo AS 'Mobile No', Userz.EmailAdress AS Email, Userz.Address " +
             *  "FROM Registration"+
             *  "INNER JOIN  Userz ON Registration.RegistrationId = Userz.RegistrationId " +
             * "INNER JOIN Country ON Userz.Country_Id = Country.CountryId " +
             * "INNER JOIN City ON Country.CountryId = City.CountryId " +
             * "where ((Registration.RegistraionId='" + registrationNo + "') AND (Userz.FName='" + fname + "' ))" +
             * " OR((Userz.FName='" + fname + "') AND (Userz.LName='" + lname + "')) " +
             * " OR (Userz.FName='" + fname + "') OR (Userz.LName='" + lname + "') OR (City.CityName='" + city + "') OR (Country.CountryName='" + Country + "')";
             *
             * //"ORDER BY 'Frist Name', 'Last Name'"; */
            try
            {
                conn = RegisterStudentToDB.ConnectDB();
                conn.Open();
                stdDA = new SqlDataAdapter(cmd, conn);

                stdDA.Fill(stdInfo);
                return;
            }
            catch (Exception e)
            {
                e.StackTrace.GetType();
            }
        }
예제 #20
0
        public DataSet returnUserz()
        {
            conn = RegisterStudentToDB.ConnectDB();
            ds   = new DataSet();
            string getUserQuery = "select UserName from Login";

            try
            {
                conn.Open();
                dapt = new SqlDataAdapter(getUserQuery, conn);
                dapt.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    return(ds);
                }
                //dapt.Fill(
                conn.Close();
                return(ds);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public string enterStudentMarksDLL(string userName, string className, string subjectName, ref DataSet res)
        {
            DataSet       s    = new DataSet();
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();
            DataSet result = new DataSet();
            int     lid, uid, stdid, cid, tid, subid;
            string  getLoginId = "select LoginId from  Login where  UserName= '******'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getLoginId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "login");

                DataTable dt = ds.Tables["login"];
                lid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }


            string getUserId = "select UserId from Userz where  Login_Id= '" + lid + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getUserId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "user");
                DataTable dt = ds.Tables["user"];
                uid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }


            string getTeacherId = "select TeacherId from Teacher where  User_Id= '" + uid + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getTeacherId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "teacher");
                DataTable dt = ds.Tables["teacher"];
                tid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            string getClassId = "select ClassId from Class where  ClassName= '" + className + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getClassId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "class");
                DataTable dt = ds.Tables["class"];
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return("This Class doesnt Exist");
                }
                cid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            string cType;
            string getCourseId = "select CourseId,CourseType from Courses where  CourseName= '" + subjectName + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getCourseId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "course");
                DataTable dt = ds.Tables["course"];
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return("This Subject doesnt Exist, Enter Again");
                }
                subid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                cType = ds.Tables[0].Rows[0][1].ToString();
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }

            string chkClassSubject = "select * from Subject where  (TeacherId= '" + tid + "' and ClassId='" + cid + "' and SubjectName='" + subjectName + "')";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(chkClassSubject, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "CS");
                DataTable dt = ds.Tables["CS"];
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return("This Subject is not Associated with this Class or you might not have been assigned to this class or subject., Enter Again");
                }
                //csid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            string getClassStudents = "select StudentId from Student where Class_Id='" + cid + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getClassStudents, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(res, "std");
                DataTable dt = res.Tables["std"];
                if (res.Tables[0].Rows.Count == 0)
                {
                    return("There are no students addmitted in this class yet.");
                }
                //csid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            string getAllMarks = "select StudentRollNo,SubjectName,SubjectType,TotalMarks,ObtainedMarks,Test1Marks,Test2Marks,Test3Marks,Test4Marks,Test5Marks,Assignment1Marks,Assignment2Marks,Assignment3Marks,Assignment4Marks,Assignment5Marks,weightage from Subject s,Tests_Assignments a, Student std where  (s.TeacherId= '" + tid + "' and s.ClassId= '" + cid + "' and s.SubjectName= '" + subjectName + "' and std.StudentId=s.StudentId and a.TestId=s.Test_Id)";

            try
            {
                conn.Open();
                SqlDataAdapter marks = new SqlDataAdapter(getAllMarks, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "allMarks");
                DataTable dt = ds.Tables["allMarks"];
                if (ds.Tables[0].Rows.Count != 0)
                {
                    return("Marks have all ready been entered for this subject. To view/update go back and select 'View/Update Marks'.");
                }
                //csid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            int testId;

            for (int i = 0; i < res.Tables[0].Rows.Count; i++)
            {
                int a;
                testId = 0;
                a      = Int32.Parse(res.Tables[0].Rows[i][0].ToString());
                string createMarksAreaInTest = "insert into Tests_Assignments values(null,null,null,null,null,null,null,null,null,null,50);SELECT @@IDENTITY";
                try
                {
                    conn.Open();

                    SqlCommand cmd       = new SqlCommand(createMarksAreaInTest, conn);
                    Object     testIdent = cmd.ExecuteScalar();
                    testId = Int32.Parse(testIdent.ToString());
                    conn.Close();
                }
                catch (Exception e)
                {
                    throw;
                }
                string createMarksAreaInSubject = "insert into Subject values('" + subjectName + "','" + cType + "',100,null,'" + testId + "','" + a + "','" + tid + "','" + cid + "');SELECT @@IDENTITY";
                try
                {
                    conn.Open();

                    SqlCommand cmd      = new SqlCommand(createMarksAreaInSubject, conn);
                    Object     subIdent = cmd.ExecuteScalar();
                    //Id = Int32.Parse(testIdent.ToString());
                    conn.Close();
                }
                catch (Exception e)
                {
                    throw;
                }
            }
            res.Clear();
            res.Reset();
            getAllMarks = "select StudentRollNo,SubjectName,SubjectType,TotalMarks,ObtainedMarks,Test1Marks,Test2Marks,Test3Marks,Test4Marks,Test5Marks,Assignment1Marks,Assignment2Marks,Assignment3Marks,Assignment4Marks,Assignment5Marks,weightage from Subject s,Tests_Assignments a, Student std where  (s.TeacherId= '" + tid + "' and s.ClassId= '" + cid + "' and s.SubjectName= '" + subjectName + "' and std.StudentId=s.StudentId and a.TestId=s.Test_Id)";
            try
            {
                conn.Open();
                SqlDataAdapter marks = new SqlDataAdapter(getAllMarks, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(res, "allMarks");
                DataTable dt = res.Tables["allMarks"];
                if (res.Tables[0].Rows.Count == 0)
                {
                    return("Memory allocation error.");
                }
                //csid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            return("true");
        }
        public void getStudentDetailsDLL(string userName, ref string fName, ref string lName, ref string rollNo)
        {
            string        sid;
            string        lid;
            string        uid;
            SqlConnection conn = RegisterStudentToDB.ConnectDB();

            try
            {
                conn.Open();
                lid = "select LoginId from Login where UserName='******'";
                DataSet        ds   = new DataSet();
                SqlDataAdapter dabt = new SqlDataAdapter(lid, conn);
                dabt.Fill(ds, "l");
                DataTable dt = ds.Tables["l"];
                lid = ds.Tables[0].Rows[0][0].ToString();
                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                conn.Open();
                string         getName = "select UserId,FName,LName from Userz where Login_Id='" + lid + "'";
                DataSet        ds      = new DataSet();
                SqlDataAdapter dabt    = new SqlDataAdapter(getName, conn);
                dabt.Fill(ds, "Student");
                DataTable dt = ds.Tables["Student"];

                uid   = ds.Tables[0].Rows[0][0].ToString();
                fName = ds.Tables[0].Rows[0][1].ToString();
                lName = ds.Tables[0].Rows[0][2].ToString();

                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                conn.Open();
                string         getRollNo = "select StudentRollNo from Student where UserId='" + uid + "'";
                DataSet        ds        = new DataSet();
                SqlDataAdapter dabt      = new SqlDataAdapter(getRollNo, conn);
                dabt.Fill(ds, "Std");
                DataTable dt = ds.Tables["Std"];

                rollNo = ds.Tables[0].Rows[0][0].ToString();

                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #23
0
        public bool enterClassToDb(string clsname, string section, string roomno, string capacity, string st)
        {
            SqlConnection conn        = null;
            int           clsIdentity = 0;
            object        ident       = null;
            int           cid         = 0;


            try
            {
                conn = RegisterStudentToDB.ConnectDB();
                conn.Open();
                string         getclassid = "select ClassId from Class where ClassName='" + clsname + "'";
                DataSet        ds         = new DataSet();
                SqlDataAdapter dabt       = new SqlDataAdapter(getclassid, conn);
                dabt.Fill(ds, "Class");
                DataTable dt = ds.Tables["Class"];
                if (ds.Tables[0].Rows.Count != 0)
                {
                    string cid1 = ds.Tables[0].Rows[0][0].ToString();
                    cid = Int32.Parse(cid1);
                }

                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }

            if (cid != 0)
            {
                return(false);
            }

            else
            {
                try
                {
                    // conn = RegisterStudentToDB.ConnectDB();
                    conn.Open();

                    string     enterClassRoomInfo = "insert into ClassRooms values('" + capacity + "','" + roomno + "','" + st + "');SELECT @@IDENTITY ";
                    SqlCommand cmd = new SqlCommand(enterClassRoomInfo, conn);
                    ident = cmd.ExecuteScalar();

                    clsIdentity = Int32.Parse(ident.ToString());
                    // return clsIdentity;
                    conn.Close();
                    //return true;
                }
                catch (Exception)
                {
                    throw;
                }

                try
                {
                    conn.Open();


                    string     enterClassInfo = "insert into Class values('" + section + "','" + clsname + "','" + clsIdentity + "',null,null);SELECT @@IDENTITY ";
                    SqlCommand cmd            = new SqlCommand(enterClassInfo, conn);
                    ident = cmd.ExecuteScalar();

                    clsIdentity = Int32.Parse(ident.ToString());
                    conn.Close();

                    /* string enterClassInfo = "insert into Class values('" + section + "','" + clsname + "','"+clsIdentity+"',null,null)";
                     * SqlCommand cmd1 = new SqlCommand(enterClassInfo, conn);
                     * ident = cmd1.ExecuteScalar();
                     * conn.Close();*/
                    return(true);
                    //return clsIdentity;
                }

                catch (Exception)
                {
                    throw;
                }

                return(false);
            }
        }
        public string markAttendanceDLL(string rollNo, string date, string isPresent, int flag)
        {
            DateTime      d = DateTime.Parse(date);
            string        sid;
            string        aid  = "0";
            SqlConnection conn = RegisterStudentToDB.ConnectDB();

            try
            {
                conn.Open();
                string         getStudentID = "select StudentId from Student where StudentRollNo='" + rollNo + "'";
                DataSet        ds           = new DataSet();
                SqlDataAdapter dabt         = new SqlDataAdapter(getStudentID, conn);
                dabt.Fill(ds, "student");
                DataTable dt = ds.Tables["student"];
                sid = ds.Tables[0].Rows[0][0].ToString();
                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }
            try
            {
                conn.Open();
                string         check = "select AttandanceId from Attandance where StudentId='" + sid + "' and date='" + d + "'";
                DataSet        ds    = new DataSet();
                SqlDataAdapter dabt  = new SqlDataAdapter(check, conn);
                dabt.Fill(ds, "s");
                DataTable dt = ds.Tables["s"];
                if (ds.Tables[0].Rows.Count != 0)
                {
                    aid = ds.Tables[0].Rows[0][0].ToString();

                    if (flag == 0)
                    {
                        return("false");
                    }
                }
                conn.Close();

                /*if (Int32.Parse(aid) > 0)
                 * {
                 * }
                 * else
                 *  return "false";*/
            }
            catch (Exception)
            {
                throw;
            }
            try
            {
                string markAttendance = null;
                conn.Open();

                /*if(isPresent.ToLower()=="p")
                 * {
                 *  markAttendance = "insert into Attandance values('"+ date +"',P,null,'"+ sid +"');SELECT @@ IDENTITY";
                 * }*/
                //else if (isPresent.ToLower() == "a")
                if (flag == 0)//0 means inserting new attendance values
                {
                    markAttendance = "insert into Attandance values('" + d + "','" + isPresent + "',null,'" + sid + "'); SELECT @@IDENTITY ";
                }
                else if (flag == 1)//1 means query for updating exitisting attendance
                {
                    markAttendance = "update Attandance set isPresent='" + isPresent + "' where (date='" + d + "' and StudentId= '" + sid + "' )";
                }
                SqlCommand cmd = new SqlCommand(markAttendance, conn);
                object     ident;
                if (flag == 0)
                {
                    ident = cmd.ExecuteScalar();
                    int AttendanceID = Int32.Parse(ident.ToString());
                    if (AttendanceID > 0)
                    {
                        return("true");
                    }
                }
                else if (flag == 1)
                {
                    cmd.ExecuteScalar();


                    return("true");
                }

                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }
            return("false");
        }
        public bool assignSubjectToTeacher(string tName, string clname, string sbname, string sbt, string clsSec)
        {
            SqlConnection conn     = null;
            int           courseid = 0;
            int           cid      = 0;
            int           uid      = 0;
            int           tid      = 0;

            conn = RegisterStudentToDB.ConnectDB();
            try
            {
                conn.Open();
                string         getcourseid = "select CourseID from Courses where CourseName='" + sbname + "'";
                DataSet        ds          = new DataSet();
                SqlDataAdapter dabt        = new SqlDataAdapter(getcourseid, conn);
                dabt.Fill(ds, "Courses");
                DataTable dt   = ds.Tables["Courses"];
                string    cid1 = ds.Tables[0].Rows[0][0].ToString();
                courseid = Int32.Parse(cid1);
                //if(cid!=0)
                //    return cid;


                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                conn.Open();
                string         getclassid = "select ClassId from Class where ClassName='" + clname + "'";
                DataSet        ds         = new DataSet();
                SqlDataAdapter dabt       = new SqlDataAdapter(getclassid, conn);
                dabt.Fill(ds, "Class");
                DataTable dt   = ds.Tables["Class"];
                string    cid1 = ds.Tables[0].Rows[0][0].ToString();
                cid = Int32.Parse(cid1);
                //if (cid != 0)
                //  return cid;


                conn.Close();
            }
            catch (Exception)
            {
                throw;
            }


            try
            {
                conn.Open();
                string         getcourseid = "select UserId from Userz where (FName='" + tName + "' and User_Type='teacher')";
                DataSet        ds          = new DataSet();
                SqlDataAdapter dabt        = new SqlDataAdapter(getcourseid, conn);
                dabt.Fill(ds, "Userz");
                DataTable dt   = ds.Tables["Userz"];
                string    cid1 = ds.Tables[0].Rows[0][0].ToString();
                uid = Int32.Parse(cid1);
                //if (uid != 0)
                //  return ;
                bool i;

                SqlCommand    cmd       = null;
                SqlDataReader dr        = null;
                string        updateCmd = "UPDATE Teacher SET Class_Id='" + cid + "',CourseId='" + courseid + "' WHERE User_Id='" + uid + "'";
                cmd = new SqlCommand(updateCmd, conn);
                dr  = cmd.ExecuteReader();
                i   = dr.HasRows;
                if (i)
                {
                    return(false);
                }
                dr.Close();
                conn.Close();
                //return true;
            }
            catch (Exception)
            {
                throw;
            }
            string getTeacherId = "select TeacherId from Teacher where  User_Id= '" + uid + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getTeacherId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "teacher");
                DataTable dt = ds.Tables["teacher"];
                tid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }

            string insertSubject = "insert into Subject values('" + sbname + "','" + sbt + "',100,null,null,null,'" + tid + "','" + cid + "')";

            try
            {
                conn.Open();

                SqlCommand cmd      = new SqlCommand(insertSubject, conn);
                Object     subIdent = cmd.ExecuteScalar();
                //Id = Int32.Parse(testIdent.ToString());
                conn.Close();
                return(true);
            }
            catch (Exception e)
            {
                throw;
            }


            return(false);
        }
        public String Assign_To_Class_DLL(string course, string className)
        {
            //string course = course.ToLower();
            //string type = type.ToLower();
            string        cid = null;
            long          sid;
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();


            string courseName = null;
            string courseType = null;

            //string CreateLoginCmd = "insert into Login values('"+  txtUsername +"',123)";
            string getCourseDetails = "select CourseName,CourseType from Courses where CourseName = '" + course + "'";

            try
            {
                conn.Open();

                SqlDataAdapter CourseDetails = new SqlDataAdapter(getCourseDetails, conn);
                DataSet        ds            = new DataSet();
                CourseDetails.Fill(ds, "Courses");
                //conn.Close();
                DataTable dt = ds.Tables["Courses"];
                //sid = long.Parse(ds.Tables[0].Rows[0][0].ToString());
                courseName = ds.Tables[0].Rows[0][0].ToString();
                courseType = ds.Tables[0].Rows[0][1].ToString();
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            try
            {
                conn.Open();
                string     EnterSubjectCmd = "insert into Subject values('" + courseName + "','" + courseType + "', null, null, null,null,null,null);SELECT @@IDENTITY";
                SqlCommand cmd             = new SqlCommand(EnterSubjectCmd, conn);
                Object     subjectID       = cmd.ExecuteScalar();
                sid = long.Parse(subjectID.ToString());
                conn.Close();
            }

            catch (Exception e)
            {
                throw;
            }
            try
            {
                conn.Open();
                string checkDuplicatonClassCmd = "select * from Class where ClassName = '" + className + "'";

                SqlCommand    cmd = new SqlCommand(checkDuplicatonClassCmd, conn);
                SqlDataReader dr1 = cmd.ExecuteReader();
                bool          i   = dr1.HasRows;
                dr1.Close();

                if (i)
                {
                    string getClassID = "select * from Class where ClassName = '" + className + "'";
                    //conn.Open();
                    //SqlCommand cmd = new SqlCommand(CreateLoginCmd, conn);
                    //cmd.ExecuteScalar();

                    SqlDataAdapter ClassDetails = new SqlDataAdapter(getClassID, conn);
                    DataSet        ds           = new DataSet();
                    ClassDetails.Fill(ds, "Class");
                    //conn.Close();
                    DataTable dt = ds.Tables["Class"];
                    cid = ds.Tables[0].Rows[0][0].ToString();
                }
                else
                {
                    string EnterClassCmd = "insert into Class values(null, '" + className + "',null, null, null);SELECT @@IDENTITY";
                    cmd = new SqlCommand(EnterClassCmd, conn);
                    Object classID = cmd.ExecuteScalar();
                    cid = classID.ToString();
                }
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            try
            {
                conn.Open();
                string     EnterClassSubjectCmd = "insert into Class_Subjects values('" + cid + "','" + sid + "')";
                SqlCommand cmd = new SqlCommand(EnterClassSubjectCmd, conn);
                cmd.ExecuteScalar();


                conn.Close();
                return("true");
            }
            catch (Exception e)
            {
                throw;
            }

            return("false");
        }
        public string getMarks4TeacherDLL(string userName, string className, string subjectName, ref DataSet res)
        {
            DataSet       s    = new DataSet();
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();
            DataSet result = new DataSet();
            int     lid, uid, stdid, cid, tid, subid;
            string  getLoginId = "select LoginId from  Login where  UserName= '******'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getLoginId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "login");

                DataTable dt = ds.Tables["login"];
                lid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }


            string getUserId = "select UserId from Userz where  Login_Id= '" + lid + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getUserId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "user");
                DataTable dt = ds.Tables["user"];
                uid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }


            string getTeacherId = "select TeacherId from Teacher where  User_Id= '" + uid + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getTeacherId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "teacher");
                DataTable dt = ds.Tables["teacher"];
                tid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            string getClassId = "select ClassId from Class where  ClassName= '" + className + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getClassId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "class");
                DataTable dt = ds.Tables["class"];
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return("This Class doesnt Exist");
                }
                cid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            string getCourseId = "select CourseId from Courses where  CourseName= '" + subjectName + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getCourseId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "course");
                DataTable dt = ds.Tables["course"];
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return("This Subject doesnt Exist, Enter Again");
                }
                subid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }


            int    csid;
            string chkClassSubject = "select * from Subject where  (TeacherId= '" + tid + "' and ClassId='" + cid + "' and SubjectName='" + subjectName + "')";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(chkClassSubject, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "CS");
                DataTable dt = ds.Tables["CS"];
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return("This Subject is not Associated with this Class or you might not have been assigned to this class or subject., Enter Again");
                }
                //csid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            string getAllMarks = "select StudentRollNo,SubjectName,SubjectType,TotalMarks,ObtainedMarks,Test1Marks,Test2Marks,Test3Marks,Test4Marks,Test5Marks,Assignment1Marks,Assignment2Marks,Assignment3Marks,Assignment4Marks,Assignment5Marks,weightage from Subject s,Tests_Assignments a, Student std where  (s.TeacherId= '" + tid + "' and s.ClassId= '" + cid + "' and s.SubjectName= '" + subjectName + "' and std.StudentId=s.StudentId and a.TestId=s.Test_Id)";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getAllMarks, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(res, "allMarks");
                DataTable dt = res.Tables["allMarks"];
                if (res.Tables[0].Rows.Count == 0)
                {
                    return("You have not yet entered marks for this subject. Go to Enter Marks Section.");
                }
                //csid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }

            return("true");
        }
        public string saveStudentMarksDLL(string userName, string className, string subjectName, ref DataSet res)
        {
            DataSet       s    = new DataSet();
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();
            DataSet result = new DataSet();
            int     lid, uid, stdid, cid, tid, subid;
            string  getLoginId = "select LoginId from  Login where  UserName= '******'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getLoginId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "login");

                DataTable dt = ds.Tables["login"];
                lid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }


            string getUserId = "select UserId from Userz where  Login_Id= '" + lid + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getUserId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "user");
                DataTable dt = ds.Tables["user"];
                uid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }


            string getTeacherId = "select TeacherId from Teacher where  User_Id= '" + uid + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getTeacherId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "teacher");
                DataTable dt = ds.Tables["teacher"];
                tid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            string getClassId = "select ClassId from Class where  ClassName= '" + className + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getClassId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "class");
                DataTable dt = ds.Tables["class"];
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return("This Class doesnt Exist");
                }
                cid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            string cType;
            string getCourseId = "select CourseId,CourseType from Courses where  CourseName= '" + subjectName + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getCourseId, conn);
                DataSet        ds    = new DataSet();
                marks.Fill(ds, "course");
                DataTable dt = ds.Tables["course"];
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return("This Subject doesnt Exist, Enter Again");
                }
                subid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                cType = ds.Tables[0].Rows[0][1].ToString();
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            DataSet std;
            string  getClassStudents = "select StudentId from Student where Class_Id='" + cid + "'";

            try
            {
                conn.Open();

                SqlDataAdapter marks = new SqlDataAdapter(getClassStudents, conn);
                std = new DataSet();
                marks.Fill(std, "std");
                DataTable dt = std.Tables["std"];
                if (std.Tables[0].Rows.Count == 0)
                {
                    return("There are no students addmitted in this class yet.");
                }
                //csid = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }

            for (int i = 0; i < res.Tables[0].Rows.Count; i++)
            {
                string saveMarks = "update Subject set obtainedMarks='" + res.Tables[0].Rows[i][4] + "' where(TeacherId= '" + tid + "' and ClassId= '" + cid + "' and SubjectName= '" + subjectName + "' and StudentId='" + std.Tables[0].Rows[i][0] + "')";
                try
                {
                    conn.Open();
                    SqlCommand    cmd = new SqlCommand(saveMarks, conn);
                    SqlDataReader dr  = cmd.ExecuteReader();
                    bool          c   = dr.HasRows;
                    //if (c)
                    //  return "Marks Saved Successfully.";
                    dr.Close();
                    conn.Close();
                }
                catch (Exception e)
                {
                    throw;
                }
                string getTestId = "select Test_Id from Subject where(TeacherId= '" + tid + "' and ClassId= '" + cid + "' and SubjectName= '" + subjectName + "' and StudentId='" + std.Tables[0].Rows[i][0] + "')";
                int    testId;
                try
                {
                    conn.Open();
                    SqlDataAdapter da = new SqlDataAdapter(getTestId, conn);
                    DataSet        ds = new DataSet();
                    da.Fill(ds, "t");
                    DataTable dt = ds.Tables["t"];
                    //if (ds.Tables[0].Rows.Count == 0)
                    //  return "problem in getting test id in Save part.";
                    testId = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
                    conn.Close();
                }
                catch (Exception e)
                {
                    throw;
                }
                string saveMarksInTest = "update Tests_Assignments set Test1Marks='" + res.Tables[0].Rows[i][5] + "', Test2Marks='" + res.Tables[0].Rows[i][6] + "',Test3Marks='" + res.Tables[0].Rows[i][7] + "',Test4Marks='" + res.Tables[0].Rows[i][8] + "',Test5Marks='" + res.Tables[0].Rows[i][9] + "', Assignment1Marks='" + res.Tables[0].Rows[i][10] + "', Assignment2Marks='" + res.Tables[0].Rows[i][11] + "', Assignment3Marks='" + res.Tables[0].Rows[i][12] + "', Assignment4Marks='" + res.Tables[0].Rows[i][13] + "', Assignment5Marks='" + res.Tables[0].Rows[i][14] + "', Weightage='" + res.Tables[0].Rows[i][15] + "' where testId= '" + testId + "'";
                try
                {
                    conn.Open();
                    SqlCommand    cmd = new SqlCommand(saveMarksInTest, conn);
                    SqlDataReader dr  = cmd.ExecuteReader();
                    bool          c   = dr.HasRows;
                    //if (c)
                    //  return "Marks Saved Successfully in Test.";
                    dr.Close();
                    conn.Close();
                }
                catch (Exception e)
                {
                    throw;
                }
            }
            return("true");
        }
        public String CreateUser(string txtFName, string txtLName, string txtPhoneNo, string txtMobileNo, string txtEmail, string txtAddress, string txtUsername, string txtCountry, string comboUserType)
        {
            long          CId  = insertCountry(txtCountry);
            SqlConnection conn = null;

            conn = RegisterStudentToDB.ConnectDB();
            string checkDuplicatonCmd = "select * from Login where UserName = '******'";

            try
            {
                conn.Open();
                SqlCommand    cmd = new SqlCommand(checkDuplicatonCmd, conn);
                SqlDataReader dr  = cmd.ExecuteReader();
                bool          i   = dr.HasRows;
                if (i)
                {
                    return("user Already Exist");
                }

                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }

            string LID            = null;
            string CreateLoginCmd = "insert into Login values('" + txtUsername + "',123)";
            string getLoginId     = "select LoginId from Login where username = '******'";

            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(CreateLoginCmd, conn);
                cmd.ExecuteScalar();

                SqlDataAdapter userLoginId = new SqlDataAdapter(getLoginId, conn);
                DataSet        ds          = new DataSet();
                userLoginId.Fill(ds, "Login");

                DataTable dt = ds.Tables["Login"];
                LID = ds.Tables[0].Rows[0][0].ToString();

                conn.Close();
            }
            catch (Exception e)
            {
                throw;
            }
            object ident = null;
            string createUserLoginCommand = "insert into Userz values('" + txtFName + "', '" + txtLName + "', '" + txtPhoneNo + "', '" + txtMobileNo + "', '" + txtEmail + "', '" + txtAddress + "', '" + LID + "', '" + comboUserType + "' , null , '" + CId + "');SELECT @@IDENTITY ";

            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(createUserLoginCommand, conn);
                ident = cmd.ExecuteScalar();
                conn.Close();
                long id = long.Parse(ident.ToString());
                if (comboUserType.ToLower() == "teacher")
                {
                    string enterTeacher = "insert into Teacher values(null,null,null,'" + id + "')";
                    conn.Open();
                    cmd = new SqlCommand(enterTeacher, conn);
                    cmd.ExecuteScalar();
                    conn.Close();
                }
                else if (comboUserType.ToLower() == "admin")
                {
                    string enterAdmin = "insert into Admin values('" + id + "')";
                    conn.Open();
                    cmd = new SqlCommand(enterAdmin, conn);
                    cmd.ExecuteScalar();
                    conn.Close();
                }
                return("true");
            }
            catch (Exception e)
            {
                throw;
            }
            return("false");
        }