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

📄 table.cpp

📁 比较简陋的数据库应用,唯一能看的就是对ODBC的封装...
💻 CPP
字号:
#include <iostream>
#include "Table.h"

#define ROWTITLEWIDTH 3
#define COLTITLEHEIGHT 1

static String prerow[] ={
	"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
	"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"
};

Table::Table(int nrow, int ncol)
{
	rowNum = nrow;
	colNum = ncol;
	colTitle = NULL;
	rowTitle = NULL;
	gr = NULL;
	colWidth = new int[colNum];
	rowHeight = new int[rowNum];
	curRow = 0;
}

Table::~Table()
{
	int i;
	delete [] colWidth;
	delete [] rowHeight;
	for (i = 0; i < rowNum; i++)
	{
		delete [] gr[i];
	}
	delete [] gr;

}

void Table::SetColTitle(const String *str)
{
	colTitle = str;
	for (int i = 0; i < colNum; i++)
		colWidth[i] = colTitle[i].getlenth();
}

void Table::SetRowTitle(const String *str)
{
	rowTitle = str;
	if (rowTitle == NULL)
		rowTitle = prerow;
	for (int i = 0; i < rowNum; i++)
		rowHeight[i] = 2;
}

void Table::SetTable(Grid** aGr)
{
	int i, j;
	gr = aGr;
	for (i = 0; i < rowNum; i++)
	{
		for (j = 0; j < colNum; j++)
		{
			if (colWidth[j] < gr[i][j].GetWidth())
				colWidth[j] = gr[i][j].GetWidth();
			if (rowHeight[i] < gr[i][j].GetHeight())
				rowHeight[i] = gr[i][j].GetHeight();
		}
	}
	for (i = 0; i < rowNum; i++)
	{
		for (j = 0; j < colNum; j++)
		{
			gr[i][j].SetHeight(rowHeight[i]);
			gr[i][j].SetWidth(colWidth[j]);
		}
	}
}

void Table::ShowTable(int page)
{
	int i, j, k;
	DrawBottom();
	std::cout << '|' << String(' ', ROWTITLEWIDTH) << '|';
	for (i = 0; i < colNum; i++)
		std::cout << colTitle[i] << String(' ', colWidth[i] - colTitle[i].getlenth()) << '|';
	std::cout << std::endl;
	DrawBottom();
	for (i = 0; i < rowNum; i++)
	{
		k = 0;
		std::cout << '|' << rowTitle[i] << String(' ', ROWTITLEWIDTH - rowTitle[i].getlenth());
		while (k < rowHeight[i])
		{
			if (k != 0)
				std::cout << '|' << String(' ', ROWTITLEWIDTH);
			std::cout << '|';
			for (j = 0; j < colNum; j++)
				std::cout << gr[i][j].GetInfo()->m_Info[k] << '|';
			std::cout << std::endl;
			k++;
		}
		DrawBottom();
	}
}

void Table::DrawBottom()
{
	std::cout << '+' << String('-', ROWTITLEWIDTH) << '+';
	for (int i = 0; i < colNum; i++)
	{
		std::cout << String('-', colWidth[i]) << '+';
	}
	std::cout << std::endl;
}

⌨️ 快捷键说明

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