-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
869 lines (727 loc) · 33.3 KB
/
MainForm.cs
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Display;
namespace ArcGISFoundation
{
public sealed partial class MainForm : Form
{
#region private members
private IMapControl3 m_mapControl = null;
TocMapContextMenu m_tocMapContextMenu = null;
TocLayerContextMenu m_tocLayerContextMenu = null;
MapControlContextMenu m_mapControlContextMenu = null;
DataSource m_datasource = null;
private QueryInput m_qinput_f;
int m_selectedLayer = 0;
#endregion
#region For UI
//临时位置
private Point temp_point;
//当前路径
private string currPath = "";
private int m_query_area_detail = 0;
const int CS_DropSHADOW = 0x20000;
const int GCL_STYLE = (-26);
//声明Win32 API
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
[DllImport("User32.dll", EntryPoint = "ReleaseCapture")]
private static extern int ReleaseCapture();
#endregion
#region Ctor
public MainForm()
{
InitializeComponent();
//this.MyFormMouseDown += new MouseEventHandler(panel_title_bar_MouseDown);
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW); //API函数加载,实现窗体边框阴影效果
//
currPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
//MessageBox.Show("获取和设置包括该应用程序的目录的名称:" + currPath);
}
#endregion
#region MainForm Function
#region MainForm_Load
//MainForm_Load
private string m_bin_path;
ArcGISFoundation.Source.Query.DecisionMaking_query m_dmq = new ArcGISFoundation.Source.Query.DecisionMaking_query();
private void MainForm_Load(object sender, EventArgs e)
{
//test_start
m_dmq = new ArcGISFoundation.Source.Query.DecisionMaking_query();
m_dmq.init("../data/牧草数据.xlsx","../data/次适宜区牧草.xlsx");
//test_end
m_mapControl = (IMapControl3)axMapControl1.Object;
m_isQuery = false;
m_bin_path = System.Environment.CurrentDirectory +'\\';
m_qf = new QueryForm(m_bin_path);
m_qf.Owner = this;
//init toc context menu
InitTocContextMenu();
//init map control context menu
InitMapControlContextMenu();
//init data source
InitDataSouce();
//init main tool bar
InitMainToolbar();
// open map tree
this.xPanderPanel_tree.Expand = true;
radioButton_sheng.Checked = true;
}
//toc context menu
private void InitTocContextMenu()
{
//Add map menu
m_tocMapContextMenu = new TocMapContextMenu(m_mapControl);
//Add layer menu
m_tocLayerContextMenu = new TocLayerContextMenu(m_mapControl);
}
//axMapControl1 context menu
private void InitMapControlContextMenu()
{
//Add map menu
m_mapControlContextMenu = new MapControlContextMenu(m_mapControl);
}
//init data source
private void InitDataSouce()
{
string strPastureData = m_bin_path + @"..\data\牧草数据\";
string strAdministrativeData = m_bin_path + @"..\data\行政图\";
m_datasource = new DataSource();
m_datasource.Init(strAdministrativeData, strPastureData, m_mapControl, treeView_all_cao);
m_datasource.RefreshAdministrative();
m_datasource.RefreshPasture();
string strInitData = @"白三叶";
if (m_datasource.SwitchPasture(strInitData))
{
this.xPanderPanel_tree.Text =
"图层管理--" + strInitData;
m_mucao = strInitData;
}
//m_datasource.GetPastureByFilter("省");
}
//toc context menu
private void InitMainToolbar()
{
// 增加打开档命令
string progID;
//progID = "esriControlToolsGeneric.ControlsOpenDocCommand";
//maintoolbar.AddItem(progID, -1, -1, false, 0,
// esriCommandStyles.esriCommandStyleIconOnly);
//progID = "esriControlToolsGeneric.ControlsSaveAsDocCommand";
//maintoolbar.AddItem(progID, -1, -1, false, 0,
// esriCommandStyles.esriCommandStyleIconOnly);
//progID = "esriControlToolsGeneric.ControlsAddDataCommand";
//maintoolbar.AddItem(progID, -1, -1, false, 0,
// esriCommandStyles.esriCommandStyleIconOnly);
// 增加地图导航命令
progID = "esriControls.ControlsMapZoomInTool";
maintoolbar.AddItem(progID, -1, -1, true, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID = "esriControls.ControlsMapZoomOutTool";
maintoolbar.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID = "esriControls.ControlsMapPanTool";
maintoolbar.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID = "esriControls.ControlsMapFullExtentCommand";
maintoolbar.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID = "esriControls.ControlsMapHyperlinkTool";
maintoolbar.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID = "esriControls.ControlsMapFindCommand";
maintoolbar.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID = "esriControls.ControlsMapIdentifyTool";
maintoolbar.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
}
#endregion
private void MainForm_Shown(object sender, EventArgs e)
{
}
//窗体改变大小时
private void MainForm_Resize(object sender, EventArgs e)
{
Point min_point = new Point(this.Width - 100, 0);
this.min.Location = min_point;
Point max_point = new Point(this.Width - 70, 0);
this.max.Location = max_point;
Point close_point = new Point(this.Width - 40, 0);
this.close.Location = close_point;
//刷新
this.Refresh();
}
#endregion
#region public properties
// Returns the MapControl
public IMapControl3 MapControl
{
get { return m_mapControl; }
}
#endregion
#region Main UI Event
private void close_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void min_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void close_MouseEnter(object sender, EventArgs e)
{
this.close.Image = Image.FromFile(m_bin_path+@"..\images\close_hover.png");
}
private void close_MouseLeave(object sender, EventArgs e)
{
this.close.Image = Image.FromFile(m_bin_path+@"..\images\close.png");
}
private void max_MouseEnter(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
this.max.Image = Image.FromFile(m_bin_path+@"..\images\max_hover.png");
}
else
{
this.max.Image = Image.FromFile(m_bin_path+@"..\images\yuan_hover.png");
}
}
private void max_MouseLeave(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
this.max.Image = Image.FromFile(m_bin_path+@"..\images\max.png");
}
else
{
this.max.Image = Image.FromFile(m_bin_path+@"..\images\yuan.png ");
}
}
private void max_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
this.FormBorderStyle = FormBorderStyle.None;
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.WindowState = FormWindowState.Maximized;
}
else
{
this.WindowState = FormWindowState.Normal;
}
}
private void min_MouseEnter(object sender, EventArgs e)
{
this.min.Image = Image.FromFile(m_bin_path+@"..\images\min_hover.png");
}
private void min_MouseLeave(object sender, EventArgs e)
{
this.min.Image = Image.FromFile(m_bin_path+@"..\images\min.png");
}
private void panel_title_bar_MouseDown(object sender, MouseEventArgs e)
{
temp_point = new Point(e.X, e.Y);
}
private void panel_title_bar_DoubleClick(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
this.FormBorderStyle = FormBorderStyle.None;
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
//设置还原图片
this.max.Image = Image.FromFile(m_bin_path+@"..\images\yuan.png");
this.WindowState = FormWindowState.Maximized;
}
else
{
this.max.Image = Image.FromFile(m_bin_path+@"..\images\max.png");
this.WindowState = FormWindowState.Normal;
}
}
private void panel_title_bar_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && (e.X - temp_point.X != 0 || e.Y - temp_point.Y != 0))
{
ReleaseCapture();
SendMessage(this.Handle.ToInt32(), 0x0112, 0xF012, 0);
}
}
//边框的绘制
private void panel_container_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics,
this.panel_container.ClientRectangle,
Color.LightSeaGreen, //left
1,
ButtonBorderStyle.None,
Color.LightSeaGreen, //top
0,
ButtonBorderStyle.Solid,
Color.LightSeaGreen, //right
1,
ButtonBorderStyle.Solid,
Color.LightSeaGreen, //bottom
1,
ButtonBorderStyle.Solid);
}
private void panel_right_map_Paint(object sender, PaintEventArgs e)
{
}
private void pictureBox_tools1_Click(object sender, EventArgs e)
{
this.axMapControl1.CurrentTool = null;
// this.axMapControl1.ActiveView.Selection.
m_isQuery = true;
return;
}
private void pictureBox_query_Click(object sender, EventArgs e)
{
string strImageName = @"MapPrameter";
string strImageType = @"JPG";
string strImageDir = m_bin_path + @"../Output";
string localFilePath = "";
string strImagePath = m_bin_path + @"../Output/Map.JPG";
Size size = new Size(3474,1479);
//this.folderBrowserDialog_printer.Filter = "Special Files(*.png)|*.jpg|All files (*.*)|*.*";
//this.openFileDialog_printer.Description = "请选择路径";
this.saveFileDialog_printer.Filter = "jpg files (*.jpg)|*.jpg|png files (*.png)|*.png|gif files(*.gif)|*.gif|bmp files (*.bmp)|*.bmp|tiff files (*.tiff)|*.tiff";
this.saveFileDialog_printer.FilterIndex = 1;
//this.openFileDialog_printer.RootFolder = Environment.SpecialFolder.Desktop;
DialogResult result = this.saveFileDialog_printer.ShowDialog();
//保存对话框是否记忆上次打开的目录
this.saveFileDialog_printer.RestoreDirectory = true;
if (result == DialogResult.OK)
{
//获得文件路径
localFilePath = this.saveFileDialog_printer.FileName.ToString();
//获取文件名,不带路径
strImageName = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);
strImageType = strImageName.Substring(strImageName.LastIndexOf(".") + 1);
strImageName = strImageName.Substring(0,strImageName.LastIndexOf("."));
//获取文件路径,不带文件名
strImageDir = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
//this.folderBrowserDialog_printer.
PrintHelper.ExportActiveView(m_mapControl.ActiveView, 300, 5, strImageType, strImageDir, strImageName, true, m_mapControl.ActiveView.Extent);
}
//PrintHelper.ExportActiveView(m_mapControl.ActiveView, size, strImagePath);
}
private void pictureBox4_Click(object sender, EventArgs e)
{
ExcelImportForm form = new ExcelImportForm(m_bin_path);
form.ShowDialog(this);
}
private void maintoolbar_OnItemClick(object sender, IToolbarControlEvents_OnItemClickEvent e)
{
m_isQuery = false;
}
private void treeView_all_cao_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Left &&
e.Node.Level > 1 &&
m_datasource.SwitchPasture(e.Node.Text))
{
Pasture pasture= m_datasource.GetActivePasture();
this.xPanderPanel_tree.Text = "图层管理--" + pasture.strPasture;
this.xPanderPanel_tree.Expand = true;
this.xPanderPanel_query.Expand = false;
//m_LayerList.Items.Clear();
for (int i = 0; i < m_mapControl.LayerCount; ++i)
{
//string layername = m_mapControl.Layer[i].Name;
//m_LayerList.Items.Add(m_mapControl.Layer[i].Name);
}
//m_LayerList.SelectedIndex = 0;
m_mucao = pasture.strPasture;
}
}
private void m_LayerList_DropDown(object sender, EventArgs e)
{
//m_LayerList.Items.Clear();
//for (int i = 0; i < m_mapControl.LayerCount; ++i)
//{
// //string layername = m_mapControl.Layer[i].Name;
// m_LayerList.Items.Add(m_mapControl.Layer[i].Name);
//}
}
private void m_LayerList_SelectedIndexChanged(object sender, EventArgs e)
{
//m_selectedLayer = m_LayerList.SelectedIndex;
}
#endregion
#region Control Event
private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{
//make sure that the user right clicked
if (2 != e.button)
return;
//use HitTest in order to test whether the user has selected a featureLayer
esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap map = null;
ILayer layer = null;
object other = null;
object index = null;
//do the HitTest
toccontrol.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
//set the featurelayer as the custom property of the MapControl
axMapControl1.CustomProperty = layer;
//Ensure the item gets selected
if (item == esriTOCControlItem.esriTOCControlItemMap)
toccontrol.SelectItem(map, null);
else
toccontrol.SelectItem(layer, null);
//Set the layer into the CustomProperty (this is used by the custom layer commands)
axMapControl1.CustomProperty = layer;
//Popup the correct context menu
if (item == esriTOCControlItem.esriTOCControlItemMap)
m_tocMapContextMenu.PopupMenu(e.x, e.y, toccontrol.hWnd);
if (item == esriTOCControlItem.esriTOCControlItemLayer)
m_tocLayerContextMenu.PopupMenu(e.x, e.y, toccontrol.hWnd);
}
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
//make sure that the user right clicked
if (m_isQuery && 1 == e.button)
{
// m_isQuery = false;//暂时这样处理
nw_query(e);
return;
}
if (2 != e.button)
return;
m_isQuery = false;
m_mapControlContextMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);
}
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
this.coorText.Text = string.Format("{0}{1}{2}{3} {4}", "坐标:", e.mapX.ToString("#######.###"), ",", e.mapY.ToString("#######.###"), axMapControl1.MapUnits.ToString().Substring(4));
}
#endregion
private void nw_query()
{
ILayer layer = axMapControl1.get_Layer(0);
axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;
ESRI.ArcGIS.Geometry.IGeometry geometry = null;
geometry = axMapControl1.TrackRectangle();
IFeatureLayer featureLayer = layer as IFeatureLayer;
//获取featureLayer的featureClass
IFeatureClass featureClass = featureLayer.FeatureClass;
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
IQueryFilter pQueryFilter = pSpatialFilter as ISpatialFilter;
//设置过滤器的Geometry
pSpatialFilter.Geometry = geometry;
//设置空间关系类型
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;//esriSpatialRelContains;
//获取FeatureCursor游标
IFeatureCursor pFeatureCursor = featureClass.Search(pQueryFilter, true);
//遍历FeatureCursor
IFeature pFeature;
System.Collections.Generic.List<IFeature> pList = new System.Collections.Generic.List<IFeature>();
while ((pFeature = pFeatureCursor.NextFeature()) != null)
{
// ESRI.ArcGIS.Geodatabase.IField filed = pFeature.Fields.FindField("rate_shiyi");
ESRI.ArcGIS.Geodatabase.IRow row = pFeature.Table.GetRow(pFeature.OID);
//string str = row.Value[].ToString();
double a = System.Convert.ToDouble(row.get_Value(pFeature.Fields.FindField(nw_getQueryFiledName())));
pList.Add(pFeature);
}
MessageBox.Show(pList.Count.ToString());
if (pFeature != null)
{
axMapControl1.Map.SelectFeature(axMapControl1.get_Layer(0), pFeature);
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
/* axMapControl1.Map.SelectByShape(geometry, null, false);
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);*/
}
private void radioButton_shi_CheckedChanged(object sender, EventArgs e)
{
if (radioButton_shi.Checked)
{
m_query_area_detail = 1;
axMapControl1.Map.Layer[0].Visible = false;
axMapControl1.Map.Layer[1].Visible = true;
axMapControl1.Map.Layer[2].Visible = false;
axMapControl1.ActiveView.Refresh();
}
}
private void radioButton_sheng_CheckedChanged(object sender, EventArgs e)
{
if (radioButton_sheng.Checked)
{
m_query_area_detail = 0;
axMapControl1.Map.Layer[0].Visible =true ;
axMapControl1.Map.Layer[1].Visible = false;
axMapControl1.Map.Layer[2].Visible = false;
axMapControl1.ActiveView.Refresh();
}
}
private void radioButton_xian_CheckedChanged(object sender, EventArgs e)
{
if (radioButton_xian.Checked)
{
m_query_area_detail = 2;
axMapControl1.Map.Layer[0].Visible = false;
axMapControl1.Map.Layer[1].Visible = false;
axMapControl1.Map.Layer[2].Visible =true ;
axMapControl1.ActiveView.Refresh();
}
}
private void queryBtn_Click(object sender, EventArgs e)
{
char[] fl = {';',';',',',','};
string[] ary = textBox1.Text.Split(fl);
//m_nactcn = textBox1.Text;
if (ary.Length < 1) return;
ILayer layer = m_datasource.GetAdministrativeMap().get_Layer(m_query_area_detail);
ILayer layer_shiyi = null;// = axMapControl1.Map.get_Layer (m_selectedLayer);
ILayer layer_cishi = null;//= axMapControl1.Map.get_Layer(m_selectedLayer);
getLayer(m_query_area_detail, ref layer_shiyi, ref layer_cishi);
//resolveNameRate(layer.Name);
//resolveNameRange(layer.Name);
//layer_name[1];
//
axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;
IQueryFilter queryFilter = new QueryFilterClass();
//IFeatureCursor featureCusor;
queryFilter.WhereClause = m_range_en + " LIKE '%" + ary[0] + "%' ";
for (int i= 1; i<ary.Length;++i )
{
queryFilter.WhereClause += " or "+m_range_en+" LIKE '%"+ary[i]+"%'";
}
//获取FeatureCursor游标
IFeatureLayer featureLayer = layer as IFeatureLayer;
//获取featureLayer的featureClass
IFeatureClass featureClass = featureLayer.FeatureClass;
IFeatureCursor pFeatureCursor = featureClass.Search(queryFilter, true);
//遍历FeatureCursor
IFeature pFeature = pFeatureCursor.NextFeature();
//获取FeatureCursor游标
IFeatureLayer featureLayer1 = layer_shiyi as IFeatureLayer;
//获取featureLayer的featureClass
IFeatureClass featureClass1 = featureLayer1.FeatureClass;
IFeatureCursor pFeatureCursor1 = featureClass1.Search(queryFilter, true);
//遍历FeatureCursor
IFeature pFeature1 = pFeatureCursor1.NextFeature();
//获取FeatureCursor游标
IFeatureLayer featureLayer2 = layer_cishi as IFeatureLayer;
//获取featureLayer的featureClass
IFeatureClass featureClass2 = featureLayer2.FeatureClass;
IFeatureCursor pFeatureCursor2 = featureClass2.Search(queryFilter, true);
//遍历FeatureCursor
IFeature pFeature2 = pFeatureCursor2.NextFeature();
//QueryForm qf = new QueryForm(m_bin_path);
m_qf.m_mapControl = axMapControl1;
m_qf.m_featureLayer = featureLayer;
m_qf.m_query_name = m_range_en;
m_qf.m_mucao = m_mucao;
//qf.m_layername = "当前图层:" + layer.Name;
m_qf.QueryForm_SetText(/*m_layername +*/ " 牧草:" + m_mucao);
System.Windows.Forms.ListView listView_data = m_qf.nw_getListView();
listView_data.Items.Clear();
listView_data.Columns.Clear();
listView_data.Columns.Add(m_range + "名", 120, HorizontalAlignment.Left);//省名,,
listView_data.Columns.Add("适宜面积比", 120, HorizontalAlignment.Left);
listView_data.Columns.Add("适宜面积", 120, HorizontalAlignment.Left);
listView_data.Columns.Add("次适宜面积比", 120, HorizontalAlignment.Left);
listView_data.Columns.Add("次适宜面积", 120, HorizontalAlignment.Left);
m_qf.m_range = m_range;
string area1 = "area" + m_rate_en;
string rate1 = "rate" + m_rate_en;
string area2 = "area" + m_rate_en;
string rate2 = "rate" + m_rate_en;
if (pFeature1 != null)
{
for (int i = 0; i < pFeature1.Fields.FieldCount; ++i)
{
if (pFeature1.Fields.Field[i].Name.IndexOf("area_") > -1)
{
area1 = pFeature1.Fields.Field[i].Name;
}
else if (pFeature1.Fields.Field[i].Name.IndexOf("rate_") > -1)
{
rate1 = pFeature1.Fields.Field[i].Name;
}
}
}
if (pFeature2 != null)
{
for (int i = 0; i < pFeature2.Fields.FieldCount; ++i)
{
if (pFeature2.Fields.Field[i].Name.IndexOf("area_") > -1)
{
area2 = pFeature2.Fields.Field[i].Name;
}
else if (pFeature2.Fields.Field[i].Name.IndexOf("rate_") > -1)
{
rate2 = pFeature2.Fields.Field[i].Name;
}
}
}
System.Collections.Generic.List<IFeature> pList = new System.Collections.Generic.List<IFeature>();
while (pFeature != null)
{
// ESRI.ArcGIS.Geodatabase.IField filed = pFeature.Fields.FindField("rate_shiyi");
//ESRI.ArcGIS.Geodatabase.IRowBuffer buff = (IRowBuffer)pFeature;
//string str = buff.Value[pFeature.Fields.FindField("NAME")].ToString();
//ESRI.ArcGIS.Geodatabase.IRow row = pFeature.Table.GetRow(pFeature.OID);
//string str = row.Value[].ToString();
//double a = System.Convert.ToDouble(row.get_Value(pFeature.Fields.FindField(nw_getQueryFiledName())));
//pList.Add()
//pList.Add(pFeature.);
ListViewItem lvi = new ListViewItem();
// ESRI.ArcGIS.Geodatabase.IRowBuffer buff = (IRowBuffer)pFeature;
m_nactcn = lvi.Text = pFeature.Value[pFeature.Fields.FindField(m_range_en)].ToString();
if (pFeature1 != null)
{
lvi.SubItems.Add(pFeature1.Value[pFeature1.Fields.FindField(rate1)].ToString());//rate_shiyi
lvi.SubItems.Add(System.Convert.ToDecimal(pFeature1.Value[pFeature1.Fields.FindField(area1)]).ToString("N"));//
}
if (pFeature2 != null)
{
lvi.SubItems.Add(pFeature2.Value[pFeature2.Fields.FindField(rate2)].ToString());//rate_shiyi
lvi.SubItems.Add(System.Convert.ToDecimal(pFeature2.Value[pFeature2.Fields.FindField(area2)]).ToString("N"));//
}
listView_data.Items.Add(lvi);
pFeature = pFeatureCursor.NextFeature();
if (pFeature1 != null)
pFeature1 = pFeatureCursor1.NextFeature();
if (pFeature2 != null)
pFeature2 = pFeatureCursor2.NextFeature();
}
axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault;
m_qf.Show();
highLight(featureLayer);
}
private void queryBtn_Click1(object sender, EventArgs e)
{
char[] fl = {';',';',',',','};
string[] ary = textBox1.Text.Split(fl);
//m_nactcn = textBox1.Text;
if (ary.Length < 1) return;
// ILayer layer = m_datasource.GetAdministrativeMap().get_Layer(m_query_area_detail);
// ILayer layer_shiyi = null;// = axMapControl1.Map.get_Layer (m_selectedLayer);
// ILayer layer_cishi = null;//= axMapControl1.Map.get_Layer(m_selectedLayer);
// getLayer(m_query_area_detail, ref layer_shiyi, ref layer_cishi);
//resolveNameRate(layer.Name);
//resolveNameRange(layer.Name);
//layer_name[1];
//
//axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;
m_range_en = "NAME";
switch (m_query_area_detail)
{
case 0://省
m_range = "省";
m_range_en = "NAME";
break;
case 1://市
m_range = "市";
m_range_en = "CITY";
break;
case 2://县
m_range = "县";
m_range_en = "COUNTY";
break;
default:
break;
}
IQueryFilter queryFilter = new QueryFilterClass();
//IFeatureCursor featureCusor;
queryFilter.WhereClause = m_range_en + " LIKE '%" + ary[0] + "%' ";
for (int i= 1; i<ary.Length;++i )
{
queryFilter.WhereClause += " or "+m_range_en+" LIKE '%"+ary[i]+"%'";
}
System.Windows.Forms.ListView listView_data = m_qf.nw_getListView();
listView_data.Items.Clear();
listView_data.Columns.Clear();
listView_data.Columns.Add("牧草名", 120, HorizontalAlignment.Left);//省名,,
listView_data.Columns.Add("适宜面积比", 120, HorizontalAlignment.Left);
listView_data.Columns.Add("适宜面积", 120, HorizontalAlignment.Left);
listView_data.Columns.Add("次适宜面积比", 120, HorizontalAlignment.Left);
listView_data.Columns.Add("次适宜面积", 120, HorizontalAlignment.Left);
m_qf.QueryForm_SetText(ary[0]);
IMap mmap = m_datasource.GetPastureByFilter(m_range);
ListViewItem lvi =null;
bool myflag =false;
for (int k = 0; k < mmap.LayerCount; ++k)
{
ILayer ly = mmap.get_Layer(k);
if(k%2 == 0){
string name = ly.Name;
name = name.Substring(0, name.IndexOf('_'));
lvi = new ListViewItem();
lvi.Text = name;
myflag = false;
}
IFeatureLayer featureLayer1 = ly as IFeatureLayer;
//获取featureLayer的featureClass
IFeatureClass featureClass1 = featureLayer1.FeatureClass;
IFeatureCursor pFeatureCursor1 = featureClass1.Search(queryFilter, true);
//遍历FeatureCursor
IFeature pFeature1 = pFeatureCursor1.NextFeature();
string area1="", rate1="";
if (pFeature1 != null)
{
myflag = true;
for (int i = 0; i < pFeature1.Fields.FieldCount; ++i)
{
if (pFeature1.Fields.Field[i].Name == "area_cis_1")
{
rate1 = pFeature1.Fields.Field[i].Name;
}
else if (pFeature1.Fields.Field[i].Name.IndexOf("area_") > -1)
{
area1 = pFeature1.Fields.Field[i].Name;
}
else if (pFeature1.Fields.Field[i].Name.IndexOf("rate_") > -1)
{
rate1 = pFeature1.Fields.Field[i].Name;
}
}
if (area1 != "" && rate1 != "")
{
lvi.SubItems.Add(pFeature1.Value[pFeature1.Fields.FindField(rate1)].ToString());//rate_shiyi
lvi.SubItems.Add(System.Convert.ToDecimal(pFeature1.Value[pFeature1.Fields.FindField(area1)]).ToString("N"));//
}
}
if(k%2 != 0 && myflag)
listView_data.Items.Add(lvi);
}
m_qf.Show();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
queryBtn_Click(sender, e);
}
}
private void pictureBox6_Click(object sender, EventArgs e)
{
m_qinput_f = new QueryInput(m_bin_path);
m_qinput_f.m_dmq = m_dmq;
m_qinput_f.m_qf = m_qf;
m_qinput_f.Show();
}
}
}