#include "stdafx.h"
#include "CalGCSLTool.h"
#include "DrawRoad.h"
#include "ZCOutTabDlg.h"
#include "BAS_DRAW_FUN1.h"
#include "BAS_DRAW_FUN.h"
#include "BAS_DRAW_FUN.cpp"
#include "BAS_DRAW_FUN1.cpp"

extern int incZX;
extern int G_ISSX;
extern vector<CBaseLine*> pJXGTZXArray;
extern CString ZHGXSyspath;//zhgx.arx路径
extern CString StationPath;//站场数据库路径  xxx//xx.mdb
extern CString GXpath;//综合管线数据库路径   xxx//xx.mdb
extern CString MYGXYZpath;//当前方案管线设计原则路径
extern CString GXName;//管线项目名
extern CString GlobalZhuanYeType;//全局专业类型
extern CString BZtmp;//各专业管线标准
CString SNZC_mdbname;
extern  YXCTAB YXCB;
extern int issetpos;
//extern CProgressCtrl m_SingleTable;
int isSNZC = 0;
//CZCOutTabDlg pcuuwindow = new CZCOutTabDlg;
int IsDCJDZB = 0;

void CCalGCSLTool::FORM_SNSL(CString mdbname)
{
	m_MdbName = mdbname;
	isneedarea = 0;
	//强制从数据库读取基线
	pJXGTZXArray.clear();
	CalJXAndGD::GetBaseLineArrayFromMdb(pJXGTZXArray);

	//形成股道数组
	CalJXAndGD::GetGTZXArrayFromMdb(pGTZXArray);
	(pGTZXArray);
	pGTZXArray_SEL.clear();
	//判断股道是否在面域范围内
	for (int i = 0; i < (int)pGTZXArray.size(); i++)
	{
		/*CString sjst = pGTZXArray[i]->SJST;
		if (sjst.Find(L"预留") >= 0)
		continue;*/
		if (BAS_DRAW_FUN::JudgeAcharIsHaveCstring(pGTZXArray[i]->SJST, L"预留") == 1)
		{
			continue;
		}
		/*if (_tcscmp(pGTZXArray[i]->SJST, L"预留") == 0)
			continue;*/
			//if(JudgeIsInShuLiangArea_GD(pGTZXArray[i],ChooseArea)==1)
		pGTZXArray_SEL.push_back(pGTZXArray[i]);
	}
	DBS.InitDataBase();
	DBS.isNeedDisConnect = 0;
	DBS.isNeedConnect = 1;
	DBS.Read_StationDbs(m_MdbName, L"");
	DBS.isNeedConnect = 0;


	pLMDArray_SEL.clear();
	//形成道岔
	pSwitchArray_SEL.clear();
	DBS.Read_StationDbs(m_MdbName, ENC("道岔表"));
	//判断道岔是否在面域范围内
	for (int i = 0; i < (int)DBS.pSwitch.size(); i++)
	{
		if (BAS_DRAW_FUN::JudgeAcharIsHaveCstring(DBS.pSwitch[i].SJST, L"预留") == 1)
			continue;
		//if(JudgeIsInShuLiangArea_DC(DBS.pSwitch[i],ChooseArea)==1)
		pSwitchArray_SEL.push_back(DBS.pSwitch[i]);
	}
	DBS.Disconnect_StationDbs();
}

void CCalGCSLTool::CalGDBData(int& RowNum)
{
	//读取道岔表
	DBS.isNeedDisConnect = 0;
	DBS.isNeedConnect = 1;
	DBS.Read_StationDbs(m_MdbName, L"");
	DBS.isNeedConnect = 0;

	CString Condition = L"[" + ENC("设计时态") + "]<>'预留'";
	DBS.Read_StationDbs(m_MdbName, ENC("道岔表"), Condition);
	Condition = L"[" + ENC("时态") + "]<>'预留' AND [" + ENC("标注编号") + "]<>-99999";
	DBS.Read_StationDbs(m_MdbName, ENC("车挡汇总表"), Condition);
	Condition = L"[" + ENC("设计时态") + "]<>'预留' AND [" + ENC("股道编号") + "]<>''";
	DBS.Read_StationDbs(m_MdbName, ENC("股道汇总表"), Condition);
	CString BIANHAO, InquireString;

	//剔除既有拆除、改移道岔
	for (int i = 0; i < (int)DBS.pSwitch.size(); i++)
	{
		//20200527 puhao 补 删除预留道岔

		if ((_tcscmp(DBS.pSwitch[i].SJST, L"既有") == 0 &&
			(DBS.pSwitch[i].m_IsChaiChu == 1 || DBS.pSwitch[i].m_IsJYGaiYi == 1)) || BAS_DRAW_FUN::JudgeAcharIsHaveCstring(DBS.pSwitch[i].SJST, L"预留") == 1)
		{
		DBS.pSwitch.erase(DBS.pSwitch.begin() + i);
		i--;
		};


	}
	//剔除拆除车挡
	for (int i = 0; i < (int)DBS.pCDManage.size(); i++)
	{
		if (_tcscmp(DBS.pCDManage[i].SheJiShiTai, L"既有") == 0 &&
			DBS.pCDManage[i].m_IsChaiChu == 1)
		{
			DBS.pCDManage.erase(DBS.pCDManage.begin() + i);
			i--;
		}
	}

	//获取所有股道和基线
	CalJXAndGD JXAndGD;
	vector<ZCGTZX*> pGTZXArray1;//股道数组
	vector<CBaseLine*> pBaseLineArray;//基线数组
	JXAndGD.GetBaseLineArrayFromMdb(pBaseLineArray);
	JXAndGD.GetGTZXArrayFromMdb_PM(pBaseLineArray, pGTZXArray1, false);

	// 新建、在建、既有股道没有拆除
	//设计编号为空时也直接删掉 渡线股道直接删掉
	for (int i = 0; i < (int)pGTZXArray1.size(); i++)
	{
		int isdel = 0;
		if (BAS_DRAW_FUN::JudgeAcharIsHaveCstring(pGTZXArray1[i]->SJST, L"预留") == 1 ||
			_tcscmp(pGTZXArray1[i]->DesignBianHao, L"") == 0 ||
			(pGTZXArray1[i]->isDXGD == 1 && pGTZXArray1[i]->NJD == 2))
		{
			isdel = 1;
		}
		else if (_tcscmp(pGTZXArray1[i]->SJST, L"既有") == 0)
		{
			if (pGTZXArray1[i]->m_ChaiChuArray.size() > 0)
				isdel = 1;
		}

		if (isdel == 1)
		{
			pGTZXArray1.erase(pGTZXArray1.begin() + i);
			i--;
		}
	}
	RowNum = (int)pGTZXArray1.size();
	//计算车挡坐标
	CBaseLine* pBaseLine1 = NULL;
	for (int i = 0; i < (int)DBS.pCDManage.size(); i++)
	{
		pBaseLine1 = JXAndGD.GetBaseLineFromBianhao(DBS.pCDManage[i].CZJXStrArray, pBaseLineArray);
		if (pBaseLine1 == NULL)
			pBaseLine1 = JXAndGD.GetBaseLineFromCkml(DBS.pCDManage[i].Ckml, pBaseLineArray);
		if (pBaseLine1 == NULL)
			continue;
		pBaseLine1->TrsCkmlPtToNE(DBS.pCDManage[i].Ckml, DBS.pCDManage[i].DistToJX, DBS.pCDManage[i].N, DBS.pCDManage[i].E);
	}

	DCAndQX OneDCAndQX;//一个道岔曲线
	size_t GDNum = (int)pGTZXArray.size();

	//对所有股道循环
	ZCGTZX* pGTZX = NULL;
	CString XLType;
	BAS_DRAW_FUN BAS;
	//对股道排序
	ZCGTZX::Sort_GDTypeArray(pGTZXArray);

	vector<DCAndQX> DCAndQXArray;//经由道岔曲线
	GDBArray.clear();
	GDBArray.resize(GDNum);
	GDB GDBtmp;
	for (int i = 0; i < GDNum; i++)
	{
		_tcscpy(GDBtmp.BH, L"");//编号
		_tcscpy(GDBtmp.Name, L"");//名称
		_tcscpy(GDBtmp.GX, L"");//轨型
		_tcscpy(GDBtmp.StartDCZT, L"");//起道岔
		_tcscpy(GDBtmp.StartDCBH, L"");
		GDBtmp.DCNoArray.clear(); //经由道岔
		_tcscpy(GDBtmp.EndDCZT, L"");//终道岔
		_tcscpy(GDBtmp.EndDCBH, L"");
		_tcscpy(GDBtmp.QuanChang, L"");//全长
		_tcscpy(GDBtmp.YouXiaoChang, L"");//有效长
		_tcscpy(GDBtmp.PuGuiChang, L"");//铺轨长
		_tcscpy(GDBtmp.Note, L"");

		DCAndQXArray.clear();
		DCAndQX StartDC, EndDC;//起终道岔
		bool HasStartDC = false;
		bool HasEndDC = false;
		pGTZX = pGTZXArray[i];

		//取出所有道岔
		for (int k = 0; k < (int)DBS.pSwitch.size(); k++)
		{
			//先判断道岔直股两侧各延长1m，其方位角与股道两端比较，若相同，且股道端点在直线上作为起始道岔
			double dist1 = 0, dist2 = 0, dist_sum = 0, dist3 = 0, dist4 = 0;
			DPoint3d pt1, pt2, ptgd1, ptgd2;
			DPoint3d StaPt, End1, End2, End3, End4;
			double SingleXY[9];
			for (int i1 = 0; i1 < 7; i1++)
				SingleXY[i1] = DBS.pSwitch[k].XYArray[i1];

			SingleXY[7] = DBS.pSwitch[k].a;
			SingleXY[8] = DBS.pSwitch[k].b;//a ,b
			BAS_DRAW_FUN bas;
			bas.GetSingleSwitchCoordinate1(SingleXY, StaPt, End1, End2, End3, End4);
			DVec3d vec;
			vec = End1 - StaPt;
			vec.Normalize();
			pt1 = StaPt - vec;
			pt2 = End1 + vec;
			ptgd1.Init(pGTZX->JDarray[0][2], pGTZX->JDarray[0][1], 0);
			ptgd2.Init(pGTZX->JDarray[pGTZX->NJD - 1][2], pGTZX->JDarray[pGTZX->NJD - 1][1], 0);
			dist1 = pt1.DistanceXY(ptgd1);
			dist2 = pt2.DistanceXY(ptgd1);
			dist_sum = pt1.DistanceXY(pt2);
			dist3 = pt1.DistanceXY(ptgd2);
			dist4 = pt2.DistanceXY(ptgd2);

			OneDCAndQX.Leibie = L"道岔";
			_tcscpy(OneDCAndQX.ZT, DBS.pSwitch[k].BianHaoZT);

			/*	if(_tcscmp(DBS.pSwitch[k].SJST,L"既有")==0)
					OneDCAndQX.BianHao = DBS.pSwitch[k].JYBZBianHao;
				else*/
			OneDCAndQX.BianHao = DBS.pSwitch[k].BZBianHao;

			OneDCAndQX.PtN = DBS.pSwitch[k].XYArray[5];
			OneDCAndQX.PtE = DBS.pSwitch[k].XYArray[6];
			OneDCAndQX.Projml = pGTZX->PROJ_ML(pGTZX->array, pGTZX->tarray, OneDCAndQX.PtN, OneDCAndQX.PtE, OneDCAndQX.PtN, OneDCAndQX.PtE);
			if (fabs(dist1 + dist2 - dist_sum) < 0.001)
			{
				StartDC = OneDCAndQX;
				HasStartDC = true;
			}
			else if (fabs(dist3 + dist4 - dist_sum) < 0.001)
			{
				EndDC = OneDCAndQX;
				HasEndDC = true;
			}
			else
			{
				if (_tcscmp(DBS.pSwitch[k].InTrackNo, pGTZX->BianHao) == 0)
				{
					//_stprintf(OneDCAndQX.BianHao, L"%s%d", DBS.pSwitch[k].BianHaoZT,DBS.pSwitch[k].BZBianHao);
				/*	if(_tcscmp(DBS.pSwitch[k].SJST,L"既有")==0)
						OneDCAndQX.BianHao = DBS.pSwitch[k].JYBZBianHao;
					else*/
					OneDCAndQX.BianHao = DBS.pSwitch[k].BZBianHao;
					_tcscpy(OneDCAndQX.ZT, DBS.pSwitch[k].BianHaoZT);
					OneDCAndQX.PtN = DBS.pSwitch[k].XYArray[5];
					OneDCAndQX.PtE = DBS.pSwitch[k].XYArray[6];
					OneDCAndQX.Projml = pGTZX->PROJ_ML(pGTZX->array, pGTZX->tarray, OneDCAndQX.PtN, OneDCAndQX.PtE, OneDCAndQX.PtN, OneDCAndQX.PtE);
					DCAndQXArray.push_back(OneDCAndQX);
				}

				if (_tcscmp(DBS.pSwitch[k].OutTrackNo[0], pGTZX->BianHao) == 0 || _tcscmp(DBS.pSwitch[k].OutTrackNo[1], pGTZX->BianHao) == 0
					|| _tcscmp(DBS.pSwitch[k].OutTrackNo[2], pGTZX->BianHao) == 0 || _tcscmp(DBS.pSwitch[k].OutTrackNo[3], pGTZX->BianHao) == 0)
				{
					//_stprintf(OneDCAndQX.BianHao, L"%s%d", DBS.pSwitch[k].BianHaoZT,DBS.pSwitch[k].BZBianHao);
					if (_tcscmp(DBS.pSwitch[k].SJST, L"既有") == 0)
						OneDCAndQX.BianHao = DBS.pSwitch[k].JYBZBianHao;
					else
						OneDCAndQX.BianHao = DBS.pSwitch[k].BZBianHao;

					//	OneDCAndQX.BianHao = DBS.pSwitch[k].BZBianHao;
					_tcscpy(OneDCAndQX.ZT, DBS.pSwitch[k].BianHaoZT);
					OneDCAndQX.PtN = DBS.pSwitch[k].XYArray[5];
					OneDCAndQX.PtE = DBS.pSwitch[k].XYArray[6];
					OneDCAndQX.Projml = pGTZX->PROJ_ML(pGTZX->array, pGTZX->tarray, OneDCAndQX.PtN, OneDCAndQX.PtE, OneDCAndQX.PtN, OneDCAndQX.PtE);
					double dx = OneDCAndQX.PtN - pGTZX->JDarray[0][1];
					double dy = OneDCAndQX.PtE - pGTZX->JDarray[0][2];
					if (fabs(dx) < 0.01 && fabs(dy) < 0.01)
					{
						StartDC = OneDCAndQX;
						HasStartDC = true;
					}
					else
					{
						dx = OneDCAndQX.PtN - pGTZX->JDarray[pGTZX->NJD - 1][1];
						dy = OneDCAndQX.PtE - pGTZX->JDarray[pGTZX->NJD - 1][2];
						if (fabs(dx) < 0.01 && fabs(dy) < 0.01)
						{
							EndDC = OneDCAndQX;
							HasEndDC = true;
						}
					}
				}
			}
		}

		//取出所有车档
		for (int k = 0; k < (int)DBS.pCDManage.size(); k++)
		{
			if (_tcscmp(DBS.pCDManage[k].TrackNo, pGTZX->BianHao) == 0)
			{
				//_stprintf(OneDCAndQX.BianHao, L"%s%d", DBS.pCDManage[k].WBianHaoZiTou, DBS.pCDManage[k].NoteBianhao);
				OneDCAndQX.Leibie = L"车挡";
				_tcscpy(OneDCAndQX.ZT, DBS.pCDManage[k].WBianHaoZiTou);
				OneDCAndQX.BianHao = DBS.pCDManage[k].NoteBianhao;
				OneDCAndQX.PtN = DBS.pCDManage[k].N;
				OneDCAndQX.PtE = DBS.pCDManage[k].E;
				OneDCAndQX.Projml = pGTZX->PROJ_ML(pGTZX->array, pGTZX->tarray, OneDCAndQX.PtN, OneDCAndQX.PtE, OneDCAndQX.PtN, OneDCAndQX.PtE);
				double dx = OneDCAndQX.PtN - pGTZX->JDarray[0][1];
				double dy = OneDCAndQX.PtE - pGTZX->JDarray[0][2];
				if (fabs(dx) < 0.01 && fabs(dy) < 0.01)
				{
					StartDC = OneDCAndQX;
					HasStartDC = true;
				}
				else
				{
					dx = OneDCAndQX.PtN - pGTZX->JDarray[pGTZX->NJD - 1][1];
					dy = OneDCAndQX.PtE - pGTZX->JDarray[pGTZX->NJD - 1][2];
					if (fabs(dx) < 0.01 && fabs(dy) < 0.01)
					{
						EndDC = OneDCAndQX;
						HasEndDC = true;
					}
				}
			}
		}

		//人为设置
		if (pGTZX->isuserQZD)
		{
			if (pGTZX->GTZXQDType == 1)//起始为道岔
			{
				int j = 0;
				for (j = 0; j < (int)DBS.pSwitch.size(); j++)
				{
					if (_tcscmp(DBS.pSwitch[j].BianHao, pGTZX->GTZXQDID) == 0)
						break;
				}
				if (j < DBS.pSwitch.size())
				{
					OneDCAndQX.Leibie = L"道岔";
					_tcscpy(OneDCAndQX.ZT, DBS.pSwitch[j].BianHaoZT);
					/*	if(_tcscmp(DBS.pSwitch[j].SJST,L"既有")==0)
							OneDCAndQX.BianHao = DBS.pSwitch[j].JYBZBianHao;
						else*/
					OneDCAndQX.BianHao = DBS.pSwitch[j].BZBianHao;

					//	OneDCAndQX.BianHao = DBS.pSwitch[j].BZBianHao;
					OneDCAndQX.PtN = DBS.pSwitch[j].XYArray[5];
					OneDCAndQX.PtE = DBS.pSwitch[j].XYArray[6];
					OneDCAndQX.Projml = pGTZX->PROJ_ML(pGTZX->array, pGTZX->tarray, OneDCAndQX.PtN, OneDCAndQX.PtE, OneDCAndQX.PtN, OneDCAndQX.PtE);
					StartDC = OneDCAndQX;
					HasStartDC = true;
				}
			}
			if (pGTZX->GTZXQDType == 2)//起始为车档
			{
				int j = 0;
				for (j = 0; j < (int)DBS.pCDManage.size(); j++)
				{
					if (_tcscmp(DBS.pCDManage[j].BianHao, pGTZX->GTZXQDID) == 0)
						break;
				}
				if (j < DBS.pSwitch.size())
				{
					OneDCAndQX.Leibie = L"车挡";
					_tcscpy(OneDCAndQX.ZT, DBS.pCDManage[j].WBianHaoZiTou);
					OneDCAndQX.BianHao = DBS.pCDManage[j].NoteBianhao;
					OneDCAndQX.PtN = DBS.pCDManage[j].N;
					OneDCAndQX.PtE = DBS.pCDManage[j].E;
					OneDCAndQX.Projml = pGTZX->PROJ_ML(pGTZX->array, pGTZX->tarray, OneDCAndQX.PtN, OneDCAndQX.PtE, OneDCAndQX.PtN, OneDCAndQX.PtE);
					StartDC = OneDCAndQX;
					HasStartDC = true;
				}
			}
		}

		//如果没有找到终点 但是认为设置了终点
		if (pGTZX->isuserQZD)
		{
			if (pGTZX->GTZXZDType == 1 || pGTZX->GTZXZDType == 2)//道岔更改
			{
				if (pGTZX->GTZXZDType == 1)//终点为道岔
				{
					int j = 0;
					for (j = 0; j < (int)DBS.pSwitch.size(); j++)
					{
						if (_tcscmp(DBS.pSwitch[j].BianHao, pGTZX->GTZXZDID) == 0)
							break;
					}
					if (j < DBS.pSwitch.size())
					{
						OneDCAndQX.Leibie = L"道岔";
						_tcscpy(OneDCAndQX.ZT, DBS.pSwitch[j].BianHaoZT);
						/*       if(_tcscmp(DBS.pSwitch[j].SJST,L"既有")==0)
								  OneDCAndQX.BianHao = DBS.pSwitch[j].JYBZBianHao;
							   else*/
						OneDCAndQX.BianHao = DBS.pSwitch[j].BZBianHao;

						//OneDCAndQX.BianHao = DBS.pSwitch[j].BZBianHao;
						OneDCAndQX.PtN = DBS.pSwitch[j].XYArray[5];
						OneDCAndQX.PtE = DBS.pSwitch[j].XYArray[6];
						OneDCAndQX.Projml = pGTZX->PROJ_ML(pGTZX->array, pGTZX->tarray, OneDCAndQX.PtN, OneDCAndQX.PtE, OneDCAndQX.PtN, OneDCAndQX.PtE);
						EndDC = OneDCAndQX;
						HasEndDC = true;
					}
				}
				else if (pGTZX->GTZXZDType == 2)//终为车档
				{
					int j = 0;
					for (j = 0; j < (int)DBS.pCDManage.size(); j++)
					{
						if (_tcscmp(DBS.pCDManage[j].BianHao, pGTZX->GTZXZDID) == 0)
							break;
					}
					if (j < DBS.pCDManage.size())
					{
						OneDCAndQX.Leibie = L"车挡";
						_tcscpy(OneDCAndQX.ZT, DBS.pCDManage[j].WBianHaoZiTou);
						OneDCAndQX.BianHao = DBS.pCDManage[j].NoteBianhao;
						OneDCAndQX.PtN = DBS.pCDManage[j].N;
						OneDCAndQX.PtE = DBS.pCDManage[j].E;
						OneDCAndQX.Projml = pGTZX->PROJ_ML(pGTZX->array, pGTZX->tarray, OneDCAndQX.PtN, OneDCAndQX.PtE, OneDCAndQX.PtN, OneDCAndQX.PtE);
						EndDC = OneDCAndQX;
						HasEndDC = true;
					}
				}
			}
		}

		if (pGTZX->isuserQZD)
		{
			DCAndQXArray.clear();
			for (int i2 = 0; i2 < (int)pGTZX->JYDC.size(); i2++)
			{
				int j = 0;
				ACHAR TMP[STR_SHORT];
				_tcscpy(TMP, pGTZX->JYDC[i2]);
				for (j = 0; j < (int)DBS.pSwitch.size(); j++)
				{
					if (_tcscmp(DBS.pSwitch[j].BianHao, TMP) == 0)
						break;
				}
				if (j < DBS.pSwitch.size())
				{
					_tcscpy(OneDCAndQX.ZT, DBS.pSwitch[j].BianHaoZT);

					//	if(_tcscmp(DBS.pSwitch[j].SJST,L"既有")==0)
					  //      OneDCAndQX.BianHao = DBS.pSwitch[j].JYBZBianHao;
					//	else
					//	    OneDCAndQX.BianHao = DBS.pSwitch[j].BZBianHao;

					OneDCAndQX.BianHao = DBS.pSwitch[j].BZBianHao;
					OneDCAndQX.PtN = DBS.pSwitch[j].XYArray[5];
					OneDCAndQX.PtE = DBS.pSwitch[j].XYArray[6];
					OneDCAndQX.Projml = pGTZX->PROJ_ML(pGTZX->array, pGTZX->tarray, OneDCAndQX.PtN, OneDCAndQX.PtE, OneDCAndQX.PtN, OneDCAndQX.PtE);
					DCAndQXArray.push_back(OneDCAndQX);
				}
			}
		}

		for (int j = 0; j < (int)DCAndQXArray.size(); j++)
		{
			if (DCAndQXArray[j].BianHao <= 0)
			{
				DCAndQXArray.erase(DCAndQXArray.begin() + j);
				j--;
			}
		}
		//排序
		if (DCAndQXArray.size() > 1)
		{
			for (int j = 0; j < (int)DCAndQXArray.size() - 1; j++)
			{
				for (int k = j + 1; k < (int)DCAndQXArray.size(); k++)
				{
					if (DCAndQXArray[j].Projml > DCAndQXArray[k].Projml)
					{
						OneDCAndQX = DCAndQXArray[j];
						DCAndQXArray[j] = DCAndQXArray[k];
						DCAndQXArray[k] = OneDCAndQX;
					}
				}
			}
		}


		//检测起始是否为车档，如为车档将其翻转
		int bhtmp;
		ACHAR zttmp[STR_SHORT];
		if (HasStartDC)
		{
			if (StartDC.Leibie == L"车挡")
			{
				if (HasEndDC)
				{
					if (EndDC.Leibie == L"道岔")
					{
						bhtmp = EndDC.BianHao;
						_tcscpy(zttmp, EndDC.ZT);
						EndDC.Leibie = L"车挡";
						EndDC.BianHao = StartDC.BianHao;
						_tcscpy(EndDC.ZT, StartDC.ZT);
						StartDC.Leibie = L"道岔";
						StartDC.BianHao = bhtmp;
						_tcscpy(StartDC.ZT, zttmp);
					}
				}
				else
				{
					HasEndDC = true;
					EndDC.Leibie = L"车挡";
					EndDC.BianHao = StartDC.BianHao;
					_tcscpy(EndDC.ZT, StartDC.ZT);
					HasStartDC = false;
				}
				//翻转中间道岔
				vector<DCAndQX> DCAndQXArrayTMP;
				DCAndQXArrayTMP = DCAndQXArray;
				for (int i3 = 0; i3 < (int)DCAndQXArray.size(); i3++)
					DCAndQXArray[i3] = DCAndQXArrayTMP[DCAndQXArray.size() - 1 - i];
			}
		}

		//填写数据
		if (HasStartDC)
		{
			if (StartDC.Leibie == L"车挡")
			{
				_tcscpy(GDBtmp.StartDCZT, L"挡");
				_stprintf(GDBtmp.StartDCBH, L"%d", StartDC.BianHao);
			}
			else
			{
				_tcscpy(GDBtmp.StartDCZT, StartDC.ZT);
				_stprintf(GDBtmp.StartDCBH, L"%d", StartDC.BianHao);
			}
		}
		else
		{
			if (DCAndQXArray.size() > 0)
			{
				_tcscpy(GDBtmp.StartDCZT, DCAndQXArray[0].ZT);
				_stprintf(GDBtmp.StartDCBH, L"%d", DCAndQXArray[0].BianHao);
				DCAndQXArray.erase(DCAndQXArray.begin());
			}
			else
			{
				_tcscpy(GDBtmp.StartDCZT, L"");
				_tcscpy(GDBtmp.StartDCBH, L"");
			}
		}

		if (HasEndDC)
		{
			if (EndDC.Leibie == L"车挡")
			{
				_tcscpy(GDBtmp.EndDCZT, L"挡");
				_stprintf(GDBtmp.EndDCBH, L"%d", EndDC.BianHao);
			}
			else
			{
				_tcscpy(GDBtmp.EndDCZT, EndDC.ZT);
				_stprintf(GDBtmp.EndDCBH, L"%d", EndDC.BianHao);
			}
		}
		else
		{
			if (DCAndQXArray.size() > 0)
			{
				_tcscpy(GDBtmp.EndDCZT, DCAndQXArray[(int)DCAndQXArray.size() - 1].ZT);
				_stprintf(GDBtmp.EndDCBH, L"%d", DCAndQXArray[(int)DCAndQXArray.size() - 1].BianHao);
				DCAndQXArray.pop_back();
			}
			else
			{
				_tcscpy(GDBtmp.EndDCZT, L"");
				_tcscpy(GDBtmp.EndDCBH, L"");
			}
		}


		vector<CString> DCNoArray;
		DCNoArray.resize((int)DCAndQXArray.size());
		for (int k = 0; k < (int)DCAndQXArray.size(); k++)
			DCNoArray[k].Format(L"%s%d", DCAndQXArray[k].ZT, DCAndQXArray[k].BianHao);
		GDBtmp.DCNoArray = DCNoArray;

		_tcscpy(GDBtmp.BH, pGTZX->DesignBianHao);

		CString XLType1 = pGTZX->ConvertXLTypeIntToCstring(pGTZX->XLType);
		_tcscpy(GDBtmp.Name, XLType1);

		//找出钢轨类型最长的一段
		double MaxDist = -99999.9;
		double Disttmp = 0.0;
		Disttmp = pGTZX->m_GGLXArray[0].FDCML - pGTZX->StartCml;
		MaxDist = Disttmp;
		int index = 0;
		for (int kk = 1; kk < (int)pGTZX->m_GGLXArray.size(); kk++)
		{
			Disttmp = pGTZX->m_GGLXArray[kk].FDCML - pGTZX->m_GGLXArray[kk - 1].FDCML;
			if (Disttmp > MaxDist)
			{
				index = kk;
				MaxDist = Disttmp;
			}
		}

		if (pGTZX->m_GGLXArray.size() > 0)
			_tcscpy(GDBtmp.GX, pGTZX->m_GGLXArray[index].GGLX);
		else
			_tcscpy(GDBtmp.GX, L"");

		CString BIANHAO1, InquireString1;
		for (int m = 0; m < (int)DBS.pTrackManage.size(); m++)
		{
			if (_tcscmp(DBS.pTrackManage[m].BianHao, pGTZX->BianHao) == 0)
			{
				double d, d1, d2;
				//全长
				_stprintf(GDBtmp.QuanChang, L"%.0lf", DBS.pTrackManage[m].Span);

				BIANHAO1 = DBS.pTrackManage[m].BianHao;
				InquireString1 = L"[" + ENC("对象ID") + L"]=\"" + BIANHAO1 + L"\"";
				if (DBS.Read_StationDbs(m_MdbName, ENC("股道有效长表"), InquireString1))
				{
					if (DBS.YXCB.UpValidL > -0.1)
						d1 = DBS.YXCB.UpValidL;
					else
						d1 = 100000.0;
					if (DBS.YXCB.DownValidL > -0.1)
						d2 = DBS.YXCB.DownValidL;
					else
						d2 = 100000.0;
					d = min(d1, d2);

					//有效长
					if (d > 99999.9 || d < 0.1)
						_tcscpy(GDBtmp.YouXiaoChang, L" ");
					else
						_stprintf(GDBtmp.YouXiaoChang, L"%d", int(d + 0.1));
				}
				else
				{
					_tcscpy(GDBtmp.YouXiaoChang, L" ");
				}

				//铺轨长
				_stprintf(GDBtmp.PuGuiChang, L"%.0lf", DBS.pTrackManage[m].TracklayingL);
			}
		}
		_tcscpy(GDBtmp.Note, L"");//附注
		GDBArray[i] = GDBtmp;
	}
	DBS.Disconnect_StationDbs();
};
