/// <summary> /// 删除回调 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ContextMenuClick_Del(object sender, RoutedEventArgs e) { if (m_catalog.ActiveMapDoc.ActiveLayerIndex < 0) { MessageBox.Show("请激活该编辑的图层", "提示", MessageBoxButton.OK); return; } TabItem item = tabControl1.SelectedItem as TabItem; if (item != null) { DataGrid datagrid = item.Content as DataGrid; if (datagrid != null) { m_lastSelDataGrid = datagrid; int tabIndex = Convert.ToInt32(((System.Windows.FrameworkElement)(((System.Windows.Controls.ContentControl)(tabControl1.SelectedItem)).Content)).Name.ToString().Split('_')[1]); if (tabIndex >= 0 && tabIndex < _lastSelRlt.AttDS[0].attTables.Length) { if (MessageBox.Show("你真的要删除吗?执行后将不能撤消!", "删除确认", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { BindClass bc = datagrid.SelectedItem as BindClass; m_lastSelItem = bc; CGetObjByID getGeo = new CGetObjByID(); getGeo.FeatureID = Convert.ToInt64(bc.key0); getGeo.LayerIndex = tabIndex; COpenMap openmap = new COpenMap(); openmap.MapName = new string[] { m_catalog.ActiveMapDoc.MapDocName }; getGeo.MapName = openmap; m_catalog.ActiveMapDoc.DeleteFeature(getGeo, new UploadStringCompletedEventHandler(OnDeleteFeature)); } } } } }
/// <summary> /// 编辑回调 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ContextMenuClick_Edit(object sender, RoutedEventArgs e) { if (m_catalog.ActiveLayerObj.ActiveLayerIndex < 0 || m_catalog.ActiveLayerObj.ActiveGdbIndex < 0) { MessageBox.Show("请激活该编辑的图层", "提示", MessageBoxButton.OK); return; } TabItem item = tabControl1.SelectedItem as TabItem; if (item != null) { DataGrid datagrid = item.Content as DataGrid; if (datagrid != null) { m_lastSelDataGrid = datagrid; m_lastSelItem = datagrid.SelectedItem as BindClass; if (LayerEditorObj == null) { LayerEditorObj = new LayerEditor() { ActiveLayerObj = m_catalog.ActiveLayerObj, GraphicsLayer = this.GraphicsLayer } } ; if (datagrid.Tag is TmpInfo) { int gdbIndex = (datagrid.Tag as TmpInfo).GDBIndex; int layerIndex = (datagrid.Tag as TmpInfo).LayerIndex; LayerEditorObj.ActiveLayerObj = m_catalog.ActiveLayerObj; LayerEditorObj.GraphicsLayer = GraphicsLayer; LayerEditorObj.SetAttStruct(_lastSelRlt.AttDS[gdbIndex].attTables[layerIndex].Columns, datagrid.SelectedItem as BindClass, this); } } } }
/// <summary> /// 编辑回调 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ContextMenuClick_Edit(object sender, RoutedEventArgs e) { if (m_catalog.ActiveMapDoc.ActiveLayerIndex < 0) { MessageBox.Show("请激活该编辑的图层", "提示", MessageBoxButton.OK); return; } TabItem item = tabControl1.SelectedItem as TabItem; if (item != null) { DataGrid datagrid = item.Content as DataGrid; if (datagrid != null) { m_lastSelDataGrid = datagrid; int tabIndex = Convert.ToInt32(((System.Windows.FrameworkElement)(((System.Windows.Controls.ContentControl)(tabControl1.SelectedItem)).Content)).Name.ToString().Split('_')[1]); if (tabIndex >= 0 && tabIndex < _lastSelRlt.AttDS[0].attTables.Length) { m_lastSelItem = datagrid.SelectedItem as BindClass; if (MapDocEditorObj == null) { MapDocEditorObj = new MapDocEditor() { ActiveMapDoc = m_catalog.ActiveMapDoc, GraphicsLayer = this.GraphicsLayer } } ; MapDocEditorObj.SetAttStruct(_lastSelRlt.AttDS[0].attTables[tabIndex].Columns, datagrid.SelectedItem as BindClass, this); } } } }
/// <summary> /// 查询完毕回调 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NextPageSelectCallback(object sender, UploadStringCompletedEventArgs e) { CLayerSelectAndGetAtt selRlt = activeLayer.OnLayerSelectAndGetAtt(e); TabItem item; string name; DataGrid grid; for (int k = 0; k < selRlt.Count.Length; k++) { for (int i = 0; i < selRlt.Count[k].Length; i++) { if (selRlt.Count[k][i] > 0 && selRlt.AttDS[k].attTables != null && selRlt.AttDS[k].attTables[i].Rows != null) { name = activeLayer.LayerObj.LayerAccessInfo[k].LayerInfoList[i].LayerDataName; //if (this.FindName(name) == null) //{ // item = new TabItem() // { // Header = name, // Name = name // }; // grid = new DataGrid() // { // Name = "datagrid" + name + "_" + k + "_" + i, // Height = 221, // Width = 493, // AutoGenerateColumns = false, // IsReadOnly = true, // Tag = new TmpInfo() { LayerIndex = i, GDBIndex = k } // }; // grid.MouseLeftButtonUp += new MouseButtonEventHandler(DataGrid_MouseLeftButtonUp); // item.Content = grid; // tabControl1.Items.Add(item); //} //else { item = this.FindName(name) as TabItem; grid = item.Content as DataGrid; grid.Columns.Clear(); grid.ItemsSource = null; } List <string> addColumnlHeadArr = new List <string>(); addColumnlHeadArr.Add("FID"); string[][] arr = new string[/*selRlt.Count[0][i]*/ selRlt.AttDS[k].attTables[i].Rows.Length + 1][]; arr[0] = selRlt.AttDS[k].attTables[i].Columns.FldName; List <string[]> addColumnlContentArr = new List <string[]>(); string[] fidArr = new string[selRlt.AttDS[k].attTables[i].Rows.Length]; for (int j = 0; j < selRlt.AttDS[k].attTables[i].Rows.Length; j++) { fidArr[j] = selRlt.AttDS[k].attTables[i].Rows[j].FID.ToString(); arr[j + 1] = selRlt.AttDS[k].attTables[i].Rows[j].Values; } addColumnlContentArr.Add(fidArr); BindClass bingclass = new BindClass(); bingclass.ColumnDisplay(grid, arr, addColumnlHeadArr, addColumnlContentArr); } } } }
/// <summary>初始化明细数据源 /// /// </summary> private void DoInitDetailGridSource() { const string strBindSql = "SELECT ProjectID,Name From BseProject;SELECT 'gridDetailmrzProjectID '"; BindClass bindClass = new BindClass() { SqlType = SqlType.SqlServer, BindSql = strBindSql }; m_dsDetailGridSource = BindSourceHelper.GetBindSourceDataSet(bindClass, GlobalHelp.Conn); }
/// <summary>初始主表数据源 /// /// </summary> private void DoInitMasterGridSource() { const string strBindSql = "SELECT Name,value FROM [BseDictionary] WHERE ParentID=19;SELECT Name,value FROM [BseDictionary] WHERE ParentID=22;SELECT 'gridmrzCategory ','gridmrzOnLevel '"; BindClass bindClass = new BindClass() { SqlType = SqlType.SqlServer, BindSql = strBindSql }; m_dsMasterGridSource = BindSourceHelper.GetBindSourceDataSet(bindClass, GlobalHelp.Conn); }
/// <summary> /// 查询完毕回调 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NextPageSelectCallback(object sender, UploadStringCompletedEventArgs e) { CMapSelectAndGetAtt selRlt = m_catalog.ActiveMapDoc.OnSelect(e); TabItem item; string name; DataGrid grid; for (int i = 0; i < selRlt.Count[0].Length; i++) { if (selRlt.AttDS[0].attTables != null && selRlt.AttDS[0].attTables[i] != null && selRlt.AttDS[0].attTables[i].Rows != null)//selRlt.Count[0][i] > 0) { name = activeMapDoc.GetLayerInfo(i).LayerDataName; //if (this.FindName(name) == null) //{ // item = new TabItem() // { // Header = name, // Name = name // }; // grid = new DataGrid() // { // Height = 221, // Width = 493, // AutoGenerateColumns = false, // IsReadOnly = true // }; // item.Content = grid; // tabControl1.Items.Add(item); //} //else { item = this.FindName(name) as TabItem; grid = item.Content as DataGrid; grid.Columns.Clear(); grid.ItemsSource = null; } List <string> addColumnlHeadArr = new List <string>(); addColumnlHeadArr.Add("FID"); string[][] arr = new string[/*selRlt.Count[0][i]*/ selRlt.AttDS[0].attTables[i].Rows.Length + 1][]; arr[0] = selRlt.AttDS[0].attTables[i].Columns.FldName; List <string[]> addColumnlContentArr = new List <string[]>(); string[] fidArr = new string[selRlt.AttDS[0].attTables[i].Rows.Length]; for (int j = 0; j < selRlt.AttDS[0].attTables[i].Rows.Length; j++) { fidArr[j] = selRlt.AttDS[0].attTables[i].Rows[j].FID.ToString(); arr[j + 1] = selRlt.AttDS[0].attTables[i].Rows[j].Values; } addColumnlContentArr.Add(fidArr); BindClass bingclass = new BindClass(); bingclass.ColumnDisplay(grid, arr, addColumnlHeadArr, addColumnlContentArr); } } }
/// <summary>初始化绑定 /// /// </summary> private void DoInitData() { const string strBindEditSql = "select TableName From CacheTables;SELECT 'cboEditTableName '"; BindClass bindClass = new BindClass() { SqlType = SqlType.SqlServer, BindSql = strBindEditSql }; DataSet ds = BindSourceHelper.GetBindSourceDataSet(bindClass, GlobalHelp.Conn); ComboBoxHelper.BindComboBox(cboEditTableName, ds.Tables["cboEditTableName"], "TableName", "TableName"); }
/// <summary>初始化绑定 /// /// </summary> private void DoInitData() { const string strBindSql = "select '学习记录' as Name union all select '其它记录' as Name ;SELECT 'cboEditType '"; BindClass bindClass = new BindClass() { SqlType = SqlType.SqlServer, BindSql = strBindSql }; DataSet ds = BindSourceHelper.GetBindSourceDataSet(bindClass, GlobalHelp.Conn); ComboBoxHelper.BindComboBox(cboEditType, ds.Tables["cboEditType"], "Name", "Name"); }
/// <summary>初始化Detail绑定 /// /// </summary> private void DoInitDetailData() { const string strBindEditSql = "SELECT ProjectID,Name From BseProject;SELECT 'cboDetailEditProjectID '"; BindClass bindClass = new BindClass() { SqlType = SqlType.SqlServer, BindSql = strBindEditSql }; DataSet ds = BindSourceHelper.GetBindSourceDataSet(bindClass, GlobalHelp.Conn); ComboBoxHelper.BindComboBox(cboDetailEditProjectID, ds.Tables["cboDetailEditProjectID"], "Name", "ProjectID"); }
private void onGetMapAttStruct(object sender, UploadStringCompletedEventArgs e) { CAttStruct attStruct = m_catalog.ActiveMapDoc.OnGetMapLayerAttStruct(e); this.m_bufferControl.setTargetattStrct(attStruct); BindClass bindobj = ((System.Windows.Controls.DataGrid)(((System.Windows.Controls.ContentControl)(tabControl1.SelectedItem)).Content)).SelectedItem as BindClass; CGetObjByID getobj = new CGetObjByID(); getobj.MapDocIndex = 0; getobj.LayerIndex = Convert.ToInt32(((System.Windows.FrameworkElement)(((System.Windows.Controls.ContentControl)(tabControl1.SelectedItem)).Content)).Name.ToString().Split('_')[1]); getobj.FeatureID = Convert.ToInt64(bindobj.key0); m_catalog.ActiveMapDoc.GetFeatureByID(getobj, new UploadStringCompletedEventHandler(onGetFeatureByID)); }
/// <summary>初始化Master绑定 /// /// </summary> private void DoInitMasterData() { const string strBindEditSql = "SELECT Name,value FROM [BseDictionary] WHERE ParentID=19;SELECT Name,value FROM [BseDictionary] WHERE ParentID=22;SELECT 'cboEditCategory ','cboEditOnLevel '"; BindClass bindClass = new BindClass() { SqlType = SqlType.SqlServer, BindSql = strBindEditSql }; DataSet ds = BindSourceHelper.GetBindSourceDataSet(bindClass, GlobalHelp.Conn); ComboBoxHelper.BindComboBox(cboEditCategory, ds.Tables["cboEditCategory"], "Name", "Value"); ComboBoxHelper.BindComboBox(cboEditOnLevel, ds.Tables["cboEditOnLevel"], "Name", "Value"); }
public static DataSet GetBindSourceDataSet(BindClass bindClass) { bindClass.Connections = GlobalHelpDemoForm.DemoConn1; IDbHelper helper = DbHelper.GetDbHelper(bindClass.SqlType, bindClass.Connections); helper.CreateCommand(bindClass.BindSql); DataSet ds = helper.ExecuteQueryDataSet(); for (int i = 0; i < ds.Tables.Count - 1; i++) { ds.Tables[i].TableName = ds.Tables[ds.Tables.Count - 1].Rows[0][0].ToString().Trim().Split(',')[i]; } return(ds); }
private void grdData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { if (m_dsGridSource == null) { const string strBindGridSql = "SELECT Name,value FROM [BseDictionary] WHERE ParentID=22;SELECT Name,value FROM [BseDictionary] WHERE ParentID=19;SELECT 'gridcboOnLevel ','gridcboCategory '"; BindClass bindClass = new BindClass() { SqlType = SqlType.SqlServer, BindSql = strBindGridSql }; m_dsGridSource = BindSourceHelper.GetBindSourceDataSet(bindClass, GlobalHelp.Conn); } DataGridViewComboBoxCell gridcboOnLevelCell = this.grdData.Rows[e.RowIndex].Cells[gridcboOnLevel.Name] as DataGridViewComboBoxCell; ComboBoxHelper.BindDataGridViewComboBoxCell(gridcboOnLevelCell, m_dsGridSource.Tables["gridcboOnLevel"], "Name", "Value"); DataGridViewComboBoxCell gridcboCategoryCell = this.grdData.Rows[e.RowIndex].Cells[gridcboCategory.Name] as DataGridViewComboBoxCell; ComboBoxHelper.BindDataGridViewComboBoxCell(gridcboCategoryCell, m_dsGridSource.Tables["gridcboCategory"], "Name", "Value"); }
/// <summary> /// 更新记录 /// </summary> public void UpdateRecord(string[] AttValue) { if (m_lastSelDataGrid != null && m_lastSelItem != null && m_lastSelDataGrid.ItemsSource is List <BindClass> ) { if (AttValue.Length == m_lastSelItem.ColumnCount - 1) { for (int i = 0; i < AttValue.Length; i++) { m_lastSelItem.keyarr[i + 1] = AttValue[i]; } m_lastSelItem.Refresh(); } IEnumerable ie = m_lastSelDataGrid.ItemsSource; m_lastSelDataGrid.ItemsSource = null; m_lastSelDataGrid.ItemsSource = ie; } m_lastSelDataGrid = null; m_lastSelItem = null; }
/// <summary> /// 删除完毕回调 /// </summary> private void OnDeleteFeature(object sender, UploadStringCompletedEventArgs e) { COperResult rlt = m_catalog.ActiveMapDoc.OnDeleteFeature(e); if (rlt.OperResult == true) { MessageBox.Show("删除成功", "提示", MessageBoxButton.OK); if (m_lastSelDataGrid != null && m_lastSelItem != null && m_lastSelDataGrid.ItemsSource is List <BindClass> ) { (m_lastSelDataGrid.ItemsSource as List <BindClass>).Remove(m_lastSelItem); IEnumerable ie = m_lastSelDataGrid.ItemsSource; m_lastSelDataGrid.ItemsSource = null; m_lastSelDataGrid.ItemsSource = ie; } //m_catalog.ActiveMapDoc.Refresh(); m_catalog.ActiveMapDoc.MapContainer.OperType = IMSOperType.Refresh; } else { MessageBox.Show("删除失败,错误信息:" + rlt.ErrorInfo, "提示", MessageBoxButton.OK); } m_lastSelDataGrid = null; m_lastSelItem = null; }
public static string BindClass(string entidad, FieldArray fields, IDictionary extendedProperties) { BindClass bindclass = new BindClass(fields, entidad, extendedProperties); return(bindclass.ToString()); }
/// <summary> /// 查询完毕回调 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SelectCallback(object sender, UploadStringCompletedEventArgs e) { //if (activeMapDoc != null && !activeMapDoc.Equals(m_catalog.ActiveMapDoc)) //{//不是同一个图层,清除原来的结果 // tabControl1.Items.Clear(); //} dataPager1.DataContext = null; tabControl1.Items.Clear(); pageSize = m_catalog.ActiveMapDoc.GetPageSize(); activeMapDoc = m_catalog.ActiveMapDoc; CMapSelectAndGetAtt selRlt = m_catalog.ActiveMapDoc.OnSelect(e); _lastSelRlt = selRlt; TabItem item; string name; DataGrid grid = null; int maxCount = 0; for (int i = 0; i < selRlt.Count[0].Length; i++) { if (selRlt.Count[0][i] > 0 && selRlt.AttDS[0].attTables != null && selRlt.AttDS[0].attTables[i].Rows != null) { name = activeMapDoc.GetLayerInfo(i).LayerDataName; if (this.FindName(name) == null) { item = new TabItem() { Header = name, Name = name }; grid = new DataGrid() { Name = "datagrid" + name + "_" + i, Height = 221, Width = 493, AutoGenerateColumns = false, IsReadOnly = true, Tag = new TmpInfo() { LayerIndex = i } }; grid.MouseLeftButtonUp += new MouseButtonEventHandler(DataGrid_MouseLeftButtonUp); grid.LoadingRow += new EventHandler <DataGridRowEventArgs>(DataGrid_LoadingRow); item.Content = grid; if (ContextMenuService.GetContextMenu(grid) == null) { ContextMenu contextMenu = GetContexMenu(i); ContextMenuService.SetContextMenu(grid, contextMenu); } tabControl1.Items.Add(item); } else { item = this.FindName(name) as TabItem; grid = item.Content as DataGrid; grid.Columns.Clear(); grid.ItemsSource = null; } List <string> addColumnlHeadArr = new List <string>(); addColumnlHeadArr.Add("FID"); string[][] arr = new string[/*selRlt.Count[0][i]*/ selRlt.AttDS[0].attTables[i].Rows.Length + 1][]; arr[0] = selRlt.AttDS[0].attTables[i].Columns.FldName; List <string[]> addColumnlContentArr = new List <string[]>(); string[] fidArr = new string[selRlt.AttDS[0].attTables[i].Rows.Length]; for (int j = 0; j < selRlt.AttDS[0].attTables[i].Rows.Length; j++) { fidArr[j] = selRlt.AttDS[0].attTables[i].Rows[j].FID.ToString(); arr[j + 1] = selRlt.AttDS[0].attTables[i].Rows[j].Values; } addColumnlContentArr.Add(fidArr); if (maxCount < selRlt.Count[0][i]) { maxCount = selRlt.Count[0][i]; } BindClass bingclass = new BindClass(); dataPager1.DataContext = new PagedCollectionView(bingclass.ColumnDisplay(grid, arr, addColumnlHeadArr, addColumnlContentArr)); item.IsSelected = true; } } if (maxCount > 0) { dataPager1.PageSize = (int)Math.Ceiling(Convert.ToDouble(pageSize * pageSize) / maxCount); dataPager1.PageIndexChanged += new EventHandler <EventArgs>(dataPager1_PageIndexChanged); } if (tabControl1.Items.Count <= 0) //&& grid != null && grid.ItemsSource == null) { m_graphicsLayer.MapContainer.SetErrorText("矢量文档查询结果为空,请检查图层是否设置为可查询状态或者输入条件是否正确后重试!"); } //MessageBox.Show("没有查询到结果,请更换条件后重试!", "提示", MessageBoxButton.OK); else { this.Show(); } }
public void SetAttStruct(CAttStruct attStruct, BindClass values = null, MapDocDataViewer mapDocDataViewer = null) { m_mapDocDataViewer = mapDocDataViewer; m_attStruct = attStruct; m_featureStyle = null; Clear(); Label label; TextBox txtbox; if (values != null && values.ColumnCount > 0) { m_featureID = Convert.ToInt32(values.keyarr[0]); } for (int i = 0; i < m_attStruct.FldNumber; i++) { grid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); label = new Label() { Content = m_attStruct.FldName[i] + ":", Width = 60 }; grid1.Children.Add(label); Grid.SetRow(label, i); txtbox = new TextBox() { Width = 120, Height = 23, Text = "0" }; //, Name = "Fld_" + m_attStruct.FldName[i] }; grid1.Children.Add(txtbox); m_textBoxArr.Add(txtbox); if (values != null && values.ColumnCount > i + 1) { txtbox.Text = values.keyarr[i + 1]; } Grid.SetRow(txtbox, i); Grid.SetColumn(txtbox, 1); } if (values == null) { switch ((m_targetGeo as IWebGeometry).GetGeomType()) { case WebGeomType.Point: m_style = new PointStyle(); break; case WebGeomType.Line: m_style = new LineStyle(); break; case WebGeomType.Polygon: m_style = new PolygonStyle(); break; } grid2.Children.Add(m_style as UIElement); } else { CGetObjByID feature = new CGetObjByID(); feature.FeatureID = this.m_featureID; feature.LayerIndex = this.ActiveMapDoc.ActiveLayerIndex; ActiveMapDoc.GetFeatureStyleInfo(feature, new UploadStringCompletedEventHandler(OnGetStyle)); } Button btn = new Button() { Width = 70 }; btn.Content = "提交"; if (values == null) { btn.Click += new RoutedEventHandler(SubmitForAdd); } else { btn.Click += new RoutedEventHandler(SubmitForEdit); } grid3.Children.Add(btn); btn = new Button() { Width = 70 }; btn.Content = "关闭"; btn.Click += new RoutedEventHandler(Close); grid3.Children.Add(btn); Grid.SetColumn(btn, 1); if (values != null) { grid3.ColumnDefinitions.Add(new ColumnDefinition());// { Width = new GridLength(120) }); btn = new Button() { Width = 90 }; btn.Content = "调整要素位置"; btn.Click += new RoutedEventHandler(EditPoint); grid3.Children.Add(btn); Grid.SetColumn(btn, 2); } this.Show(); }