/*-------------------------------------------------------------+
|   HelloWorld.cpp                                                |
+-------------------------------------------------------------*/

#include "TieYiYuan_ProjectCalculation.h"
#include "ado.cpp"
#include "StationDataBase.cpp"
#include "CalJXAndGD.cpp"
#include "BaseLine.cpp"
#include "DrawRoad.cpp"
#include "DES_MODULE.cpp"
#include "CalGCSLTool.cpp"
#include "GTZX.cpp"
#include "ZCOutTabDlg.cpp"

USING_NAMESPACE_BENTLEY_DGNPLATFORM
USING_NAMESPACE_BENTLEY_MSTNPLATFORM
USING_NAMESPACE_BENTLEY_MSTNPLATFORM_ELEMENT

double g_1mu;
StationDataBase DBSForFA;//导入方案	

//数据库数据
CString DefaultFileName;
CString FilePathName;
CString m_ProNo;
vector<CBaseLine*> pJXGTZXArray;//全局变量

void INPUTPMDL(CString m_MdbName)  //导入道路
{
	int res = 0;
	int num = 0;
	DBSForFA.pRoadManage.clear();
	res = DBSForFA.Read_StationDbsDL(m_MdbName, ENC("道路汇总表"));
	//vector<Road>RD;
	CDrawRoad RDObject;
	if (res)//读道路
	{
		num = (int)DBSForFA.pRoadManage.size();
		CString bh;
		if (num > 0)
		{
			vector<vector<Road>>RD;
			RD.clear();
			for (int i = 0; i < num; i++)
			{
				if (DBSForFA.pRoadManage[i].JDARRAY.size() > 1)
					RDObject.CheckRD(DBSForFA.pRoadManage[i], RD);
			}
			for (int i = 0; i < (int)RD.size(); i++)
			{
				CString BIANHAO, InquireString;
				DBSForFA.pConRDManage.clear();
				BIANHAO.Format(_T("%s"), RD[i][0].BianHaoIn);
				InquireString = L"[" + ENC("路网编号") + L"]=\"" + BIANHAO + L"\"";
				DBSForFA.Read_StationDbs(m_MdbName, ENC("路网半径表"), InquireString);

				CDrawRoad* ppRoad;
				ppRoad = new CDrawRoad(RD[i]);
				ppRoad->ConRDArray.clear();
				for (int j = 0; j < (int)DBSForFA.pConRDManage.size(); j++)
					ppRoad->ConRDArray.push_back(DBSForFA.pConRDManage[j].ConRD);
				if (DBSForFA.pConRDManage.size() >= 1)
				{
					ppRoad->isDrawPDB = DBSForFA.pConRDManage[0].isDrawPDB;
				}
				ppRoad->CalAndDrawRoad();
			}
		}
	}
}

extern "C" DLLEXPORT void GetRoadDataFromMDB()
{
	CString MDB = L".mdb";
	CString Text = L"mdb文件(*.mdb)|*.mdb|所有文件 (*.*)|*.*||";
	CFileDialog dlg(TRUE,//TRUE是创建打开文件对话框，FALSE则创建的是保存文件对话框 
		MDB,//默认的打开文件的类型 
		DefaultFileName,//默认打开的文件名 
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,//打开只读文件 
		Text);//所有可以打开的文件类型 
	if (dlg.DoModal() == IDOK)
	{
		FilePathName = dlg.GetPathName(); //文件名保存在了FilePathName里
		m_ProNo = dlg.GetFileName();
		FilePathName.MakeUpper();
		m_ProNo.MakeUpper();
		//FilePathName.Replace((L"\\DATA\\" + m_ProNo), NULL);
	}
	StationDataBase DBS;
	INPUTPMDL(FilePathName);
}



extern "C" DLLEXPORT void MdlMain(int argc, WCharCP argv[])
{
	GetRoadDataFromMDB();
	CZCOutTabDlg dlg1;
	dlg1.OnBnClickedOk();
	
	CCalGCSLTool dlg;
	int RowNum;
    dlg.CalGDBData(RowNum);
}