protected void btnUpdate_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;
            }

            MoodleCategory category;
            XmlDocument    doc = new XmlDocument();

            category = new MoodleCategory
            {
                Id                = Convert.ToInt32(txtId.Text),
                Name              = HttpUtility.HtmlDecode(txtName.Text),
                Parent            = 0,
                IdNumber          = HttpUtility.HtmlDecode(txtIdnumber.Text),
                Description       = HttpUtility.HtmlDecode(txtName.Text),
                DescriptionFormat = 1,
                Theme             = null
            };

            List <MoodleCategory> lst = new List <MoodleCategory>();

            lst.Add(category);
            doc.LoadXml(MoodleCategory.UpdateCategories(lst, (string)Session["token"]));
            doc.Save("D:\\faculty_" + txtId.Text + ".xml");
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtId.Text == "" || Convert.ToInt32(txtId.Text) < 1)
            {
                lblUpdateMessage.Text = "Vui lòng nhập một ID bộ môn > 0";
                txtId.Focus();
                return;
            }

            DCVimaruDataContext dc = new DCVimaruDataContext();
            Khoa khoa   = dc.Khoas.Single(t => t.MaKhoa == cboFilter.SelectedValue);
            int  parent = Convert.ToInt32(khoa.Id);

            MoodleCategory category;
            XmlDocument    doc = new XmlDocument();

            category = new MoodleCategory
            {
                Id                = Convert.ToInt32(txtId.Text),
                Name              = HttpUtility.HtmlDecode(txtName.Text),
                Parent            = parent,
                IdNumber          = HttpUtility.HtmlDecode(txtIdnumber.Text),
                Description       = HttpUtility.HtmlDecode(txtName.Text),
                DescriptionFormat = 1,
                Theme             = null
            };

            List <MoodleCategory> lst = new List <MoodleCategory>();

            lst.Add(category);
            doc.LoadXml(MoodleCategory.UpdateCategories(lst, (string)Session["token"]));
            doc.Save("D:\\department_" + txtId.Text + ".xml");
        }
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            SaveCheckedValues();

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

            MoodleCategory category;
            XmlDocument    doc    = new XmlDocument();
            ArrayList      arrIDs = ConvertToArrayList(txtListId.Text);
            string         idnum  = "0";

            DCVimaruDataContext dc = new DCVimaruDataContext();
            Khoa khoa   = dc.Khoas.Single(t => t.MaKhoa == cboFilter.SelectedValue);
            int  parent = Convert.ToInt32(khoa.Id);

            foreach (GridViewRow row in grvDepartment.Rows)
            {
                if (row.Cells[2].Text != "0")
                {
                    continue;
                }
                idnum = grvDepartment.DataKeys[row.RowIndex]["MaBoMon"].ToString();
                if (arrIDs.Contains(idnum))
                {
                    category = new MoodleCategory
                    {
                        Name              = HttpUtility.HtmlDecode(row.Cells[4].Text),
                        Parent            = parent,
                        IdNumber          = HttpUtility.HtmlDecode(row.Cells[3].Text),
                        Description       = HttpUtility.HtmlDecode(row.Cells[4].Text),
                        DescriptionFormat = 1,
                        Theme             = null
                    };

                    List <MoodleCategory> lst = new List <MoodleCategory>();
                    lst.Add(category);
                    doc.LoadXml(MoodleCategory.CreateCategories(lst, (string)Session["token"]));
                    doc.Save("D:\\department_" + category.IdNumber + ".xml");
                    if (doc.DocumentElement.Name == "RESPONSE")
                    {
                        long  id    = (long)Convert.ToUInt32(doc.DocumentElement.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText);
                        BoMon bomon = dc.BoMons.Single(t => t.MaBoMon == Convert.ToInt32(category.IdNumber));
                        bomon.Id = id;
                        dc.SubmitChanges();
                    }
                }
            }

            grvDepartment.AllowPaging = true;
        }
        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 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 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();
        }