Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        protected void btnCreateCategory_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "")
            {
                lblCategoryMessage.Text = "Vui lòng nhập tên mục!";
                txtName.Focus();
                return;
            }

            MoodleCategory category = new MoodleCategory();

            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> list = new List <MoodleCategory>();

            list.Add(category);
            doc.LoadXml(MoodleCategory.CreateCategories(list, (string)Session["token"]));
            doc.Save("D:\\Category_" + txtIdnumber.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();
        }