JXStringTable::JXStringTable
	(
	JStringTableData*	data,
	JXScrollbarSet*		scrollbarSet,
	JXContainer*		enclosure,
	const HSizingOption	hSizing,
	const VSizingOption	vSizing,
	const JCoordinate	x,
	const JCoordinate	y,
	const JCoordinate	w,
	const JCoordinate	h
	)
	:
	JXStyleTable(scrollbarSet, enclosure, hSizing,vSizing, x,y, w,h)
{
	assert( data != NULL );

	itsStringData = data;
	SetTableData(data);

	itsStringInputField = NULL;
}
Ejemplo n.º 2
0
bool TextTable::InitializeFromXmlDoc(XMLDoc* pXmlDoc, WCHAR* pwszFileName, bool bReload)
{
	if (NULL == pXmlDoc)
	{
		return false;
	}

	BSTR rowXPathFormat;
	rowXPathFormat = ::SysAllocString(L"/dataroot/%s/F%d");
	WCHAR wszXPath[MAX_UNICODE_XPATH_LENGTH + 1];

	DWORD dwSheetIndex = 0;
	WCHAR** ppwszSheetList = GetSheetListInWChar();

	BSTR bstr = NULL;

	while (ppwszSheetList[dwSheetIndex])
	{
		swprintf_s<_countof(wszXPath)>(wszXPath, rowXPathFormat, ppwszSheetList[dwSheetIndex], m_nField);

		IXMLDOMNodeList* pIndexNodeList = NULL;
		pIndexNodeList = pXmlDoc->SelectNodeList(wszXPath);
		if (!pIndexNodeList)
		{
			::SysFreeString(rowXPathFormat);

			return false;
		}

		LONG nIndexLength = 0;
		if (FAILED(pIndexNodeList->get_length(&nIndexLength)))
		{
			pIndexNodeList->Release();
			::SysFreeString(rowXPathFormat);

			return false;
		}

		swprintf_s<_countof(wszXPath)>(wszXPath, rowXPathFormat, ppwszSheetList[dwSheetIndex], m_nField + 1);

		IXMLDOMNodeList* pTextNodeList = NULL;
		pTextNodeList = pXmlDoc->SelectNodeList(wszXPath);
		if (!pTextNodeList)
		{
			pIndexNodeList->Release();
			::SysFreeString(rowXPathFormat);

			return false;
		}

		LONG nTextLength = 0;
		if (FAILED(pTextNodeList->get_length(&nTextLength)))
		{
			pIndexNodeList->Release();
			pTextNodeList->Release();
			::SysFreeString(rowXPathFormat);

			return false;
		}

		if (nTextLength != nIndexLength)
		{
			pIndexNodeList->Release();
			pTextNodeList->Release();
			::SysFreeString(rowXPathFormat);

			return false;
		}

		// 제목은 버린다.
		for (INT j = 1; j < nIndexLength; ++j)
		{
			VOID* pvTable = AllocNewTable(ppwszSheetList[dwSheetIndex], m_dwCodePage);
			if (!pvTable)
			{
				pIndexNodeList->Release();
				pTextNodeList->Release();
				::SysFreeString(rowXPathFormat);

				return false;
			}

			IXMLDOMNode* pCellNode = NULL;
			IXMLDOMNode* pDataNode = NULL;

			if (FAILED(pIndexNodeList->get_item(j, &pCellNode)))
			{
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			if (!pCellNode)
			{
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				break;
			}

			if (FAILED(pCellNode->get_firstChild(&pDataNode)))
			{
				pCellNode->Release();
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			if (!pDataNode)
			{
				pCellNode->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				break;
			}

			if (FAILED(pDataNode->get_text(&bstr)))
			{
				::SysFreeString(bstr);
				pDataNode->Release();
				pCellNode->Release();
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			SetTableData(pvTable, ppwszSheetList[dwSheetIndex], INDEX, bstr);

			::SysFreeString(bstr);
			pCellNode->Release();
			pDataNode->Release();

			pCellNode = NULL;
			pDataNode = NULL;

			if (FAILED(pTextNodeList->get_item(j, &pCellNode)))
			{
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			if (!pCellNode)
			{
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				break;
			}

			if (FAILED(pCellNode->get_firstChild(&pDataNode)))
			{
				//- yoshiki : TODO!(Get the field name)
				Table::CallErrorCallbackFunction("[File] : %S\n[Error] : Table data is null.(Row Index : %d, Field Name = %S)", pwszFileName, j - 1, L"FIELD_NAME!");

				pCellNode->Release();
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			if (!pDataNode)
			{
				//- yoshiki : TODO!(Get the field name)
				Table::CallErrorCallbackFunction("[File] : %S\n[Error] : Table data is null.(Row Index : %d, Field Name = %S)", pwszFileName, j - 1, L"FIELD_NAME!");

				pCellNode->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				_ASSERT(0);		// Index는 있고 Data는 공란인경우.
				break;
			}

			if (FAILED(pDataNode->get_text(&bstr)))
			{
				::SysFreeString(bstr);
				pDataNode->Release();
				pCellNode->Release();
				pIndexNodeList->Release();
				pTextNodeList->Release();
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
				::SysFreeString(rowXPathFormat);

				return false;
			}

			SetTableData(pvTable, ppwszSheetList[dwSheetIndex], TEXT, bstr);

			::SysFreeString(bstr);
			pCellNode->Release();
			pDataNode->Release();

			if (!AddTable(pvTable, bReload))
			{
				DeallocNewTable(pvTable, ppwszSheetList[dwSheetIndex]);
			}
		}

		pIndexNodeList->Release();
		pTextNodeList->Release();
		++dwSheetIndex;
	}

	::SysFreeString(rowXPathFormat);

	return true;
}