protected void btnDelete_Click(object sender, EventArgs e) { SaveCheckedValues(); grvCourse.AllowPaging = false; grvCourse.DataBind(); XmlDocument doc = new XmlDocument(); ArrayList arrIDs = ConvertToArrayList(txtListId.Text); string idnum = "0"; DCVimaruDataContext dc = new DCVimaruDataContext(); foreach (GridViewRow row in grvCourse.Rows) { idnum = grvCourse.DataKeys[row.RowIndex]["STT"].ToString(); if (arrIDs.Contains(idnum)) { int id = Convert.ToInt32(row.Cells[2].Text); List <int> list = new List <int>(); if (id != 0) { list.Add(id); } else { continue; } doc.LoadXml(MoodleCourse.DeleteCourses(list, (string)Session["token"])); doc.Save("D:\\course_delete_" + row.Cells[3].Text + ".xml"); if (doc.DocumentElement.Name == "RESPONSE") { int maTKB = Convert.ToInt32(row.Cells[3].Text); // Reset Moodle Id of Thoi khoa bieu to 0 ThoiKhoaBieu tkb = dc.ThoiKhoaBieus.Single(t => t.STT == maTKB); tkb.Id = 0; // Reset GhiDanh of Dang ky to false and ID_Nhom to null dc.ExecuteCommand("UPDATE [dbo].[DangKy] SET GhiDanh = 0 , ID_Nhom = null WHERE MaTKB = {0}", maTKB); // Delete group dc.ExecuteCommand("DELETE FROM [dbo].[Nhom] WHERE MaTKB = {0}", maTKB); // Delete grouping dc.ExecuteCommand("DELETE FROM [dbo].[To] WHERE MaTKB = {0}", maTKB); dc.SubmitChanges(); } } } grvCourse.AllowPaging = true; }
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; }
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(); }