#include "NewReGister.h"
#include "MainCtl.h"

#define nrdNoneColor	clMedGray	


#define TextTopOffSet	6
#define ListLineCnt	10


static const char *StrWaitForReply = "等待接收到新数据";
static const char *StrGotNewReg = "已接收一个注册包";

void TNewRegister::Init(int x1, int y1, int aW, int aH, int OwnerX, int OwnerY, u32 aColor)
{
	#define CH	30	//Caption Height
	unsigned short Left,Right, Top, Bottom, Width, Height, i;
	Bound.SetBySize(OwnerX + x1, OwnerY + y1, aW, aH);
	Left = Bound.Left +3;
	Top = Bound.Top+3;
	Width = aW - 7;
	Height = aH - 7;
	Right = Bound.Right -4;
	Bottom = Bound.Bottom -4;
	Caption.Init(Left,Top,Width, CH, 0, 0, clWhite, clMaroon);
	Content.Set(Left, Top+CH, Right-20, Bottom);
	VScrollBarBox.Set(Right-20 +1, Top+CH, Right, Bottom);
	Color = aColor;
	#undef CH

	ActiveLineNum=0;
	
	ListView.ColHeight = 33;
	ListView.TopIndex=0;
	ListView.RowCount = 9;
	ListView.FixColTop = Content.Top;
	ListView.FixColBottom = ListView.FixColTop + ListView.ColHeight;
	ListView.ColTop[0] = ListView.FixColBottom + 1;
	ListView.ColBottom[0] = ListView.ColTop[0] + ListView.ColHeight -1;
	ListView.ColLeft[0] = 1;
	ListView.ColRight[0] = ListView.ColWidth[0] +1;
	for(i=1; i<12; i++){
		ListView.ColTop[i] = ListView.ColTop[i -1] + ListView.ColHeight;
		ListView.ColBottom[i] =  ListView.ColBottom[i-1] + ListView.ColHeight; 
	}
	for(i=1;i<ListView.RowCount;i++){
		ListView.ColLeft[i] = ListView.ColWidth[i-1] + ListView.ColLeft[i-1];
		ListView.ColRight[i] = ListView.ColWidth[i] + ListView.ColLeft[i];
	}
	
	Caption.Border.Color = clGray;
	VScrollBar.Color = clFrmFace;
	VScrollBar.RibbonColor =  clGray;
	
	FixColColor = clMaroon;
	FixColTextColor = clNearWhite;
	
	TextColor = clNearBlack;
	SelectedColor = clBlue;
	SelectedTextColor = clNearWhite;
	
	LineCount = 10;
	
	State = nrCtl;
	CtlIndex = 0;
	NewRegCompleted = 0;
}

void TNewRegister::SetListColWidth(int w0, int w1, int w2, int w3, int w4,int w5,int w6, int w7, int w8)
{
	unsigned int i;
	ListView.ColWidth[0] = w0;
	ListView.ColWidth[1] = w1;
	ListView.ColWidth[2] = w2;
	ListView.ColWidth[3] = w3;
	ListView.ColWidth[4] = w4;
	ListView.ColWidth[5] = w5;
	ListView.ColWidth[6] = w6;
	ListView.ColWidth[7] = w7;
	ListView.ColWidth[8] = w8;
	
	ListView.ColLeft[0] = Content.Left +1;
	ListView.ColRight[0] = ListView.ColLeft[0] + w0;
	for(i=1; i<9; i++){
		ListView.ColLeft[i] = ListView.ColRight[i-1] +1;
		ListView.ColRight[i] = ListView.ColLeft[i] + ListView.ColWidth[i];	
	}
}

void TNewRegister::RenderBackGround(void)
{
	RectFillRender(Content.Left, Content.Top, Content.Right, Content.Bottom, Color);
}

void TNewRegister::RenderBackGround(unsigned int aClr)
{
	RectFillRender(Content.Left, Content.Top, Content.Right, Content.Bottom, aClr);
}

void TNewRegister::RenderContent(void)
{
	#define FixColColor	clMedGray
	#define OddColor		clNearMoneyGreen
	unsigned int x,y, y2, clr;
	RectFillRender(Content.Left, ListView.FixColTop, Content.Right, ListView.FixColBottom, FixColColor);
	y = ListView.FixColBottom + 1;
	for(x=0; x<(LineCount+1); x++){	
		y2 =  y + ListView.ColHeight - 1;
		if(y2 > Content.Bottom)y2 = Content.Bottom;		
		if(x == ListView.SelectedCol){
				RectFillRender(Content.Left, y, Content.Right, y2, SelectedColor);			
		}else{
			if(x & 1){
				RectFillRender(Content.Left, y, Content.Right, y2, OddColor);
			}else{
				RectFillRender(Content.Left, y, Content.Right, y2, Color);
			}							
		}
		y = y2 + 1;
		if(y>Content.Bottom)break;
	}	
}

void TNewRegister::DrawSelf(void)
{
	unsigned int x, y, x2, y2, w, h;
	
	VertLineRender(Bound.Left,		Bound.Top, 			Bound.Height -1,			0xFFFFFFFF);
	VertLineRender(Bound.Right -1,	Bound.Top +1,		Bound.Height -2,			0xFF808080);
	VertLineRender(Bound.Right,		Bound.Top,			Bound.Height,			0xFF404040);
	
	HorizLineRender(Bound.Left, 		Bound.Top, 			Bound.Width - 1, 			0xFFFFFFFF);
	HorizLineRender(Bound.Left +1, 	Bound.Bottom -1,  	Bound.Width - 2, 			0xFF808080);
	HorizLineRender(Bound.Left,		Bound.Bottom,		Bound.Width,			0xFF404040);
	
	x = Bound.Left +2 ;	
	x2 = Bound.Right -2;
	y = Bound.Top +2;
	y2 = Bound.Bottom - 2;
	w = Bound.Width -4;
	h = Bound.Height - 4;
	VertLineRender	(x,		y, 		h-1,	0xFF808080);
	HorizLineRender	(x,		y, 		w-1,	0xFF808080);
		
	VertLineRender	(x+1,		y+1, 		h-2,	0xFF404040);
	HorizLineRender	(x+1,		y+1, 		w-2,	0xFF404040);
	
	VertLineRender	(x2-1,	y+1, 		h-2,	0xFFD4D0C8);
	HorizLineRender	(x+1,		y2-1, 	w-2,	0xFFD4D0C8);

	VertLineRender	(x2,		y, 	  	h,	0xFFFFFFFF);
	HorizLineRender	(x,		y2, 		w,	0xFFFFFFFF);
	
	RenderContent();
}

void TNewRegister::DrawCaption(void)
{	
	Caption.Show();
}

void TNewRegister::DrawVertScrollBar(void)
{
	TVScrollBar::sDrawBySize(VScrollBarBox.Left, VScrollBarBox.Top,
					VScrollBarBox.Width, VScrollBarBox.Height,
					VScrollBar.RibbonColor, VScrollBar.Color,
					10, 10, ListView.TopIndex);
}

void TNewRegister::DrawBtn(unsigned int x, unsigned int y, unsigned int x2, unsigned int y2,  unsigned int aClr)
{
	RectFillRender(x, y, x2, y2, aClr);
	
	VertLineRender(x,		y, 		y2-y+1-1,	0xFFFFFFFF);
	VertLineRender(x2 -1,	y +1,		y2-y+1-2,	0xFF808080);
	VertLineRender(x2,	y,		y2-y+1-2,	0xFF404040);
	
	HorizLineRender(x, 	y, 		x2-x+1-1, 	0xFFFFFFFF);
	HorizLineRender(x +1, 	y2 -1,  	x2-x+1 - 2, 0xFF808080);
	HorizLineRender(x,	y2,		x2-x+1,	0xFF404040);
}

void TNewRegister::DrawCtlItem()
{
	unsigned int x, y, x2, y2, aClr, aClrText;
	
	TMyString::sFromStr("注册设备-本机", Caption.Text);
	DrawCaption();
	
	Content.SetWidth(Bound.Width -7);
	RenderBackGround(clMoneyGreen);
	
	x =100; y =100; x2 =420; y2 = y+36;	//0
	if(CtlIndex == 0){aClr = clNavy; aClrText =clNearWhite;}
	else{aClr = clFrmFace; aClrText =clNearBlack;}
	DrawBtn(x,y,x2,y2,aClr);
	TextRender_string24(x+30,y+6, aClrText, "读取显示本机原注册信息");
	
	x =100; y =160; x2 =420; y2 = y+36;	//1
	if(CtlIndex == 1){aClr = clNavy; aClrText =clNearWhite;}
	else{aClr = clFrmFace; aClrText =clNearBlack;}
	DrawBtn(x,y,x2,y2,aClr);
	TextRender_string24(x+30,y+6, aClrText, "开始重新注册");
	
	x =100; y =220; x2 =420; y2 = y+36;	//2
	if(CtlIndex == 2){aClr = clNavy; aClrText =clNearWhite;}
	else{aClr = clFrmFace; aClrText =clNearBlack;}
	DrawBtn(x,y,x2,y2,aClr);
	if(NewRegCompleted)
		TextRender_string24(x+30,y+6, aClrText, "显示新注册概览");
	else
		TextRender_string24(x+30,y+6, clSilver, "显示新注册概览");
	
	x =100; y =280; x2 =420; y2 = y+36;	//3
	if(CtlIndex == 3){aClr = clRed; aClrText =clNearWhite;}
	else{aClr = clFrmFace; aClrText =clNearBlack;}
	DrawBtn(x,y,x2,y2,aClr);
	if(NewRegCompleted)
		TextRender_string24(x+30,y+6, aClrText, "保存到本机 !");
	else
		TextRender_string24(x+30,y+6, clSilver, "保存到本机 !");
	
	x =100; y =340; x2 =420; y2 = y+36;	//3
	if(CtlIndex == 4){aClr = clNavy; aClrText =clNearWhite;}
	else{aClr = clFrmFace; aClrText =clNearBlack;}
	DrawBtn(x,y,x2,y2,aClr);
	TextRender_string24(x+30,y+6, aClrText, "停止注册并退出");
}

void TNewRegister::DrawList(void)
{
	int i, index, BGClr, TextClr, aTop;
	unsigned int aClr;
	//if(EntryCount < 1)return;

	RenderContent();		
	aTop = ListView.FixColTop + TextTopOffSet;

	SetListColWidth(30,90,100,130,100,100,1,1,1);
	TextRender_string24(ListView.ColLeft[1],aTop,TextColor, " 序号" );	
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, " 路径");
	TextRender_string24(ListView.ColLeft[3],aTop,TextColor, "设备类型");
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "棣属于");
	TextRender_string24(ListView.ColLeft[5],aTop,TextColor, "棣属于");

	for(i=0; i<LineCount; i++){
		if(i == ListView.SelectedCol)aClr = SelectedTextColor;
		else aClr = TextColor;
		aTop = ListView.ColTop[i] + TextTopOffSet;
		if(  1){

		}
	}
}

void TNewRegister::Show(void)
{
	DrawSelf();
	Caption.Enable = 1;
	DrawCaption();
	DrawVertScrollBar();
	DrawList();	
}

void TNewRegister::ReDraw(void)
{
	Caption.Enable = 1;
	DrawCaption();
	DrawVertScrollBar();
	DrawList();	
}

void TNewRegister::ShowCtl(void)
{
	unsigned int aClr,i;
	DrawCaption();
	DrawCtlItem();
}

void TNewRegister::DrawOverViewName(void)
{
	int i;
	unsigned int CountAllEpDev, aTop, aClr;
	
	//Line0,ALl
	//Line1,CountRootDev
	//Line2,CountPort
	//Line3,CountHandCtl
	//Line4,CountDirectCtl
	//Line5,CountMotherBoard
	//Line6,CountCommBoard
	//Line7,CountEpAll
	//Line8,CountHandCtlPad
	//Line9,CountDirectCtlPad
	
	Content.SetWidth(Bound.Width -7);
	RenderBackGround(clMoneyGreen);
	
	TMyString::sFromStr("注册信息详情", Caption.Text);
	DrawCaption();
	
	SetListColWidth(120,160,130,150,120,120,1,1,1);
		
	aTop = ListView.FixColTop + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "  条目" );	
	TextRender_string24(ListView.ColLeft[1],aTop,TextColor, "总数量   |");
	
	aTop = ListView.ColTop[0] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "所有设备" );
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "根设备" );
	
	aTop = ListView.ColTop[2] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "回路" );
	
	aTop = ListView.ColTop[3] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "总线盘" );
	
	aTop = ListView.ColTop[4] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "直控盘" );
	
	aTop = ListView.ColTop[5] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "回路母板" );
	
	aTop = ListView.ColTop[6] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "通讯板" );
	
	aTop = ListView.ColTop[7] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "终端设备" );
	
	aTop = ListView.ColTop[8] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "总线盘按钮" );
	
	aTop = ListView.ColTop[9] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "直控盘按钮" );
	//___________________________________________________________________
	aTop = ListView.FixColTop + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "条目");	
	TextRender_string24(ListView.ColLeft[3],aTop,TextColor, "  数量   |");

	aTop = ListView.ColTop[0] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "点型烟感" );
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "点型温感" );
	
	aTop = ListView.ColTop[2] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "烟温一体" );
	
	aTop = ListView.ColTop[3] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "手报" );
	
	aTop = ListView.ColTop[4] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "输入模块" );
	
	aTop = ListView.ColTop[5] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "输出模块" );
	
	aTop = ListView.ColTop[6] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "输入输出模块" );
	
	aTop = ListView.ColTop[7] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "声光报警" );
	
	aTop = ListView.ColTop[8] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "断路器" );
	
	aTop = ListView.ColTop[9] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "显示盘" );
	
	//___________________________________________________________________
	aTop = ListView.FixColTop + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "条目");	
	TextRender_string24(ListView.ColLeft[5],aTop,TextColor, "  数量 |");

	aTop = ListView.ColTop[0] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "未定义设备" );
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "未知设备" );	
}

void TNewRegister::DrawOverViewCountHost()
{
	int i;
	unsigned int CountAllEpDev, aTop, aClr;
	TThisMainCtl *aP = &MainCtl;
	//Line0,ALl
	//Line1,CountRootDev
	//Line2,CountPort
	//Line3,CountHandCtl
	//Line4,CountDirectCtl
	//Line5,CountMotherBoard
	//Line6,CountCommBoard
	//Line7,CountEpAll
	//Line8,CountHandCtlPad
	//Line9,CountDirectCtlPad
	if(aP == nullptr)return;
	
	Content.SetWidth(Bound.Width -7);
	RenderBackGround(clMoneyGreen);
	
	TMyString::sFromStr("注册信息详情", Caption.Text);
	DrawCaption();
	
	SetListColWidth(120,160,110,160,110,120,1,1,1);
		
	aTop = ListView.FixColTop + TextTopOffSet;
	
	aTop = ListView.ColTop[0] + TextTopOffSet;
	if(aP->CountAllDevice)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountAllDevice);
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	if(aP->CountAllDevice)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountRootDev);
	
	aTop = ListView.ColTop[2] + TextTopOffSet;
	if(aP->CountRootDev)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountPort);
	
	aTop = ListView.ColTop[3] + TextTopOffSet;
	if(aP->CountHandCtl)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountHandCtl);
	
	aTop = ListView.ColTop[4] + TextTopOffSet;
	if(aP->CountDirectCtl)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountDirectCtl);
	
	aTop = ListView.ColTop[5] + TextTopOffSet;
	if(aP->CountMotherBoard)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountMotherBoard);
	
	aTop = ListView.ColTop[6] + TextTopOffSet;
	if(aP->CountCommBoard)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountCommBoard);
	
	aTop = ListView.ColTop[7] + TextTopOffSet;
	if(aP->CountEpAll)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountEpAll);
	
	aTop = ListView.ColTop[8] + TextTopOffSet;
	if(aP->CountHandCtlPad)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountHandCtlPad);
	
	aTop = ListView.ColTop[9] + TextTopOffSet;
	if(aP->CountDirectCtlPad)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountDirectCtlPad);
	//___________________________________________________________________
	aTop = ListView.FixColTop + TextTopOffSet;

	aTop = ListView.ColTop[0] + TextTopOffSet;
	if(aP->CountEp.Smoker)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Smoker);
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	if(aP->CountEp.Tempe)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Tempe);
	
	aTop = ListView.ColTop[2] + TextTopOffSet;
	if(aP->CountEp.SmokeTempe)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.SmokeTempe);
	
	aTop = ListView.ColTop[3] + TextTopOffSet;
	if(aP->CountEp.HandReport)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.HandReport);
	
	aTop = ListView.ColTop[4] + TextTopOffSet;
	if(aP->CountEp.Input)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Input);
	
	aTop = ListView.ColTop[5] + TextTopOffSet;
	if(aP->CountEp.Output)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Output);
	
	aTop = ListView.ColTop[6] + TextTopOffSet;
	if(aP->CountEp.InOut)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.InOut);
	
	aTop = ListView.ColTop[7] + TextTopOffSet;
	if(aP->CountEp.VaAlram)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.VaAlram);
	
	aTop = ListView.ColTop[8] + TextTopOffSet;
	if(aP->CountEp.BusBroke)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.BusBroke);
	
	aTop = ListView.ColTop[9] + TextTopOffSet;
	if(aP->CountEp.DisplayPad)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.DisplayPad);
	
	//___________________________________________________________________
	aTop = ListView.FixColTop + TextTopOffSet;

	aTop = ListView.ColTop[0] + TextTopOffSet;
	if(aP->CountEp.UnDefine)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[5], aTop, aClr, aP->CountEp.UnDefine);
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	if(aP->CountEp.Unknown)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[5], aTop, aClr, aP->CountEp.Unknown);
}

void TNewRegister::DrawOverViewAllHost()
{
	TThisMainCtl *aP = &MainCtl;
	if(aP == nullptr)return;
}

void TNewRegister::DrawOverViewHost()
{
	int i;
	unsigned int aTop, aClr;
	TThisMainCtl *aP = &MainCtl;
	//Line0,ALl
	//Line1,CountRootDev
	//Line2,CountPort
	//Line3,CountHandCtl
	//Line4,CountDirectCtl
	//Line5,CountMotherBoard
	//Line6,CountCommBoard
	//Line7,CountEpAll
	//Line8,CountHandCtlPad
	//Line9,CountDirectCtlPad
	if(aP == nullptr)return;
	
	Content.SetWidth(Bound.Width -7);
	RenderBackGround(clMoneyGreen);
	
	TMyString::sFromStr("注册信息详情", Caption.Text);
	DrawCaption();
	
	SetListColWidth(120,160,130,150,120,120,1,1,1);
		
	aTop = ListView.FixColTop + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "  条目" );	
	TextRender_string24(ListView.ColLeft[1],aTop,TextColor, "总数量   |");
	
	aTop = ListView.ColTop[0] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "所有设备" );
	if(aP->CountAllDevice)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountAllDevice);
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "根设备" );
	if(aP->CountAllDevice)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountRootDev);
	
	aTop = ListView.ColTop[2] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "回路" );
	if(aP->CountRootDev)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountPort);
	
	aTop = ListView.ColTop[3] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "总线盘" );
	if(aP->CountHandCtl)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountHandCtl);
	
	aTop = ListView.ColTop[4] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "直控盘" );
	if(aP->CountDirectCtl)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountDirectCtl);
	
	aTop = ListView.ColTop[5] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "回路母板" );
	if(aP->CountMotherBoard)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountMotherBoard);
	
	aTop = ListView.ColTop[6] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "通讯板" );
	if(aP->CountCommBoard)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountCommBoard);
	
	aTop = ListView.ColTop[7] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "终端设备" );
	if(aP->CountEpAll)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountEpAll);
	
	aTop = ListView.ColTop[8] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "总线盘按钮" );
	if(aP->CountHandCtlPad)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountHandCtlPad);
	
	aTop = ListView.ColTop[9] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "直控盘按钮" );
	if(aP->CountDirectCtlPad)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountDirectCtlPad);
	//___________________________________________________________________
	aTop = ListView.FixColTop + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "条目");	
	TextRender_string24(ListView.ColLeft[3],aTop,TextColor, "  数量   |");

	aTop = ListView.ColTop[0] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "点型烟感" );
	if(aP->CountEp.Smoker)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Smoker);
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "点型温感" );
	if(aP->CountEp.Tempe)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Tempe);
	
	aTop = ListView.ColTop[2] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "烟温一体" );
	if(aP->CountEp.SmokeTempe)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.SmokeTempe);
	
	aTop = ListView.ColTop[3] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "手报" );
	if(aP->CountEp.HandReport)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.HandReport);
	
	aTop = ListView.ColTop[4] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "输入模块" );
	if(aP->CountEp.Input)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Input);
	
	aTop = ListView.ColTop[5] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "输出模块" );
	if(aP->CountEp.Output)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Output);
	
	aTop = ListView.ColTop[6] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "输入输出模块" );
	if(aP->CountEp.InOut)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.InOut);
	
	aTop = ListView.ColTop[7] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "声光报警" );
	if(aP->CountEp.VaAlram)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.VaAlram);
	
	aTop = ListView.ColTop[8] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "断路器" );
	if(aP->CountEp.BusBroke)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.BusBroke);
	
	aTop = ListView.ColTop[9] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "显示盘" );
	if(aP->CountEp.DisplayPad)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.DisplayPad);
	
	//___________________________________________________________________
	aTop = ListView.FixColTop + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "条目");	
	TextRender_string24(ListView.ColLeft[5],aTop,TextColor, "  数量  |");

	aTop = ListView.ColTop[0] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "未定义设备" );
	if(aP->CountEp.UnDefine)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[5], aTop, aClr, aP->CountEp.UnDefine);
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "未知设备" );
	if(aP->CountEp.Unknown)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[5], aTop, aClr, aP->CountEp.Unknown);
}

void TNewRegister::DrawOverViewReg()
{
	int i;
	unsigned int aTop, aClr;
	TThisMainCtl *aP = &MainCtlReg;
	//Line0,ALl
	//Line1,CountRootDev
	//Line2,CountPort
	//Line3,CountHandCtl
	//Line4,CountDirectCtl
	//Line5,CountMotherBoard
	//Line6,CountCommBoard
	//Line7,CountEpAll
	//Line8,CountHandCtlPad
	//Line9,CountDirectCtlPad
	if(aP == nullptr)return;
	
	Content.SetWidth(Bound.Width -7);
	RenderBackGround(clMoneyGreen);
	
	TMyString::sFromStr("注册信息详情", Caption.Text);
	DrawCaption();
	
	SetListColWidth(120,160,130,150,120,120,1,1,1);
		
	aTop = ListView.FixColTop + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "  条目" );	
	TextRender_string24(ListView.ColLeft[1],aTop,TextColor, "总数量   |");
	
	aTop = ListView.ColTop[0] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "所有设备" );
	if(aP->CountAllDevice)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountAllDevice);
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "根设备" );
	if(aP->CountAllDevice)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountRootDev);
	
	aTop = ListView.ColTop[2] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "回路" );
	if(aP->CountRootDev)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountPort);
	
	aTop = ListView.ColTop[3] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "总线盘" );
	if(aP->CountHandCtl)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountHandCtl);
	
	aTop = ListView.ColTop[4] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "直控盘" );
	if(aP->CountDirectCtl)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountDirectCtl);
	
	aTop = ListView.ColTop[5] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "回路母板" );
	if(aP->CountMotherBoard)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountMotherBoard);
	
	aTop = ListView.ColTop[6] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "通讯板" );
	if(aP->CountCommBoard)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountCommBoard);
	
	aTop = ListView.ColTop[7] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "终端设备" );
	if(aP->CountEpAll)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountEpAll);
	
	aTop = ListView.ColTop[8] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "总线盘按钮" );
	if(aP->CountHandCtlPad)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountHandCtlPad);
	
	aTop = ListView.ColTop[9] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[0],aTop,TextColor, "直控盘按钮" );
	if(aP->CountDirectCtlPad)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[1], aTop, aClr, aP->CountDirectCtlPad);
	//___________________________________________________________________
	aTop = ListView.FixColTop + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "条目");	
	TextRender_string24(ListView.ColLeft[3],aTop,TextColor, "  数量   |");

	aTop = ListView.ColTop[0] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "点型烟感" );
	if(aP->CountEp.Smoker)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Smoker);
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "点型温感" );
	if(aP->CountEp.Tempe)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Tempe);
	
	aTop = ListView.ColTop[2] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "烟温一体" );
	if(aP->CountEp.SmokeTempe)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.SmokeTempe);
	
	aTop = ListView.ColTop[3] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "手报" );
	if(aP->CountEp.HandReport)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.HandReport);
	
	aTop = ListView.ColTop[4] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "输入模块" );
	if(aP->CountEp.Input)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Input);
	
	aTop = ListView.ColTop[5] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "输出模块" );
	if(aP->CountEp.Output)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.Output);
	
	aTop = ListView.ColTop[6] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "输入输出模块" );
	if(aP->CountEp.InOut)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.InOut);
	
	aTop = ListView.ColTop[7] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "声光报警" );
	if(aP->CountEp.VaAlram)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.VaAlram);
	
	aTop = ListView.ColTop[8] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "断路器" );
	if(aP->CountEp.BusBroke)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.BusBroke);
	
	aTop = ListView.ColTop[9] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[2],aTop,TextColor, "显示盘" );
	if(aP->CountEp.DisplayPad)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[3], aTop, aClr, aP->CountEp.DisplayPad);
	
	//___________________________________________________________________
	aTop = ListView.FixColTop + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "条目");	
	TextRender_string24(ListView.ColLeft[5],aTop,TextColor, "  数量  |");

	aTop = ListView.ColTop[0] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "未定义设备" );
	if(aP->CountEp.UnDefine)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[5], aTop, aClr, aP->CountEp.UnDefine);
	
	aTop = ListView.ColTop[1] + TextTopOffSet;
	TextRender_string24(ListView.ColLeft[4],aTop,TextColor, "未知设备" );
	if(aP->CountEp.Unknown)aClr = clBlack; else aClr =nrdNoneColor;
	TextDigitRender6Right24(ListView.ColLeft[5], aTop, aClr, aP->CountEp.Unknown);
}


TGuiMsgReturn TNewRegister::KeyIn(unsigned char aKey)
{
	int ind,i,aIndex;
	TGuiMsgReturn aMsg = guiMsgNone;
	//Up or Down One Index___________________
	
	if(aKey == VK_TAB){
		
	}
	if(1){
		if(VK_UP == aKey){
			if(State == nrCtl){
				if(CtlIndex >0){
					CtlIndex--;
					if( (CtlIndex == 2) || (CtlIndex == 3) ){
						CtlIndex =1;
					}
					DrawCtlItem();
				}
			}
			if(ListView.SelectedCol >0){

			}else{
				if(ListView.TopIndex >0){	
					ReDraw();
				}
			}
		}else
		if(VK_DOWN == aKey){
			if(State == nrCtl){
				if(CtlIndex < 4){
					CtlIndex++;
					if( (CtlIndex == 2) || (CtlIndex == 3) ){
						CtlIndex =4;
					}
					DrawCtlItem();
				}
			}
			if( ListView.SelectedCol < (ListLineCnt -1) ){

			}else{

			}
		}
	}
	
	if(aKey == VK_EXECUTE){
		//Open path Device
		if(State == nrCtl){
			if(CtlIndex ==0){
				MainCtl.LoadVisioInf();
				DrawOverViewHost();
				State = nrShowDetails;
			}else
			if(CtlIndex ==1){
				NewRegCompleted = 0;
			}else
			if(CtlIndex ==2){
				if(NewRegCompleted){
					MainCtlReg.LoadVisioInf();
					DrawOverViewReg();
					State = nrShowDetails;
				}
			}else
			if(CtlIndex ==3){
				if(NewRegCompleted){

				}
			}else
			if(CtlIndex ==4){
				//do something before return
				aMsg = guiMsgReturn;
			}
		}else
		if(State == nrShowDetails){
			State = nrCtl;
			DrawCtlItem();
		}
	}else
	if(aKey == VK_F2){
		
	}else
	if(aKey == VK_RETURN){
		if(State == nrShowDetails){
			State = nrCtl;
			DrawCtlItem();
		}
	}	

	return aMsg;	
}

