protected void btnGetEnrolledUsers_Click(object sender, EventArgs e)
        {
            DCVimaruDataContext dc = new DCVimaruDataContext();
            //get courseId
            ThoiKhoaBieu tkb = dc.ThoiKhoaBieus.Single(t => t.STT == Convert.ToInt32(cboFilterCourse.SelectedValue));

            int courseId = Convert.ToInt32(tkb.Id);

            //create options to get 4 fields of user is id, username, fullname, email
            List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >();

            list.Add(new KeyValuePair <string, string>("userfields", "id"));
            list.Add(new KeyValuePair <string, string>("userfields", "username"));
            list.Add(new KeyValuePair <string, string>("userfields", "fullname"));
            list.Add(new KeyValuePair <string, string>("userfields", "email"));

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(MoodleEnrol.GetEnrolledUsers(courseId, list, (string)Session["token"]));
            doc.Save("D:\\enrolled_users_" + courseId + ".xml");

            XmlNode xmlnode = doc.ChildNodes[1];

            treeDetail.Nodes.Clear();
            treeDetail.Nodes.Add(new TreeNode(doc.DocumentElement.Name));
            TreeNode tNode;

            tNode = treeDetail.Nodes[0];
            MoodleUtilites.AddNode(xmlnode, tNode);
            treeDetail.ExpandAll();
        }
        private void EnrolUsers(int suspend)
        {
            SaveCheckedValues();
            grvUser.AllowPaging = false;
            grvUser.DataBind();

            DCVimaruDataContext dc = new DCVimaruDataContext();
            //get courseId
            ThoiKhoaBieu tkb      = dc.ThoiKhoaBieus.Single(t => t.STT == Convert.ToInt32(cboFilterCourse.SelectedValue));
            int          courseId = Convert.ToInt32(tkb.Id);
            //role: Học viên
            int roleId = 5;

            MoodleEnrol enrol;
            XmlDocument doc    = new XmlDocument();
            ArrayList   arrIDs = ConvertToArrayList(txtMaSV.Text);
            string      MaSV   = "0";

            foreach (GridViewRow row in grvUser.Rows)
            {
                MaSV = grvUser.DataKeys[row.RowIndex]["MaSV"].ToString();
                if (arrIDs.Contains(MaSV))
                {
                    CheckBox chk = row.Cells[4].Controls[0] as CheckBox;
                    if (row.Cells[3].Text == "0" || (suspend == 0 && chk.Checked) || (suspend == 1 && !chk.Checked))
                    {
                        continue;
                    }
                    enrol = new MoodleEnrol
                    {
                        RoleId    = roleId,
                        UserId    = Convert.ToInt32(row.Cells[3].Text),
                        CourseId  = courseId,
                        TimeStart = 0,
                        TimeEnd   = 0,
                        Suspend   = suspend
                    };

                    List <MoodleEnrol> list = new List <MoodleEnrol>();
                    list.Add(enrol);
                    doc.LoadXml(MoodleEnrol.EnrolUsers(list, (string)Session["token"]));
                    doc.Save("D:\\enrol_" + enrol.UserId + ".xml");
                    if (doc.DocumentElement.Name == "RESPONSE")
                    {
                        DangKy dk = dc.DangKies.Single(t => t.STT == Convert.ToInt64(row.Cells[2].Text));
                        dk.GhiDanh = !chk.Checked;
                        dc.SubmitChanges();
                    }
                }
            }

            grvUser.AllowPaging = true;
        }
        protected void btnGetCourses_Click(object sender, EventArgs e)
        {
            if (txtId.Text == "" || Convert.ToInt32(txtId.Text) < 1)
            {
                lblUpdateUserMessage.Text = "Vui lòng nhập một ID người dùng > 0";
                txtId.Focus();
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(MoodleEnrol.GetUsersCourses(Convert.ToInt32(txtId.Text), (string)Session["token"]));
            doc.Save("D:\\user_courses_" + txtId.Text + ".xml");

            XmlNode xmlnode = doc.ChildNodes[1];

            treeDetail.Nodes.Clear();
            treeDetail.Nodes.Add(new TreeNode(doc.DocumentElement.Name));
            TreeNode tNode;

            tNode = treeDetail.Nodes[0];
            MoodleUtilites.AddNode(xmlnode, tNode);
            treeDetail.ExpandAll();
        }