#include "RuntimeData.h"
#include "ProjectSet.h"
#include "DevMask.h"

extern "C"{	
	#include "user_eeprom.h"
}

void TProjectSet::DrawFixText()
{
	if(LanguageEnCn==0){
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "工程->工程信息");
		TextRender_string24(Lv.Grid.Left[0] + 6, Lv.Grid.Top[0] +8, clNearWhite,  "工程名称");
		TextRender_string24(Lv.Grid.Left[1] + 6, Lv.Grid.Top[1] +10, clNearWhite,  "维保提醒");
		TextRender_string24(Lv.Grid.Left[2] + 6, Lv.Grid.Top[2] +10, clNearWhite,  "运行模式");
		TextRender_string24(Lv.Grid.Left[3] + 6, Lv.Grid.Top[3] +10, clNearWhite,  "系统授权");
		TextRender_string24(Lv.Grid.Left[4] + 6, Lv.Grid.Top[4] +10, clNearWhite,  "设计数量");
		TextRender_string24(Lv.Grid.Left[0] + 520, Lv.Grid.Top[0] +8, clNearWhite,  "运行时长:");
		TextDigitRender5Right24(Lv.Grid.Left[0] + 636, Lv.Grid.Top[0] +8, clNearWhite, TimeSecHasRun / 24);
		TextRender_string24(Lv.Grid.Left[0] + 698, Lv.Grid.Top[0] +8, clNearWhite,  "天");
		TextDigitRender2Right24(Lv.Grid.Left[0] + 722, Lv.Grid.Top[0] +8, clNearWhite, TimeSecHasRun % 24);
		TextRender_string24(Lv.Grid.Left[0] + 746, Lv.Grid.Top[0] +8, clNearWhite,  "小时");
	}else{
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "Project->Project Information");	
		TextRender_string24(Lv.Grid.Left[0] + 6, Lv.Grid.Top[0] +8, clNearWhite,   "Project ");
		TextRender_string24(Lv.Grid.Left[1] + 6, Lv.Grid.Top[1] +10, clNearWhite,  "Maintena");
		TextRender_string24(Lv.Grid.Left[2] + 6, Lv.Grid.Top[2] +10, clNearWhite,  "RunMode ");
		TextRender_string24(Lv.Grid.Left[3] + 6, Lv.Grid.Top[3] +10, clNearWhite,  "Mandate ");
		TextRender_string24(Lv.Grid.Left[4] + 6, Lv.Grid.Top[4] +10, clNearWhite,  "Design Num of Terminal Device");		
	}
}

void TProjectSet::Init()
{
	IsExtInput = 1;
	Tag.Reset();
	SubItemActive =0;
	IsPermission = 0;
	IsEditting = 0;
}

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

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

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

void TProjectSet::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);

	DrawFixText();

	
	//TRoundRect::sDrawBySize(Lv.Grid.Left[2] +10, Lv.Grid.Top[0] + 166, 100, 40, 7, clDeepBlue, "保存", 14, clNearWhite);
	vEdit.Init(Lv.Grid.Left[0] +104, Lv.Grid.Top[0] + 2, 400, 32, 0,0,1,ItemColor);
	vEdit.Str.Clear();
	vEdit.MaxLen = 32;
	vEdit.IsShowCursor = 0;
	vEdit.Enable = 1;
	vEdit.Visible = 1; 
}

void TProjectSet::DrawRecoveCnInput()
{
	RectFillRender(aPanel->Bound.Left, aPanel->Bound.Top, aPanel->Bound.Right, aPanel->Bound.Bottom, ContentColor);
	PermissionCmdReturnDraw();
	vEdit.Selected = 1;
	vEdit.Show();
}

void TProjectSet::DrawCaption(void)
{	

}

void TProjectSet::Show()
{
	RenderBackGround();
	DrawSelf();
	LoadCfg();
	ShowInf();
	Check4Selected();
}

