using HydroUI; namespace PBS.WinFrmUI.Hydro { public partial class ModelTemplatePage : DocumentPage { public ModelTemplatePage() { InitializeComponent(); this.modelTemplateTreeListCtrl1.SelectModelTemplateEvent += ModelTemplateTreeListCtrl1_SelectModelTemplateEvent; this.modelTemplateTreeListCtrl1.RefreshDataEvent += () => { RefreshData(); }; } private ModelTemplateVmo _modelTemplate = null; private Template _template = null; private MapViewer _mapView; private PropertyForm _propertyForm; /// /// 初始化数据源 /// public override void InitialDataSource() { base.InitialDataSource(); InitialMapViewer(); InitialData(); } //初始化数据 private async void InitialData() { var overlay = this.ShowOverlay(); var allModelTemplateList = await BLLFactory.Instance.GetAll(); this.modelTemplateTreeListCtrl1.SetBindingData(allModelTemplateList); overlay.Close(); } //初始化视图 private void InitialMapViewer() { _mapView = new MapViewer(); _mapView.Lock2DView = true; _mapView.ShowPropertyForm = false; _mapView.Location = new System.Drawing.Point(0, 0); _mapView.Dock = DockStyle.Fill; this.panelControl1.Controls.Add(_mapView); _propertyForm = new PropertyForm(); _propertyForm.Dock = DockStyle.Fill; this.dockPanelModelProperty.Controls.Add(_propertyForm); GlobalObject.PropertyForm = _propertyForm; GlobalObject.map = _mapView; } private void ModelTemplateTreeListCtrl1_SelectModelTemplateEvent(ModelTemplateVmo obj) { if (obj == null) { _modelTemplate = null; _template = null; _mapView.Clear(); return; } if (string.IsNullOrEmpty(obj.ModelPath)) { var filePath = "template\\" + obj.TemplateType + "\\" + obj.ID + ".inp"; var fullPath = Path.Combine(Directory.GetCurrentDirectory(), filePath); var directoryPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(directoryPath)) Directory.CreateDirectory(directoryPath); if (!File.Exists(fullPath)) File.Create(fullPath).Close(); obj.ModelPath = fullPath; } if (string.IsNullOrEmpty(obj.ModelInfo)) { obj.ModelInfo = Yw.JsonHelper.Object2Json(new Template() { ID = obj.ID.ToString(), Name = obj.Name, Type = obj.TemplateType, filePath = obj.ModelPath, }); } _modelTemplate = obj; _template = Yw.JsonHelper.Json2Object