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) + Dict.Extenstions.XmlModel_Extension; if (File.Exists(fileName)) { MessageBox.Show("文件已经存在"); return; } var writer = File.CreateText(fileName); writer.Flush(); writer.Close(); var dataModel = new XmlModelNode(); 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 cmdHost = CommandHostManager.Instance().Get( CommandHostManager.HostType.XmlMode); var cmd = cmdHost.GetCommand(Dict.Commands.NewXmlModel) as NewXmlModelCommand; cmd.File = dataModel.FullName; cmdHost.RunCommand(Dict.Commands.NewXmlModel); }
//static T CreateNode<T>(DatabaseType dbType) where T : BaseNode //{ // if (dbType == DatabaseType.SqlServer) // { // if (typeof(T).Equals(typeof(FieldNode))) // { // BaseNode node = new SqlFieldNode(); // return (T)node; // } // if (typeof(T).Equals(typeof(ColumnNode))) // { // BaseNode node = new SqlColumnNode(); // return (T)node; // } // } // if (dbType == DatabaseType.Postgres) // { // if (typeof(T).Equals(typeof(FieldNode))) // { // BaseNode node = new PostgresFieldNode(); // return (T)node; // } // if (typeof(T).Equals(typeof(ColumnNode))) // { // BaseNode node = new PostgresColumnNode(); // return (T)node; // } // } // return default(T); //} //public static T CreateNode<T>() where T : BaseNode //{ // if (GlobalService.DbType == DatabaseType.UnKnown) // { // System.Windows.Forms.MessageBox.Show("请确保选择一个链接节点"); // return null; // } // return CreateNode<T>(GlobalService.DbType); //} public static BaseNode Create(Dict.NodeType nodeType , string name = null, string text = null) { if (string.IsNullOrWhiteSpace(name)) { } BaseNode node = null; if (nodeType == Dict.NodeType.Unknown) throw new Exception("必须有节点类型"); if (nodeType == Dict.NodeType.Project) node = new DesignProjectNode(); if (nodeType == Dict.NodeType.XmlModelSet) node = new XmlModelSetNode(); if (nodeType == Dict.NodeType.XmlModel) node = new XmlModelNode(); if (nodeType == Dict.NodeType.DataModelSet) node= new DataModelSetNode(); if (nodeType == Dict.NodeType.DataModel) node = new DataModelNode(); //if (nodeType == Dict.NodeType.DataViewSet) // node = new DataViewSetNode(); //if (nodeType == Dict.NodeType.DataView) // node = new DataViewNode(); //if (nodeType == Dict.NodeType.ViewModel) // node = new ViewModelNode(); //if (nodeType == Dict.NodeType.ViewModelSet) // node = new ViewModelSetNode(); //if (nodeType == Dict.NodeType.WorkFlow) // node = new WorkFlowNode(); //if (nodeType == Dict.NodeType.WorkFlowSet) // node = new WorkFlowSetNode(); if (node != null) { if (name != null) node.Name = name; if (text != null) node.Text = text; } return node; }
protected override void LoadFile() { //var dir = new DirectoryInfo(this.Path); //foreach (var f in dir.GetFiles()) //{ // if (f.Extension == Dict.Extenstion.XmlModel_Extension) // { // var file_node = NodeFactory.Create(Dict.NodeType.XmlModel, f.Name, f.Name); // file_node.Parent = this; // } //} var directory = new DirectoryInfo(Path); foreach (var dm in directory.GetFiles("*" + Dict.Extenstions.XmlModel_Extension)) { var dmNode = new XmlModelNode(); dmNode.FullName = dm.FullName; dmNode.Parent = this; } }