Inheritance: ConnectionClass1
示例#1
0
    public void DictTest()
    {
        Dictionary <(int, string), StudentClass> dict = new Dictionary <(int, string), StudentClass>();

        dict.Add((1, "1"), new StudentClass()
        {
            Age = 1
        });


        var newStudent = new StudentClass()
        {
            Age = 22
        };

        if (dict.TryGetValue((1, "1"), out StudentClass student))
        {
            student = newStudent;
        }

        if (dict.TryGetValue((1, "1"), out StudentClass student1))
        {
            Console.WriteLine(student1.Age);
        }

        Console.WriteLine(dict[(1, "1")].Age);
示例#2
0
    void ValueRefTest()
    {
        string str1 = "1";       //str1 ---> new string("1")
        string str2 = str1;      //str2 --> str1传递引用

        str2 = "2";              //str2 --> new string("2") 传引用,str2指向一个新的字符串,str1没有改变
        Console.WriteLine(str1); //1
        //但是string又有值传递的效果,这bai是因为string是常量,不能更改

        StudentClass studentClass1 = new StudentClass();

        studentClass1.Age = 1;
        StudentClass studentClass2 = studentClass1;

        studentClass2.Age = 2;
        Console.WriteLine(studentClass1.Age);//2


        StudentStruct studentStruct1 = new StudentStruct();

        studentStruct1.Age = 1;

        StudentStruct studentStruct2 = studentStruct1;

        studentStruct2.Age = 2;
        Console.WriteLine(studentStruct1.Age);//3
    }
示例#3
0
        public void AddClass(StudentClass studentClass)
        {
            _conn.Open();

            try
            {
                using (SqlCommand cmd = _conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO dbo.Class(ClassName, Time, StudentId) " +
                                      "VALUES(@className, @time, @studentId)";

                    SqlParameter param1 = new SqlParameter("className", SqlDbType.NVarChar, 100);
                    SqlParameter param2 = new SqlParameter("time", SqlDbType.DateTime);
                    SqlParameter param3 = new SqlParameter("studentId", SqlDbType.Int);


                    param1.Value = studentClass.ClassName.Trim();
                    param2.Value = studentClass.Time;
                    param3.Value = studentClass.StudentId;

                    cmd.Parameters.AddRange(new[] { param1, param2, param3 });

                    int result = cmd.ExecuteNonQuery();
                }
            }
            finally
            {
                _conn.Close();
            }
        }
示例#4
0
        public bool addStudent(StudentClass s)
        {
            bool flag = false;

            using (SqlConnection con = new SqlConnection(Dbhelper.dbsr))
            {
                Dbhelper     DB  = new Dbhelper(con);
                SqlParameter pNo = new SqlParameter {
                    ParameterName = "@sNo", SqlDbType = SqlDbType.Char, Value = s.sNo
                };
                SqlParameter pName = new SqlParameter {
                    ParameterName = "@sName", SqlDbType = SqlDbType.Char, Value = s.sName
                };
                SqlParameter pPass = new SqlParameter {
                    ParameterName = "@sPass", SqlDbType = SqlDbType.Char, Value = s.sPass
                };
                try
                {
                    if (DB.ExecuteSQL("insert into students(sNo,sName,sPass)values(@sNo,@sName,@sPass)", pNo, pName, pPass) > 0)
                    {
                        flag = true;
                    }
                }
                catch { }
                con.Close();
            }
            return(flag);
        }
示例#5
0
        //根据班级查询
        private void cboClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            StudentClass coSelected = (StudentClass)cboClass.SelectedItem;

            gbStat.Text = "班级考试成绩统计";

            dgvScoreList.AutoGenerateColumns = false;
            dgvScoreList.DataSource          = objScore.GetScoreList(cboClass.Text);
            Dictionary <string, string> scoreDic = new Dictionary <string, string>();

            if (cboClass.SelectedIndex != -1)
            {
                //统计平均分数
                scoreDic = objScore.GetScoreInfo(coSelected.ClassId.ToString());
            }
            else
            {
                scoreDic = objScore.GetScoreInfo();
            }

            lblAttendCount.Text = scoreDic["stuCount"];
            lblDBAvg.Text       = scoreDic["avgSql"];
            lblCSharpAvg.Text   = scoreDic["avgCsharp"];
            lblCount.Text       = scoreDic["absentCount"];
            //显示缺考人员
            lblList.DataSource = null;
            if (cboClass.SelectedIndex != -1)
            {
                lblList.DataSource = objScore.GetAbsentList(coSelected.ClassId.ToString());
            }
            else
            {
                lblList.DataSource = objScore.GetAbsentList();
            }
        }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //  0 means insert ,1 means not insert, 2 means runtime error
        try
        {
            StudentClassObject = new StudentClass();
            ReturnValue = StudentClassObject.SaveStudentData(txtStudentName.Text, txtStudentAddress.Text, txtStudyingClass.Text);
            if (ReturnValue == "0")
            {
                lblerrormsg_Submit.Text = "Successfully Submitted";
                DisplayStudent_Grid();
                ClrSubmitData();
            }
            else if (ReturnValue == "1")
            {
                lblerrormsg_Submit.Text = "Not  Submitted";

            }
            else if (ReturnValue == "2")
            {
                lblerrormsg_Submit.Text = "Rutime Error while Student Class";
            }
            else
            { lblerrormsg_Submit.Text = "Rutime Error while Student Class return some thing"; }
        }
        catch (Exception)
        {

            lblerrormsg_Submit.Text = "Runtime error while submitting same page";
        }
    }
 public VivaClass(string date, string time, bool isMake, string Gid, string uName, string Prjct, string city)
 {
     StudentObJ = new StudentClass(Gid, uName, Prjct, city);
     this.Date = date;
     this.Time = time;
     this.isMake = isMake;
 }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();

        try
        {
            StudentClassObject = new StudentClass();
            dt = StudentClassObject.CheckLoginCredentials(txtuserName.Text, txtPassword.Text);

            if (dt.Rows[0][0].ToString() == "Active")
            {
                // string key = Session.SessionID.ToString();
                // Response.Write(Session.SessionID.ToString());
                Response.Redirect("home.aspx");
            }
            else
            {
                lblerrormsg.Text = dt.Rows[0][0].ToString();
            }
        }
        catch (Exception)
        {
            // ReturnValue = "2";
        }
        // return ds;
    }
