private void btnAddCustomProject_Click(object sender, EventArgs e) { try { if (treeView1.SelectedNode == null) { throw new ArgumentException("请选择矢量区域!"); } if (listView1.Items.Count == 0 || listView1.SelectedItems.Count < 1) { throw new ArgumentException("请选择统计区域!"); } string vectorName = treeView1.SelectedNode.Text; string[] fieldNames = (listView1.Items[0].Tag as Feature).FieldNames; int idx = 0; string keyfieldName = null; int ifld = 0; foreach (string fld in fieldNames) { if (fld.ToUpper().Contains("NAME") || fld.Contains("名称") || fld.ToUpper().Contains("CHINESE")) { if (!fld.ToUpper().Contains("ENAME")) { idx = ifld; keyfieldName = fld; break; } } ifld++; } List <string> selectedKeyValues = new List <string>(); foreach (ListViewItem item in listView1.SelectedItems) { Feature fea = item.Tag as Feature; if (keyfieldName == null) { keyfieldName = fea.FieldNames[idx]; } selectedKeyValues.Add(fea.FieldValues[idx]); } CustomAOISolutionArgs arg = new CustomAOISolutionArgs(); using (frmAddNewCustomAOISolution frm = new frmAddNewCustomAOISolution(arg.SolutionNames)) { frm.ParentForm = this; if (frm.ShowDialog() == DialogResult.OK) { if (frm.IsDeleteMode) { arg._tryDeletedSolutions = frm.DeletedSolutions; arg.UpdateDeleteSolutions(); } if (frm.IsAddMode) { arg._newSolutionName = frm.NewCustomAOISolutionName; arg._vectorName = vectorName; arg._keyFieldName = keyfieldName; arg._statRegionNames = selectedKeyValues.ToArray(); arg.ToXml(); } MessageBox.Show("自定义方案编辑成功!"); } } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private void btnUseCustomBlock_Click(object sender, EventArgs e) { if (treeView1.Nodes.Count < 1) { MessageBox.Show("不存在可选择的矢量区域!"); return; } try { CustomAOISolutionArgs arg = new CustomAOISolutionArgs(); string[] slsNames = arg.SolutionNames; String solutionName = null; string vecName, kryfName; string[] aoiNames; using (frmApplyCustomAOISolution frm = new frmApplyCustomAOISolution(slsNames)) { frm.ParentForm = this; if (frm.ShowDialog() == DialogResult.OK) { solutionName = frm.SelectedSolutionName; } else { return; } } if (solutionName != null) { arg.GetUniqueSolution(solutionName, out vecName, out kryfName, out aoiNames); foreach (TreeNode node in treeView1.Nodes) { if (node.Text.ToUpper() == vecName.ToUpper()) { node.Checked = true; //AddTreeListViewItems(node); break; } } int idx = -1; foreach (ColumnHeader col in listView1.Columns) { if (col.Text == kryfName) { idx = col.Index; break; } } foreach (ListViewItem it in this.listView1.Items) { foreach (string aoiname in aoiNames) { if (it.SubItems[idx].Text == aoiname) { it.Selected = true; it.Checked = listView1.CheckBoxes; break; } } } listView1.Focus(); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }