Exemplo n.º 1
0
        /// <summary>
        /// 获取连接
        /// </summary>
        /// <returns></returns>
        public static List <Model.Connection> GetConnectionList()
        {
            List <Model.Connection> list = new List <Hxj.Tools.EntityDesign.Model.Connection>();
            XmlDocument             doc  = getXmlDocument();

            XmlNodeList xmlNodeList = doc.SelectNodes("servers/server");

            if (null != xmlNodeList && xmlNodeList.Count > 0)
            {
                foreach (XmlNode node in xmlNodeList)
                {
                    if (!node.HasChildNodes)
                    {
                        continue;
                    }

                    Model.Connection connection = new Hxj.Tools.EntityDesign.Model.Connection();

                    connection.ID               = new Guid(node.Attributes["id"].Value);
                    connection.Name             = node.Attributes["name"].Value;
                    connection.Database         = node.Attributes["database"].Value;
                    connection.ConnectionString = node.FirstChild.InnerText;
                    connection.DbType           = node.Attributes["dbtype"].Value;
                    list.Add(connection);
                }
            }
            return(list);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取连接
        /// </summary>
        /// <returns></returns>
        public static List<Model.Connection> GetConnectionList()
        {
            List<Model.Connection> list = new List<Hxj.Tools.EntityDesign.Model.Connection>();
            XmlDocument doc = getXmlDocument();

            XmlNodeList xmlNodeList = doc.SelectNodes("servers/server");
            if (null != xmlNodeList && xmlNodeList.Count > 0)
            {
                foreach (XmlNode node in xmlNodeList)
                {
                    if (!node.HasChildNodes)
                        continue;

                    Model.Connection connection = new Hxj.Tools.EntityDesign.Model.Connection();

                    connection.ID = new Guid(node.Attributes["id"].Value);
                    connection.Name = node.Attributes["name"].Value;
                    connection.Database = node.Attributes["database"].Value;
                    connection.ConnectionString = node.FirstChild.InnerText;
                    connection.DbType = node.Attributes["dbtype"].Value;
                    list.Add(connection);

                }
            }
            return list;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取一个连接配置
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Model.Connection GetConnectionModel(string id)
        {
            Model.Connection connModel = null;
            if (string.IsNullOrEmpty(id))
            {
                return(connModel);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(DatabaseconfigPath);

            XmlNode xmlNode = doc.SelectSingleNode("servers/server[@id='" + id.ToString() + "']");

            if (null != xmlNode)
            {
                connModel                  = new Hxj.Tools.EntityDesign.Model.Connection();
                connModel.ID               = new Guid(xmlNode.Attributes["id"].Value);
                connModel.Name             = xmlNode.Attributes["name"].Value;
                connModel.Database         = xmlNode.Attributes["database"].Value;
                connModel.ConnectionString = xmlNode.FirstChild.InnerText;
                connModel.DbType           = xmlNode.Attributes["dbtype"].Value;
            }

            return(connModel);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 代码生成
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void 生成代码ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (null != newcontentForm)
     {
         Model.Connection conModel = list.Find(delegate(Model.Connection con) { return(con.ID.ToString().Equals(tview.SelectedNode.Parent.Parent.Parent.Tag.ToString())); });
         conModel.ConnectionString = tview.SelectedNode.Parent.Parent.Tag.ToString();
         newcontentForm(conModel, tview.SelectedNode.Text, tview.SelectedNode.Parent.Parent.Text, tview.SelectedNode.Tag.ToString().Equals("V"));
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 批量生成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 批量生成ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = tview.SelectedNode;

            Model.Connection conModel = list.Find(delegate(Model.Connection con) { return(con.ID.ToString().Equals(node.Parent.Tag.ToString())); });

            BatchForm bf = new BatchForm();

            bf.DatabaseName    = node.Text;
            bf.ConnectionModel = conModel;
            bf.ShowDialog();
        }
Exemplo n.º 6
0
        private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string stringid = tview.SelectedNode.Tag.ToString();

            Utils.DeleteConnection(stringid);
            Model.Connection tempconn = list.Find(delegate(Model.Connection conn) { return(conn.ID.ToString().Equals(stringid)); });
            if (null != tempconn)
            {
                list.Remove(tempconn);
            }
            tview.Nodes.Remove(tview.SelectedNode);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 刷新服务器
        /// </summary>
        private void refreshConnectionList()
        {
            List <Model.Connection> connList = Utils.GetConnectionList();

            foreach (Model.Connection conn in connList)
            {
                Model.Connection tempconn = list.Find(delegate(Model.Connection connin) { return(conn.ID.ToString().Equals(connin.ID.ToString())); });
                if (null == tempconn)
                {
                    TreeNode nnode = new TreeNode(conn.Name, 0, 0);
                    nnode.ContextMenuStrip = contextMenuStripDatabase;
                    nnode.Tag = conn.ID.ToString();
                    tview.Nodes[0].Nodes.Add(nnode);
                }
            }

            list = connList;
        }
Exemplo n.º 8
0
        /// <summary>
        /// 刷新数据库表和视图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 刷新ToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            TreeNode node = tview.SelectedNode;

            node.Nodes.Clear();

            Model.Connection conModel = list.Find(delegate(Model.Connection con) { return(con.ID.ToString().Equals(node.Parent.Tag.ToString())); });

            IDBO.IDbObject dbObject;

            if (conModel.DbType.Equals(Dos.ORM.DatabaseType.MsAccess.ToString()))
            {
                dbObject = new Hxj.DbObjects.OleDb.DbObject(conModel.ConnectionString);
                gettables(node, dbObject.GetTables(""), dbObject.GetVIEWs(""));
            }
            else if (conModel.DbType.Equals(Dos.ORM.DatabaseType.SqlServer.ToString()))
            {
                dbObject = new Hxj.DbObjects.SQL2000.DbObject(conModel.ConnectionString);
                gettables(node, dbObject.GetTables(node.Text), dbObject.GetVIEWs(node.Text));
            }
            else if (conModel.DbType.Equals(Dos.ORM.DatabaseType.SqlServer9.ToString()))
            {
                dbObject = new Hxj.DbObjects.SQL2005.DbObject(conModel.ConnectionString);
                gettables(node, dbObject.GetTables(node.Text), dbObject.GetVIEWs(node.Text));
            }
            else if (conModel.DbType.Equals(Dos.ORM.DatabaseType.Oracle.ToString()))
            {
                dbObject = new Hxj.DbObjects.Oracle.DbObject(conModel.ConnectionString);
                gettables(node, dbObject.GetTables(node.Text), dbObject.GetVIEWs(node.Text));
            }
            else if (conModel.DbType.Equals(Dos.ORM.DatabaseType.MySql.ToString()))
            {
                dbObject = new Hxj.DbObjects.Oracle.DbObject(conModel.ConnectionString);
                gettables(node, dbObject.GetTables(node.Text), dbObject.GetVIEWs(node.Text));
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="conection"></param>
        public static void AddConnection(Model.Connection conection)
        {
            XmlDocument doc = getXmlDocument();

            XmlNode root = doc.SelectSingleNode("servers");

            XmlElement xe = doc.CreateElement("server");

            xe.SetAttribute("id", conection.ID.ToString());
            xe.SetAttribute("name", conection.Name);
            xe.SetAttribute("database", conection.Database);
            xe.SetAttribute("dbtype", conection.DbType);

            XmlElement      xe1   = doc.CreateElement("connectionstring");
            XmlCDataSection cdata = doc.CreateCDataSection(conection.ConnectionString);

            xe1.AppendChild(cdata);

            xe.AppendChild(xe1);

            root.AppendChild(xe);

            doc.Save(DatabaseconfigPath);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 获取一个连接配置
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Model.Connection GetConnectionModel(string id)
        {
            Model.Connection connModel = null;
            if (string.IsNullOrEmpty(id))
                return connModel;

            XmlDocument doc = new XmlDocument();
            doc.Load(DatabaseconfigPath);

            XmlNode xmlNode = doc.SelectSingleNode("servers/server[@id='" + id.ToString() + "']");
            if (null != xmlNode)
            {
                connModel = new Hxj.Tools.EntityDesign.Model.Connection();
                connModel.ID = new Guid(xmlNode.Attributes["id"].Value);
                connModel.Name = xmlNode.Attributes["name"].Value;
                connModel.Database = xmlNode.Attributes["database"].Value;
                connModel.ConnectionString = xmlNode.FirstChild.InnerText;
                connModel.DbType = xmlNode.Attributes["dbtype"].Value;
            }

            return connModel;
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        private void getDatabaseinfo()
        {
            TreeNode node = tview.SelectedNode;

            Model.Connection conModel = list.Find(delegate(Model.Connection con) { return(con.ID.ToString().Equals(node.Tag.ToString())); });

            IDBO.IDbObject dbObject;

            if (conModel.DbType.Equals(Dos.ORM.DatabaseType.MsAccess.ToString()))
            {
                dbObject = new Hxj.DbObjects.OleDb.DbObject(conModel.ConnectionString);

                TreeNode tnode = new TreeNode(conModel.Database, 1, 1);
                tnode.Tag = conModel.ConnectionString;
                tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                node.Nodes.Add(tnode);



                gettables(tnode, dbObject.GetTables(""), dbObject.GetVIEWs(""));
            }
            else if (conModel.DbType.Equals(Dos.ORM.DatabaseType.Sqlite3.ToString()))
            {
                dbObject = new Hxj.DbObjects.SQLite.DbObject(conModel.ConnectionString);

                TreeNode tnode = new TreeNode(conModel.Database, 1, 1);
                tnode.Tag = conModel.ConnectionString;
                tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                node.Nodes.Add(tnode);

                gettables(tnode, dbObject.GetTables(""), dbObject.GetVIEWs(""));
            }
            else if (conModel.DbType.Equals(Dos.ORM.DatabaseType.SqlServer.ToString()) || conModel.DbType.Equals(Dos.ORM.DatabaseType.SqlServer9.ToString()))
            {
                if (conModel.DbType.Equals(Dos.ORM.DatabaseType.SqlServer.ToString()))
                {
                    dbObject = new Hxj.DbObjects.SQL2000.DbObject(conModel.ConnectionString);
                }
                else
                {
                    dbObject = new Hxj.DbObjects.SQL2005.DbObject(conModel.ConnectionString);
                }

                if (conModel.Database.Equals("all"))
                {
                    DataTable dt = dbObject.GetDBList();

                    foreach (DataRow dr in dt.Rows)
                    {
                        TreeNode tnode = new TreeNode(dr[0].ToString(), 1, 1);
                        tnode.Tag = conModel.ConnectionString.Replace("master", dr[0].ToString());
                        tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                        node.Nodes.Add(tnode);

                        gettables(tnode, dbObject.GetTables(tnode.Text), dbObject.GetVIEWs(tnode.Text));
                    }
                }
                else
                {
                    TreeNode tnode = new TreeNode(conModel.Database, 1, 1);
                    tnode.Tag = conModel.ConnectionString;
                    tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                    node.Nodes.Add(tnode);

                    gettables(tnode, dbObject.GetTables(tnode.Text), dbObject.GetVIEWs(tnode.Text));
                }
            }
            else if (conModel.DbType.Equals(Dos.ORM.DatabaseType.Oracle.ToString()))
            {
                dbObject = new Hxj.DbObjects.Oracle.DbObject(conModel.ConnectionString);

                TreeNode tnode = new TreeNode(conModel.Database, 1, 1);
                tnode.Tag = conModel.ConnectionString;
                tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                node.Nodes.Add(tnode);

                gettables(tnode, dbObject.GetTables(tnode.Text), dbObject.GetVIEWs(tnode.Text));
            }
            else if (conModel.DbType.Equals(Dos.ORM.DatabaseType.MySql.ToString()))
            {
                dbObject = new Hxj.DbObjects.MySQL.DbObject(conModel.ConnectionString);

                if (conModel.Database.Equals("all"))
                {
                    DataTable dt = dbObject.GetDBList();

                    foreach (DataRow dr in dt.Rows)
                    {
                        TreeNode tnode = new TreeNode(dr[0].ToString(), 1, 1);
                        tnode.Tag = conModel.ConnectionString.Replace("master", dr[0].ToString());
                        tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                        node.Nodes.Add(tnode);

                        gettables(tnode, dbObject.GetTables(tnode.Text), dbObject.GetVIEWs(tnode.Text));
                    }
                }
                else
                {
                    TreeNode tnode = new TreeNode(conModel.Database, 1, 1);
                    tnode.Tag = conModel.ConnectionString;
                    tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                    node.Nodes.Add(tnode);

                    gettables(tnode, dbObject.GetTables(tnode.Text), dbObject.GetVIEWs(tnode.Text));
                }
            }
        }