⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbtree.cpp

📁 查看sql数据库 中的表 vc++源码 好麻烦呀 只好多写几个字了
💻 CPP
📖 第 1 页 / 共 2 页
字号:
								0, 
								0, 
								DEFAULT_CHARSET, 
								OUT_DEFAULT_PRECIS,
								CLIP_DEFAULT_PRECIS, 
								DEFAULT_QUALITY,
								DEFAULT_PITCH|FF_DONTCARE, 
								"黑体");
			pDC->SelectObject(&hNewFont);
			pDC->SetTextAlign(TA_LEFT);
			strPrint = strTableName;
			pDC->TextOut(x + lCellSpace, y, strPrint);
			hNewFont.DeleteObject();

			/* 左侧竖线 */
			pDC->MoveTo(x, y + 10);
			pDC->LineTo(x, y - line + 10);
			/* 右侧竖线 */
			pDC->MoveTo(Width - right, y + 10);
			pDC->LineTo(Width - right, y - line + 10);
			/* 上面横线 */
			pDC->MoveTo(left, y + 10);
			pDC->LineTo(Width - right, y + 10);
			/* 下面横线 */
			pDC->MoveTo(left, y -line + 10);
			pDC->LineTo(Width - right, y - line + 10);
			y -= line;

			pRS_Column = pDoc->m_pConnection->Execute(_bstr_t("Select a.status as Status, a.cdefault as cdefault, a.id as id, a.colorder as colorder, c.name as TableName, a.name as ColumnName, b.name as TypeName, a.length as Length, a.scale as Scale, a.isnullable as IsNullAble from syscolumns a, systypes b, sysObjects c where a.xtype = b.xtype and a.id = c.id and c.xtype='U' and c.name = '" + strTableName + "' order by a.colorder"), NULL, adCmdText);
			if (aryPrintInfo[pInfo->m_nCurPage - 1].nTableIndex == nStep)
			{
				pRS_Column->Move(aryPrintInfo[pInfo->m_nCurPage - 1].nIndex);
			}
			/* 打印表头 */
			hNewFont.CreateFont(-34,
								0, 
								0, 
								0, 
								FW_BOLD, 
								0, 
								0, 
								0, 
								DEFAULT_CHARSET, 
								OUT_DEFAULT_PRECIS,
								CLIP_DEFAULT_PRECIS, 
								DEFAULT_QUALITY,
								DEFAULT_PITCH|FF_DONTCARE, 
								"宋体");
			pDC->SelectObject(&hNewFont);
			pDC->SetTextAlign(TA_LEFT);

			pDC->MoveTo(x, y + 10);
			pDC->LineTo(x, y - line + 10);
			x += lColumn0;

			strPrint = "列名";
			pDC->TextOut(x + lCellSpace, y, strPrint);
			pDC->MoveTo(x, y + 10);
			pDC->LineTo(x, y - line + 10);
			x += lColumn1;
			strPrint = "类型";
			pDC->TextOut(x + lCellSpace, y, strPrint);
			pDC->MoveTo(x, y + 10);
			pDC->LineTo(x, y - line + 10);
			x += lColumn2;
			strPrint = "长度";
			pDC->TextOut(x + lCellSpace, y, strPrint);
			pDC->MoveTo(x, y + 10);
			pDC->LineTo(x, y - line + 10);
			x += lColumn3;
			strPrint = "空";
			pDC->TextOut(x + lCellSpace, y, strPrint);
			pDC->MoveTo(x, y + 10);
			pDC->LineTo(x, y - line + 10);
			x += lColumn4;
			strPrint = "默认值";
			pDC->TextOut(x + lCellSpace, y, strPrint);
			pDC->MoveTo(x, y + 10);
			pDC->LineTo(x, y - line + 10);
			x += lColumn5;
			strPrint = "自增";
			pDC->TextOut(x + lCellSpace, y, strPrint);
			pDC->MoveTo(x, y + 10);
			pDC->LineTo(x, y - line + 10);
			x += lColumn6;
			strPrint = "说明";
			pDC->TextOut(x + lCellSpace, y, strPrint);
			pDC->MoveTo(x, y + 10);
			pDC->LineTo(x, y - line + 10);
			pDC->MoveTo(Width - right, y + 10);
			pDC->LineTo(Width - right, y - line + 10);
			pDC->MoveTo(left, y - line + 10);
			pDC->LineTo(Width - right, y - line + 10);
			hNewFont.DeleteObject();

			/* 打印表内容 */
			hNewFont.CreateFont(-34,
								0, 
								0, 
								0, 
								FW_NORMAL, 
								0, 
								0, 
								0, 
								DEFAULT_CHARSET, 
								OUT_DEFAULT_PRECIS,
								CLIP_DEFAULT_PRECIS, 
								DEFAULT_QUALITY,
								DEFAULT_PITCH|FF_DONTCARE, 
								"宋体");
			pDC->SelectObject(&hNewFont);
			pDC->SetTextAlign(TA_LEFT);
			
			while (!pRS_Column->adoEOF)
			{
				x = left;
				y -= line;
				if (y < bottom - Height)
					return;

				pRS_Column_Detail = pDoc->m_pConnection->Execute(_bstr_t("sp_pkeys '") + _bstr_t(strTableName) + _bstr_t("'"), NULL, adCmdText);
				bKeys = false;
				while (!pRS_Column_Detail->adoEOF)
				{
					bKeys = (bKeys || (_bstr_t(pRS_Column_Detail->GetCollect("COLUMN_NAME")) == _bstr_t(pRS_Column->GetCollect("ColumnName"))));
					pRS_Column_Detail->MoveNext();
				}
				if (bKeys)
					strPrint = "K";
				else
					strPrint = "";
				pDC->TextOut(x + 7, y, strPrint);
				pDC->MoveTo(x, y + 10);
				pDC->LineTo(x, y - line + 10);
				x += lColumn0;

				/* 第一列 */
				varValue = pRS_Column->GetCollect("ColumnName");
				strPrint = "";
				strPrint += _bstr_t(varValue);

				pDC->TextOut(x + lCellSpace, y, strPrint);
				pDC->MoveTo(x, y + 10);
				pDC->LineTo(x, y - line + 10);
				x += lColumn1;

				/* 第二列 */
				varValue = pRS_Column->GetCollect("TypeName");
				strPrint = "";
				strPrint += _bstr_t(varValue);
				pDC->TextOut(x + lCellSpace, y, strPrint);
				pDC->MoveTo(x, y + 10);
				pDC->LineTo(x, y - line + 10);
				x += lColumn2;

				/* 第三列 */
				varValue = pRS_Column->GetCollect("Length");
				strPrint = "";
				strPrint += _bstr_t(varValue);
				pDC->TextOut(x + lCellSpace, y, strPrint);
				pDC->MoveTo(x, y + 10);
				pDC->LineTo(x, y - line + 10);
				x += lColumn3;

				/* 第四列 */
				varValue = pRS_Column->GetCollect("IsNullAble");
				strPrint = "";
				strPrint += _bstr_t(varValue);
				if (strPrint == "0")
				{
					pDC->TextOut(x + lCellSpace, y, "否");
				}
				pDC->MoveTo(x, y + 10);
				pDC->LineTo(x, y - line + 10);
				x += lColumn4;

				/* 第五列 */
				pRS_Column_Detail = pDoc->m_pConnection->Execute(_bstr_t("select text from syscomments where id = " + _bstr_t(pRS_Column->GetCollect("cdefault"))), NULL, adCmdText);
				if (!pRS_Column_Detail->adoEOF)
				{
					varValue = pRS_Column_Detail->GetCollect("text");
					strPrint = "";
					strPrint += _bstr_t(varValue);
					pDC->TextOut(x + lCellSpace, y, strPrint);
				}
				pDC->MoveTo(x, y + 10);
				pDC->LineTo(x, y - line + 10);
				x += lColumn5;

				/* 第六列 */
				if (_bstr_t(pRS_Column->GetCollect("Status")) == _bstr_t("128"))
				{
					pDC->TextOut(x + lCellSpace, y, "是");
				}
				pDC->MoveTo(x, y + 10);
				pDC->LineTo(x, y - line + 10);
				x += lColumn6;


				/* 第七列 */
				pRS_Column_Detail = pDoc->m_pConnection->Execute(_bstr_t("select c.name as tablename, a.name as columnname from syscolumns a, (select rkeyid, rkey from sysforeignkeys where fkeyid = " + _bstr_t(pRS_Column->GetCollect("id")) + " and fkey = " + _bstr_t(pRS_Column->GetCollect("colorder")) + ") b, sysobjects c where a.id = b.rkeyid and a.colorder = b.rkey and a.id = c.id"), NULL, adCmdText);
				if (!pRS_Column_Detail->adoEOF)
				{
					strPrint = "外码: ";
					strPrint += _bstr_t(pRS_Column_Detail->GetCollect("tablename")) + " - " + _bstr_t(pRS_Column_Detail->GetCollect("columnname"));
					pDC->TextOut(x + lCellSpace, y, strPrint);
				}
				pDC->MoveTo(x, y + 10);
				pDC->LineTo(x, y - line + 10);
				pDC->MoveTo(Width - right, y + 10);
				pDC->LineTo(Width - right, y - line + 10);

				/* 底线 */
				pDC->MoveTo(left, y - line + 10);
				pDC->LineTo(Width - right, y - line + 10);

				pRS_Column->MoveNext();
			}
			hNewFont.DeleteObject();
			y -= line;
		}

		CSize sizeTotal1(344, 291);
		CSize sizePage1(sizeTotal.cx, sizeTotal.cy);
		CSize sizeLine1(sizeTotal.cx, sizeTotal.cy);
	}

	SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
	CTreeView::OnPrint(pDC, pInfo);
}

