protected void OnNewViewModel(object sender, EventArgs args) { var dlg = new NewFrm(); if (dlg.ShowDialog() != DialogResult.OK) { return; } var newName = dlg.GetName(); if (string.IsNullOrWhiteSpace(newName)) { MessageBox.Show("名称不能为空"); return; } var fileName = System.IO.Path.Combine(this.Path, newName) + Dict.Extenstions.ViewModel_Extension; if (File.Exists(fileName)) { MessageBox.Show("文件已经存在"); return; } var writer = File.CreateText(fileName); writer.Flush(); writer.Close(); var dataModel = new ViewModelNode(); dataModel.Parent = this; dataModel.FileName = System.IO.Path.GetFileNameWithoutExtension(fileName); dataModel.Name = dataModel.Text = System.IO.Path.GetFileNameWithoutExtension(fileName); dataModel.FullName = fileName; this.TreeNode.Expand(); var cmd = CommandHostManager.Instance().Get<NewViewModelCommand> (CommandHostManager.HostType.ViewModel, Dict.Commands.NewViewModel); cmd.File = dataModel.FullName; cmd.Execute(); //cmdHost.RunCommand(Dict.Commands.NewXmlModel); }
protected void OnNewDataModel(object sender, EventArgs args) { var dlg = new NewFrm(); if (dlg.ShowDialog() != DialogResult.OK) { return; } var newName = dlg.GetName(); if (string.IsNullOrWhiteSpace(newName)) { MessageBox.Show("名称不能为空"); return; } var fileName = System.IO.Path.Combine(this.Path, newName) + ".dm"; if (File.Exists(fileName)) { MessageBox.Show("文件已经存在"); return; } var writer = File.CreateText(fileName); writer.Flush(); writer.Close(); var dataModel = new DataModelNode(); dataModel.Parent = this; dataModel.Text = dataModel.Name = newName; dataModel.FullName = fileName; this.TreeNode.Expand(); var cmdHost = CommandHostManager.Instance().Get( CommandHostManager.HostType.DataModel); var cmd = cmdHost.GetCommand(Dict.Commands.NewDataModel) as NewDataModelCommand; cmd.File = dataModel.FullName; dataModel.FileId = Guid.NewGuid(); cmdHost.RunCommand(Dict.Commands.NewDataModel); }