void TProjectSet::ShowSta()
{
	if(LanguageEnCn==0){
		if(Sta == 0){
			TextRender_string24(ResultTipPoint.x, ResultTipPoint.y, clNearWhite, ContentColor, "          ");
		}else
		if(Sta == 1){
			TextRender_string24(ResultTipPoint.x, ResultTipPoint.y, clNearWhite, ContentColor, "保存成功  ");
		}else
		if(Sta == -1){
			TextRender_string24(ResultTipPoint.x, ResultTipPoint.y, clNearWhite, ContentColor, "保存失败  ");
		}
	}else{
		if(Sta == 0){
			TextRender_string24(ResultTipPoint.x, ResultTipPoint.y, clNearWhite, ContentColor, "          ");
		}else
		if(Sta == 1){
			TextRender_string24(ResultTipPoint.x, ResultTipPoint.y, clNearWhite, ContentColor, "Save OK   ");
		}else
		if(Sta == -1){
			TextRender_string24(ResultTipPoint.x, ResultTipPoint.y, clNearWhite, ContentColor, "Save Err  ");
		}
	}
}

void TProjectSet::ShowSta(int aSta)
{
	Sta = aSta;
	ShowSta();
}

void TProjectSet::FullRedraw(int Prm)
{
	if(SubItemActive){
		if(SubItemActive == 1){
			Maintain.FullRedraw(Prm);
		}else
		if(SubItemActive == 2){
			RunModeCfg.FullRedraw(Prm);
		}else
		if(SubItemActive == 3){
			DevAuthorize.FullRedraw(Prm);
		}else
		if(SubItemActive == 4){
			DesignPrmSet.FullRedraw(Prm);
		}
	}else{
		if(Prm == 0){
			Show();
			Check4Selected();
		}else
		if(Prm == 1){
			RectFillRender(GuiRedrawDataList[1][0], GuiRedrawDataList[1][1], GuiRedrawDataList[1][2], GuiRedrawDataList[1][3], ContentColor);
			DrawSelf();
			ShowInf();
			Check4Selected();
			
			if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
		}
	}
}

void TProjectSet::PermissionCmdReturnDraw()
{
	RectFillRender(Lv.Grid.Left[1] + 200-10, Lv.Grid.Top[1] + 0, Lv.Grid.Left[1] + 200-10 + 420, Lv.Grid.Top[1] + 0 + 164, ContentColor);
	for(int i=0; i<4; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);

	DrawFixText();
	
	vEdit.Show();
	
	ShowInf();
}

void TProjectSet::PermissionCmdGO()
{
	//Save Data Here
	if(PermissionCmd == 1){
		Write2Eep();
	}else
	if(PermissionCmd == 2){
		vEdit.Selected = 0;
		vEdit.Show();
		InitPanel();
		IsEditting = 1;
		IsExtInput = 1;
	}
}
			

void TProjectSet::ClearSelected(void)
{
	switch(Tag.Inx){
		case 0:
			vEdit.Selected = 0;
			vEdit.Show();
			break;
		case 1:
			RectFillRender(Lv.Grid.Left[1],  Lv.Grid.Top[1],  Lv.Grid.Left[1] + Lv.Grid.Right[1],  Lv.Grid.Top[1] + 3,  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Left[1],  Lv.Grid.Top[1],  Lv.Grid.Left[1] + 3,  Lv.Grid.Bottom[1],  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Right[1] -3,  Lv.Grid.Top[1],  Lv.Grid.Right[1],  Lv.Grid.Bottom[1],  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Left[1],  Lv.Grid.Bottom[1] -3,  Lv.Grid.Right[1],  Lv.Grid.Bottom[1],  ItemColor);   //draw rectangle
			break;
		case 2:
			RectFillRender(Lv.Grid.Left[2],  Lv.Grid.Top[2],  Lv.Grid.Left[2] + Lv.Grid.Right[2],  Lv.Grid.Top[2] + 3,  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Left[2],  Lv.Grid.Top[2],  Lv.Grid.Left[2] + 3,  Lv.Grid.Bottom[2],  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Right[2] -3,  Lv.Grid.Top[2],  Lv.Grid.Right[2],  Lv.Grid.Bottom[2],  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Left[2],  Lv.Grid.Bottom[2] -3,  Lv.Grid.Right[2],  Lv.Grid.Bottom[2],  ItemColor);   //draw rectangle
			break;
		case 3:
			RectFillRender(Lv.Grid.Left[3],  Lv.Grid.Top[3],  Lv.Grid.Left[3] + Lv.Grid.Right[3],  Lv.Grid.Top[3] + 3,  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Left[3],  Lv.Grid.Top[3],  Lv.Grid.Left[3] + 3,  Lv.Grid.Bottom[3],  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Right[3] -3,  Lv.Grid.Top[3],  Lv.Grid.Right[3],  Lv.Grid.Bottom[3],  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Left[3],  Lv.Grid.Bottom[3] -3,  Lv.Grid.Right[3],  Lv.Grid.Bottom[3],  ItemColor);   //draw rectangle
			break;
		case 4:
			RectFillRender(Lv.Grid.Left[4],  Lv.Grid.Top[4],  Lv.Grid.Left[4] + Lv.Grid.Right[4],  Lv.Grid.Top[4] + 3,  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Left[4],  Lv.Grid.Top[4],  Lv.Grid.Left[4] + 3,  Lv.Grid.Bottom[4],  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Right[4] -3,  Lv.Grid.Top[4],  Lv.Grid.Right[4],  Lv.Grid.Bottom[4],  ItemColor);   //draw rectangle
			RectFillRender(Lv.Grid.Left[4],  Lv.Grid.Bottom[4] -3,  Lv.Grid.Right[4],  Lv.Grid.Bottom[4],  ItemColor);   //draw rectangle
			break;
		default:

			break;
	}		
}

void TProjectSet::Check4Selected(void)
{
	unsigned int i;
	vEdit.Selected = 0;

	switch(Tag.Inx){
		case 0:
			vEdit.Selected = 1;
			vEdit.Show();
			break;
		case 1:
			RectFillRender(Lv.Grid.Left[1],  Lv.Grid.Top[1],  Lv.Grid.Left[1] + Lv.Grid.Right[1],  Lv.Grid.Top[1] + 3,  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Left[1],  Lv.Grid.Top[1],  Lv.Grid.Left[1] + 3,  Lv.Grid.Bottom[1],  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Right[1] -3,  Lv.Grid.Top[1],  Lv.Grid.Right[1],  Lv.Grid.Bottom[1],  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Left[1],  Lv.Grid.Bottom[1] -3,  Lv.Grid.Right[1],  Lv.Grid.Bottom[1],  clBlue);   //draw rectangle
			break;
		case 2:
			RectFillRender(Lv.Grid.Left[2],  Lv.Grid.Top[2],  Lv.Grid.Left[2] + Lv.Grid.Right[2],  Lv.Grid.Top[2] + 3,  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Left[2],  Lv.Grid.Top[2],  Lv.Grid.Left[2] + 3,  Lv.Grid.Bottom[2],  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Right[2] -3,  Lv.Grid.Top[2],  Lv.Grid.Right[2],  Lv.Grid.Bottom[2],  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Left[2],  Lv.Grid.Bottom[2] -3,  Lv.Grid.Right[2],  Lv.Grid.Bottom[2],  clBlue);   //draw rectangle
			break;
		case 3:
			RectFillRender(Lv.Grid.Left[3],  Lv.Grid.Top[3],  Lv.Grid.Left[3] + Lv.Grid.Right[3],  Lv.Grid.Top[3] + 3,  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Left[3],  Lv.Grid.Top[3],  Lv.Grid.Left[3] + 3,  Lv.Grid.Bottom[3],  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Right[3] -3,  Lv.Grid.Top[3],  Lv.Grid.Right[3],  Lv.Grid.Bottom[3],  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Left[3],  Lv.Grid.Bottom[3] -3,  Lv.Grid.Right[3],  Lv.Grid.Bottom[3],  clBlue);   //draw rectangle
			break;
		case 4:
			RectFillRender(Lv.Grid.Left[4],  Lv.Grid.Top[4],  Lv.Grid.Left[4] + Lv.Grid.Right[4],  Lv.Grid.Top[4] + 3,  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Left[4],  Lv.Grid.Top[4],  Lv.Grid.Left[4] + 3,  Lv.Grid.Bottom[4],  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Right[4] -3,  Lv.Grid.Top[4],  Lv.Grid.Right[4],  Lv.Grid.Bottom[4],  clBlue);   //draw rectangle
			RectFillRender(Lv.Grid.Left[4],  Lv.Grid.Bottom[4] -3,  Lv.Grid.Right[4],  Lv.Grid.Bottom[4],  clBlue);   //draw rectangle
			break;
		default:

			break;
	}		
}