示例#9
0
        /// <summary>
        /// 获取文本框的值赋给实体类里面变量的方法
        /// </summary>
        /// <returns></returns>
        private PlanBook txtText()
        {
            PlanBook plan = new PlanBook();                  //初始化实体类PlanBook

            plan.CourseName     = txtCourseName.Text.Trim(); //为实体类里面的字段赋值
            plan.BookName       = txtBookName.Text.Trim();
            plan.Author         = txtAuthor.Text.Trim();
            plan.ISBN           = txtISBN.Text.Trim();
            plan.Price          = float.Parse(txtPrice.Text.Trim());
            plan.Publish        = txtPublish.Text.Trim();
            plan.StudentBookNum = int.Parse(txtStudentBookNum.Text.Trim());
            plan.TeacherBookNum = int.Parse(txtTeacherBookNum.Text.Trim());

            StudentClass student = common.GetAllCollegeInfo_Class(cmbStudentClass.Text); //以下拉框班级的文本值作参数调用方法GetAllCollegeInfo_Class()并赋值给实体类

            plan.MajorInfoID    = student.MajorInfoID;                                   //获取实体类StudentClass中的专业编号赋值给实体类PlanBook中的专业编号
            plan.StudentClassID = student.StudentClassID;                                //获取实体类StudentClass中的学院编号赋值给实体类PlanBook中的学院编号

            plan.SchoolTermID = cmbSchoolTerm.SelectedIndex;                             //获取下拉框学年学期的索引值并赋值给实体类PlanBook里面的SchoolTermID字段
            plan.CourseID     = cmbCourseType.SelectedIndex;                             //获取下拉框课程类型的索引值并赋值给实体类PlanBook里面的CourseID字段
            plan.CollegeID    = cmbCollege.SelectedIndex;                                //获取下拉框学院名称的索引值并赋值给实体类PlanBook里面的CollegeID字段

            plan.YearMonth    = DateTime.Now;
            plan.BookTotalNum = plan.StudentBookNum + plan.TeacherBookNum;

            return(plan);
        }
