#include "DateTimeSet.h"
#include "XBox.h"
#include "Runtime.h"
#include "CnCpp.h"



static constexpr short svGridX_Date[4] = {
42, 
100,
160,
600
};

static constexpr short svGridX_Time[4] = {
16, 
64 ,
106 ,
600
}; 

void TDateTimeCfg::Init()
{
	IsShow =0;
	IsEditing = 0;
	OpaState =0;
	SlaveDateTimeHasBeenSet = 0;
	
	Tag.Group = 0;
	Tag.Inx0 = 0;
	Tag.Inx1 = 0;
	
	vtValue[0] = 0;
	vtValue[1] = 0;
	vtValue[2] = 0;
	vtValue[3] = 0;
	vtValue[4] = 0;
	vtValue[5] = 0;
}

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

void TDateTimeCfg::DrawTextFirst()
{
	if(LanguageEnCn==0){
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "本机->日期时间 ");
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +10, clNearWhite,  "日期");
		//TextRender_string24(Lv.Grid.Left[0] + 10+100, Lv.Grid.Top[0] +10, clRed, "注意:更改日期到上次维保事件之前会清除维保事件");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +10, clNearWhite,  "时间");
		TextRender_string24(Lv.Grid.Left[0] +12, Lv.Grid.Top[0] +46, clNearWhite,  "20");
		TextRender_string24(Lv.Grid.Left[0] +72, Lv.Grid.Top[0] +46, clNearWhite,  "年");
		TextRender_string24(Lv.Grid.Left[0] +128, Lv.Grid.Top[0] +46, clNearWhite,  "月");
		TextRender_string24(Lv.Grid.Left[0] +198, Lv.Grid.Top[0] +46, clNearWhite,  "日");
		TextRender_string24(Lv.Grid.Left[1] +46, Lv.Grid.Top[1] +46, clNearWhite,  ":");
		TextRender_string24(Lv.Grid.Left[1] +88, Lv.Grid.Top[1] +46, clNearWhite,  ":");
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 12, 122, 40, 7, clDeepBlue, "网络校时", 14, clNearWhite);
	}else{
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite,  "Local->Date Time");
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +10, clNearWhite,  "Date");
		//TextRender_string24(Lv.Grid.Left[0] + 10+100, Lv.Grid.Top[0] +10, clRed, "注意:更改日期到上次维保事件之前会清除维保事件");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +10, clNearWhite,  "Time");
		TextRender_string24(Lv.Grid.Left[0] +12, Lv.Grid.Top[0] +46, clNearWhite,  "20");
		TextRender_string24(Lv.Grid.Left[0] +72, Lv.Grid.Top[0] +46, clNearWhite,  "YY");
		TextRender_string24(Lv.Grid.Left[0] +128, Lv.Grid.Top[0] +46, clNearWhite,  "MM");
		TextRender_string24(Lv.Grid.Left[0] +198, Lv.Grid.Top[0] +46, clNearWhite,  "DD");
		TextRender_string24(Lv.Grid.Left[1] +46, Lv.Grid.Top[1] +46, clNearWhite,  ":");
		TextRender_string24(Lv.Grid.Left[1] +88, Lv.Grid.Top[1] +46, clNearWhite,  ":");
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 12, 122, 40, 7, clDeepBlue, "Network ", 14, clNearWhite);
	}
}

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

	DrawTextFirst();
	
	if(Tag.Group == 2){
		DrawNwSetDateTime(1);
	}else{
		DrawNwSetDateTime(0);
	}
}

void TDateTimeCfg::Show(void)
{
	RenderBackGround();
	DrawSelf();
	LoadDateTime();
	DrawDateEntry();
	DrawTimeEntry();
	IsShow = 1;
}

void TDateTimeCfg::FullRedraw(int Prm)
{
	if(Prm == 0){
		RenderBackGround();
		DrawSelf();
	}else
	if(Prm == 1){
		RectFillRender(GuiRedrawDataList[1][0], GuiRedrawDataList[1][1], GuiRedrawDataList[1][2], GuiRedrawDataList[1][3], ContentColor);
		DrawSelf();
		DrawDateEntry();
		DrawTimeEntry();
		
		//if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
	}
}