void TProjectSet::ShowInf(void)
{
	vEdit.Show();
	
	Maintain.ExtLoadData();
	RunModeCfg.ExtLoadData();
	//SysAuthorize
	DesignPrmSet.ExtLoadData();
	
	if(LanguageEnCn==0){
				if(Maintain.ExtLoadSetting.IsCustomTime){
					if(Maintain.ExtLoadSetting.IsHalfYear)TextRender_string24(Lv.Grid.Left[1] + 20, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, "定时维保");
					TMyString::sClear( Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Month[0], Text);
					TMyString::sAddOnStr("月",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Day[0], Text);
					TMyString::sAddOnStr("日  ",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Month[1], Text);
					TMyString::sAddOnStr("月",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Day[1], Text);
					TMyString::sAddOnStr("日  ",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Month[2], Text);
					TMyString::sAddOnStr("月",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Day[2], Text);
					TMyString::sAddOnStr("日  ",Text);
					//TMyString::sFillFixLen(Text, 28);
					TextRender_string24(Lv.Grid.Left[1] + 140, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, Text);
				}else{
					if(Maintain.ExtLoadSetting.IsHalfYear)TextRender_string24(Lv.Grid.Left[1] + 20, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, "半年");
					else TextRender_string24(Lv.Grid.Left[1] + 20, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, "一年");
					//TMyString::sClear( Text);
					//TMyString::sAddOnStr("  ",Text);
					//TMyString::sFillFixLen(Text, 28);
					//TextRender_string24(Lv.Grid.Left[1] + 140, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, Text);
				}

				if(RunState != TRunModeCfg::RunModeAdjust){
					TextRender_string24(Lv.Grid.Left[2] + 20, Lv.Grid.Top[2] + 42, clNearWhite, ItemColor, "正常运行");
				}else{
					TextRender_string24(Lv.Grid.Left[2] + 20, Lv.Grid.Top[2] + 42, clNearWhite, ItemColor, "调试运行");
				}
				
				if(SysAuthorize.fDa.Done){
					TCircle::sRender(Lv.Grid.Left[3] + 24, Lv.Grid.Top[3] +54, 12, clDeepGreen, 1);
					TextRender_string24(Lv.Grid.Left[3] + 46, Lv.Grid.Top[3] +42, clNearWhite,  "系统已授权");
					
					TextRender_string24(Lv.Grid.Left[3] + 186, Lv.Grid.Top[3] +42, clNearWhite,  "                              ");
				}else{
					TCircle::sRender(Lv.Grid.Left[3] + 24, Lv.Grid.Top[3] +54, 12, clRed, 1);
					TextRender_string24(Lv.Grid.Left[3] + 46, Lv.Grid.Top[3] +42, clNearWhite,  "系统未授权");
					
					TextRender_string24(Lv.Grid.Left[3] + 186, Lv.Grid.Top[3] +42, clNearWhite,  "试用截止日期:     年   月   日");
				}
				
				if(MainCtl.fData.Split.NetworkMode == 1){
					TextRender_string24(Lv.Grid.Left[4] + 20, Lv.Grid.Top[4] +42, clNearWhite,  "共   种设备类型.   点位总数      点.    系统总容量      点.");
				}else
				if(MainCtl.fData.Split.NetworkMode == 2){
					TextRender_string24(Lv.Grid.Left[4] + 20, Lv.Grid.Top[4] +42, clNearWhite,  "共   种设备类型.   点位总数      点.    本机为区域机       ");
				}else{
					TextRender_string24(Lv.Grid.Left[4] + 20, Lv.Grid.Top[4] +42, clNearWhite,  "共   种设备类型.   点位总数      点.    本机为单机         ");
				}
	}else{
				if(Maintain.ExtLoadSetting.IsCustomTime){
					if(Maintain.ExtLoadSetting.IsHalfYear)TextRender_string24(Lv.Grid.Left[1] + 20, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, "Regularly");
					TMyString::sClear( Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Month[0], Text);
					TMyString::sAddOnStr("Mon ",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Day[0], Text);
					TMyString::sAddOnStr("Day,  ",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Month[1], Text);
					TMyString::sAddOnStr("Mon ",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Day[1], Text);
					TMyString::sAddOnStr("Day,  ",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Month[2], Text);
					TMyString::sAddOnStr("Mon ",Text);
					TMyString::sAddOn2Dg(Maintain.ExtLoadSetting.Day[2], Text);
					TMyString::sAddOnStr("Day",Text);
					//TMyString::sFillFixLen(Text, 42);
					TextRender_string24(Lv.Grid.Left[1] + 140, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, Text);
				}else{
					if(Maintain.ExtLoadSetting.IsHalfYear)TextRender_string24(Lv.Grid.Left[1] + 20, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, "Half Yesr");
					else TextRender_string24(Lv.Grid.Left[1] + 20, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, "YEAR");
					//TMyString::sClear( Text);
					//TMyString::sAddOnStr("  ",Text);
					//TMyString::sFillFixLen(Text, 28);
					//TextRender_string24(Lv.Grid.Left[1] + 140, Lv.Grid.Top[1] + 42, clNearWhite, ItemColor, Text);
				}

				if(RunState != TRunModeCfg::RunModeAdjust){
					TextRender_string24(Lv.Grid.Left[2] + 20, Lv.Grid.Top[2] + 42, clNearWhite, ItemColor, "Working ");
				}else{
					TextRender_string24(Lv.Grid.Left[2] + 20, Lv.Grid.Top[2] + 42, clNearWhite, ItemColor, "TestMode");
				}
				
				if(SysAuthorize.fDa.Done){
					TCircle::sRender(Lv.Grid.Left[3] + 24, Lv.Grid.Top[3] +54, 12, clDeepGreen, 1);
					TextRender_string24(Lv.Grid.Left[3] + 46, Lv.Grid.Top[3] +42, clNearWhite,  "Authorized");
					
					TextRender_string24(Lv.Grid.Left[3] + 186, Lv.Grid.Top[3] +42, clNearWhite,  "                              ");
				}else{
					TCircle::sRender(Lv.Grid.Left[3] + 24, Lv.Grid.Top[3] +54, 12, clRed, 1);
					TextRender_string24(Lv.Grid.Left[3] + 46, Lv.Grid.Top[3] +42, clNearWhite,  "Unauthoriz");
					
					TextRender_string24(Lv.Grid.Left[3] + 186, Lv.Grid.Top[3] +42, clNearWhite,  "Trial Period:     Y   M   D");
				}
				
				if(MainCtl.fData.Split.NetworkMode == 1){
					TextRender_string24(Lv.Grid.Left[4] + 20, Lv.Grid.Top[4] +42, clNearWhite,  "     Types Of Dev; Devices:      ;    Devs On Sys:         ");
				}else
				if(MainCtl.fData.Split.NetworkMode == 2){
					TextRender_string24(Lv.Grid.Left[4] + 20, Lv.Grid.Top[4] +42, clNearWhite,  "     Types Of Dev; Devices:      ;    Regional             ");
				}else{
					TextRender_string24(Lv.Grid.Left[4] + 20, Lv.Grid.Top[4] +42, clNearWhite,  "     Types Of Dev; Devices:      ;    Stand Alone          ");
				}		
	}
	
	
	ShowDesignedCount();
}