示例#10
0
        private void cntxtmsUpdate_Click(object sender, EventArgs e)                                                   //右键修改列表信息的方法
        {
            cmbSchoolTerm.Text = dgvPlanBook.CurrentRow.Cells[0].Value.ToString();                                     //获取选中的行  索引值为0的单元格的值  当成 下拉框学年学期 初始化的值
            cmbCollege.Text    = dgvPlanBook.CurrentRow.Cells[1].Value.ToString();                                     //获取选中的行  索引值为1的单元格的值 当成 下拉框学院名称 初始化的值

            StudentClass student   = common.GetAllCollegeInfo_Class(dgvPlanBook.CurrentRow.Cells[3].Value.ToString()); //获取选中的行  索引值为3的单元格的值为方法GetAllCollegeInfo_Class()的参数 并把返回值赋值给CollegeID
            int          CollegeID = student.CollegeID;

            cmbstudentclass(CollegeID);                                              //以CollegeID作为参数调用方法cmbstudentclass()重新加载年级下拉框的各个项
            cmbStudentClass.Text = dgvPlanBook.CurrentRow.Cells[3].Value.ToString(); //获取选中的行  索引值为3的单元格的值 当成 下拉框班别名称 初始化的值

            cmbCourseType.Text = dgvPlanBook.CurrentRow.Cells[4].Value.ToString();   //获取选中的行  索引值为4的单元格的值 当成 下拉框课程类型 初始化的值
            txtAuthor.Text     = dgvPlanBook.CurrentRow.Cells[8].Value.ToString();

            txtBookName.Text   = dgvPlanBook.CurrentRow.Cells[6].Value.ToString();
            txtCourseName.Text = dgvPlanBook.CurrentRow.Cells[5].Value.ToString();
            txtISBN.Text       = dgvPlanBook.CurrentRow.Cells[7].Value.ToString();

            txtPrice.Text          = dgvPlanBook.CurrentRow.Cells[10].Value.ToString();
            txtPublish.Text        = dgvPlanBook.CurrentRow.Cells[9].Value.ToString();
            txtStudentBookNum.Text = dgvPlanBook.CurrentRow.Cells[12].Value.ToString();

            txtTeacherBookNum.Text = dgvPlanBook.CurrentRow.Cells[11].Value.ToString();

            isbn          = dgvPlanBook.CurrentRow.Cells[7].Value.ToString();
            btnOK.Text    = "确认修改";
            btnOK.Enabled = false;
        }
示例#11
0
        static void Main()
        {
            Foo();
            return;

            StudentClass studentClass1 = new StudentClass();
            StudentClass studentClass2 = new StudentClass();

            Console.WriteLine(studentClass1.GetHashCode());
            Console.WriteLine(studentClass2.GetHashCode());

            //SimpleDictTest();
            StackTest();

            return;

            Console.WriteLine("---");
            //list 无法被=null
            List <int> vs = new List <int>();

            CreateList(vs);
            Console.WriteLine(vs.Count);//0


            //传递了list这个引用过去 可以Add到元素
            var list = new List <int>();

            AddList(list);
            Console.WriteLine(list.Count);//1
        }
        public void GetStudentDetail()
        {
            List <StudentClass> students = new List <StudentClass>();

            using (SqlCommand cmd = new SqlCommand("FetchAllStudent", db.DbConnect()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    StudentClass student = new StudentClass();
                    student.StudentId = Convert.ToInt32(rdr["student_id"]);
                    //faculty.FirstName = rdr["first_name"].ToString();
                    //faculty.LastName = rdr["last_name"].ToString();
                    student.FullName     = rdr["first_name"].ToString() + " " + rdr["last_name"].ToString();
                    student.EnrollmentNo = rdr["enrollment_no"].ToString();
                    student.AvatarPath   = rdr["avatar"].ToString();
                    student.ThumbPath    = rdr["thumb_img"].ToString();
                    //faculty.UserName = rdr["username"].ToString();
                    //faculty.EmailId = rdr["email"].ToString();
                    student.ContactNo = rdr["stud_contact"].ToString();
                    //student.ParentNo = rdr["parent_contact"].ToString();
                    student.DeptName = student.FetchDeptById(rdr["dept_id"].ToString());
                    students.Add(student);
                }
            }
            JavaScriptSerializer js = new JavaScriptSerializer();

            Context.Response.Write(js.Serialize(students));
        }
