Newer
Older
EMS_REFACTOR / FrmValveStatistics.cs
nn-203 on 26 Jul 2017 8 KB first commit
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using Cyberpipe.PATM_Forms;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Globe;

namespace Cyberpipe
{
    public partial class FrmValveStatistics : Office2007Form
    {
        private MainFrm.DataGridViewDelegate m_InitDataGridViewX1;
        private Dictionary<string, GSOFeatures> map;
        private GSOGlobeControl globeControl1;
        private GSOGeoPolygon3D polygon;
        private MainFrm.PageControlStuct _pageControl;

        public FrmValveStatistics(GSOGlobeControl ctl, GSOGeoPolygon3D polygon, MainFrm.DataGridViewDelegate InitDataGridViewX1, MainFrm.PageControlStuct pageControl)
        {
            InitializeComponent();
            globeControl1 = ctl;
            m_InitDataGridViewX1 = InitDataGridViewX1;
            this.polygon = polygon;
            _pageControl = pageControl;
        }
        /// <summary>
        /// 窗体初始化事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmLayerSelectedQuery_Load(object sender, EventArgs e)
        {
            map = getValveMap(polygon);
            drawChart();
        }

        private void drawChart() {
            try
            {
                chaFamenStatis.ChartAreas["ChartArea1"].AxisX.Title = "阀门类型";
                chaFamenStatis.ChartAreas["ChartArea1"].AxisY.Title = "阀门个数";
                chaFamenStatis.ChartAreas["ChartArea1"].AxisX.Interval = 1;
                LabelStyle labeStyleAxisX = new LabelStyle();
                labeStyleAxisX.Angle = -45;
                labeStyleAxisX.Enabled = true;
                chaFamenStatis.ChartAreas["ChartArea1"].AxisX.LabelStyle = labeStyleAxisX;

                chaFamenStatis.Series["阀门"].ChartType = SeriesChartType.Column;
                chaFamenStatis.Series["阀门"]["DrawingStyle"] = "Cylinder";
                chaFamenStatis.Series["阀门"].IsValueShownAsLabel = true;

                Dictionary<string, int> workWellLengthAndType = new Dictionary<string, int>();
                foreach (KeyValuePair<string, GSOFeatures> kv in map)
                {
                    workWellLengthAndType.Add(kv.Key, kv.Value.Length);
                }
                chaFamenStatis.Series["阀门"].Points.DataBindXY(workWellLengthAndType.Keys, workWellLengthAndType.Values);
                for (int m = 0; m < workWellLengthAndType.Values.Count; m++)
                {
                    if (chaFamenStatis.Series["阀门"].Points[m].YValues[0].ToString() != "0")
                    {
                        chaFamenStatis.Series["阀门"].Points[m].Label = chaFamenStatis.Series[0].Points[m].YValues[0].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                //LogError.PublishError(ex);
            }
        }

        /// <summary>
        /// 图表鼠标单击事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chaFamenStatis_MouseClick(object sender, MouseEventArgs e)
        {
            HitTestResult result = chaFamenStatis.HitTest(e.X, e.Y, true);
            int indexHit = result.PointIndex;
            if (indexHit >= 0)
            {

                //GSOFeatures fs = list[indexHit];
//                string sql = "";

                string pipetype = chaFamenStatis.Series["阀门"].Points[indexHit].AxisLabel;
                GSOFeatures fs = map[pipetype];

                string layername = pipetype.Substring(0, pipetype.Length - 2) + "管线附属物";
                //MainFrm.m_CurrentQueryLayer = layername;
                GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(layername);
                if (layer == null || fs.Length <= 0)
                {
                    return;
                }

//                sql = "select " + GetpipeLineFields.GetFields(layername, globeControl1) + " from " + layer.Name;
//                sql += " where 1>2 ";
//                for (int i = 0; i < fs.Length; i++)
//                {
//                    if (fs[i].GetValue("编号") == null) continue;
//                    sql += " or 编号 = '" + fs[i].GetValue("编号") + "'";
//                }
//
//                DataTable table = OledbHelper.QueryTable(sql);
//                string strLable = " 阀门类型:" + pipetype + "||共有:" + Convert.ToString(table.Rows.Count) + "条记录";
//                m_InitDataGridViewX1(table, strLable, layername, true);


                List<string> list = new List<string>();
                 for (int i = 0; i < fs.Length; i++)
                 {
                     string value = (string)fs[i].GetValue("编号");
                    if (value == null) continue;
                    list.Add(value);
                }
                PaginationUtil.ResetPagination();
                int total = PaginationUtil.CountSql(layername, "编号", list);
                if (total > 0)
                {
                    string strLable = " 阀门类型:" + pipetype + "||共有:" + Convert.ToString(total) + "条记录";
                    string sql = PaginationUtil.GetQuerySql(globeControl1, layername, "编号", list);
                    PaginationUtil pagination = PaginationUtil.InitPagination(sql, total, _pageControl,
                        m_InitDataGridViewX1, strLable, layername);
                    pagination.FillDataGridView();
                }
                else
                {
                    m_InitDataGridViewX1(null, "", "", false);
                    MessageBox.Show("没有查到符合条件的数据");
                }
            }
        }
        /// <summary>
        /// 图表鼠标移动事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chaFamenStatis_MouseMove(object sender, MouseEventArgs e)
        {
            HitTestResult result = chaFamenStatis.HitTest(e.X, e.Y, true);
            if (result.PointIndex >= 0)
            {
                Cursor = Cursors.Hand;
            }
            else
            {
                Cursor = Cursors.Default;
            }
        }
       
        /// <summary>
        /// 窗体关闭事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmLayerSelectedQuery_FormClosing(object sender, FormClosingEventArgs e)
        {
            globeControl1.Globe.ClearAnalysis();
            m_InitDataGridViewX1(null, "", "", false);
        }

        private void 导出统计专题图ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            F_PATMTitle frm = new F_PATMTitle("S", chaFamenStatis);
            frm.Show();
        }
        /// <summary>
        /// 获取区域内的各图层阀门
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public Dictionary<string, GSOFeatures> getValveMap(GSOGeoPolygon3D polygon)
        {
            Dictionary<string, GSOFeatures> map = new Dictionary<string, GSOFeatures>();
            //找到所有阀门 
            if (Utility.LayerNamesList != null)
            {
                ArrayList listpt = Utility.LayerNamesList;
                for (int i = 0; i < listpt.Count; i++)
                {
                    string pipelineType = (string)Utility.LayerNamesList[i];

                    if ((pipelineType == "给水") || (pipelineType == "天然气") || (pipelineType == "热力"))
                    {
                        GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(pipelineType + "管线附属物");
                        if (layer == null)  return null;
                        GSOFeatures fs = FeatureStatisticsService.Intersect_PointLayerByType(polygon, layer, "阀门井");
                        if (fs == null) continue;
                        map.Add(pipelineType+"阀门",fs);
                    }
                }
            }
            return map;
        }
    }
}