void TProjectSet::InitPanel()
{
	int x,y,x2,y2, aW,aH,i;

	x = 20;
	y = 120;
	x2 = 799;
	y2 = 310;
	aW = x2 - x +1;
	aH = y2 -y +1;
	
	aPanel->Init(x,y,aW,aH,0,0,clMoneyGreen, bvRaised);
	
	aPanel->Caption.Init(1,1,aW-3,32,x,y,clNearWhite,clBlue);
	if(LanguageEnCn==0)aPanel->Caption.SetText("按中/EN键切换输入法,设置键保存更改,返回键放弃更改并返回",24);
	else aPanel->Caption.SetText("'中/EN':switch input method; 'Set':Save",24); 
	aPanel->Caption.Enable = 1;
	aPanel->Caption.Visible = 1;

	aPanel->SText[0].Init(460,40,300,34,x,y,clNearBlack,clMoneyGreen);
	if(LanguageEnCn==0)TMyString::sFromStr(	"请根据以下输入法提示输入", aPanel->SText[0].Text);
	else TMyString::sFromStr(			"According To The Prompts", aPanel->SText[0].Text);
	aPanel->SText[0].Enable = 1;
	aPanel->SText[0].Visible = 1;
	
	aPanel->Edit[ 0].Init(10,40,420,30,x,y,1,clNearBlack);
	aPanel->Edit[ 0].Str.FromStr(vEdit.Str.Text);
	
	for(i=0; i<1;i++){
		aPanel->Edit[i].Enable = 1;
		aPanel->Edit[i].Visible = 1;
		aPanel->Edit[i].SetMaxLen(32);
		aPanel->Edit[i].SetPstTail();
		aPanel->Edit[i].Selected = 1;
	}
	
	aPanel->Show();
	aPanel->Caption.Show();
	aPanel->SText[0].Show();
	aPanel->Edit[0].Show();
	aPanel->Edit[0].ShowCursor();
	
	IsExtInput = 1;
	CnInput.Init(aPanel->Bound.Left + 10, aPanel->Bound.Top +80, 760, 90, 0, 0, clGray);
	CnInput.Show();
	if(LanguageEnCn==0)TMyString::sFromStr(	"请根据以下输入法提示输入", aPanel->SText[0].Text);
	else TMyString::sFromStr(			"According To The Prompts", aPanel->SText[0].Text); 
	aPanel->SText[0].Show();
}