示例#13
0
 public Student(string name, Class studentClass)
 {
     this.Name         = name;
     this.StudentClass = studentClass;
     this.classNumber  = StudentClass.ReturnStudentID();
     this.StudentClass.Students.Add(this);
 }
示例#14
0
        public async Task <ActionResult <StudentClass> > PostStudentClass(StudentClass studentClass)
        {
            _context.StudentClass.Add(studentClass);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetStudentClass", new { id = studentClass.Id }, studentClass));
        }
示例#15
0
        private void btnAccept_Click(object sender, EventArgs e)
        {
            //This will need to change each student account selected and then remove the pending requests from the DB
            TutorMasterDBEntities4 db = new TutorMasterDBEntities4();            //side note, we should carefully control the life cycle of object contexts like these   //open the db

            int reqNum = lvPendingRequests.CheckedItems.Count;                   //identify how many requests have been checked

            for (int i = 0; i < reqNum; i++)                                     //iterate for how many requests have been clicked
            {
                string CC  = lvPendingRequests.CheckedItems[i].SubItems[1].Text; //pull the classcode from the request in question
                string Id  = lvPendingRequests.CheckedItems[i].SubItems[2].Text;
                int    Id2 = Int32.Parse(Id);                                    //Change the string into an int, this is really fragile if a bad id number is put in the system somehow. typechecking for those ids should prevent it

                StudentClass newClass = new StudentClass();
                newClass.Key       = getNextRequestKey();
                newClass.ClassCode = CC;
                newClass.ID        = Id2;
                db.StudentClasses.AddObject(newClass);

                Student tutor = (from row in db.Students where row.ID == Id2 select row).First();
                tutor.Tutor = true;
                TutorRequest delU = (from row in db.TutorRequests where ((row.ClassCode == CC) && (row.ID == Id2)) select row).First(); //find the request that has the right ID and class code

                if (delU != null)
                {
                    db.TutorRequests.DeleteObject(delU);                                                                //delete the object in the db
                    db.SaveChanges();                                                                                   //save the cahnges to the db
                }
            }

            db.SaveChanges();
            MessageBox.Show("The selected tutor requests have been accepted and the tutors have been approved to tutor the selected courses");
            lvPendingRequests.Clear(); //clean out the box
            SetupPendingRequests(id);  //Set up the box again
        }
示例#16
0
    /// <summary>
    /// this method using for get the student data and return table 
    /// </summary>
    public void DisplayStudent_Grid()
    {

        try
        {
            StudentClassObject = new StudentClass();
            ds = new DataSet();
            ds = StudentClassObject.GetStudentData(Convert.ToInt32(Session["ID"].ToString()), "");
            GridView1.DataSource = null;
            if (ds.Tables.Count != 0)
            {
                GridView1.DataSource = ds.Tables[0];
            }

            //GridView1.DataBind();
        }
        catch (Exception)
        {
            GridView1.DataSource = null;
        }
        finally
        {
            GridView1.DataBind();
        }
    }
示例#17
0
    public void CheckLoginCredentials(string UserName, string Password)
    {
        rows       = new List <Dictionary <string, object> >();
        serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

        ReturnValue      = string.Empty;
        StudentClsObject = new StudentClass();
        DataTable dt = new DataTable();

        dt = StudentClsObject.CheckLoginCredentials(UserName, Password);
        Dictionary <string, object> row;

        foreach (DataRow dr in dt.Rows)
        {
            row = new Dictionary <string, object>();
            foreach (DataColumn col in dt.Columns)
            {
                row.Add(col.ColumnName, dr[col]);
            }
            rows.Add(row);
        }
        //  string s = HttpContext.Current.Session["ID"].ToString(); ;
        //HttpContext.Current.Session["ID"] = HttpContext.Current.Session["ID"].ToString();
        // Context.Response.Clear();
        // Context.Response.ContentType = "application/json";
        Context.Response.Write(serializer.Serialize(rows));
    }
        public async Task <IActionResult> Edit(int id, [Bind("ID,ClassID,StudentID")] StudentClass studentClass)
        {
            if (id != studentClass.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(studentClass);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentClassExists(studentClass.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(studentClass));
        }
示例#19
0
        private void SaveClassButton_Clicked(object sender, EventArgs e)
        {
            if (!ValidateEntries())
            {
                return;
            }

            if (newClass)
            {
                StudentClass sc = new StudentClass();

                using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
                {
                    conn.CreateTable <StudentClass>();
                    conn.Insert(UpdateClass(sc));
                }

                CheckAndUpdateAssessments();
            }
            else
            {
                using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
                {
                    conn.CreateTable <StudentClass>();
                    StudentClass sc = conn.Table <StudentClass>().ToList().Single(s => s.Id == PrimaryId);
                    conn.Update(UpdateClass(sc));
                }
            }

            SetNotification();

            Navigation.PopAsync();
        }
示例#20
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     //  0 means insert ,1 means not insert, 2 means runtime error
     try
     {
         StudentClassObject = new StudentClass();
         ReturnValue        = StudentClassObject.SaveStudentData(txtStudentName.Text, txtStudentAddress.Text, txtStudyingClass.Text);
         if (ReturnValue == "0")
         {
             lblerrormsg_Submit.Text = "Successfully Submitted";
             DisplayStudent_Grid();
             ClrSubmitData();
         }
         else if (ReturnValue == "1")
         {
             lblerrormsg_Submit.Text = "Not  Submitted";
         }
         else if (ReturnValue == "2")
         {
             lblerrormsg_Submit.Text = "Rutime Error while Student Class";
         }
         else
         {
             lblerrormsg_Submit.Text = "Rutime Error while Student Class return some thing";
         }
     }
     catch (Exception)
     {
         lblerrormsg_Submit.Text = "Runtime error while submitting same page";
     }
 }
