#include "RuntimeData.h"
#include "DesignPrmSet.h"
#include "DevMask.h"

extern "C"{
	//#include "user_norflash.h"
	#include "user_eeprom.h"
	#include "task.h"
}

#define Icon16_Up		1
#define Icon16_Down	2

#define dfAddrLineNum 6
#define dfDescpLineNum 4
#define dfDescpMax	250

#define dWdClr		clSkyBlue
#define dWdDisabelClr	clNearWhite

#define dWWidth	24
#define dWHeigh	24
#define dRoundR	7

#define dAddr_DescpBuf	dAddrSdRam_Commom


void TDesignPrmSet::Init()
{
	Tag.Reset();
	Setting.Reset();
	SaveSta = 0;
	LoadBaseTypeList();
	ReadData();
	
	IsPermission = 0;
	CntError = 0;
}

void TDesignPrmSet::InitBackEnd()
{
	Setting.Reset();
	LoadBaseTypeList();
	ReadData();
	
	IsPermission = 0;
	CntError = 0;
}

void TDesignPrmSet::DelayMs(unsigned int aMs)
{
	volatile unsigned int mTick;
	volatile unsigned int Tick;
	for(Tick=0; Tick<aMs; Tick++){
		for(mTick=0; mTick<160000; mTick++);
	}
}

void TDesignPrmSet::RenderBackGround(void)
{
	RectFillRender(ContentGeometry.Left, ContentGeometry.Top, ContentGeometry.Right, ContentGeometry.Bottom, ContentColor);
}

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

void TDesignPrmSet::DrawSelf(void)
{
	RectFillRender(Lv.Caption.Left, Lv.Caption.Top, Lv.Caption.Right, Lv.Caption.Bottom, CaptionColor);
	
	
	for(int i=0; i<Lv.Grid.UsingCount; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	IconList->Render(16,Icon16_Up  , ArrowUpPoint.x, ArrowUpPoint.y);
	IconList->Render(16,Icon16_Down  , ArrowDownPoint.x, ArrowDownPoint.y);
	if(LanguageEnCn==0){
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "工程->设计数量");
		if(MainCtl.fData.Split.NetworkMode == 1){
			TextRender_string24(Lv.Grid.Left[0] + 6, Lv.Grid.Top[0] +8, clNearWhite,  "共   种设备类型.  点位总数      点.  系统总容量      点.");
		}else
		if(MainCtl.fData.Split.NetworkMode == 2){
			TextRender_string24(Lv.Grid.Left[0] + 6, Lv.Grid.Top[0] +8, clNearWhite,  "共   种设备类型.  点位总数      点.  本机为区域机       ");
		}else{
			TextRender_string24(Lv.Grid.Left[0] + 6, Lv.Grid.Top[0] +8, clNearWhite,  "共   种设备类型.  点位总数      点.  本机为单机         ");
		}
	}else{
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "Project->Number Of Designe");
		if(MainCtl.fData.Split.NetworkMode == 1){
			TextRender_string24(Lv.Grid.Left[0] + 6, Lv.Grid.Top[0] +8, clNearWhite,  "     Types Of Dev; Devices      ;  Devs On Sys:         ");
		}else
		if(MainCtl.fData.Split.NetworkMode == 2){
			TextRender_string24(Lv.Grid.Left[0] + 6, Lv.Grid.Top[0] +8, clNearWhite,  "     Types Of Dev; Devices      ;  Regional             ");
		}else{
			TextRender_string24(Lv.Grid.Left[0] + 6, Lv.Grid.Top[0] +8, clNearWhite,  "     Types Of Dev; Devices      ;  Stand Alone          ");
		}
	}
	
}

void TDesignPrmSet::ShowState()
{
	if(SaveSta == 0){
		TextRender_string24(ResultSavePoint.x, ResultSavePoint.y ,clNearWhite, ItemColor, "        ");
	}else
	if(SaveSta == 1){
		if(LanguageEnCn==0)	TextRender_string24(ResultSavePoint.x, ResultSavePoint.y ,clNearWhite, ItemColor, "保存成功");
		else 				TextRender_string24(ResultSavePoint.x, ResultSavePoint.y ,clNearWhite, ItemColor, "Saved OK");
	}
}