TGuiMsgReturn TProjectSet::KeyIn(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	int i;
	const char *p;
	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{
		if(SubItemActive){
			TGuiMsgReturn SubReturnMsg;
			SubReturnMsg = guiMsgNone;
			if(SubItemActive == 1){
				SubReturnMsg = Maintain.KeyIn(aKey);
			}else
			if(SubItemActive == 2){
				SubReturnMsg = RunModeCfg.KeyIn(aKey);
			}else
			if(SubItemActive == 3){
				SubReturnMsg = DevAuthorize.KeyIn(aKey);
			}else
			if(SubItemActive == 4){
				SubReturnMsg = DesignPrmSet.KeyIn(aKey);
			}
			
			if(SubReturnMsg == guiMsgReturn){
				SubItemActive = 0;
				Show();
			}
			return aMsg;
		}
		
		if(IsEditting){
			if(aKey == dfKEY_SETUP){
				TMyString::sFromStr(aPanel->Edit[0].Str.Text, vEdit.Str.Text);
				TMyString::sBrokeFixLen(vEdit.Str.Text, 32);
				DrawRecoveCnInput();
				IsEditting = 0;
			}else
			if(aKey == dfKEY_ENCN){
				CnInput.KeyIn(aKey);
				if(0){
					IsExtInput = 0;
					CnInput.OverPrint(this->aPanel->Color);
					aPanel->Show();
					aPanel->Caption.Show();
					aPanel->SText[0].Show();
					aPanel->Edit[0].Show();
					aPanel->Edit[0].ShowCursor();
					if(LanguageEnCn==0)TMyString::sFromStr("当前快捷输入数字", aPanel->SText[0].Text);
					else TMyString::sFromStr("Enter 0..9", aPanel->SText[0].Text);
					aPanel->SText[0].Show();
				}
			}else
			if(aKey == VK_RETURN){
				//Just return
				DrawRecoveCnInput();
				ShowInf();
				IsEditting = 0;
			}else{
				if(  (aKey == VK_DELETE)  &&  (CnInput.sEdit.Pst == -1) ){
					aPanel->Edit[0].KeyIn(aKey);
					aPanel->Edit[0].Show();
					aPanel->Edit[0].ShowCursor();
				}else{
					p = CnInput.KeyIn(aKey);
					if(p != nullptr){
						if(CnInput.GotChar[0] != '\0'){
							aPanel->Edit[0].Pst = aPanel->Edit[0].Str.Insert(CnInput.GotChar, aPanel->Edit[0].Pst);
							aPanel->Edit[0].Str.BrokeFixLen(32);
							aPanel->Edit[0].CorrectPst();
							aPanel->Edit[0].Show();
						}
					}
				}
			}
		}else{
			switch(aKey){
				/*case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
				case VK_LEFT:
				case VK_RIGHT:
				case VK_DELETE:
					if(Tag.Inx == 0){
						vEdit.KeyIn(aKey);
						vEdit.Str.BrokeFixLen(32);
						vEdit.CorrectPst();
						vEdit.Show();
					}
					break;*/
				case VK_UP:
					if(Tag.Inx >0){
						ClearSelected();
						Tag.Inx--;
						Check4Selected();
					}
					break;
				case VK_DOWN:
					if(Tag.Inx <4){
						ClearSelected();
						Tag.Inx++;
						Check4Selected();
					}
					break;
				case dfKEY_SETUP:
					if(Tag.Inx == 0){
						PermissionCmd =2;
						if(SystemPermission > 2){
							PermissionCmdGO();
						}else{
							IsPermission = 1;
							PmsIntervene4Gui.Show4Gui(Lv.Grid.Left[1] + 200, Lv.Grid.Top[1] + 12, 400, 140, 3);
						}
					}
					break;
				case VK_TAB:

					break;
				case VK_EXECUTE:
					if(Tag.Inx == 0){
						PermissionCmd =1;
						if(SystemPermission > 2){
							PermissionCmdGO();
						}else{
							IsPermission = 1;
							PmsIntervene4Gui.Show4Gui(Lv.Grid.Left[1] + 200, Lv.Grid.Top[1] + 12, 400, 140, 3);
						}
					}else{
						if(Tag.Inx == 1){
							SubItemActive = 1;
							Maintain.Init() ;
							Maintain.aPanel = &CommonPanel;
							Maintain.InitPanel();
							Maintain.Show();
							Maintain.LoadData();
						}else
						if(Tag.Inx == 2){
							SubItemActive = 2;
							RunModeCfg.Init() ;
							RunModeCfg.aPanel = &CommonPanel;
							RunModeCfg.InitPanel();
							RunModeCfg.Show();
							RunModeCfg.LoadData();
						}else
						if(Tag.Inx == 3){
							SubItemActive = 3;
							DevAuthorize.Init() ;
							DevAuthorize.aPanel = &CommonPanel;
							DevAuthorize.Show();
							DevAuthorize.InitPanel();
							DevAuthorize.LoadData();
						}else
						if(Tag.Inx == 4){
							SubItemActive = 4;
							DesignPrmSet.Init() ;
							DesignPrmSet.IconList = &ImageList;
							DesignPrmSet.aPanel = &CommonPanel;
							DesignPrmSet.LoadBaseTypeList();
							DesignPrmSet.Show();
							DesignPrmSet.InitPanel();
						}	
					}
					break;
				case VK_RETURN:
					aMsg = guiMsgReturn;
					break;
			}
		}
		if(VK_EXECUTE != aKey){
			ShowSta(0);
		}
	}	
	return aMsg;	
}