void TDateTimeCfg::DrawNwSetDateTime(int Selected)
{
	if(LanguageEnCn==0){
		if(Selected){
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 12, 122, 40, 7, clDeepBlue, "网络校时", 14, clNearWhite);
		}else{
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 12, 122, 40, 7, clNearWhite, "网络校时", 14, clNearBlack);
		}
	}else{
		if(Selected){
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 12, 122, 40, 7, clDeepBlue, "Network ", 14, clNearWhite);
		}else{
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 12, 122, 40, 7, clNearWhite, "Network ", 14, clNearBlack);
		}
	}
}

void TDateTimeCfg::DrawBoxTimeOutLine()
{
	int aLen, aW;
	unsigned int aClr,aTClr;
	aLen = 4;
	aW = aLen * 12 +12;
	
	if(0){
		aClr = clBlue;
		aTClr = clBlue;
	}else{
		aClr = clGray;
		aTClr = clNearBlack;
	}
	
}

void TDateTimeCfg::LoadDateTime()
{	
	vtValue[0] = DateTime.Date.Split.Year;
	vtValue[1] = DateTime.Date.Split.Month;
	vtValue[2] = DateTime.Date.Split.Day;
	
	vtValue[3] = DateTime.Time.Split.Hour;
	vtValue[4] = DateTime.Time.Split.Minute;
	vtValue[5] = DateTime.Time.Split.Second;
}

void TDateTimeCfg::DrawDateEntry(void)
{
	int i;
	unsigned char aHex0, aHex1;
	
	for(i=0; i<3; i++){
		aHex0 = vtValue[i] / 16 % 10;
		aHex1 = vtValue[i] % 16 % 10;
		vtText[i][0] = aHex0 + '0';
		vtText[i][1] = aHex1 + '0';
		vtText[i][2] = 0;
		if( (Tag.Group == 0) && (i == Tag.Inx0) ){
			vEdit.Init(svGridX_Date[i] -4, Lv.Grid.Top[0] +46 -4, 32, 30, 0,0 ,1, clTeal); 
			vEdit.Color = clTeal;
			vEdit.SetMaxLen(2);
			vEdit.Str.FromStr(vtText[i]);
			vEdit.SetPstTail();
			vEdit.Selected = 1;
			vEdit.Show();
			vEdit.ShowCursor(clNearWhite);			
		}else{
			RectFillRender(svGridX_Date[i] -4, Lv.Grid.Top[0] +46 -4, svGridX_Date[i] + 28, Lv.Grid.Top[0] +46 + 28, ItemColor);
			TextRender_string24(svGridX_Date[i], Lv.Grid.Top[0] +46, clNearWhite, vtText[i]);
			
		}
	}
}

void TDateTimeCfg::ShowSta()
{
	if(IsShow != 1)return ;
	if(LanguageEnCn==0){
		if(OpaState ==0){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "                             ");
		}else
		if(OpaState ==1){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "日期时间配置成功             ");
		}else
		if(OpaState ==2){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "设置各区域机日期时间,完成    ");
		}else
		if(OpaState ==3){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "从集中机获取日期时间         ");
		}else
		if(OpaState ==4){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "从集中机获取日期时间成功     ");
		}else
		if(OpaState ==5){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "无效操作,本机为单机          ");
		}else
		
		
		if(OpaState ==11){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "日期时间配置成功 维保清除成功");
		}else
		if(OpaState ==21){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "日期时间配置成功 维保清除失败");
		}else
		if(OpaState ==14){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "获取日期时间成功 维保清除成功");
		}else
		if(OpaState ==24){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "获取日期时间成功 维保清除失败");
		}
	}else{
		if(OpaState ==0){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "                                                  ");
		}else
		if(OpaState ==1){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "Completed Setting Date Time                       ");
		}else
		if(OpaState ==2){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "Completed Setting Regional                        ");
		}else
		if(OpaState ==3){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "Getting From Master                               ");
		}else
		if(OpaState ==4){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "Completed Getting From Master                     ");
		}else
		if(OpaState ==5){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "No Action,Stand Alone Local                       ");
		}else
		
		
		if(OpaState ==11){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "Completed Setting,Maintenance Record Cleared      ");
		}else
		if(OpaState ==21){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "Completed Setting,Fail To Clrae Maintenance Record");
		}else
		if(OpaState ==14){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "Completed Getting,Maintenance Record Cleared      ");
		}else
		if(OpaState ==24){
			TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +8, clNearWhite, ContentColor, "Completed Getting,Fail To Clrae Maintenance Record");
		}
	}
}

void TDateTimeCfg::ShowSta(unsigned char aSta)
{
	OpaState = aSta;
	if(IsShow){
		ShowSta();
	}
}

