예제 #1
0
파일: Utils.cs 프로젝트: lzmj/Sharp
        /// <summary>
        /// 获取连接
        /// </summary>
        /// <returns></returns>
        public static List <Entity.Connection> GetConnectionList()
        {
            List <Entity.Connection> list = new List <SharpTools.Entity.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;
                    }

                    Entity.Connection connection = new SharpTools.Entity.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.ConvertTo <DataBaseType>();
                    list.Add(connection);
                }
            }
            return(list);
        }
예제 #2
0
파일: Utils.cs 프로젝트: lzmj/Sharp
        /// <summary>
        /// 获取一个连接配置
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Entity.Connection GetConnectionModel(string id)
        {
            Entity.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 SharpTools.Entity.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.ConvertTo <DataBaseType>();
            }

            return(connModel);
        }
예제 #3
0
 /// <summary>
 /// 创建生成
 /// </summary>
 /// <param name="conModel"></param>
 /// <param name="tableName"></param>
 void lp_newcontentForm(DockContentForm dkContentFm, Entity.Connection conModel, string tableName, bool isView)
 {
     dkContentFm.Text            = "(" + new DB(conModel.DbType, conModel.ConnectionString).DBaseType + ")" + tableName;
     dkContentFm.TableName       = tableName;
     dkContentFm.IsView          = isView;
     dkContentFm.ConnectionModel = conModel;
     dkContentFm.Show(dpleft);
 }
예제 #4
0
파일: LeftPanel.cs 프로젝트: lzmj/Sharp
        /// <summary>
        ///
        /// </summary>
        private void getDatabaseinfo(TreeNode currNode)
        {
            TreeNode node = currNode;

            Entity.Connection conModel = list.Find(t => t.ID.ToString().Equals(node.Tag.ToString(), StringComparison.OrdinalIgnoreCase));

            DB     db     = null;
            DBInfo dbInfo = null;

            db     = new DB(conModel.DbType, conModel.ConnectionString);
            dbInfo = db.Info;

            if (!conModel.Database.Equals("all"))
            {
                TreeNode tnode = new TreeNode(conModel.Database, 1, 1);
                tnode.Tag = conModel.ConnectionString;
                tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                node.Nodes.Add(tnode);

                gettables(tnode, dbInfo.TableNames, dbInfo.GetAllViews());
            }
            else
            {
                DataTable dt = new DataTable();
                if (conModel.DbType == DataBaseType.MsSql)
                {
                    dt = db.QueryTable("Select name from master..sysdatabases");
                }
                else if (conModel.DbType == DataBaseType.MySql)
                {
                    dt = db.QueryTable("SHOW DATABASES");
                }


                foreach (DataRow dr in dt.Rows)
                {
                    TreeNode tnode = new TreeNode(dr[0].ToString(), 1, 1);
                    if (conModel.DbType == DataBaseType.MsSql)
                    {
                        tnode.Tag = conModel.ConnectionString.Replace("master", dr[0].ToString());
                    }
                    else if (conModel.DbType == DataBaseType.MySql)
                    {
                        tnode.Tag = conModel.ConnectionString.ToLower().Replace("database=", "database=" + dr[0].ToString());
                    }

                    tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                    node.Nodes.Add(tnode);

                    db     = new DB(conModel.DbType, tnode.Tag.ToString());
                    dbInfo = db.Info;

                    gettables(tnode, dbInfo.TableNames, dbInfo.GetAllViews());
                }
            }
        }
예제 #5
0
파일: LeftPanel.cs 프로젝트: lzmj/Sharp
 private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (null != newcontentForm)
     {
         Entity.Connection conModel = list.Find(delegate(Entity.Connection con) { return(con.ID.ToString().Equals(tview.SelectedNode.Parent.Parent.Parent.Tag.ToString())); });
         conModel.ConnectionString  = tview.SelectedNode.Parent.Parent.Tag.ToString();
         ContentForm contentFm = new ContentForm();
         newcontentForm(contentFm, conModel, tview.SelectedNode.Text, tview.SelectedNode.Tag.ToString().Equals("V"));
     }
 }
예제 #6
0
파일: LeftPanel.cs 프로젝트: lzmj/Sharp
        private void 表别名设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = tview.SelectedNode;

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

            form.ConnectionModel = conModel;
            form.ShowDialog();
        }
예제 #7
0
파일: LeftPanel.cs 프로젝트: lzmj/Sharp
        private void 导入PDM文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = tview.SelectedNode;

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

            cmf.DatabaseName    = node.Text;
            cmf.ConnectionModel = conModel;
            cmf.ShowDialog();
        }
예제 #8
0
파일: LeftPanel.cs 프로젝트: lzmj/Sharp
        private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string stringid = tview.SelectedNode.Tag.ToString();

            Utils.DeleteConnection(stringid);
            Entity.Connection tempconn = list.Find(delegate(Entity.Connection conn) { return(conn.ID.ToString().Equals(stringid)); });
            if (null != tempconn)
            {
                list.Remove(tempconn);
            }
            tview.Nodes.Remove(tview.SelectedNode);
        }
예제 #9
0
파일: LeftPanel.cs 프로젝트: lzmj/Sharp
        /// <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();

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

            DB db = null;

            db = new DB(conModel.DbType, conModel.ConnectionString);
            DBInfo dbInfo = db.Info;

            gettables(node, dbInfo.TableNames, dbInfo.GetAllViews());
        }
예제 #10
0
파일: LeftPanel.cs 프로젝트: lzmj/Sharp
        /// <summary>
        /// 刷新服务器
        /// </summary>
        private void refreshConnectionList()
        {
            List <Entity.Connection> connList = Utils.GetConnectionList();

            foreach (Entity.Connection conn in connList)
            {
                Entity.Connection tempconn = list.Find(delegate(Entity.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;
        }
예제 #11
0
파일: LeftPanel.cs 프로젝트: lzmj/Sharp
        private void 插入测试数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //TreeNode node = tview.SelectedNode;
            //Entity.Connection conModel = list.Find(delegate (Entity.Connection con) { return con.ID.ToString().Equals(node.Parent.Tag.ToString()); });

            //InsertForm insertForm = new InsertForm();
            //insertForm.DatabaseName = node.Text;
            //insertForm.ConnectionModel = conModel;
            //insertForm.ShowDialog();


            if (null != newcontentForm)
            {
                Entity.Connection conModel = list.Find(delegate(Entity.Connection con) { return(con.ID.ToString().Equals(tview.SelectedNode.Parent.Parent.Parent.Tag.ToString())); });
                conModel.ConnectionString  = tview.SelectedNode.Parent.Parent.Tag.ToString();
                InsertForm contentFm = new InsertForm();
                newcontentForm(contentFm, conModel, tview.SelectedNode.Text, tview.SelectedNode.Tag.ToString().Equals("V"));
            }
        }