示例#1
0
        //-------------------------------------------------------------------------
        /* Transform and convert xml to table, get data to Parent.DT, field names to Fields */
        void LoadXmlData(bool fieldsOnly = false)
        {
            Fields = new List <string>();
            DataTable dt;

            try
            {
                XmlDocument xml = XmlController.GetXml(CommonProc.GetFilePath(NameXml), Codepage);
                if (!XsltNone)
                {
                    xml = XmlController.Transform(xml, XsltFromFile ? CommonProc.GetFilePath(NameXslt) : XsltScript, XsltFromFile);
                }

                if (UseFieldsMap)
                {
                    dt = XmlController.GetData(xml, PathRow, FieldsMap, fieldsOnly); // getting data based on FieldMap
                }
                else
                {
                    dt = XmlController.GetData(xml, PathRow, DataFromTag, DataFromAttr, fieldsOnly); // getting data from tags/attributes
                }
                Fields = dt.Columns.OfType <DataColumn>().Select(x => x.ColumnName).ToList();

                if (!fieldsOnly)
                {
                    Parent.DT           = dt.Copy();
                    Parent.DT.TableName = Parent.Name;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(Parent.Name + ": " + ex.Message, ex);
            }
        }
示例#2
0
        //~~~~~~~~ Convert ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        #region
        //-------------------------------------------------------------------------
        private void bConvert_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            try
            {
                bs.EndEdit();
                bsFields.EndEdit();

                tbResult.Clear();
                tbResult.ClearUndo();
                dgResult.DataSource = null;
                XmlController.Dt    = null;
                GC.Collect();

                statusLabel.Text          = "";
                dgResult.ContextMenuStrip = null;
                Refresh();

                XmlDocument xml = XmlController.GetXml(CommonProc.GetFilePath(tbNameXml.Text), tbCodepage.Text);
                if (!rbXsltNotUse.Checked)
                {
                    xml = XmlController.Transform(xml, rbXsltFile.Checked ? CommonProc.GetFilePath(tbNameXslt.Text) : tbXslt.Text, rbXsltFile.Checked);
                }
                if (xml != null)
                {
                    tbResult.Language = xml.OuterXml.Length > MAX_XMLBYTES_FOR_COLOR ? Language.Custom : Language.HTML;
                    tbResult.Text     = xml.OuterXml;
                }
                if (cbUseFieldsMap.Checked)
                {
                    XmlController.Dt = XmlController.GetData(xml, tbPathRow.Text, (List <FieldMap>)bsFields.DataSource);
                }
                else
                {
                    XmlController.Dt = XmlController.GetData(xml, tbPathRow.Text, cbFromTag.Checked, cbFromAttrib.Checked);
                }
                dgResult.DataSource = XmlController.Dt;
                statusLabel.Text    = string.Format("{0} rows converted", XmlController.Dt.Rows.Count);
                if (XmlController.Dt.Rows.Count > 0)
                {
                    dgResult.ContextMenuStrip = cmsResult;
                }
                tabs.SelectedTab = tabPageResult;
            }
            catch (Exception ex)
            {
#if DEBUG
                MessageBox.Show(string.Format("{0}\n{1}", ex.Message, ex.InnerException), "Convert error", MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show(ex.Message, "Convert error", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }