silverlight 生成图表 WCF 解析XML代码.svc.cs 文件

silverlight 调用wcf 文件代码

  private ListItem AnalyzeXML(string XMLCode, string Reportdate, string ChartName, string OildomName)
        {
            IDataBase oDB = DBFactory.GetDBInstance();
            ListItem liChart = new ListItem();
            XmlDocument config;
            string basePath = System.AppDomain.CurrentDomain.BaseDirectory + "Silverlight\Config\SCYX\";
            string configPath = basePath + XMLCode;
            if (!System.IO.File.Exists(configPath))
            {
                throw new Exception("指定配置文件不存在!");
            }
            config = new XmlDocument();
            config.Load(configPath);

            XmlNode rootNode = config.SelectSingleNode("/ChartSet");
            if (rootNode == null)
            {
                throw new Exception("图集合的配置不存在!");
            }
            for (int i = 0; i < rootNode.ChildNodes.Count; i++)
            {
                try
                {
                    DataTable dt;
                    XmlNode ChartNode = rootNode.ChildNodes[i];
                    if (ChartNode == null)
                    {
                        throw new Exception("图的配置不存在!");
                    }
                    #region 获取Chart基本信息
                    if (ChartNode == null)
                    {
                        throw new Exception("图的配置不存在!");
                    }
                    liChart.ChartName = ChartName;
                    liChart.Title = ChartNode.Attributes["Title"].Value;
                    liChart.Title = liChart.Title.Replace("{Date}", Reportdate);
                    liChart.Title = liChart.Title.Replace("{OildomName}", OildomName);
                    liChart.ChartType = ChartNode.Attributes["ChartType"].Value;
                    #endregion

                    #region 获取Command信息
                    XmlNode xnCommand = ChartNode.SelectSingleNode("Command");
                    string sSQL = "";
                    if (xnCommand == null && xnCommand.ChildNodes.Count == 0)
                    {
                        throw new Exception("未找到配置数据SQL");
                    }
                    else
                    {
                        // string strBeginRepordate = Reportdate.Substring(0, 6) + "01";//月初
                        //string strEndRepordate = DateTime.ParseExact(strBeginRepordate, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture).AddMonths(1).AddDays(-1).ToString("yyyyMMdd");//月末
                        string strBeginRepordate = DateTime.ParseExact(Reportdate, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture).AddMonths(-1).ToString("yyyyMMdd");//当前日期前一个月
                        sSQL = (xnCommand.ChildNodes[0]).InnerText;
                        sSQL = sSQL.Replace("{Reportdate}", Reportdate);
                        sSQL = sSQL.Replace("{strBeginRepordate}", strBeginRepordate);
                        sSQL = sSQL.Replace("{OildomName}", OildomName);
                        dt = oDB.GetDataTable(sSQL);
                    }
                    #endregion

                    #region 获取AxisX信息
                    XmlNode xnAxisX = ChartNode.SelectSingleNode("AxisX");
                    string[] sXAXIS = new string[dt.Rows.Count];
                    for (int h = 0; h < dt.Rows.Count; h++)
                    {
                        sXAXIS[h] = dt.Rows[h][xnAxisX.Attributes["XField"].Value].ToString();
                    }
                    liChart.XAXIS = sXAXIS;
                    #endregion

                    #region 获取AxisY信息
                    XmlNode xnAxisY = ChartNode.SelectSingleNode("AxisY");
                    if (xnAxisY.Attributes["Unit"] != null)
                        liChart.YUint = xnAxisY.Attributes["Unit"].Value;
                    string strYear = Reportdate.Substring(0, 4);//本年
                    string strBegReportDate = DateTime.ParseExact(Reportdate, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture).AddYears(-1).ToString("yyyyMMdd").Substring(0, 4);//上一年
                    for (int j = 0; j < xnAxisY.ChildNodes.Count; j++)
                    {
                        XmlNode xnYChild = xnAxisY.ChildNodes[j];
                        YAXIS oYAXIS = new YAXIS();
                        oYAXIS.Name = xnYChild.Attributes["Name"].Value;
                        oYAXIS.Name = oYAXIS.Name.Replace("{Year-1}", strBegReportDate);
                        oYAXIS.Name = oYAXIS.Name.Replace("{Year}", strYear);
                        oYAXIS.Color = xnYChild.Attributes["Color"].Value;
                        oYAXIS.XField = xnYChild.Attributes["XField"].Value;
                        oYAXIS.YField = xnYChild.Attributes["YField"].Value;
                        double[] sYAXIS = new double[dt.Rows.Count];
                        for (int k = 0; k < dt.Rows.Count; k++)
                        {
                            sYAXIS[k] = Convert.ToDouble(dt.Rows[k][oYAXIS.YField]);
                        }
                        oYAXIS.YValue = sYAXIS;
                        liChart.YAXISs.Add(oYAXIS);
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    throw new Exception("获取配置文件失败!" + e.Message);
                }
            }

            return liChart;
        }

原文地址:https://www.cnblogs.com/xuxin-1989/p/3627530.html