Example #1
0
        /// <summary>
        /// Load XML
        /// </summary>
        private void ACTION_LoadXML()
        {
            string fname = VSUICommonFunctions.SelectFile(DEFX.KEY_LOAD_XML, "Select XML file for load", "XML files (*.xml" + ")|*.xml");

            if (fname != "")
            {
                VXmlNode n = cont.GetNode(VSLib.ConvertStringToLong(tvCat.SelectedNode.Name));
                tsNode.Text = "Loading " + fname + " ...";
                Application.DoEvents();
                Cursor.Current = Cursors.WaitCursor;
                cont.Begin();
                string rc = "";
                try
                {
                    if (n.NodeTypeCode == DEFX.NODE_TYPE_DOCUMENT)
                    {
                        VXmlDocument d = (VXmlDocument )cont.GetNode(n.Id);
                        rc = d.Load(fname);
                    }
                    else
                    {
                        rc = n.Load(fname);
                    }
                }
                catch (VXmlException e1)
                {
                    rc = e1.Message;
                }

                if (rc == "")
                {
                    cont.Commit();
                    SHOW_NodeInTree(n);
                }
                else
                {
                    cont.RollBack();
                    MessageBox.Show(rc, "Load error", MessageBoxButtons.OK);
                }
            }
            Cursor.Current = Cursors.Default;
            SELECT_Node();
        }
Example #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            short node_type = 0;

            string V = "";
            string N = "";

            for (int i = 0; i < n_type.Length; i++)
            {
                if (n_type[i] == cbNodeType.Text)
                {
                    node_type = n_type_code[i];
                    break;
                }
            }

            RC = 0;
            g.Read();
            N = g.GetValue("name");
            V = g.GetValue("value");

            if ((N == "") & DEFX.BR_NODE_NEED_NAME(node_type))
            {
                MessageBox.Show("Name field is not defined", "Error");
            }
            else if ((node_type == DEFX.NODE_TYPE_CONTENT) &
                     ((g.GetValue("file") == "") | (g.GetValue("title") == "")))
            {
                MessageBox.Show("File name or Title not defined", "Error");
            }
            else
            {
                VXmlNode node = CONT.GetNode(VSLib.ConvertStringToLong(TN.Name));
                try
                {
                    if (node_type == DEFX.NODE_TYPE_CONTENT)
                    {
                        VXmlContent c = node.CreateContent(g.GetValue("file"));
                    }
                    else if (node_type == DEFX.NODE_TYPE_CATALOG)
                    {
                        VXmlCatalog cat    = (VXmlCatalog)CONT.GetNode(node.Id);
                        VXmlCatalog newcat = cat.CreateCatalog(g.GetValue("name"));
                        if (V != "")
                        {
                            newcat.Value = V;
                        }
                    }
                    else if (node_type == DEFX.NODE_TYPE_DOCUMENT)
                    {
                        VXmlCatalog  cat = (VXmlCatalog)CONT.GetNode(node.Id);
                        VXmlDocument d   = cat.CreateDocument(N);
                        if (V != "")
                        {
                            d.Value = V;
                        }
                    }
                    else if (node_type == DEFX.NODE_TYPE_ATTRIBUTE)
                    {
                        node.SetAttribute(N, V);
                    }
                    else if (node_type == DEFX.NODE_TYPE_COMMENT)
                    {
                        node.CreateComment(V);
                    }
                    else if (node_type == DEFX.NODE_TYPE_TEXT)
                    {
                        node.CreateTextNode(V);
                    }
                    else if (node_type == DEFX.NODE_TYPE_TAG)
                    {
                        node.SetTag(V.Trim());
                    }
                    else if (node_type == DEFX.NODE_TYPE_ELEMENT)
                    {
                        VXmlElement el = node.CreateElement(N, V);
                    }
                    else
                    {
                        MessageBox.Show("Invalid node type '" + DEFX.GET_NODETYPE(node_type) + "'", "Error");
                        RC = 1;
                    }
                }
                catch (VXmlException ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                    RC = 1;
                }
                if (RC == 0)
                {
                    this.Close();
                }
            }
        }