void TDateTimeCfg::DrawTimeEntry(void)
{
	int i;
	unsigned char aHex0, aHex1;

	for(i=0; i<3; i++){
		aHex0 = vtValue[i+3] / 16 % 10;
		aHex1 = vtValue[i+3] % 16 % 10;
		vtText[i+3][0] = aHex0 + '0';
		vtText[i+3][1] = aHex1 + '0';
		vtText[i+3][2] = 0;
		if( (Tag.Group == 1) && (i == Tag.Inx1) ){
			vEdit.Init(svGridX_Time[i] -4, Lv.Grid.Top[1] +46 -4, 32, 30, 0,0 ,1, clTeal); 
			vEdit.Color = clTeal;
			vEdit.SetMaxLen(2);
			vEdit.Str.FromStr(vtText[i+3]);
			vEdit.SetPstTail();
			vEdit.Selected = 1;
			vEdit.Show();
			vEdit.ShowCursor(clNearWhite);	
		}else{
			RectFillRender(svGridX_Time[i] -4, Lv.Grid.Top[1] +46 -4, svGridX_Time[i] + 28, Lv.Grid.Top[1] +46 + 28, ItemColor);
			TextRender_string24(svGridX_Time[i], Lv.Grid.Top[1] +46, clNearWhite, vtText[i+3]);
		}
	}
}

void TDateTimeCfg::SetEditStart(void)
{
	int i;
	unsigned char aHex0, aHex1;
	
	IsEditing =1;
	
	if(Tag.Group == 0){
		i = Tag.Inx0;
		
		aHex0 = vtValue[i] / 16 % 10;
		aHex1 = vtValue[i] % 16 % 10;
		vtText[i][0] = aHex0 + '0';
		vtText[i][1] = aHex1 + '0';
		vtText[i][2] = 0;

		vEdit.Init(svGridX_Date[i] -4, Lv.Grid.Top[0] +46 -4, 32, 30, 0,0 ,1, clTeal); 
		vEdit.Color = clTeal;
		vEdit.SetMaxLen(2);
		vEdit.Str.FromStr(vtText[i]);
		vEdit.SetPstTail();
		vEdit.Selected = 1;
		vEdit.Show();
		vEdit.ShowCursor(clNearWhite);			
	}else	
	if( Tag.Group == 1){
		i = Tag.Inx1;
		
		aHex0 = vtValue[i+3] / 16 % 10;
		aHex1 = vtValue[i+3] % 16 % 10;
		vtText[i+3][0] = aHex0 + '0';
		vtText[i+3][1] = aHex1 + '0';
		vtText[i+3][2] = 0;
		
		vEdit.Init(svGridX_Time[i] -4, Lv.Grid.Top[1] +46 -4, 32, 30, 0,0 ,1, clTeal); 
		vEdit.Color = clTeal;
		vEdit.SetMaxLen(2);
		vEdit.Str.FromStr(vtText[i+3]);
		vEdit.SetPstTail();
		vEdit.Selected = 1;
		vEdit.Show();
		vEdit.ShowCursor(clNearWhite);
	}
}

void TDateTimeCfg::RestoreFromEdit(void)
{
	int i;
	if(Tag.Group == 0){
		if(Tag.Inx0 < 3){
			i = Tag.Inx0;
			vtText[i][0] = vEdit.Str.Text[0];
			vtText[i][1] = vEdit.Str.Text[1];
			vtText[i][2] = 0;
			RectFillRender(svGridX_Date[i] -4, Lv.Grid.Top[0] +46 -4, svGridX_Date[i] + 28, Lv.Grid.Top[0] +46 + 28, ItemColor);
			TextRender_string24(svGridX_Date[i], Lv.Grid.Top[0] +46, clNearWhite, vtText[i]);
		}
	}else
	if(Tag.Group == 1){
		if(Tag.Inx1 < 3){
			i = Tag.Inx1;
			vtText[i +3][0] = vEdit.Str.Text[0];
			vtText[i +3][1] = vEdit.Str.Text[1];
			vtText[i +3][2] = 0;
			RectFillRender(svGridX_Time[i] -4, Lv.Grid.Top[1] +46 -4, svGridX_Time[i] + 28, Lv.Grid.Top[1] +46 + 28, ItemColor);
			TextRender_string24(svGridX_Time[i], Lv.Grid.Top[1] +46, clNearWhite, vtText[i+3]);
		}
	}
}

