using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors; using KGIS.Plugin.LayerProperty.Interface; using ESRI.ArcGIS.Carto; using KGIS.Framework.Utils.Helper; namespace KGIS.Plugin.LayerProperty.View.UC_Controls { public partial class UCGeneralProperty : XtraUserControl, IUCPropertyPageEx, IPropertyPage { private string m_Name = ""; private string m_AliasName = ""; private bool m_Visible = true; private bool m_IsCustomLayer; private bool isDirty; private string m_GUID = Guid.NewGuid().ToString(); private string m_Description = ""; private bool m_StartUpLoad = true; private double m_MaxScale; private double m_MinScale; //internal event SelectionChangedEventHandler SelectTableChanged; private ILayerProperty m_LayerPropertyObject; private ILayer m_FeatureLayer; public UCGeneralProperty() { InitializeComponent(); } public int Priority { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public bool IsPageDirty { get { return this.isDirty; } set { this.isDirty = value; } } public event System.EventHandler EditorChanged; public int Activate() { throw new NotImplementedException(); } public void Cancel() { throw new NotImplementedException(); } public void Write2Prop() { try { if (this.m_IsCustomLayer) { //this.m_LayerPropertyObject.BeginUpdate(); //if (this.m_LayerPropertyObject is IDatabaseLayerProperty) //{ // IDatabaseLayerProperty databaseLayerProperty = this.m_LayerPropertyObject as IDatabaseLayerProperty; // databaseLayerProperty.DataSource = this.m_DataSource; //} //IDisplayControler displayControler = this.m_LayerPropertyObject as IDisplayControler; //this.m_LayerPropertyObject.AliasName = this.m_AliasName; //this.m_LayerPropertyObject.Description = this.m_Description; //this.m_LayerPropertyObject.Key = this.m_GUID; //displayControler.MaxScale = this.m_MaxScale; //displayControler.MinScale = this.m_MinScale; //this.m_LayerPropertyObject.Name = this.m_Name; //displayControler.Visible = this.m_Visible; //displayControler.StartupLoad = this.m_StartUpLoad; //this.m_LayerPropertyObject.EndUpdate(); } else { ILayerGeneralProperties layerGeneralProperties = this.m_FeatureLayer as ILayerGeneralProperties; this.m_FeatureLayer.Name = this.m_AliasName; layerGeneralProperties.LayerDescription = this.m_Description; this.m_FeatureLayer.MaximumScale = this.m_MaxScale; this.m_FeatureLayer.MinimumScale = this.m_MinScale; this.m_FeatureLayer.Visible = this.m_Visible; } this.isDirty = false; } catch (Exception ex) { //RdbUtil.AddException(ex); } } public bool CanWrite2Prop() { try { if (this.m_IsCustomLayer && this.m_Name == "") { MessageHelper.ShowTips("请选择数据源!"); this.btnDataSource.Focus(); bool result = false; return result; } if (this.m_AliasName == "") { MessageHelper.ShowTips("未设置图层别名!"); this.txtLayerAliasName.Focus(); this.txtLayerAliasName2.Focus(); bool result = false; return result; } } catch (Exception ex) { //RdbUtil.AddException(ex); } return this.isDirty; } public void Deactivate() { throw new NotImplementedException(); } public void InitUC(ILayerProperty LayerPropertyObject, bool isNew) { try { this.m_IsCustomLayer = true; this.m_LayerPropertyObject = LayerPropertyObject; this.cmbMinScale.Init(); this.cmbMaxScale.Init(); if (!isNew) { //if (LayerPropertyObject is IDatabaseLayerProperty) //{ // IDatabaseLayerProperty databaseLayerProperty = LayerPropertyObject as IDatabaseLayerProperty; // this.m_DataSource = databaseLayerProperty.DataSource; // if (databaseLayerProperty.DataSource != null) // { // this.txtDataSetType.Text = databaseLayerProperty.DataSource.Category; // this.btnDataSource.Text = databaseLayerProperty.DataSource.Name; // this.btnDataSource.Enabled = true; // } //} //else //{ // if (LayerPropertyObject is IUniversalDatabaseLayerProperty) // { // IUniversalDatabaseLayerProperty universalDatabaseLayerProperty = LayerPropertyObject as IUniversalDatabaseLayerProperty; // this.m_DatasetName = universalDatabaseLayerProperty.DataSourceName; // if (universalDatabaseLayerProperty.DataSourceName != null) // { // this.txtDataSetType.Text = universalDatabaseLayerProperty.LayerType.ToString(); // this.btnDataSource.Text = universalDatabaseLayerProperty.Name; // this.btnDataSource.Enabled = false; // } // else // { // if (universalDatabaseLayerProperty.Layer != null) // { // this.txtDataSetType.Text = universalDatabaseLayerProperty.LayerType.ToString(); // this.btnDataSource.Text = universalDatabaseLayerProperty.Layer.Name; // this.btnDataSource.Enabled = false; // } // } // } // else // { // if (LayerPropertyObject is ITempLayerProperty) // { // ITempLayerProperty tempLayerProperty = LayerPropertyObject as ITempLayerProperty; // this.m_DatasetName = tempLayerProperty.DataSource; // if (tempLayerProperty.DataSource != null) // { // this.txtDataSetType.Text = tempLayerProperty.LayerType.ToString(); // this.btnDataSource.Text = tempLayerProperty.Name; // this.btnDataSource.Enabled = false; // } // else // { // if (tempLayerProperty.Layer != null) // { // this.txtDataSetType.Text = tempLayerProperty.LayerType.ToString(); // this.btnDataSource.Text = tempLayerProperty.Layer.Name; // this.btnDataSource.Enabled = false; // } // } // } // } //} //IDisplayControler displayControler = LayerPropertyObject as IDisplayControler; //this.txtGUID.Text = LayerPropertyObject.Key; //this.txtLayerAliasName.Text = LayerPropertyObject.AliasName; //this.memDescription.Text = LayerPropertyObject.Description; //this.chkVisible.Checked = displayControler.Visible; //this.chkStartUpLoad.Checked = displayControler.StartupLoad; //this.radioGroup1.SelectedIndex = ((displayControler.MaxScale + displayControler.MinScale == 0.0) ? 0 : 1); //this.cmbMaxScale.ScaleValue = displayControler.MaxScale; //this.cmbMinScale.ScaleValue = displayControler.MinScale; } else { //this.m_DataSource = null; this.txtDataSetType.Text = ""; this.txtGUID.Text = this.m_GUID; this.txtLayerAliasName.Text = ""; this.btnDataSource.Text = ""; this.chkVisible.Checked = true; this.chkStartUpLoad.Checked = true; this.radioGroup1.SelectedIndex = 0; this.cmbMaxScale.Enabled = false; this.cmbMinScale.Enabled = false; } this.m_AliasName = this.txtLayerAliasName.Text; this.m_Description = this.memDescription.Text; this.m_GUID = this.txtGUID.Text; this.m_Name = this.btnDataSource.Text; this.m_Visible = this.chkVisible.Checked; this.m_StartUpLoad = this.chkStartUpLoad.Checked; this.LayoutControls(); } catch (Exception ex) { //RdbUtil.AddException(ex); } } private void LayoutControls() { if (this.m_IsCustomLayer) { this.pnlMain.Controls.Clear(); this.pnlLayerProps.Visible = true; this.pnlLayerProps2.Visible = false; this.pnlMain.Refresh(); this.pnlLayerProps.Dock = DockStyle.Fill; this.pnlMain.Controls.Add(this.pnlLayerProps); this.chkStartUpLoad.Visible = true; return; } this.pnlMain.Controls.Clear(); this.pnlLayerProps2.Visible = true; this.pnlLayerProps.Visible = false; this.pnlMain.Refresh(); this.pnlLayerProps2.Dock = DockStyle.Fill; this.pnlMain.Controls.Add(this.pnlLayerProps2); this.chkStartUpLoad.Visible = false; } public void InitUC(object LayerPropertyObject) { try { if (LayerPropertyObject == null) { //this.m_DataSource = null; this.txtDataSetType.Text = ""; this.txtGUID.Text = this.m_GUID; this.txtLayerAliasName.Text = ""; this.txtLayerAliasName2.Text = ""; this.btnDataSource.Text = ""; this.chkVisible.Checked = true; this.chkVisible2.Checked = true; this.chkStartUpLoad.Checked = true; this.radioGroup1.SelectedIndex = 0; this.cmbMaxScale.Enabled = false; this.cmbMinScale.Enabled = false; this.memDescription.Text = ""; this.memDescription2.Text = ""; this.InitUC(null, true); } else { if (LayerPropertyObject is ILayerProperty) { ILayerProperty layerPropertyObject = LayerPropertyObject as ILayerProperty; this.InitUC(layerPropertyObject, false); return; } this.m_IsCustomLayer = false; this.m_FeatureLayer = (LayerPropertyObject as ILayer); this.cmbMinScale.Init(); this.cmbMaxScale.Init(); ILayerGeneralProperties layerGeneralProperties = LayerPropertyObject as ILayerGeneralProperties; this.txtDataSetType.Text = ""; this.txtGUID.Text = ""; this.txtLayerAliasName.Text = this.m_FeatureLayer.Name; this.txtLayerAliasName2.Text = this.m_FeatureLayer.Name; if (layerGeneralProperties != null) { this.memDescription.Text = layerGeneralProperties.LayerDescription; this.memDescription2.Text = layerGeneralProperties.LayerDescription; } this.radioGroup1.SelectedIndex = ((this.m_FeatureLayer.MaximumScale + this.m_FeatureLayer.MinimumScale == 0.0) ? 0 : 1); this.cmbMaxScale.ScaleValue = this.m_FeatureLayer.MaximumScale; this.cmbMinScale.ScaleValue = this.m_FeatureLayer.MinimumScale; this.chkVisible.Checked = this.m_FeatureLayer.Visible; this.chkVisible2.Checked = this.m_FeatureLayer.Visible; } this.m_AliasName = this.txtLayerAliasName.Text; this.m_Description = this.memDescription.Text; this.m_GUID = this.txtGUID.Text; this.m_Name = this.btnDataSource.Text; this.m_Visible = this.chkVisible.Checked; this.m_StartUpLoad = this.chkStartUpLoad.Checked; this.m_MaxScale = this.cmbMaxScale.ScaleValue; this.m_MinScale = this.cmbMinScale.ScaleValue; this.LayoutControls(); } catch (Exception ex) { //RdbUtil.AddException(ex); } } public void SetDefaultValue(object value) { throw new NotImplementedException(); } private void txtLayerAliasName_EditValueChanged(object sender, System.EventArgs e) { this.m_AliasName = (sender as TextEdit).Text; this.InvokeEditValueChanged(sender, e); } private void InvokeEditValueChanged(object sender, System.EventArgs e) { if (this.EditorChanged != null) { this.EditorChanged(sender, e); } this.isDirty = true; } private void radioGroup1_SelectedIndexChanged(object sender, System.EventArgs e) { this.cmbMaxScale.Enabled = Convert.ToBoolean(this.radioGroup1.SelectedIndex); this.cmbMinScale.Enabled = Convert.ToBoolean(this.radioGroup1.SelectedIndex); if (this.radioGroup1.SelectedIndex == 0) { this.m_MaxScale = 0.0; this.m_MinScale = 0.0; } this.InvokeEditValueChanged(sender, e); } private void txtGUID_EditValueChanged(object sender, System.EventArgs e) { this.m_GUID = this.txtGUID.Text; } private void chkVisible_CheckedChanged(object sender, System.EventArgs e) { this.m_Visible = (sender as CheckEdit).Checked; if (this.m_Visible) { this.chkStartUpLoad.Checked = true; } } private void btnDataSource_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { try { //if (this.m_LayerPropertyObject is IDatabaseLayerProperty || this.m_LayerPropertyObject == null) //{ // if (this.frmAETableSelector == null) // { // this.frmAETableSelector = new FormAETableSelector(); // } // this.frmAETableSelector.InitForm(false); // DialogResult dialogResult = this.frmAETableSelector.ShowDialog(); // if (dialogResult == DialogResult.OK) // { // AETable aETable = this.frmAETableSelector.SelectedTables[0]; // if (aETable != null) // { // if (this.m_LayerPropertyObject != null && (this.m_LayerPropertyObject as IDatabaseLayerProperty).DataSource.GeometryType != aETable.GeometryType) // { // DevExpressMessageDialog.ShowMessageDialog("选择的数据源与现有数据源的几何类型不一致,请重新选择。"); // } // else // { // this.m_DataSource = aETable; // string text = this.m_DataSource.AliasName; // if (text == "") // { // text = this.m_DataSource.Name.Substring(this.m_DataSource.Name.IndexOf('.') + 1); // } // this.txtLayerAliasName.Text = text; // this.txtDataSetType.Text = this.m_DataSource.Category; // this.memDescription.Text = this.m_DataSource.Description; // this.btnDataSource.Text = this.m_DataSource.Name; // SelectionChangedEventArgs e2 = new SelectionChangedEventArgs(this.m_DataSource, this.frmAETableSelector.SelectedTables[0]); // this.SelectTableChangedInvoke(sender, e2); // } // } // } //} //else //{ // ITempLayerProperty arg_15D_0 = this.m_LayerPropertyObject as ITempLayerProperty; //} } catch (Exception ex) { //RdbUtil.AddException(ex); } } private void btnDataSource_EditValueChanged(object sender, System.EventArgs e) { this.m_Name = this.btnDataSource.Text; } private void memDescription_EditValueChanged(object sender, System.EventArgs e) { this.m_Description = (sender as MemoEdit).Text; this.InvokeEditValueChanged(sender, e); } private void chkStartUpLoad_CheckedChanged(object sender, System.EventArgs e) { this.m_StartUpLoad = this.chkStartUpLoad.Checked; if (!this.m_StartUpLoad) { this.chkVisible.Checked = false; } } private void cmbScaleMin_ScaleValueChanged(double scale) { this.m_MinScale = scale; this.InvokeEditValueChanged(null, null); } private void cmbMaxScale_ScaleValueChanged(double scale) { this.m_MaxScale = scale; this.InvokeEditValueChanged(null, null); } } }