示例#21
0
        public async Task <IActionResult> OnPostAdd(int id, int classID)
        {
            try
            {
                Class2 = await _context.Class
                         .FirstOrDefaultAsync(m => m.ClassID == classID);

                Class2.Capacity--;
                StudentClass StudentClass = new StudentClass();
                StudentClass.StudentID = id;
                StudentClass.ClassID   = classID;
                _context.Class.Update(Class2);
                _context.StudentClass.Add(StudentClass);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(Student.StudentID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./ChangeSchedule", new { id }));
        }
 public ActionResult AddNewStudentClass(StudentClass model)
 {
     ViewBag.AlreadyExists = false;
     if (ModelState.IsValid)
     {
         if (model.Id != 0)
         {
             bool IsUpdated = StudentClass.Update(model.Id, model.Name);
             if (IsUpdated)
             {
                 return(RedirectToAction("Index"));
             }
         }
         else
         {
             bool isAdded = StudentClass.AddNew(model.Name, ApplicationHelper.LoggedUserId);
             if (isAdded)
             {
                 return(RedirectToAction("Index"));
             }
         }
         ViewBag.AlreadyExists = true;
         return(View(model));
     }
     else
     {
         return(View(model));
     }
 }
示例#23
0
        public ActionResult DoSurvey(FormCollection form)
        {
            //number of criteria in survey table
            ViewBag.CountQuestion = db.SurveyQuestions.ToList().Count();
            //list criteria in the survey
            ViewBag.SurveyQuestions = db.SurveyQuestions.Select(sq => sq.Content).ToList();
            //get class id from form has name = classId
            int classId = int.Parse(form["classId"]);
            //get studentId from form
            int studentId = int.Parse(form["studentdetailId"]);
            //get student
            StudentClass studentClass = db.StudentClasses.FirstOrDefault(sc => sc.ClassId == classId);

            //check if all criteria have result
            if (form.Count < db.SurveyQuestions.ToList().Count() + 2)
            {
                ViewBag.Message = "Bạn cần phải hoàn thiện việc đánh giá tất cả các tiêu chí trước khi submit";
                return(View(studentClass));
            }
            int i = 0;

            foreach (var item in db.SurveyQuestions)
            {
                Survey survey = new Survey();
                survey.StudentClassId   = studentId;
                survey.SurveyQuestionId = item.Id;
                survey.Result           = int.Parse(form[i++]);
                db.Surveys.Add(survey);
            }
            StudentClass stu = db.StudentClasses.FirstOrDefault(sc => sc.Id == studentId);

            db.SaveChanges();
            Response.Write("<script>alert('Đánh giá môn học thành công')</script>");
            return(RedirectToAction("ShowListClass"));
        }
示例#24
0
        //Do Survey
        public ActionResult DoSurvey(int?id, int?studentId)
        {
            //if id or studentID not exists
            if (id == null || studentId == null)
            {
                //return 404
                return(RedirectToAction("Page404", "Authentication", new { area = "Authentication" }));
            }

            //get student with id and studentid
            StudentClass studentClass = db.StudentClasses.FirstOrDefault(x => x.StudentId == studentId && x.ClassId == id);

            //not found student
            if (studentClass == null)
            {
                return(RedirectToAction("Page404", "Authentication", new { area = "Authentication" }));
            }

            //check if student has survey or not
            if (db.Surveys.Any(s => s.StudentClassId == studentClass.Id))
            {
                ViewBag.Message = "Môn học này đã được đánh giá. Cảm ơn bạn đã ghé thăm";
                return(View(studentClass));
            }

            //number of criteria in survey table
            ViewBag.CountQuestion = db.SurveyQuestions.ToList().Count();

            //list criteria in the survey
            ViewBag.SurveyQuestions = db.SurveyQuestions.Select(sq => sq.Content).ToList();
            return(View(studentClass));
        }
示例#25
0
        public async Task <IActionResult> PutStudentClass(int id, StudentClass studentClass)
        {
            if (id != studentClass.Id)
            {
                return(BadRequest());
            }

            _context.Entry(studentClass).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentClassExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 StudentDetails(string stdName, StudentClass stdClass, string stdRollNo, Gender stdGender)
 {
     Name       = stdName;
     Class      = stdClass;
     RollNo     = stdRollNo;
     GenderType = stdGender;
 }
示例#27
0
        public void AddMarkToDatabase()
        {
            // Arrange
            var classes   = new List <StudentClass>();
            var queryable = classes.AsQueryable();

            var mockDbSet = new Mock <IDbSet <StudentClass> >();

            mockDbSet.As <IQueryable <StudentClass> >().Setup(m => m.Provider).Returns(queryable.Provider);
            mockDbSet.As <IQueryable <StudentClass> >().Setup(m => m.Expression).Returns(queryable.Expression);
            mockDbSet.As <IQueryable <StudentClass> >().Setup(m => m.ElementType).Returns(queryable.ElementType);
            mockDbSet.As <IQueryable <StudentClass> >().Setup(m => m.GetEnumerator()).Returns(() => queryable.GetEnumerator());
            mockDbSet.Setup(d => d.Add(It.IsAny <StudentClass>())).Callback <StudentClass>((cl) => classes.Add(cl));

            var mockDbContext = new Mock <IDatabaseContext>();

            mockDbContext.Setup(c => c.StudentClasses).Returns(mockDbSet.Object);

            var studentClassService = new StudentClassService(mockDbContext.Object);
            var studentClass        = new StudentClass("1A");

            // Act
            studentClassService.Add(studentClass);

            // Assert
            Assert.IsTrue(classes.Count() == 1);
            Assert.IsTrue(classes.Contains(studentClass));
        }
示例#28
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        try
        {
            StudentClassObject = new StudentClass();
            dt = StudentClassObject.CheckLoginCredentials(txtuserName.Text, txtPassword.Text);

            if (dt.Rows[0][0].ToString() == "Active")
            {
                // string key = Session.SessionID.ToString();
                // Response.Write(Session.SessionID.ToString());
                Response.Redirect("home.aspx");

            }
            else
            {
                lblerrormsg.Text = dt.Rows[0][0].ToString();
            }
        }
        catch (Exception)
        {

            // ReturnValue = "2";
        }
        // return ds;

    }
示例#29
0
        public async Task <Response> AddClass(Student student, Class Class)
        {
            Response response = new Response();

            try
            {
                StudentClass studentClass = new StudentClass()
                {
                    StudentID = student.ID,
                    ClassID   = Class.ID
                };
                (await _context.Students.Include(c => c.Classes).Where(c => c.ID == student.ID).FirstOrDefaultAsync()).Classes.Add(studentClass);
                await _context.SaveChangesAsync();

                return(response);
            }
            catch (Exception e)
            {
                StringBuilder sb = new StringBuilder();
                log.Error(sb.AppendLine(e.Message).AppendLine(e.StackTrace).ToString());
                response.Success = false;
                response.ErrorList.Add("Error while addind class to student.");
                return(response);
            }
        }
示例#30
0
        public void InsertData(StudentClass s1, StudentClass s2)
        {
            Dictionary <int, StudentClass> d = new Dictionary <int, StudentClass>();

            d.Add(1, s1);
            d.Add(2, s2);
        }
        public ActionResult Create([Bind(Include = "StudentClassID,ClassName")] StudentClassViewModel studentClassViewModel)
        {
            if (!ModelState.IsValid)
            {
                // ако нещо не е наред, връщаме за да се попълни/коригира
                return(View(studentClassViewModel));
            }
            StudentClass newClass = new StudentClass()
            {
                ClassName = studentClassViewModel.ClassName
            };

            ViewBag.Message = "";
            if (this.data.StudentClasses.All().Any(c => c.ClassName == newClass.ClassName))
            {
                ViewBag.Message = "Класът, който се опитахте да въведете вече съществува!";
                return(RedirectToAction("Index"));
            }
            else
            {
                this.data.StudentClasses.Add(newClass);
                this.data.SaveChanges();
                ViewBag.Message = "Класът е създаден успешно!";
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Edit([Bind(Include = "StudentClassID,ClassName")] StudentClassViewModel studentClassViewModel)
        {
            if (!ModelState.IsValid)
            {
                // не е наред, връщаме за да се попълни/коригира
                return(View(studentClassViewModel));
            }

            // намираме модела в базата за да го редактираме
            StudentClass studentClassToUpdate = this.data.StudentClasses.Find(studentClassViewModel.StudentClassID);

            if (studentClassToUpdate == null)
            {
                return(HttpNotFound());
            }
            //сменя името
            studentClassToUpdate.ClassName = studentClassViewModel.ClassName;
            if (this.data.StudentClasses.All().Any(c => c.ClassName == studentClassToUpdate.ClassName))
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                this.data.StudentClasses.Update(studentClassToUpdate);
                this.data.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
        public ActionResult NewStudent(string name, string date)
        {
            StudentClass student = new StudentClass(name, date);

            student.Save();
            return(RedirectToAction("Student"));
        }
    public static void Main()
    {
        StudentClass sc = new StudentClass();
            sc.QueryHighScores(1, 90);

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
    }
示例#35
0
    static void Main()
    {
        // == Disciplines ==
        Discipline math = new Discipline("Math", 23, 23);
        Discipline bio = new Discipline("Bio", 23, 34);
        Discipline geo = new Discipline("Geo", 27, 44);

        // == Teachers ==
        Teacher Dimitar = new Teacher("Dimitar Lilov", 34, Gender.Male);
        Dimitar.AddDiscipline(math);
        Dimitar.AddDiscipline(bio);

        Teacher Kiril = new Teacher("Kiril Nikolov", 29, Gender.Male);
        Kiril.AddDiscipline(geo);

        // == Students ==
        Student Aneliq = new Student("Aneliq Iordanova", 17, Gender.Female, 000354);
        Student Yoana = new Student("Yoana Ivanova", 18, Gender.Female, 000359);
        Yoana.AddComment("EGN - 2342623623");

        // == List Of Teachers ==
        List<Teacher> teachers = new List<Teacher>();
        teachers.Add(Dimitar);
        teachers.Add(Kiril);

        // == List Of Students ==
        List<Student> students = new List<Student>();
        students.Add(Aneliq);
        students.Add(Yoana);

        // == StudentClass ==
        StudentClass firstClass = new StudentClass("10B", students, teachers);

        // == School ==
        School washington = new School("Washington");
        washington.AddSchoolClass(firstClass);

        // == Printing ==
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("Printing School ...");
        Console.ResetColor();
        Console.WriteLine();
        Console.WriteLine(washington);

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("Printing Class ...");
        Console.ResetColor();
        Console.WriteLine();
        Console.WriteLine(firstClass);

        Console.ReadLine();
    }
示例#36
0
    public void GetStudentDetails_Json(string Session_Key, string Student_No)
    {
        int LoginID = 0;
        rows = new List<Dictionary<string, object>>();
        serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        if (HttpContext.Current.Session["ID"] == null)
        {

            Context.Response.Write("[{Status: Login is experied}]");
        }
        else if (Convert.ToString(HttpContext.Current.Session.SessionID) == Session_Key)
        {

            DataTable dt = new DataTable();
            StudentClsObject = new StudentClass();
            ds = new DataSet();
            try
            {

                LoginID = Convert.ToInt32(HttpContext.Current.Session["ID"].ToString());
                ds = StudentClsObject.GetStudentData(LoginID, Student_No);
                dt = ds.Tables[0];
                Dictionary<string, object> row;
                foreach (DataRow dr in dt.Rows)
                {
                    row = new Dictionary<string, object>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        row.Add(col.ColumnName, dr[col]);
                    }
                    rows.Add(row);
                }

            }
            catch (Exception)
            {


            }
            if (rows.Count > 0)
            {

                Context.Response.Write(serializer.Serialize(rows));
            }
        }
        else
        {
            // Context.Response.Clear();
            //  Context.Response.ContentType = "application/json; charset=utf-8";
            Context.Response.Write("[{Status: Session key is not Matched}]");
        }
    }
示例#37
0
        public void TestMethod2()
        {
            StudentClass myClassOfStudents = new StudentClass("C2334", @"Software Development 2");
            for (int i = 0; i < 10; i++)
            {
                myClassOfStudents.AddStudent(new Student("1233", "Testing" + i, "Male"));
            }

            foreach (var student in myClassOfStudents.Students)
            {
                Console.WriteLine(student.ToString());
            }
        }
示例#38
0
 public void RemoveClassByName(StudentClass studentClass)
 {
     classesInTheSchool.Add(studentClass);
 }
示例#39
0
    public DataTable GetStudentDetails_Xml(int UserID, string StudentId)
    {

        StudentClsObject = new StudentClass();
        ds = StudentClsObject.GetStudentData(UserID, StudentId);
        return ds.Tables[0];

    }
示例#40
0
    public void CheckLoginCredentials(string UserName, string Password)
    {

        rows = new List<Dictionary<string, object>>();
        serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

        ReturnValue = string.Empty;
        StudentClsObject = new StudentClass();
        DataTable dt = new DataTable();
        dt = StudentClsObject.CheckLoginCredentials(UserName, Password);
        Dictionary<string, object> row;
        foreach (DataRow dr in dt.Rows)
        {
            row = new Dictionary<string, object>();
            foreach (DataColumn col in dt.Columns)
            {
                row.Add(col.ColumnName, dr[col]);
            }
            rows.Add(row);
        }
        //  string s = HttpContext.Current.Session["ID"].ToString(); ;
        //HttpContext.Current.Session["ID"] = HttpContext.Current.Session["ID"].ToString();
        // Context.Response.Clear();
        // Context.Response.ContentType = "application/json";
        Context.Response.Write(serializer.Serialize(rows));
    }
示例#41
0
 // Method
 public void AddSchoolClass(StudentClass studentClass)
 {
     classesInTheSchool.Add(studentClass);
 }