protected void btnDelete_Click(object sender, EventArgs e) { MoodleDeleteCategory category = new MoodleDeleteCategory { Id = Convert.ToInt32(txtDeleteId.Text), NewParent = Convert.ToInt32(txtNewParent.Text), Recursive = rdbDeleteAllChildren.Checked == true?1:0 }; List <MoodleDeleteCategory> list = new List <MoodleDeleteCategory>(); list.Add(category); XmlDocument doc = new XmlDocument(); doc.LoadXml(MoodleDeleteCategory.DeleteCategories(list, (string)Session["token"])); doc.Save("D:\\" + category.Id + ".xml"); XmlNode xmlnode = doc.ChildNodes[1]; treeCategoryDetail.Nodes.Clear(); treeCategoryDetail.Nodes.Add(new TreeNode(doc.DocumentElement.Name)); TreeNode tNode; tNode = treeCategoryDetail.Nodes[0]; MoodleUtilites.AddNode(xmlnode, tNode); treeCategoryDetail.ExpandAll(); }
protected void grvGroup_SelectedIndexChanged(object sender, EventArgs e) { SaveCheckedValues(); int rowId = grvGroup.SelectedIndex; int groupId = Convert.ToInt32(grvGroup.Rows[rowId].Cells[2].Text.ToString()); XmlDocument doc = new XmlDocument(); ArrayList arrIDs = ConvertToArrayList(txtListId.Text); List <int> list = new List <int>(); list.Add(groupId); doc.LoadXml(MoodleGroup.GetGroupMembers(list, (string)Session["token"])); doc.Save("D:\\Grouping_Get_Members_" + cboGrouping.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(); }
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(); }
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(); }
protected void Page_Load(object sender, EventArgs e) { btnRedirectLogin.Visible = (Session["token"] == null || (string)Session["token"] == ""); if (!IsPostBack) { cboService.DataSource = MoodleUtilites.GetServiceTable(); cboService.DataBind(); } }
protected void btnCreate_Click(object sender, EventArgs e) { SaveCheckedValues(); grvCourse.AllowPaging = false; grvCourse.DataBind(); MoodleCourse course; XmlDocument doc = new XmlDocument(); ArrayList arrIDs = ConvertToArrayList(txtListId.Text); string idnum = "0"; DCVimaruDataContext dc = new DCVimaruDataContext(); HocPhan hocphan = dc.HocPhans.Single(t => t.MaHP == cboFilterSubject.SelectedValue); int parent = Convert.ToInt32(hocphan.Id); foreach (GridViewRow row in grvCourse.Rows) { idnum = grvCourse.DataKeys[row.RowIndex]["STT"].ToString(); if (arrIDs.Contains(idnum)) { if (row.Cells[2].Text != "0") { continue; } string fullname = HttpUtility.HtmlDecode(row.Cells[4].Text + " " + row.Cells[5].Text + "-" + row.Cells[6].Text); course = new MoodleCourse( fullname, fullname, parent, MoodleUtilites.GetIdNumber(fullname), fullname, MoodleUtilites.ConvertToTimestamp(row.Cells[6].Text) ); List <MoodleCourse> list = new List <MoodleCourse>(); list.Add(course); doc.LoadXml(MoodleCourse.CreateCourses(list, (string)Session["token"])); doc.Save("D:\\course_create_" + row.Cells[3].Text + ".xml"); if (doc.DocumentElement.Name == "RESPONSE") { long id = (long)Convert.ToUInt32(doc.DocumentElement.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText); ThoiKhoaBieu tkb = dc.ThoiKhoaBieus.Single(t => t.STT == Convert.ToInt32(row.Cells[3].Text)); tkb.Id = id; dc.SubmitChanges(); } } } grvCourse.AllowPaging = true; }
public string GetToken(string service) { MoodleWebRequest web = new MoodleWebRequest(MoodleUrl.LoginUrl, "POST", "username="******"&password="******"&service=" + service); // Chuỗi có dạng {"token":"d75f2169ec6320a689c67fb5869360e1"} string s = web.GetResponse(); string[] rs = s.Split(new char[] { '"' }); MoodleUtilites.WriteTextToFile("D:\\token.txt", s); // Sau khi tách s[5] = {"","token",":","d75f2169ec6320a689c67fb5869360e1",""} if (rs.Count() != 5) { return(""); } return(rs[3].Trim()); }
protected void btnDetail_Click(object sender, EventArgs e) { List <KeyValuePair <string, string> > lst = new List <KeyValuePair <string, string> >(); int id = ddlCriteria.SelectedIndex; if (id == 0) { lst.Add(new KeyValuePair <string, string> ("id", txtId.Text)); lst.Add(new KeyValuePair <string, string> ("name", HttpUtility.HtmlDecode(txtName.Text))); lst.Add(new KeyValuePair <string, string> ("parent", txtParent.Text)); lst.Add(new KeyValuePair <string, string> ("idnumber", txtIdnumber.Text)); } else if (id == 1) { lst.Add(new KeyValuePair <string, string> ("id", txtId.Text)); } else if (id == 2) { lst.Add(new KeyValuePair <string, string> ("name", HttpUtility.HtmlDecode(txtName.Text))); } else if (id == 3) { lst.Add(new KeyValuePair <string, string> ("parent", txtParent.Text)); } else { lst.Add(new KeyValuePair <string, string> ("idnumber", txtIdnumber.Text)); } XmlDocument doc = new XmlDocument(); doc.LoadXml(MoodleCategory.GetCategories(lst, chkSubCategory.Checked, (string)Session["token"])); doc.Save("D:\\" + txtId.Text + ".xml"); XmlNode xmlnode = doc.ChildNodes[1]; treeCategoryDetail.Nodes.Clear(); treeCategoryDetail.Nodes.Add(new TreeNode(doc.DocumentElement.Name)); TreeNode tNode; tNode = treeCategoryDetail.Nodes[0]; MoodleUtilites.AddNode(xmlnode, tNode); treeCategoryDetail.ExpandAll(); }
protected void Page_Load(object sender, System.EventArgs e) { if (Session["token"] != null && Session["token"].ToString() != "") { palLogin.Visible = false; palUser.Visible = true; MainMenu.Visible = true; } else { palLogin.Visible = true; palUser.Visible = false; MainMenu.Visible = false; if (!IsPostBack) { cboService.DataSource = MoodleUtilites.GetServiceTable(); cboService.DataBind(); } } }
protected void btnGetDetail_Click(object sender, EventArgs e) { if (txtId.Text == "" || Convert.ToInt32(txtId.Text) < 1) { lblUpdateMessage.Text = "Vui lòng nhập một ID khoa> 0"; txtId.Focus(); return; } List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >(); int id = ddlCriteria.SelectedIndex; if (id == 0) { list.Add(new KeyValuePair <string, string> ("id", txtId.Text)); } else if (id == 1) { list.Add(new KeyValuePair <string, string> ("idnumber", txtIdnumber.Text)); } else { list.Add(new KeyValuePair <string, string> ("name", HttpUtility.HtmlDecode(txtName.Text))); } XmlDocument doc = new XmlDocument(); doc.LoadXml(MoodleCategory.GetCategories(list, chkSubCategory.Checked, (string)Session["token"])); doc.Save("D:\\faculty_" + 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(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["token"] != null && (string)Session["token"] != "") { if (Session["refUrl"] != null) { Response.Redirect((string)Session["refUrl"]); } else { Response.Redirect("~/"); } } else { txtUsername.Focus(); if (!IsPostBack) { cboService.DataSource = MoodleUtilites.GetServiceTable(); cboService.DataBind(); } } }
protected void grvCourse_SelectedIndexChanged(object sender, EventArgs e) { SaveCheckedValues(); int rowId = grvCourse.SelectedIndex; GridViewRow row = grvCourse.Rows[rowId]; XmlDocument doc = new XmlDocument(); int id = Convert.ToInt32(row.Cells[2].Text); List <int> list = new List <int>(); list.Add(id); doc.LoadXml(MoodleCourse.GetCourses(list, (string)Session["token"])); doc.Save("D:\\course_detail_" + row.Cells[3].Text + ".xml"); XmlNode xmlNode = doc.ChildNodes[1]; treeDetail.Nodes.Clear(); treeDetail.Nodes.Add(new TreeNode(doc.DocumentElement.Name)); TreeNode treeNode; treeNode = treeDetail.Nodes[0]; MoodleUtilites.AddNode(xmlNode, treeNode); treeDetail.ExpandAll(); doc.LoadXml(MoodleCourse.GetCourseContents(id, (string)Session["token"])); doc.Save("D:\\course_contents_" + row.Cells[3].Text + ".xml"); xmlNode = doc.ChildNodes[1]; treeContent.Nodes.Clear(); treeContent.Nodes.Add(new TreeNode(doc.DocumentElement.Name)); treeNode = treeContent.Nodes[0]; MoodleUtilites.AddNode(xmlNode, treeNode); treeContent.ExpandAll(); treeDetail.Focus(); }
protected void btnUpdate_Click(object sender, EventArgs e) { if (txtId.Text == "") { lblCategoryMessage.Text = "Vui lòng nhập id mục cần cập nhật!"; txtId.Focus(); return; } MoodleCategory category = new MoodleCategory(); category.Id = Convert.ToInt32(txtId.Text); if (txtName.Text != "") { category.Name = txtName.Text; } if (txtParent.Text == "") { category.Parent = 0; } else { category.Parent = Convert.ToInt32(txtParent.Text); } if (txtIdnumber.Text == "") { category.IdNumber = null; } else { category.IdNumber = txtIdnumber.Text; } if (txtDecscription.Text == "") { category.Description = null; } else { category.Description = txtDecscription.Text; } if (txtDescriptionFormat.Text == "") { category.DescriptionFormat = 1; } else { category.DescriptionFormat = Convert.ToInt32(txtDescriptionFormat.Text); } if (txtTheme.Text == "") { category.Theme = null; } else { category.Theme = txtTheme.Text; } XmlDocument doc = new XmlDocument(); List <MoodleCategory> lst = new List <MoodleCategory>(); lst.Add(category); doc.LoadXml(MoodleCategory.UpdateCategories(lst, (string)Session["token"])); doc.Save("D:\\" + txtId.Text + ".xml"); XmlNode xmlnode = doc.ChildNodes[1]; treeCategoryDetail.Nodes.Clear(); treeCategoryDetail.Nodes.Add(new TreeNode(doc.DocumentElement.Name)); TreeNode tNode; tNode = treeCategoryDetail.Nodes[0]; MoodleUtilites.AddNode(xmlnode, tNode); treeCategoryDetail.ExpandAll(); }