private void CommSubMenuitem_ViewConnsql_Click(object sender, EventArgs e) { var node = tv_DBServers.SelectedNode; if (node == null) { return; } string conndb = string.Empty; if (node.Level < 2) { return; } if (node.Level == 2) { conndb = node.Text; } else { var pnode = node.Parent; while (pnode.Level != 2) { pnode = pnode.Parent; } conndb = pnode.Text; } var connsql = MySQLHelper.GetConnstringFromDBSource(GetDBSource(node), conndb); SubForm.WinWebBroswer web = new WinWebBroswer(); web.SetHtml(string.Format("<html><head><title>连接串_{1}</title></head><body><br/><add name=\"ConndbDB${1}\" connectionString=\"{0}\" providerName=\"MySql.Data.MySqlClient\"/></body></html>", connsql, conndb)); web.Show(); }
private void 生成数据字典ToolStripMenuItem_Click(object sender, EventArgs e) { var selnode = tv_DBServers.SelectedNode; if (selnode != null && selnode.Level == 3) { //库名 string tbname = string.Format("[{0}].[{1}]", selnode.Parent.Text, selnode.Text); var tbclumns = Biz.Common.Data.MySQLHelper.GetColumns(this.GetDBSource(selnode), selnode.Parent.Text, selnode.Text).ToList(); DataTable resulttb = new DataTable(); resulttb.Columns.AddRange(new string[][] { new [] { "line", "行号" }, new [] { "name", "列名" }, new [] { "iskey", "是否主键" }, new [] { "type", "类型" }, new [] { "len", "长度" }, new [] { "desc", "说明" } }.Select(s => new DataColumn { ColumnName = s[0], Caption = s[1], }).ToArray()); var tbDesc = Biz.Common.Data.MySQLHelper.GetTableColsDescription(GetDBSource(tv_DBServers.SelectedNode), tv_DBServers.SelectedNode.Parent.Text, tv_DBServers.SelectedNode.Text); Regex rg = new Regex(@"(\w+)\s*\((\w+)\)"); TreeNode selNode = tv_DBServers.SelectedNode; int idx = 1; foreach (TreeNode node in selNode.Nodes) { if (node.Text.Equals("索引") && node == selnode.LastNode) { continue; } var newrow = resulttb.NewRow(); newrow["line"] = idx++; Match m = rg.Match(node.Text); if (m.Success) { var y = (from x in tbDesc.AsEnumerable() where string.Equals((string)x["ColumnName"], m.Groups[1].Value, StringComparison.OrdinalIgnoreCase) select x["Description"]).FirstOrDefault(); //字段描述 string desc = y == DBNull.Value ? " " : (string)y; newrow["desc"] = string.IsNullOrEmpty(desc) ? " " : desc; newrow["name"] = m.Groups[1].Value; newrow["type"] = m.Groups[2].Value; bool iskey = false; if (node.Tag != null && node.Tag is TBColumn) { iskey = (node.Tag as TBColumn).IsKey; } newrow["iskey"] = iskey ? "是" : "否"; var col = tbclumns.Find(p => p.Name.Equals(m.Groups[1].Value, StringComparison.OrdinalIgnoreCase)); if (col != null) { newrow["len"] = col.prec != 0 ? col.prec.ToString() : (col.Length > 0?col.Length.ToString():" "); } resulttb.Rows.Add(newrow); } else { MessageBox.Show("生成数据字典错误:" + node.Text); break; } } //生成HTML StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"<html><head><title>数据字典-{0}</title></head><body><table cellpadding='1' cellspacing='0' border='1'>", tbname); sb.Append("<tr>"); foreach (DataColumn col in resulttb.Columns) { sb.AppendFormat("<th>{0}</th>", col.Caption); } sb.Append("</tr>"); foreach (DataRow row in resulttb.Rows) { sb.Append("<tr>"); foreach (DataColumn col in resulttb.Columns) { sb.AppendFormat("<td>{0}</td>", row[col.ColumnName]); } sb.Append("</tr>"); } sb.Append("</table></body></html>"); SubForm.WinWebBroswer web = new WinWebBroswer(); web.SetHtml(sb.ToString()); web.ShowDialog(); } }