void CDBTree::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
	CVDBDoc* pDoc = (CVDBDoc *)GetDocument();
	CTreeCtrl& TreeCtrl = GetTreeCtrl();
	CString str;
	HTREEITEM hItem;
	int iLevel = 0;					// 选中的结点的级别
	hItem = TreeCtrl.GetSelectedItem();

	while (TreeCtrl.GetParentItem(hItem) != NULL)
	{
		hItem = TreeCtrl.GetParentItem(hItem);
		iLevel ++;
	}

	hItem = TreeCtrl.GetSelectedItem();
	str = TreeCtrl.GetItemText(hItem);

	if (iLevel == 0)
		return;

	if (iLevel == 2)
	{
		CSize sizeTotal(2100, 2970);
		CSize sizePage(sizeTotal.cx, sizeTotal.cy);
		CSize sizeLine(sizeTotal.cx, sizeTotal.cy);
		pDC->SetMapMode(MM_LOMETRIC);

		bool bPrintEnd = false;

		aryPrintInfo.RemoveAll();

		const Height = 2970;	// 纸高度
		const Width = 2100;		// 纸宽度
		long y,				// 纵坐标
			top = 150,	// 上边距
			bottom = 250,	// 下边距
			left = 100,		// 左边距
			right = 200,	// 右边距
			line = 54;		// 行间距

		long lColumn1 = 400,
			lColumn2 = 300,
			lColumn3 = 250,
			lColumn4 = 850,
			lCellSpace = 10;

		CString strTableName = str;
		structPrintInfo myPrintInfo;

		int nSelCount = 1;
		int nStep;

		/* 获取选择信息 */

		myPrintInfo.nTableIndex = 0;
		myPrintInfo.nIndex = 0;
		aryPrintInfo.Add(myPrintInfo);
		y = -top;
		y -= line;		// 打印标题

		_RecordsetPtr pRS_Column;
		pRS_Column.CreateInstance("ADODB.Recordset");
		for (nStep = 0; nStep < nSelCount; nStep ++)
		{
			y -= line;		// 隔行

			myPrintInfo.nIndex = 0;

			/* 当不够打三行的时候新建一页 */
			if (y < bottom - Height + line + line + line)
			{
				myPrintInfo.nTableIndex = nStep;
				aryPrintInfo.Add(myPrintInfo);
				y = -top;
				y -= line;
			}

			y -= line;		// 打印表名

			pRS_Column = pDoc->m_pConnection->Execute("Select c.name as TableName, a.name as ColumnName, b.name as TypeName, a.length as Length, a.scale as Scale, a.isnullable as IsNullAble from syscolumns a, systypes b, sysObjects c where a.xtype = b.xtype and a.id = c.id and c.xtype='U' and c.name = '" + _bstr_t(strTableName) + "'", NULL, adCmdText);
			/* 打印表头 */
				
			while (!pRS_Column->adoEOF)
			{
				y -= line;		// 打印内容

				/* 如果到最底,新建一页 */
				if (y < bottom - Height)
				{
					myPrintInfo.nTableIndex = nStep;
					aryPrintInfo.Add(myPrintInfo);
					y = -top;
					y -= line;	// 页码
					y -= line;	// 表名
					y -= line;
				}
				myPrintInfo.nIndex ++;

				pRS_Column->MoveNext();
			}
			y -= line;
		}

		pInfo->SetMaxPage(aryPrintInfo.GetSize());
	}
	CTreeView::OnBeginPrinting(pDC, pInfo);
}

void CDBTree::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CTreeView::OnEndPrinting(pDC, pInfo);
}

BOOL CDBTree::OnPreparePrinting(CPrintInfo* pInfo) 
{
	// TODO: call DoPreparePrinting to invoke the Print dialog box
	
	return DoPreparePrinting(pInfo);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -