Ejemplo n.º 1
0
        protected void btnGetDetail_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();

            List <int> list = new List <int>();

            list.Add(Convert.ToInt32(txtId.Text));
            doc.LoadXml(MoodleUser.GetUsersById(list, (string)Session["token"]));
            doc.Save("D:\\user_profile_" + 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();
            treeDetail.Focus();
        }
Ejemplo n.º 2
0
        protected void btnGetToken_Click(object sender, EventArgs e)
        {
            MoodleUser u = new MoodleUser(txtUsername.Text, txtPassword.Text);

            txtToken.Text     = u.GetToken(cboService.SelectedItem.Value);
            txtFunctions.Text = cboService.SelectedItem.Value;
        }
Ejemplo n.º 3
0
        protected void btnUpdate_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;
            }

            MoodleUser  user;
            XmlDocument doc = new XmlDocument();

            user = new MoodleUser
            {
                Id        = Convert.ToDouble(txtId.Text),
                Username  = txtNewUsername.Text,
                Password  = txtNewPassword.Text,
                Firstname = HttpUtility.HtmlDecode(txtFirstName.Text),
                Lastname  = HttpUtility.HtmlDecode(txtLastName.Text),
                Email     = txtEmail.Text
            };

            List <MoodleUser> list = new List <MoodleUser>();

            list.Add(user);
            doc.LoadXml(MoodleUser.UpdateUsers(list, (string)Session["token"]));
            doc.Save("D:\\user_update_" + txtId.Text + ".xml");
        }
Ejemplo n.º 4
0
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            SaveCheckedValues();

            grvUser.AllowPaging = false;
            grvUser.DataBind();

            MoodleUser  user;
            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))
                {
                    if (row.Cells[2].Text != "0")
                    {
                        continue;
                    }
                    user = new MoodleUser
                    {
                        Username  = row.Cells[3].Text,
                        Password  = row.Cells[3].Text,
                        Firstname = HttpUtility.HtmlDecode(row.Cells[5].Text),
                        Lastname  = HttpUtility.HtmlDecode(row.Cells[4].Text),
                        Email     = row.Cells[6].Text,
                        Timezone  = "7.0",
                        City      = "Hai Phong",
                        Country   = "VN"
                    };

                    List <MoodleUser> list = new List <MoodleUser>();
                    list.Add(user);
                    doc.LoadXml(MoodleUser.CreateUsers(list, (string)Session["token"]));
                    doc.Save("D:\\user_create_" + user.Username + ".xml");

                    if (doc.DocumentElement.Name == "RESPONSE")
                    {
                        long userId            = (long)Convert.ToUInt64(doc.DocumentElement.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText);
                        DCVimaruDataContext dc = new DCVimaruDataContext();
                        SinhVien            sv = dc.SinhViens.Single(t => t.MaSV == user.Username);
                        sv.Id = userId;
                        dc.SubmitChanges();
                    }
                }
            }

            grvUser.AllowPaging = true;
        }
Ejemplo n.º 5
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            SaveCheckedValues();

            grvUser.AllowPaging = false;
            grvUser.DataBind();

            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))
                {
                    int userId = Convert.ToInt32(row.Cells[3].Text);

                    if (userId == 0)
                    {
                        continue;
                    }

                    List <int> list = new List <int>();
                    list.Add(userId);

                    doc.LoadXml(MoodleUser.DeleteUsers(list, (string)Session["token"]));
                    doc.Save("D:\\user_delete_" + row.Cells[5].Text + ".xml");

                    if (doc.DocumentElement.Name == "RESPONSE")
                    {
                        DCVimaruDataContext dc = new DCVimaruDataContext();
                        SinhVien            sv = dc.SinhViens.Single(t => t.MaSV == MaSV);
                        sv.Id = 0;

                        dc.ExecuteCommand("UPDATE DangKy SET GhiDanh = 0, ID_Nhom = null WHERE MaSV = {0}", MaSV);
                        dc.SubmitChanges();
                    }
                }
            }

            grvUser.AllowPaging = true;
        }
Ejemplo n.º 6
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text == "" || txtPassword.Text == "")
            {
                return;
            }
            MoodleUser u = new MoodleUser(txtUsername.Text, txtPassword.Text);
            string     s = u.GetToken(cboService.SelectedValue);

            Session["token"] = s;
            if (s != "")
            {
                if (Session["refUrl"] != null)
                {
                    Response.Redirect((string)Session["refUrl"]);
                }
                else
                {
                    Response.Redirect("~/");
                }
            }
        }
Ejemplo n.º 7
0
        public static string GetToken(string username, string password, string service)
        {
            MoodleUser u = new MoodleUser(username, password);

            return(u.GetToken(service));
        }