void TProjectSet::LoadCfg()
{
	unsigned int aAddr;
	int i;
	//Read ExistTable 
	aAddr = dEepAddrProjectName;
	sDelayMs(10);
	eeprom_read_byte(0, aAddr, PrjName, 32);
	PrjName[32] = '\0';
	PrjName[33] = '\0';
	
	if( (PrjName[0] == 0xFF) && (PrjName[1] == 0xFF) ){
		PrjName[0] = '\0';
		PrjName[1] = '\0';
	}
	
	for(i=0; i<32; i++){
		vEdit.Str.Text[i] = PrjName[i];
	}
	vEdit.Str.Text[32] = '\0';
	vEdit.Str.Text[33] = '\0';
	
	vEdit.SetPstTail();
}

void TProjectSet::Write2Eep()
{
	unsigned int aAddr;
	volatile unsigned int aWait;
	volatile unsigned int NotEqual;
	int i;
	//Read ExistTable 
	for(i=0; i<32; i++){
		PrjName[i] = vEdit.Str.Text[i];
	}
	PrjName[32] = '\0';
	PrjName[33] = '\0';
	
	aAddr = dEepAddrProjectName;
	sDelayMs(20);
	eeprom_write_byte_via_page(0, aAddr, PrjName, 32);
	
	sDelayMs(20);
	aAddr = dEepAddrProjectName;
	eeprom_read_byte(0, aAddr, PrjName, 32);	
	vEdit.Show();
	
	NotEqual = 0;
	for(int x=0; x<32; x++){
		if(PrjName[x] != vEdit.Str.Text[x]){
			NotEqual = 1;
			break;
		}			
	}
	
	if(NotEqual){
		ShowSta(-1);
	}else{
		ShowSta(1);
	}
}