TGuiMsgReturn TDateTimeCfg::KeyIn(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	int NoOpa =1;
	if(Tag.Group == 0){
		if(aKey == VK_LEFT){
			if(Tag.Inx0 <3){
				if(vEdit.Pst <0){
					if(Tag.Inx0 >0){
						RestoreFromEdit();
						Tag.Inx0--;
						SetEditStart();
					}
				}else{
					vEdit.KeyIn(VK_LEFT);
					vEdit.Show();
					vEdit.ShowCursor();
				}
			}
		}else
		if(aKey == VK_RIGHT){
			if(Tag.Inx0 <3){
				if(vEdit.Pst >0){
					if(Tag.Inx0 <2){
						RestoreFromEdit();
						Tag.Inx0++;
						SetEditStart();
					}
				}else{
					vEdit.KeyIn(VK_RIGHT);
					vEdit.Show();
					vEdit.ShowCursor();
				}
			}
		}else
		if(aKey == VK_DOWN){
			RestoreFromEdit();
			Tag.Group =1;
			Tag.Inx1 = Tag.Inx0;
			if(Tag.Inx1 > 2)Tag.Inx1 = 0;		
			SetEditStart();
		}else
		if(aKey == VK_EXECUTE){
			unsigned int tToClear, ClearOk;
			CombDt();
			tToClear = Check4ModifiedDate2ClearLastMaintain(vtValue[0], vtValue[1], vtValue[2]);
			DataTimeSet(vtValue[0], vtValue[1], vtValue[2], vtValue[3], vtValue[4] ,vtValue[5], 1);	//aWk 1..7
			Record.OperateAdd_CfgDateTime(vtValue[0], vtValue[1], vtValue[2], vtValue[3], vtValue[4] ,vtValue[5]);if(MainCtl.fData.Split.NetworkMode == 1){
			if(MainCtl.fData.Split.NetworkMode == 1)
				ProtoC2C.DateTimeSet();
			}
			NoOpa =0;
			if(tToClear == 0){
				ShowSta(1);
			}else{
				LastMaintain.Day = 0x02;
				LastMaintain.Month = 0x01;
				LastMaintain.Year = 0x21;
				LastMaintain.Cent = 0x20;
				ClearOk = Record.WriteLastMaintainTime();
				if(ClearOk == 0){
					//Clear Maintain OK
					ShowSta(11);
				}else{
					//Clear Maintain Fail
					ShowSta(21);
				}
			}
			Check4MaintainToShow();
			StateBarReflashMaintain();
		}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_DELETE:
					vEdit.KeyIn(aKey);
					vEdit.Show();
					vEdit.ShowCursor(clNearWhite);
				break;
			}
		}
	}else
	if(Tag.Group == 1){
		if(aKey == VK_LEFT){
			if(Tag.Inx1 <3){
				if(vEdit.Pst <0){
					if(Tag.Inx1 >0){
						RestoreFromEdit();
						Tag.Inx1--;
						SetEditStart();
					}
				}else{
					vEdit.KeyIn(VK_LEFT);
					vEdit.Show();
					vEdit.ShowCursor();
				}
			}
		}else
		if(aKey == VK_RIGHT){
			if(Tag.Inx1 <3){
				if(vEdit.Pst >0){
					if(Tag.Inx1 <2){
						RestoreFromEdit();
						Tag.Inx1++;
						SetEditStart();
					}
				}else{
					vEdit.KeyIn(VK_RIGHT);
					vEdit.Show();
					vEdit.ShowCursor();
				}
			}
		}else
		if(aKey == VK_UP){
			RestoreFromEdit();
			Tag.Group =0;
			Tag.Inx0 = Tag.Inx1;
			if(Tag.Inx0 > 2)Tag.Inx0 = 0;		
			SetEditStart();
		}else
		if(aKey == VK_DOWN){
			RestoreFromEdit();
			Tag.Group =2;
			DrawNwSetDateTime(1);
		}else
		if(aKey == VK_EXECUTE){
			unsigned int tToClear, ClearOk;
			CombDt();
			tToClear = Check4ModifiedDate2ClearLastMaintain(vtValue[0], vtValue[1], vtValue[2]);
			DataTimeSet(vtValue[0], vtValue[1], vtValue[2], vtValue[3], vtValue[4] ,vtValue[5], 1);	//aWk 1..7
			Record.OperateAdd_CfgDateTime(vtValue[0], vtValue[1], vtValue[2], vtValue[3], vtValue[4] ,vtValue[5]);
			FecStd.TriggerCmd04SyncTime();
			if(MainCtl.fData.Split.NetworkMode == 1){
				ProtoC2C.DateTimeSet();
			}
			NoOpa =0;
			if(tToClear == 0){
				ShowSta(1);
			}else{
				LastMaintain.Day = 0x02;
				LastMaintain.Month = 0x01;
				LastMaintain.Year = 0x21;
				LastMaintain.Cent = 0x20;
				ClearOk = Record.WriteLastMaintainTime();
				if(ClearOk == 0){
					//Clear Maintain OK
					ShowSta(11);
				}else{
					//Clear Maintain Fail
					ShowSta(21);
				}
			}
			Check4MaintainToShow();
			StateBarReflashMaintain();
		}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_DELETE:
					vEdit.KeyIn(aKey);
					vEdit.Show();
					vEdit.ShowCursor(clNearWhite);
				break;
			}
		}
	}else
	if(Tag.Group == 2){
		if(aKey == VK_UP){
			DrawNwSetDateTime(0);
			Tag.Group =1;
			if(Tag.Inx1 > 2)Tag.Inx1 = 0;		
			SetEditStart();
		}else
		if(aKey == VK_EXECUTE){
			//Set DateTime
			if(MainCtl.fData.Split.NetworkMode == 1){
				ProtoC2C.DateTimeSet();
				NoOpa =0;
				ShowSta(2);
			}else
			if(MainCtl.fData.Split.NetworkMode == 2 ){
				//Req DateTime
				ProtoC2C.DateTimeReq();
				SlaveDateTimeHasBeenSet = 0;
				NoOpa =0;
				ShowSta(3);
			}else{
				NoOpa =0;
				ShowSta(5);
			}
		}
	}
	
	if(NoOpa)ShowSta(0);

	if(aKey == VK_RETURN){
		IsShow = 0;
		aMsg = guiMsgReturn;
	}
	return aMsg;
}

