Exemplo n.º 1
0
        /// <summary>
        /// 根据参数Xml文档列表生成指定段名的宏变量参数:
        /// </summary>
        /// <param name="xmldoc">文档参数</param>
        /// <param name="bandName">段名称</param>
        /// <returns>返回参数</returns>
        static public NameObjectList BuildParamMacro(XmlDocument xmldoc, string bandName)
        {
            if (string.IsNullOrEmpty(bandName))
            {
                return(BuildParams(xmldoc));
            }
            string         strPath   = "/*/PL[(@t='{0}' and @t!='B')or(@t='B' and @n='{2}')]/L[@t='{1}']/P[@pt='M']";
            string         strPass   = "******";
            NameObjectList paramList = new NameObjectList();

            for (int i = _typerange.Length - 1; i > -1; i--)
            {
                for (int j = _typeuser.Length - 1; j > -1; j--)
                {
                    string      strFind = string.Format(strPath, _typerange[i], _typeuser[j], bandName);
                    XmlNodeList xnlist  = xmldoc.SelectNodes(strFind);
                    foreach (XmlNode xnP in xnlist)
                    {
                        if (null == xnP.Attributes["n"])
                        {
                            continue;
                        }
                        string key     = xnP.Attributes["n"].Value;
                        bool   isParam = true;
                        for (int m = i; m > -1; m--)
                        {
                            for (int n = j - 1; n > -1; n--)
                            {
                                string  strFindPass = string.Format(strPass, _typerange[m], _typeuser[n], key, bandName);
                                XmlNode xnPtemp     = xnP.SelectSingleNode(strFindPass);
                                if (null != xnPtemp)
                                {
                                    isParam = false;
                                    break;
                                }
                            }
                            if (!isParam)
                            {
                                break;
                            }
                        }
                        //增加到参数列表
                        if (isParam)
                        {
                            BuildParamList.setParamByParamNode(paramList, xnP);
                        }
                    }//foreach (XmlNode xnP in xnlist)
                }
            }
            return(paramList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据参数Xml文档列表生成指定段对应参数:数组List只限定于PL[@t='B']/L[@='D']/List
        /// </summary>
        /// <param name="xmldoc">文档参数</param>
        /// <param name="bandName">段名称</param>
        /// <returns>返回参数数组</returns>
        static public NameObjectList[] BuildParamsList(XmlDocument xmldoc, string bandName)
        {
            if (string.IsNullOrEmpty(bandName))
            {
                return(BuildParamsList(xmldoc));
            }
            string         strPath   = "/*/PL[(@t='{0}'and @t!='B')or(@t='B' and @n='{2}')]/L[@t='{1}']/P[not(@pt) or @pt!='M']";
            string         strPath2  = "/*/PL[(@t='{0}'and @t!='B')or(@t='B' and @n='{2}')]/L[@t='{1}']/List/P";
            string         strPass   = "******";
            string         strPass2  = "/*/PL[(@t='{0}'and @t!='B')or(@t='B' and @n='{3}')]/L[@t='{1}']/List/P[@n='{2}']";
            NameObjectList paramList = new NameObjectList();

            for (int i = _typerange.Length - 1; i > -1; i--)
            {
                for (int j = _typeuser.Length - 1; j > -1; j--)
                {
                    string strFind = string.Format(strPath, _typerange[i], _typeuser[j], bandName);
                    if (null != xmldoc.SelectSingleNode(string.Format(strPath2, _typerange[i], _typeuser[j], bandName)))
                    {
                        continue;
                    }
                    XmlNodeList xnlist = xmldoc.SelectNodes(strFind);
                    foreach (XmlNode xnP in xnlist)
                    {
                        if (null == xnP.Attributes["n"])
                        {
                            continue;
                        }
                        string key     = xnP.Attributes["n"].Value;
                        bool   isParam = true;
                        for (int m = i; m > -1; m--)
                        {
                            for (int n = j - 1; n > -1; n--)
                            {
                                string  strFindPass = string.Format(strPass, _typerange[m], _typeuser[n], key, bandName);
                                XmlNode xnPtemp     = xnP.SelectSingleNode(strFindPass);
                                if (null != xnPtemp)
                                {
                                    isParam = false;
                                    break;
                                }
                                string strFindPass2 = string.Format(strPass2, _typerange[m], _typeuser[n], key, bandName);
                                xnPtemp = xnP.SelectSingleNode(strFindPass2);
                                if (null != xnPtemp)
                                {
                                    isParam = false;
                                    break;
                                }
                            }
                            if (!isParam)
                            {
                                break;
                            }
                        }
                        //增加到参数列表
                        if (isParam)
                        {
                            BuildParamList.setParamByParamNode(paramList, xnP);
                        }
                    }//foreach (XmlNode xnP in xnlist)
                }
            }

            strPath2 = "/*/PL[(@t='{0}'and @t!='B')or(@t='B' and @n='{2}')]/L[@t='{1}']/List";
            string      strFind2   = string.Format(strPath2, "B", "D", bandName);
            XmlNodeList xnlistList = xmldoc.SelectNodes(strFind2);

            NameObjectList[] param = new NameObjectList[xnlistList.Count];
            for (int i = 0; i < xnlistList.Count; i++)
            {
                param[i] = new NameObjectList();
                for (int k = 0; k < paramList.Count; k++)
                {
                    param[i][paramList.Keys[k]] = paramList[k];
                }
                XmlNodeList xnlist = xnlistList[i].SelectNodes("P");
                foreach (XmlNode xnP in xnlist)
                {
                    BuildParamList.setParamByParamNode(param[i], xnP);
                }
            }
            return(param);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 对xmlData数据文档按照strFld字段进行分组合计;xmlSchema数据文档的结构
        /// </summary>
        /// <param name="xmlData">数据文档</param>
        /// <param name="xmlSchema">数据文档结构</param>
        /// <param name="strFld">数据文档分组合计的字段</param>
        /// <returns>没有数据返回null,成功返回null</returns>
        static public XmlReader XmlGroupSum(XmlDocument xmlData, XmlDocument xmlSchema, string strFld)
        {
            if (null == xmlData || null == xmlSchema || "" == strFld || string.Empty == strFld)
            {
                return(null);
            }
            XmlNode nodeRow = xmlData.SelectSingleNode("/*/*");

            if (null == nodeRow)
            {
                return(null);
            }
            XmlNamespaceManager xmlNsMgl   = new XmlNamespaceManager(xmlSchema.NameTable);
            XmlNode             xmlRootEle = xmlSchema.DocumentElement;

            for (int i = 0; i < xmlRootEle.Attributes.Count; i++)
            {
                string strPrefix    = xmlRootEle.Attributes[i].Prefix;
                string strLocalName = xmlRootEle.Attributes[i].LocalName;
                string strURI       = xmlRootEle.Attributes[i].Value;
                if ("xmlns" == strLocalName)
                {
                    xmlNsMgl.AddNamespace(string.Empty, strURI);
                }
                if ("xmlns" != strPrefix)
                {
                    continue;
                }
                xmlNsMgl.AddNamespace(strLocalName, strURI);
            }
            //添加汇总列模板参数分组的列名;
            XmlDocument         XSLGroupSum = BuildParamList.getXSLGroupSum();
            XmlNamespaceManager xmlNsMglGS  = new XmlNamespaceManager(XSLGroupSum.NameTable);

            xmlRootEle = XSLGroupSum.DocumentElement;
            for (int i = 0; i < xmlRootEle.Attributes.Count; i++)
            {
                string strPrefix    = xmlRootEle.Attributes[i].Prefix;
                string strLocalName = xmlRootEle.Attributes[i].LocalName;
                string strURI       = xmlRootEle.Attributes[i].Value;
                if ("xmlns" == strLocalName)
                {
                    xmlNsMglGS.AddNamespace(string.Empty, strURI);
                }
                if ("xmlns" != strPrefix)
                {
                    continue;
                }
                xmlNsMglGS.AddNamespace(strLocalName, strURI);
            }
            XmlElement eleKey        = XSLGroupSum.SelectSingleNode("//xsl:key", xmlNsMglGS) as XmlElement;
            XmlElement eleTpCall     = XSLGroupSum.SelectSingleNode("//xsl:call-template", xmlNsMglGS) as XmlElement;
            XmlElement eleTp         = XSLGroupSum.SelectSingleNode("//xsl:template[@name='tempsum']", xmlNsMglGS) as XmlElement;
            XmlElement eleTpCopy     = eleTp.CloneNode(true) as XmlElement;
            XmlElement eleTpCallCopy = eleTpCall.CloneNode(true) as XmlElement;
            XmlElement eleParam      = eleTpCall.SelectSingleNode("xsl:with-param[@name='groupby']", xmlNsMglGS) as XmlElement;
            string     strXML        = XSLGroupSum.OuterXml;

            eleParam.InnerText = strFld;
            eleKey.SetAttribute("match", nodeRow.LocalName);
            eleKey.SetAttribute("use", strFld);

            XmlElement  eleRowGroup = eleTp.SelectSingleNode("xsl:for-each/xsl:element", xmlNsMglGS) as XmlElement;
            XmlNodeList colList     = xmlSchema.SelectNodes("//xs:sequence//xs:element[@footer!='' and ( @type='xs:int' or @type='xs:number' or type='xs:float' or type='xs:decimal' or type='xs:double' )]", xmlNsMgl);

            for (int i = 0; i < colList.Count; i++)
            {
                XmlElement colEle  = colList[i] as XmlElement;
                string     colname = colEle.GetAttribute("name");
                string     sumfoot = colEle.GetAttribute("footer");
                eleParam = eleTpCall.InsertBefore(eleTpCall.OwnerDocument.CreateElement("xsl:with-param"), eleTpCall.FirstChild) as XmlElement;
                eleParam.SetAttribute("name", "col" + i);
                eleParam.InnerText = colname;
                eleParam           = eleTp.InsertBefore(eleTp.OwnerDocument.CreateElement("xsl:param"), eleTp.FirstChild) as XmlElement;
                eleParam.SetAttribute("name", "col" + i);

                XmlElement eleCol = eleRowGroup.AppendChild(eleRowGroup.OwnerDocument.CreateElement("xsl:element")) as XmlElement;
                eleCol.SetAttribute("name", "{$col" + i + "}");
                XmlElement eleValue = eleCol.AppendChild(eleCol.OwnerDocument.CreateElement("xsl:value-of")) as XmlElement;
                eleValue.SetAttribute("select", "sum(key('pkname',$keyvalue)/*[name()=$col" + i + "])");
            }
            if (colList.Count < 1)
            {
                XSLGroupSum.LoadXml(strXML);
                return(null);
            }
            XslTransform xsltGS = new XslTransform();

            xsltGS.Load(XSLGroupSum);
            XmlReader xmlrd = xsltGS.Transform(xmlData, null);

            XSLGroupSum.LoadXml(strXML);
            return(xmlrd);
        }