void TDesignPrmSet::ShowState(unsigned int aSta)
{
	SaveSta = aSta;
	ShowState();
}

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


void TDesignPrmSet::Show()
{
	RenderBackGround();
	DrawSelf();
}

void TDesignPrmSet::FullRedraw(int Prm)
{
	if(Prm == 0){
		RenderBackGround();
		DrawSelf();
		Analy();
		ShowSetting();
		ShowState();
	}else
	if(Prm == 1){
		RectFillRender(GuiRedrawDataList[1][0], GuiRedrawDataList[1][1], GuiRedrawDataList[1][2], GuiRedrawDataList[1][3], ContentColor);
		DrawSelf();
		Analy();
		ShowSetting();
		ShowState();
		
		if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
	}
}

void TDesignPrmSet::PermissionCmdReturnDraw()
{
	RectFillRender(Lv.Grid.Left[1] + 200 -10, Lv.Grid.Top[1] + 12 -10, Lv.Grid.Left[1] + 200 -10 + 400 + 20, Lv.Grid.Top[1] + 12 -10 + 140 + 20, ContentColor);
	for(int i=1; i<4; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	ReAligne();
}

void TDesignPrmSet::PermissionCmdGO()
{
	ReStorage();
	Write2Eep();
	ReadData(); 
	ShowState(1);
	ReAligne();
}
			

void TDesignPrmSet::DrawEntryActive(int aInx, int IsENtryActive)
{
	if(IsENtryActive)
		TRoundSquare::sDrawBySize(16, Lv.Grid.Top[aInx + 1] + 6, dWWidth, dWHeigh, dRoundR, dWdClr, 1);
	else
		TRoundSquare::sDrawBySize(16, Lv.Grid.Top[aInx + 1] + 6, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
}

void TDesignPrmSet::DrawEntryTypeString(int aInx)
{
	int x, y, dInx;
	unsigned char tType;
	x = 46;
	y = Lv.Grid.Top[aInx + 1] + 6;
	dInx = Setting.TopEntry + aInx;
	tType = TypeList.dType[dInx];
	if(LanguageEnCn==0)
		TMyString::sFromStr(StrHwType[tType], TextType);
	else 
		TMyString::sFromStr(StrHwTypeEn[tType], TextType);
	TMyString::sFillFixLen(TextType, 32);
	TextRender_string24(x,y,clNearWhite,ItemColor, TextType);
}

void TDesignPrmSet::ClearSelected(void)
{
	int i;
	for(i=0; i<5; i++){
		aPanel->Edit[i].Selected = 0;
	}
	switch(Tag.Inx){
		case 0:
			TRoundSquare::sSelected(16, Lv.Grid.Top[1] + 6, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 1:
			aPanel->Edit[0].Show();
			break;
		case 2:
			TRoundSquare::sSelected(16, Lv.Grid.Top[2] + 6, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 3:
			aPanel->Edit[1].Show();
			break;
		case 4:
			TRoundSquare::sSelected(16, Lv.Grid.Top[3] + 6, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 5:
			aPanel->Edit[2].Show();
			break;
		case 6:
			TRoundSquare::sSelected(16, Lv.Grid.Top[4] + 6, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 7:
			aPanel->Edit[3].Show();
			break;
	}
}

void TDesignPrmSet::Check4Selected(void)
{
	int i;
	for(i=0; i<5; i++){
		aPanel->Edit[i].Selected = 0;
	}
	switch(Tag.Inx){
		case 0:
			TRoundSquare::sSelected(16, Lv.Grid.Top[1] + 6, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 1:
			aPanel->Edit[0].Selected = 1;
			aPanel->Edit[0].Show();
			aPanel->Edit[0].ShowCursor();
			break;
		case 2:
			TRoundSquare::sSelected(16, Lv.Grid.Top[2] + 6, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 3:
			aPanel->Edit[1].Selected = 1;
			aPanel->Edit[1].Show();
			aPanel->Edit[1].ShowCursor();
			break;
		case 4:
			TRoundSquare::sSelected(16, Lv.Grid.Top[3] + 6, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 5:
			aPanel->Edit[2].Selected = 1;
			aPanel->Edit[2].Show();
			aPanel->Edit[2].ShowCursor();
			break;
		case 6:
			TRoundSquare::sSelected(16, Lv.Grid.Top[4] + 6, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 7:
			aPanel->Edit[3].Selected = 1;
			aPanel->Edit[3].Show();
			aPanel->Edit[3].ShowCursor();
			break;
	}
}

void TDesignPrmSet::InitPanel(void)
{
	aPanel->Init(100,100,10,10,0,0,clFrmFace, bvRaised);
	
	aPanel->Edit[0].Init(Lv.Grid.Left[1] + 14,Lv.Grid.Top[1] + 36,96,30,0,0,clNearBlack,clNearWhite);
	aPanel->Edit[1].Init(Lv.Grid.Left[2] + 14,Lv.Grid.Top[2] + 36,96,30,0,0,clNearBlack,clNearWhite);
	aPanel->Edit[2].Init(Lv.Grid.Left[3] + 14,Lv.Grid.Top[3] + 36,96,30,0,0,clNearBlack,clNearWhite);
	aPanel->Edit[3].Init(Lv.Grid.Left[4] + 14,Lv.Grid.Top[4] + 36,96,30,0,0,clNearBlack,clNearWhite);
	
	for(int i=0; i<4;i++){
		aPanel->Edit[i].Enable = 1;
		aPanel->Edit[i].Visible = 1;
		aPanel->Edit[i].SetMaxLen(6);
		aPanel->Edit[i].SetInputMaskEn();
		aPanel->Edit[i].Str.FromStr("0");
		aPanel->Edit[i].Selected = 0;
	}
	ReadData();
	Analy();
	ShowSetting();
}

void TDesignPrmSet::ShowSetting()
{
	for(int i=Setting.TopEntry, Pcnt=0; (i<TypeList.Count) && (Pcnt<4); i++,Pcnt++){
		if(Setting.Using[i]){
			DrawEntryActive(Pcnt, 1);
			DrawEntryTypeString(Pcnt);
		}else{
			DrawEntryActive(Pcnt, 0);
			DrawEntryTypeString(Pcnt);
		}
		aPanel->Edit[Pcnt].Str.FromUInt6Dg(Setting.Count[i]);
		aPanel->Edit[Pcnt].SetPstTail();
		aPanel->Edit[Pcnt].Show();
		aPanel->Edit[Pcnt].ShowCursor();
	}
	Check4Selected();	
}

void TDesignPrmSet::LoadData()
{
	int i;
	ReadData();
	
	aPanel->Edit[0].Str.FromUInt(DesigePrmData.Count.Smoke);
	aPanel->Edit[1].Str.FromUInt(DesigePrmData.Count.ModuleInOut);
	aPanel->Edit[2].Str.FromUInt(DesigePrmData.Count.Tempe);
	aPanel->Edit[3].Str.FromUInt(DesigePrmData.Count.ModuleOutput);

	
	for(i=0; i<4; i++){
		aPanel->Edit[i].SetPstTail();
		aPanel->Edit[i].Show();
	}
	
	aPanel->ReDrawItems();
	Check4Selected();
}

void TDesignPrmSet::SaveData()
{

}

TGuiMsgReturn TDesignPrmSet::KeyIn(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	int uKey, iVal;
	unsigned char aIndex;
	char LastChr;
	const char *p;
	int i;
	TGuiMsgReturn PmsRtnMsg;
	if(IsPermission){
		PmsRtnMsg = PmsIntervene4Gui.KeyIn(aKey);
		if(PmsRtnMsg == guiMsgOkAndReturn){
			//Enter And Run Go
			IsPermission = 0;
			PermissionCmdReturnDraw();
			PermissionCmdGO();
		}else
		if(PmsRtnMsg == guiMsgReturn){
			//Not Enter Redraw
			IsPermission = 0;
			PermissionCmdReturnDraw();
		}
		return aMsg;
	}else{
		switch(aKey){
			case VK_DELETE:
			case VK_LEFT:
			case VK_RIGHT:
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				if(Tag.Inx < 8){
					if(Tag.Inx & 0x01){
						const int eInx = Tag.Inx /2;
						aPanel->Edit[eInx].KeyIn(aKey);
						iVal = aPanel->Edit[eInx].Str.ToInteger();
						if( (iVal <0) || (iVal>60000) ){
							CntError = 1;
							aPanel->Edit[eInx].SelectedColor = clRed;
						}else{
							CntError = 0;
							aPanel->Edit[eInx].SelectedColor = clBlue;
						}
						aPanel->Edit[eInx].CorrectPst();
						aPanel->Edit[eInx].Show();
						ReStorage();
						Analy();
					}else{
						const int rInx = Tag.Inx /2 + 1;
						Setting.Using[Setting.Entry] = Setting.Using[Setting.Entry] ? 0 : 1;
						Setting.Using[Setting.Entry] ? 
						TRoundSquare::sDrawBySize(Lv.Grid.Left[rInx] + 16, Lv.Grid.Top[rInx] + 6, dWWidth, dWHeigh, dRoundR, dWdClr, 1) :
						TRoundSquare::sDrawBySize(Lv.Grid.Left[rInx] + 16, Lv.Grid.Top[rInx] + 6, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
						Analy();
					}
				}
				break;
			case VK_UP:
				if(CntError == 0){
					if(Tag.Inx >0){
						ClearSelected();
						Tag.Inx--;
						Setting.Entry = Setting.TopEntry + (Tag.Inx /2);
						if(Setting.Entry <0)Setting.Entry = 0;
						Check4Selected();
					}else{
						if(Setting.TopEntry >0){
							ReStorage();
							ClearSelected();
							Tag.Inx = 1;
							Setting.TopEntry--;
							Setting.Entry = Setting.TopEntry;
							ReAligne();
							Check4Selected();
						}
					}
				}
				break;
			case VK_DOWN:
				if(CntError == 0){
					if(Tag.Inx < 7){
						ClearSelected();
						Tag.Inx++;
						Setting.Entry = Setting.TopEntry + (Tag.Inx /2);
						Check4Selected();
					}else{
						if(Setting.Entry < (TypeList.Count -1)){
							ReStorage();
							ClearSelected();
							Tag.Inx = 6;
							Setting.TopEntry++;
							Setting.Entry++;
							ReAligne();
							Check4Selected();
						}
					}
				}
				break;
			case VK_TAB:
				break;
			case dfKEY_SETUP:
				if( (Tag.Inx & 0x01) == 0){
					int rInx = Tag.Inx /2 + 1;
					Setting.Using[Setting.Entry] = Setting.Using[Setting.Entry] ? 0 : 1;
					Setting.Using[Setting.Entry] ? 
					TRoundSquare::sDrawBySize(Lv.Grid.Left[rInx] + 16, Lv.Grid.Top[rInx] + 6, dWWidth, dWHeigh, dRoundR, dWdClr, 1) :
					TRoundSquare::sDrawBySize(Lv.Grid.Left[rInx] + 16, Lv.Grid.Top[rInx] + 6, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
					Analy();
				}
				break;
			case VK_EXECUTE:
				if(CntError == 0){
					if(SystemPermission > 2){
						PermissionCmdGO();
					}else{
						IsPermission = 1;
						PmsIntervene4Gui.Show4Gui(Lv.Grid.Left[1] + 200, Lv.Grid.Top[1] + 12, 400, 140, 3);
					}
				}
				break;
		}
		if( (aKey != VK_EXECUTE) && (aKey == VK_RETURN) )ShowState(0);
		if(aKey == VK_RETURN){
			aMsg = guiMsgReturn;
		}
	}
	return aMsg;	
}

void TDesignPrmSet::Write2Eep()
{
	unsigned int eAddr;
	unsigned int i;
	volatile unsigned int aWait, x, wP0, Wait4;
	unsigned char Inx;

	//Write Using Count 
	eAddr = dEepAddrDesignPrm;
	DelayMs(10);
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	ReadWriteData.D8[0] = TypeList.Count;
	eeprom_write_byte_via_page(0, eAddr, ReadWriteData.D8, 1);
	DelayMs(10);
	
	//Write List 1/2
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	for(i=0; i<128; i++){
		ReadWriteData.D8[i] = Setting.Using[i];
	}
	eAddr = dEepAddrDesignPrm + 128;
	DelayMs(10);
	eeprom_write_byte_via_page(0, eAddr, ReadWriteData.D8, 128);
	
	//Write List 2/2
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	for(i=0; i<128; i++){
		ReadWriteData.D8[i] = Setting.Using[i +128];
	}
	eAddr = dEepAddrDesignPrm + 256;
	DelayMs(10);
	eeprom_write_byte_via_page(0, eAddr, ReadWriteData.D8, 128);
	
	//Write 8 Times(32 Per Time) =  256 Point Count And Type
	for(Inx=0; Inx<8; Inx++){
		eAddr = dEepAddrDesignPrm + 384 + (Inx*128);
		if(TypeList.Count > (Inx*32)){
			for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
			x = Inx*32;
			for(i=0; i<32; i++){
				ReadWriteData.Count[i] = Setting.Count[x+i];
				ReadWriteData.Pnt[i].sType = TypeList.dType[x+i];
			}
			DelayMs(10);
			eeprom_write_byte_via_page(0, eAddr, ReadWriteData.D8, 128);
		}
	}
	DelayMs(10);
	ReadData();
	LoadData2RuntimeData();
}

void TDesignPrmSet::RecoverSetDefault()
{
	unsigned int eAddr;
	unsigned int i;
	volatile unsigned int aWait, x, wP0, Wait4;
	unsigned char Inx;

	//Write Using Count 
	SysLoopTick = 0;
	eAddr = dEepAddrDesignPrm;
	DelayMs(10);
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	eeprom_write_byte_via_page(0, eAddr, ReadWriteData.D8, 1);
	DelayMs(10);
	
	//Write List 1/2
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	eAddr = dEepAddrDesignPrm + 128;
	DelayMs(10);
	eeprom_write_byte_via_page(0, eAddr, ReadWriteData.D8, 128);
	
	//Write List 2/2
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	eAddr = dEepAddrDesignPrm + 256;
	DelayMs(10);
	eeprom_write_byte_via_page(0, eAddr, ReadWriteData.D8, 128);
	
	//Write 8 Times(32 Per Time) =  256 Point Count And Type
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	for(Inx=0; Inx<8; Inx++){
		SysLoopTick = 0;
		eAddr = dEepAddrDesignPrm + 384 + (Inx*128);
		DelayMs(10);
		eeprom_write_byte_via_page(0, eAddr, ReadWriteData.D8, 128);
	}	
}

void TDesignPrmSet::ReadData()
{
	unsigned int eAddr;
	unsigned int i;
	volatile unsigned int x, tCnt;
	unsigned char Inx, dType;

	//Read ExistTable 
	eAddr = dEepAddrDesignPrm;
	DelayMs(10);
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	eeprom_read_byte(0, eAddr, ReadWriteData.D8, 1);
	DelayMs(10);
	
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	eAddr = dEepAddrDesignPrm + 128;
	eeprom_read_byte(0, eAddr, ReadWriteData.D8, 128);
	for(i=0; i<128; i++){
		 TmpUsing[i] = ReadWriteData.D8[i];
	}
	
	for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
	eAddr = dEepAddrDesignPrm + 256;
	DelayMs(10);
	eeprom_read_byte(0, eAddr, ReadWriteData.D8, 128);
	for(i=0; i<128; i++){
		TmpUsing[i +128] = ReadWriteData.D8[i];
	}
	
	for(Inx=0; Inx<8; Inx++){
		eAddr = dEepAddrDesignPrm + 384 + (Inx*128);
		if(TypeList.Count > (Inx*32)){
			for(i=0; i<128; i++)ReadWriteData.D8[i] = 0;
			DelayMs(10);
			eeprom_read_byte(0, eAddr, ReadWriteData.D8, 128);
			
			x = Inx*32;
			for(i=0; i<32; i++){
				tCnt = ReadWriteData.Count[i] & 0x00FFFFFF;
				dType = ReadWriteData.Pnt[i].sType;
				for(int e=0; e<TypeList.Count; e++){
					if(dType == TypeList.dType[e]){
						Setting.Using[e] = TmpUsing[e];
						Setting.Count[e] = tCnt;
					}
				}
			}
		}
	}
}

void TDesignPrmSet::LoadData2RuntimeData()
{
	int x;
	unsigned char dType;
	unsigned int tCnt;
	
	DesigePrmData.Count.DisplayPad = 0;
	DesigePrmData.Count.HandReport = 0;
	DesigePrmData.Count.HydrantKp = 0;
	DesigePrmData.Count.ModuleInOut = 0;
	DesigePrmData.Count.ModuleInput = 0;
	DesigePrmData.Count.ModuleOutput = 0;
	DesigePrmData.Count.Smoke = 0;
	DesigePrmData.Count.Tempe = 0;
	DesigePrmData.Count.Va = 0;
	DesigePrmData.Count.LnkPs = 0;
	DesigePrmData.Count.Other = 0;
	
	for(int e=0; e<TypeList.Count; e++){
		dType = TypeList.dType[e];
		tCnt = Setting.Count[e];
		if(Setting.Using[e]){
			if(dType == dgTYPE_SMOKE_DETECTOR){
				DesigePrmData.Count.Smoke = tCnt;
			}else
			if(dType == dgTYPE_TEMPE_DETECTOR){
				DesigePrmData.Count.Tempe = tCnt;
			}else
			if(dType == dgTYPE_HAND_REPORT){
				DesigePrmData.Count.HandReport = tCnt;
			}else
			if(dType == dgTYPE_FIRE_HydrantKp){
				DesigePrmData.Count.HydrantKp = tCnt;
			}else
			if(dType == dgTYPE_IN_MODULE){
				DesigePrmData.Count.ModuleInput = tCnt;
			}else
			if(dType == dgTYPE_OUT_MODULE){
				DesigePrmData.Count.ModuleOutput = tCnt;
			}else
			if(dType == dgTYPE_INOUT_MODULE_NonSource){
				DesigePrmData.Count.ModuleInOut = tCnt;
			}else
			if(dType == dgType_VAALRAM){
				DesigePrmData.Count.Va = tCnt;
			}else
			if(dType == dgTYPE_DISPLAY_PAD){
				DesigePrmData.Count.DisplayPad = tCnt;
			}else
			if(dType == dgTYPE_LINKAGE_POWERSUPLY){
				DesigePrmData.Count.LnkPs = tCnt;
			}	
		}
	}
	
	if(DesigePrmData.Count.DisplayPad >= 60000)DesigePrmData.Count.DisplayPad = 0;
	if(DesigePrmData.Count.HandReport >= 60000)DesigePrmData.Count.HandReport = 0;
	if(DesigePrmData.Count.HydrantKp >= 60000)DesigePrmData.Count.HydrantKp = 0;
	if(DesigePrmData.Count.ModuleInOut >= 60000)DesigePrmData.Count.ModuleInOut = 0;
	if(DesigePrmData.Count.ModuleInput >= 60000)DesigePrmData.Count.ModuleInput = 0;
	if(DesigePrmData.Count.ModuleOutput >= 60000)DesigePrmData.Count.ModuleOutput = 0;
	if(DesigePrmData.Count.Smoke >= 60000)DesigePrmData.Count.Smoke = 0;
	if(DesigePrmData.Count.Tempe >= 60000)DesigePrmData.Count.Tempe = 0;
	if(DesigePrmData.Count.Va >= 60000)DesigePrmData.Count.Va = 0;
	if(DesigePrmData.Count.LnkPs >= 60000)DesigePrmData.Count.LnkPs = 0;
	if(DesigePrmData.Count.Other >= 60000)DesigePrmData.Count.Other = 0;
}

void TDesignPrmSet::BackEnd_LoadData2RuntimeData()
{	
	InitBackEnd();
	LoadBaseTypeList();
	ReadData();
	LoadData2RuntimeData();
}

void TDesignPrmSet::LoadBaseTypeList()
{
	int i;
	unsigned int aAddr;
	char *cText;
	
	TypeList.Count = 0;
	for(i=0; i<256; i++){
		TypeList.dType[i] = 0;
	}
	
	//Load Hw Define Type & Manufacturer Define Type
	TypeList.Count = 0;
	if(LanguageEnCn==0){
		cText = "未";
		for(i=0; i<256; i++){
			if( (StrHwType[i][0] != cText[0]) && (StrHwType[i][1] != cText[1]) ){
				TypeList.dType[TypeList.Count] = i;
				TypeList.Count++;
			}	
		}
	}else{
		cText = "un";
		for(i=0; i<256; i++){
			if( (StrHwTypeEn[i][0] != cText[0]) && (StrHwTypeEn[i][1] != cText[1]) ){
				TypeList.dType[TypeList.Count] = i;
				TypeList.Count++;
			}	
		}
	}
	
	//Load User Define Type
	for(i=0; i<256; i++){
	//	if( (StrHwType[i][0] != cText[0]) && (StrHwType[i][1] != cText[1]) ){
	//		TypeList.dType[TypeList.Count] = i;
	//		TypeList.Count++;
	//	}	
	}
}

void TDesignPrmSet::ReStorage()
{
	int tEntry = Setting.TopEntry;
	for(int i=0; i<4; i++){
		Setting.Count[tEntry] = aPanel->Edit[i].Str.ToInteger();	
		tEntry++;
		if(tEntry >= TypeList.Count)break;
	}
}

void TDesignPrmSet::ReAligne()
{
	for(int i=Setting.TopEntry, Pcnt=0; (i<TypeList.Count) && (Pcnt<4); i++,Pcnt++){
		if(Setting.Using[i]){
			DrawEntryActive(Pcnt, 1);
			DrawEntryTypeString(Pcnt);
		}else{
			DrawEntryActive(Pcnt, 0);
			DrawEntryTypeString(Pcnt);
		}
		aPanel->Edit[Pcnt].Str.FromUInt6Dg(Setting.Count[i]);
		aPanel->Edit[Pcnt].SetPstTail();
		aPanel->Edit[Pcnt].Show();
		aPanel->Edit[Pcnt].ShowCursor();
	}
}

void TDesignPrmSet::Analy()
{
	Setting.UsingTypeCount = 0;
	Setting.EpCount =0;
	for(int i=0; i<TypeList.Count; i++){
		if(Setting.Using[i] != 0){
			Setting.UsingTypeCount++;
			Setting.EpCount += Setting.Count[i]; 
		}
	}
	TextDigitRender3Right24(Lv.Grid.Left[0] +  30, Lv.Grid.Top[0] + 8, clNearWhite, ItemColor, Setting.UsingTypeCount);
	TextDigitRender6Right24(Lv.Grid.Left[0] + 318, Lv.Grid.Top[0] + 8, clNearWhite, ItemColor, Setting.EpCount);
}

void TDesignPrmSet::ExtLoadData()
{
	ExtInf.UsingTypeCount = 0;
	ExtInf.EpCount =0;
	for(int i=0; i<TypeList.Count; i++){
		if(Setting.Using[i] != 0){
			ExtInf.UsingTypeCount++;
			ExtInf.EpCount += Setting.Count[i]; 
		}
	}	
}






























