示例#1
0
        /// <summary>
        /// 注销数据库
        /// </summary>
        public void RemoveServer()
        {
            if (tvDatabase.SelectedNode == null)
            {
                return;
            }
            TreeNode rootNode = GetRoot(tvDatabase.SelectedNode);

            if (rootNode == null)
            {
                return;
            }
            Model.TreeNodeTag tag = (Model.TreeNodeTag)rootNode.Tag;
            if (tag.Type != TreeNodeType.Server)
            {
                return;
            }
            Model.Servers server = (Model.Servers)tag.Tag;
            new Common.Config_Servers().Delete(server.ID);
            rootNode.Remove();
        }
示例#2
0
        /// <summary>
        /// 加载下级节点
        /// </summary>
        private void AddNodes(bool isRefresh = false)
        {
            TreeNode selNode = tvDatabase.SelectedNode;

            if (selNode == null)
            {
                return;
            }
            if (selNode.Nodes.Count > 0 && !isRefresh)
            {
                return;
            }

            selNode.Nodes.Clear();
            TreeNode rootNode = GetRoot(selNode);

            if (rootNode == null)
            {
                return;
            }
            Model.TreeNodeTag rootNodeTag = (Model.TreeNodeTag)rootNode.Tag;
            if (!(rootNodeTag.Tag is Model.Servers))
            {
                return;
            }
            Model.Servers     server   = (Model.Servers)rootNodeTag.Tag;
            Model.TreeNodeTag nodeTag  = (Model.TreeNodeTag)selNode.Tag;
            Business.Database Database = new Business.Database(server.Type);
            string            msg;

            if (!Database.TestDatabaseConnnection(server.ID, out msg))
            {
                MessageBox.Show(msg, "连接失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            switch (nodeTag.Type)
            {
            case TreeNodeType.Server:     //服务器加载数据库
                var dbs = Database.GetDatabases(server.ID);
                foreach (var db in dbs)
                {
                    TreeNode dbNode = new TreeNode();
                    dbNode.Name               = db;
                    dbNode.Text               = db;
                    dbNode.ImageIndex         = 1;
                    dbNode.SelectedImageIndex = 1;
                    dbNode.Tag = new Model.TreeNodeTag()
                    {
                        Type = TreeNodeType.DataBase, Tag = db
                    };
                    selNode.Nodes.Add(dbNode);
                }
                break;

            case TreeNodeType.DataBase:     //数据库加载表视图节点
                //添加表节点
                TreeNode tblNode = new TreeNode();
                tblNode.Name = "表";
                tblNode.Text = "表";
                tblNode.Tag  = new Model.TreeNodeTag()
                {
                    Type = TreeNodeType.TableNode, Tag = nodeTag.Tag.ToString()
                };
                tblNode.ImageIndex         = 4;
                tblNode.SelectedImageIndex = 4;
                selNode.Nodes.Add(tblNode);

                //添加视图节点
                TreeNode viewNode = new TreeNode();
                viewNode.Name = "视图";
                viewNode.Text = "视图";
                viewNode.Tag  = new Model.TreeNodeTag()
                {
                    Type = TreeNodeType.ViewNode, Tag = nodeTag.Tag.ToString()
                };
                viewNode.ImageIndex         = 4;
                viewNode.SelectedImageIndex = 4;
                selNode.Nodes.Add(viewNode);
                break;

            case TreeNodeType.TableNode:     //表节点加载表
                var tables = Database.GetTables(server.ID, nodeTag.Tag.ToString());
                foreach (var table in tables)
                {
                    TreeNode tblNode1 = new TreeNode();
                    tblNode1.Name               = table.Name;
                    tblNode1.Text               = table.Name;
                    tblNode1.ImageIndex         = 2;
                    tblNode1.SelectedImageIndex = 2;
                    tblNode1.Tag = new Model.TreeNodeTag()
                    {
                        Type = TreeNodeType.Table, Tag = table.Name
                    };
                    selNode.Nodes.Add(tblNode1);
                }
                break;

            case TreeNodeType.ViewNode:     //视图节点加载视图
                var views = Database.GetViews(server.ID, nodeTag.Tag.ToString());
                foreach (var view in views)
                {
                    TreeNode viewNode1 = new TreeNode();
                    viewNode1.Name               = view.Name;
                    viewNode1.Text               = view.Name;
                    viewNode1.ImageIndex         = 2;
                    viewNode1.SelectedImageIndex = 2;
                    viewNode1.Tag = new Model.TreeNodeTag()
                    {
                        Type = TreeNodeType.View, Tag = view.Name
                    };
                    selNode.Nodes.Add(viewNode1);
                }
                break;

            case TreeNodeType.View:
            case TreeNodeType.Table:     //表加载字段
                var fields = Database.GetFields(server.ID, ((Model.TreeNodeTag)selNode.Parent.Tag).Tag.ToString(), ((Model.TreeNodeTag)selNode.Tag).Tag.ToString());
                foreach (var field in fields)
                {
                    TreeNode fldNode = new TreeNode();
                    fldNode.Name               = field.Name;
                    fldNode.Text               = string.Format("{0}({1}{2},{3})", field.Name, field.Type, field.Length != -1 ? "(" + field.Length.ToString() + ")" : "", field.IsNull ? "null" : "not null");
                    fldNode.ImageIndex         = field.IsPrimaryKey ? 5 : 3;
                    fldNode.SelectedImageIndex = field.IsPrimaryKey ? 5 : 3;
                    fldNode.Tag = new Model.TreeNodeTag()
                    {
                        Type = TreeNodeType.Field, Tag = field
                    };
                    selNode.Nodes.Add(fldNode);
                }
                break;
            }
            selNode.Expand();
        }
示例#3
0
        private void CreateToDir()
        {
            List <TreeNode> NodeList = MainForm.form_Database.GetTreeView1Selected();

            if (NodeList.Count == 0)
            {
                return;
            }
            TreeNode serverNode = MainForm.form_Database.GetRoot(NodeList.First());
            TreeNode dbNode     = NodeList.First().Parent.Parent;

            List <Model.BuilderMethods> methods = new List <Model.BuilderMethods>();


            Model.Servers       server     = (Model.Servers)((Model.TreeNodeTag)serverNode.Tag).Tag;
            Business.CreateCode CreateCode = new Business.CreateCode(server.Type);
            Model.CodeCreate    param      = new Model.CodeCreate();

            param.DbName      = ((Model.TreeNodeTag)dbNode.Tag).Tag.ToString();
            param.NameSpace   = new Common.Config_NameSpace().GetDefault().Name1;
            param.NameSpace1  = new Common.Config_NameSpace().GetDefault().Name2;
            param.ServerID    = server.ID;
            param.BuilderType = Model.BuilderType.Default;
            param.MethodList  = methods;
            param.CNSC        = new Common.Config_NameSpaceClass().GetDefault();

            Business.CreateCode CreateCodeInstince = new Business.CreateCode(server.Type);


            StreamWriter sw;
            string       FileName    = string.Empty;
            var          utf8WithBom = new System.Text.UTF8Encoding(true);

            foreach (TreeNode node in NodeList)
            {
                param.TableName = ((Model.TreeNodeTag)node.Tag).Tag.ToString();
                param.ClassName = param.TableName;
                List <Model.ConfigTemplate> templateList = new Common.Config_Template().GetAll();
                for (int i = 0; i < templateList.Count; i++)
                {
                    var item = templateList[i];

                    if (item.IsActive == "是")
                    {
                        item.TargetName    = item.TargetName.Replace("[ClassName]", param.ClassName);
                        item.DirectoryName = item.DirectoryName.Replace("[ClassName]", param.ClassName);
                        FileName           = Common.Func.ExistsDirectory(string.Format("{0}\\{1}\\{2}\\{3}", this.textBox_dir.Text, param.NameSpace + (param.NameSpace1.IsNullOrEmpty() ? "" : "." + param.NameSpace1), item.DirectoryName, item.TargetName));
                        //sw = File.CreateText(FileName.Substring(0, FileName.LastIndexOf(".")) + item.TargetPostfix + FileName.Substring(FileName.LastIndexOf(".")));
                        sw = new StreamWriter(FileName.Substring(0, FileName.LastIndexOf(".")) + item.TargetPostfix + FileName.Substring(FileName.LastIndexOf(".")), false, utf8WithBom);
                        //sw.Write(CreateCodeInstince.GetModelClass(param));
                        sw.Write(CreateCodeInstince.GetBuilderClass(param, item.TemplateName));
                        sw.Close();
                        sw.Dispose();
                        lbMessage.Text = string.Format("生成文件:{0}", FileName);
                    }
                }

                /*//生成实体类
                 * FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}\\{2}\\{3}.cs", this.textBox_dir.Text, param.NameSpace+(param.NameSpace1.IsNullOrEmpty() ? "" : "."+param.NameSpace1), param.CNSC.Model.Substring(param.CNSC.Model.LastIndexOf(".")+1),  param.ClassName));
                 * sw = File.CreateText(FileName);
                 * //sw.Write(CreateCodeInstince.GetModelClass(param));
                 * sw.Write(CreateCodeInstince.GetBuilderClass(param,"Entity.txt"));
                 * sw.Close();
                 * sw.Dispose();
                 * lbMessage.Text = string.Format("生成文件:{0}", FileName);
                 *
                 * //生成数据类
                 * FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}\\{2}\\{3}.cs", this.textBox_dir.Text, param.NameSpace + (param.NameSpace1.IsNullOrEmpty() ? "" : "." + param.NameSpace1), param.CNSC.Data.Substring(param.CNSC.Data.LastIndexOf(".") + 1),  param.ClassName));
                 * sw = File.CreateText(FileName.Substring(0, FileName.LastIndexOf(".")) + "DAL" + FileName.Substring(FileName.LastIndexOf(".")));
                 * //sw.Write(CreateCodeInstince.GetDataClass(param));
                 * sw.Write(CreateCodeInstince.GetBuilderClass(param, "DAL.txt"));
                 * sw.Close();
                 * sw.Dispose();
                 * lbMessage.Text = string.Format("生成文件:{0}", FileName);
                 *
                 *
                 * //生成业务类
                 * FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}\\{2}\\{3}.cs", this.textBox_dir.Text, param.NameSpace + (param.NameSpace1.IsNullOrEmpty() ? "" : "." + param.NameSpace1), param.CNSC.Business.Substring(param.CNSC.Business.LastIndexOf(".") + 1),  param.ClassName));
                 * sw = File.CreateText(FileName.Substring(0, FileName.LastIndexOf(".")) + "BLL" + FileName.Substring(FileName.LastIndexOf(".")));
                 * //sw.Write(CreateCodeInstince.GetBusinessClass(param));
                 * sw.Write(CreateCodeInstince.GetBuilderClass(param, "BLL.txt"));
                 * sw.Close();
                 * sw.Dispose();
                 * lbMessage.Text = string.Format("生成文件:{0}", FileName);
                 *
                 *
                 * //生成接口类
                 * FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}\\{2}\\{3}.cs", this.textBox_dir.Text, param.NameSpace + (param.NameSpace1.IsNullOrEmpty() ? "" : "." + param.NameSpace1), param.CNSC.Interface.Substring(param.CNSC.Interface.LastIndexOf(".") + 1), param.ClassName));
                 * sw = File.CreateText(FileName.Substring(0, FileName.LastIndexOf(".")) + "IDAL" + FileName.Substring(FileName.LastIndexOf(".")));
                 * //sw.Write(CreateCodeInstince.GetInterfaceClass(param));
                 * sw.Write(CreateCodeInstince.GetBuilderClass(param, "IDAL.txt"));
                 * sw.Close();
                 * sw.Dispose();
                 * lbMessage.Text = string.Format("生成文件:{0}", FileName);
                 *
                 *
                 * FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}\\{2}\\{3}.cs", this.textBox_dir.Text, param.NameSpace + (param.NameSpace1.IsNullOrEmpty() ? "" : "." + param.NameSpace1), param.CNSC.Interface.Substring(param.CNSC.Interface.LastIndexOf(".") + 1), param.ClassName));
                 * sw = File.CreateText(FileName.Substring(0, FileName.LastIndexOf(".")) + "IDAL" + FileName.Substring(FileName.LastIndexOf(".")));
                 * //sw.Write(CreateCodeInstince.GetInterfaceClass(param));
                 * sw.Write(CreateCodeInstince.GetBuilderClass(param, "IDAL.txt"));
                 * sw.Close();
                 * sw.Dispose();
                 * lbMessage.Text = string.Format("生成文件:{0}", FileName);
                 *
                 *
                 * FileName = Common.Func.ExistsDirectory(string.Format("{0}\\json\\ColumnName.json", this.textBox_dir.Text));
                 * sw = File.CreateText(FileName);
                 * //sw.Write(CreateCodeInstince.GetInterfaceClass(param));
                 * sw.Write(CreateCodeInstince.GetBuilderClass(param, "Json.txt"));
                 * sw.Close();
                 * sw.Dispose();
                 * lbMessage.Text = string.Format("生成文件:{0}", FileName);
                 *
                 *
                 * FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}\\Controller\\{2}.cs", this.textBox_dir.Text, param.NameSpace + (param.NameSpace1.IsNullOrEmpty() ? "" : "." + param.NameSpace1),  param.ClassName));
                 * sw = File.CreateText(FileName.Substring(0, FileName.LastIndexOf(".")) + "Controller" + FileName.Substring(FileName.LastIndexOf(".")));
                 * //sw.Write(CreateCodeInstince.GetInterfaceClass(param));
                 * sw.Write(CreateCodeInstince.GetBuilderClass(param, "Controller.txt"));
                 * sw.Close();
                 * sw.Dispose();
                 * lbMessage.Text = string.Format("生成文件:{0}", FileName);
                 * //生成Json
                 *
                 * FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}\\Views\\Index.cshtml", this.textBox_dir.Text, param.NameSpace + (param.NameSpace1.IsNullOrEmpty() ? "" : "." + param.NameSpace1)));
                 * sw = File.CreateText(FileName.Substring(0, FileName.LastIndexOf(".")) +  FileName.Substring(FileName.LastIndexOf(".")));
                 * //sw.Write(CreateCodeInstince.GetInterfaceClass(param));
                 * sw.Write(CreateCodeInstince.GetBuilderClass(param, "Index.txt"));
                 * sw.Close();
                 * sw.Dispose();
                 * lbMessage.Text = string.Format("生成文件:{0}", FileName);
                 *
                 * FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}\\Views\\Edit.cshtml", this.textBox_dir.Text, param.NameSpace + (param.NameSpace1.IsNullOrEmpty() ? "" : "." + param.NameSpace1)));
                 * sw = File.CreateText(FileName.Substring(0, FileName.LastIndexOf(".")) + FileName.Substring(FileName.LastIndexOf(".")));
                 * //sw.Write(CreateCodeInstince.GetInterfaceClass(param));
                 * sw.Write(CreateCodeInstince.GetBuilderClass(param, "Edit.txt"));
                 * sw.Close();
                 * sw.Dispose();
                 * lbMessage.Text = string.Format("生成文件:{0}", FileName);*/
            }
            MessageBox.Show("生成完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.lbMessage.Text      = "生成已完成";
            this.btnGenerate.Enabled = true;
        }