Esempio n. 1
0
 public static string SerializeToXml(ChartParameters request)
 {
     using (StringWriter writer = new StringWriter())
     {
         XmlSerializer serializer = new XmlSerializer(typeof(ChartParameters));
         serializer.Serialize(writer, request);
         return(writer.ToString());
     }
 }
Esempio n. 2
0
        public static ChartResult GetData(ChartParameters request, string ReportClassFieldID = "")
        {
            ChartResult result = new ChartResult();

            string        strCriteria;
            XmlSerializer serializer = new XmlSerializer(request.Criterias.GetType());

            using (StringWriter sw = new StringWriter())
            {
                using (var xw = XmlWriter.Create(sw, new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true
                }))
                {
                    serializer.Serialize(xw, request.Criterias);
                    strCriteria = sw.ToString();
                }
            }

            result.Series  = new List <ChartSeries>();
            result.Changes = new List <ChartChange>();

            using (Entity db = new Entity())
            {
                db.Database.Initialize(false);

                var cmd = db.Database.Connection.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "dbo.p_get_chart_data";
                cmd.Parameters.Add(new SqlParameter("@indicator_id", request.IndicatorId));
                cmd.Parameters.Add(new SqlParameter("@criteria_xml", strCriteria));
                cmd.Parameters.Add(new SqlParameter("@report_class_fieldid", ReportClassFieldID));

                try
                {
                    db.Database.Connection.Open();
                    var reader = cmd.ExecuteReader();

                    var dbSeries = ((IObjectContextAdapter)db).ObjectContext.Translate <ChartSeries>(reader);
                    foreach (var item in dbSeries)
                    {
                        result.Series.Add(item);
                    }

                    reader.NextResult();
                    var dbResults = ((IObjectContextAdapter)db).ObjectContext.Translate <TimeSeriesPoint>(reader).ToArray();
                    foreach (var s in result.Series)
                    {
                        s.Points = dbResults.Where(x => x.SeriesId == s.SeriesId).ToArray();
                    }

                    reader.NextResult();
                    var dbChanges = ((IObjectContextAdapter)db).ObjectContext.Translate <ChartChange>(reader).ToArray();
                    foreach (var c in dbChanges)
                    {
                        result.Changes.Add(c);
                    }
                }
                finally
                {
                    db.Database.Connection.Close();
                }
            }

            for (int i = 0; i < result.Series.Count; i++)
            {
                result.Series.ElementAt(i).Color = new Color(request.Criterias[i].ColorId);
            }

            if (request.AddMedian && result.Series.Count == 1)
            {
                result.RulesResult = new ChartRulesResult <DateTime>(
                    (ICollection <IPoint <DateTime> >)result.Series.ElementAt(0).Points);
            }

            return(result);
        }