duheng
2024-07-25 713d5218ee2b47c0c92f75c19c49bb7e883cd214
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using DevExpress.Charts.Native;
using DevExpress.ClipboardSource.SpreadsheetML;
using DevExpress.Utils;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using DevExpress.XtraRichEdit.Fields.Expression;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
 
using IStation.Calc;
 
namespace IStation.WinFrmUI.CalcErQu
{
    public partial class ViewRealTimeRiverWaterLevelCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public ViewRealTimeRiverWaterLevelCtrl()
        {
            InitializeComponent();
        }
 
  
        private Series _areaSeries;
 
 
        /// <summary>
        /// 初始化默认系列
        /// </summary>
        /// <param name="timeValues">数据源</param>
        public void SetBindingData(List<Model.TimeWaterLevel> timeValues)
        {
            _areaSeries = this.chartControl1.Series[0];
            if (timeValues == null || timeValues.Count() < 1)
            {
               // _defaultSeries.BindToData(timeValues, null);
            }
            else
            {
                timeValueBindingSource.DataSource = timeValues;
               // _defaultSeries.BindToData(timeValues, "Time", "Level");
            }
            //GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
            //GC.Collect(2, GCCollectionMode.Forced);
            //GC.WaitForFullGCComplete();
        }
        public List<Model.TimeWaterLevel> SetBindingData3Day(DateTime start, DateTime end,out string benchmark)
        {
            benchmark = null;
            DateTime toDay = start.Date;
            DateTime yesterDay = toDay.AddDays(-1);
            DateTime tomor = toDay.AddDays( 1);
            string benchmark1, benchmark2, benchmark3;
            string error;
            var waterLevels长江1 = IStation.WinFrmUI.CalcErQu.TideHelper.GetByTime(yesterDay, toDay, out benchmark1, out error);
            var waterLevels长江2 = IStation.WinFrmUI.CalcErQu.TideHelper.GetByTime(toDay, tomor, out benchmark2, out error);
            var waterLevels长江3 = IStation.WinFrmUI.CalcErQu.TideHelper.GetByTime(tomor, tomor.AddDays(1),out benchmark3, out error);
            List<Model.TimeWaterLevel> timeValues = new List<Model.TimeWaterLevel>();
            if (waterLevels长江1 != null)
            {
                timeValues.AddRange(waterLevels长江1);
            }
            if (waterLevels长江2 != null)
            {
                benchmark = benchmark2;
                timeValues.AddRange(waterLevels长江2);
            }
            if (waterLevels长江3 != null)
            {
                timeValues.AddRange(waterLevels长江3);
            }
            _areaSeries = this.chartControl1.Series[0];
            if (timeValues == null || timeValues.Count() < 1)
            {
                // _defaultSeries.BindToData(timeValues, null);
            }
            else
            {
                timeValueBindingSource.DataSource = timeValues;
                // _defaultSeries.BindToData(timeValues, "Time", "Level");
               // this.chartControl1.AnnotationRepository[]
                DevExpress.XtraCharts.TextAnnotation textAnnotationMax = this.chartControl1.AnnotationRepository[0] as DevExpress.XtraCharts.TextAnnotation ;
                DevExpress.XtraCharts.PaneAnchorPoint paneAnchorPointMax = textAnnotationMax.AnchorPoint as DevExpress.XtraCharts.PaneAnchorPoint ;
 
                DevExpress.XtraCharts.TextAnnotation textAnnotationMin = this.chartControl1.AnnotationRepository[1] as DevExpress.XtraCharts.TextAnnotation;
                DevExpress.XtraCharts.PaneAnchorPoint paneAnchorPointMin = textAnnotationMin.AnchorPoint as DevExpress.XtraCharts.PaneAnchorPoint;
 
                var maxLevel = timeValues.Where(x => x.Time >= start && x.Time <= end).FindObjMaxBy(x => x.Level);
                paneAnchorPointMax.AxisXCoordinate.AxisValueSerializable = maxLevel.Time.ToString();
                paneAnchorPointMax.AxisYCoordinate.AxisValueSerializable = maxLevel.Level.ToString();
                textAnnotationMax.Text = string.Format("max:{0}", maxLevel.Level);
 
                var minLevel = timeValues.Where(x => x.Time >= start && x.Time <= end).FindObjMinBy(x => x.Level);
                paneAnchorPointMin.AxisXCoordinate.AxisValueSerializable = minLevel.Time.ToString();
                paneAnchorPointMin.AxisYCoordinate.AxisValueSerializable = minLevel.Level.ToString();
                textAnnotationMin.Text = string.Format("min:{0}", minLevel.Level);
            }
            SetStripRange(start, end);
            return timeValues;
        }
 
        private bool isInitialRange=false;
        public void SetStripRange(DateTime start, DateTime end)
        {
            var xyDiagram = this.chartControl1.Diagram as DevExpress.XtraCharts.XYDiagram;
            var strp = xyDiagram.AxisX.Strips[0];
            if (!isInitialRange)
            {
                isInitialRange = true;
                strp.MaxLimit.AxisValueSerializable = end.ToString();// "01/01/0001 01:00:00.000";
                strp.MinLimit.AxisValueSerializable = start.ToString();// "01/01/0001 00:00:00.000";
            }
            else if (DateTime.Parse(strp.MinLimit.AxisValueSerializable) > end)
            {
                isInitialRange=true;
                strp.MinLimit.AxisValueSerializable = start.ToString();// "01/01/0001 00:00:00.000";
                strp.MaxLimit.AxisValueSerializable = end.ToString();// "01/01/0001 01:00:00.000";
 
            }
            else
            {
                isInitialRange = true;
                strp.MaxLimit.AxisValueSerializable = end.ToString();// "01/01/0001 01:00:00.000";
                strp.MinLimit.AxisValueSerializable = start.ToString();// "01/01/0001 00:00:00.000";       
            }
        }
 
    }
}