void TDateTimeCfg::CombDt()
{
	unsigned char aC, c, aVal, aMonDaysCount;
	if(Tag.Group == 0){
		if(Tag.Inx0 <3){
			vtText[Tag.Inx0][0] = vEdit.Str.Text[0];
			vtText[Tag.Inx0][1] = vEdit.Str.Text[1];
			vtText[Tag.Inx0][2] = 0;
		}
	}else
	if(Tag.Group == 1){
		if(Tag.Inx1 <3){
			vtText[Tag.Inx1 +3][0] = vEdit.Str.Text[0];
			vtText[Tag.Inx1 +3][1] = vEdit.Str.Text[1];
			vtText[Tag.Inx1 +3][2] = 0;
		}
	}
	
	for(c=0; c<6;c++){
		if( (vtText[c][0] < '0') || (vtText[c][0] > '9') ) {
			aVal  = 0;
		}else{
			aVal  = (vtText[c][0] - '0' ) % 10;
		}
		DecVal[c] = aVal * 10;
		aC = aVal << 4;
		if( (vtText[c][1] < '0') || (vtText[c][1] > '9') ){
			aVal =  0;
		}else{
			aVal =  (vtText[c][1] - '0' ) % 10;
		}
		DecVal[c] += aVal;
		vtValue[c] = aC + aVal;
	}
	if(DecVal[0] > 99){
		DecVal[0] = 24; 
		vtValue[0] = 0x24;
	}
	if( (DecVal[1] > 12) || (DecVal[1] == 0) ){
		DecVal[1] = 1;
		vtValue[1] = 1;
	}
	if(DecVal[1] == 2){
		if((DecVal[0] % 4) == 0){
			aMonDaysCount = 29;
		}else{
			aMonDaysCount = 28;
		}
	}else{
		aMonDaysCount = TDateTime::MonthDaysNotLeapYear[DecVal[1] -1];
	}
	if( (DecVal[2] > aMonDaysCount) || (DecVal[2] == 0) ){
		DecVal[2] = 1;
		vtValue[2] = 1;
	}
	if(DecVal[3] > 23){
		DecVal[3] = 0;
		vtValue[3] = 0;
	}
	if(DecVal[4] > 59){
		DecVal[4] = 0;
		vtValue[4] = 0;
	}
	
	if(DecVal[5] > 59){
		DecVal[5] = 0;
		vtValue[5] = 0;
	}
}