void TProjectSet::ShowDesignedCount()
{
	pDpt->ReadData();
	pDpt->LoadBaseTypeList();
	pDpt->LoadData2RuntimeData();
	pDpt->ExtLoadData();
	
	//TextRender_string24(Lv.Grid.Left[4] + 20, Lv.Grid.Top[4] +42, clNearWhite,  "共   种设备类型.   点位总数      点.    系统总容量      点.");
	TextDigitRender3Right24(Lv.Grid.Left[4] +  44, Lv.Grid.Top[4] + 42, clNearWhite, ItemColor, pDpt->ExtInf.UsingTypeCount % 1000);
	TextDigitRender6Right24(Lv.Grid.Left[4] + 344, Lv.Grid.Top[4] + 42, clNearWhite, ItemColor, pDpt->ExtInf.EpCount % 1000000);
}

void TProjectSet::sRecoverSetDefault()
{
	unsigned int aAddr;
	int i;
	//Read ExistTable 
	for(i=0; i<32; i++){
		PrjName[i] = '\0';
	}
	PrjName[32] = '\0';
	PrjName[33] = '\0';
	
	aAddr = dEepAddrProjectName;
	sDelayMs(20);
	eeprom_write_byte_via_page(0, aAddr, PrjName, 32);
	
	sDelayMs(20);
	aAddr = dEepAddrProjectName;
	eeprom_read_byte(0, aAddr, PrjName, 32);		
}












