#include "UserCodeSetByArea.h"
#include "Runtime.h"

extern "C"{
	#include "user_norflash.h"
	#include "user_eeprom.h"
	#include "uart_key_drv.h"
	#include "HW_config.h"
}

//#define dFlash4AreaChip			(0)
//#define dFlash4Area			(0x00BB'0000)

#define dWdClr		clSkyBlue
#define dWdDisabelClr	clNearWhite
#define dWdInvalidClr	clSilver

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

const int xInc = 84;
const int xDec = 180;
const int xRecover = 146;
const int xAvoid = 246;
const int xModify = 84;
const int xSave = 180;
const int xType = 360;

static const char CharBcdText[20]= {"0123456789*------\0"};

void TUserCodeSetByArea::Init()
{
	IsPermission =0;
	
	CtlIndex = 0;
	IsShow = 0;
	ListPage = 0;
	
	AreaNum =0;
	dType =0;
	
	AreaValid =1;
	dTypeValid =1;
	
	IsRecover = 0;
	IncDec = 0;
	Sta =0;
}

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

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

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

void TUserCodeSetByArea::DrawFixText()
{
	if(LanguageEnCn==0){
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite, CaptionColor, "联动->二次码编辑");
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +6, clNearWhite, "分区号");
		TextRender_string24(Lv.Grid.Left[0] + 186, Lv.Grid.Top[0] +6, clNearWhite, "机器号");
		TextRender_string24(Lv.Grid.Left[0] + 286, Lv.Grid.Top[0] +6, clNearWhite, "本机");
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +44, clNearWhite, "二次码覆盖:");
		TextRender_string24(xRecover +30, Lv.Grid.Top[0] +44, clNearWhite, "覆盖");
		TextRender_string24(xAvoid +30, Lv.Grid.Top[0] +44, clNearWhite, "绕过");
		TextRender_string24(xType, Lv.Grid.Top[0] +44, clNearWhite, "指定类型");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "简称");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +40, clNearWhite, "描述");
		TextRender_string24(Lv.Grid.Left[2] + 10, Lv.Grid.Top[2] +6, clNearWhite, "新二次码");
		TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +6, clNearWhite, "模式");
		TextRender_string24(Lv.Grid.Left[3] + xInc +30, Lv.Grid.Top[3] +8, clNearWhite, "递增");
		//TextRender_string24(Lv.Grid.Left[3] + xDec +30, Lv.Grid.Top[3] +8, clNearWhite, "递减");
		TextRender_string24(Lv.Grid.Left[4] + 10, Lv.Grid.Top[4] +6, clNearWhite, "操作");
		TRoundRect::sDrawBySize(xModify, 	Lv.Grid.Top[4] + 6, 76, 30, 7, clNearWhite, "确认", 14, clNearBlack);
		TRoundRect::sDrawBySize(xSave, 	Lv.Grid.Top[4] + 6, 76, 30, 7, clNearWhite, "保存", 14, clNearBlack);
	}else{
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite, CaptionColor, "Linkage->Aux ID Editting By Zone");
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +6, clNearWhite, "Zone");
		TextRender_string24(Lv.Grid.Left[0] + 186, Lv.Grid.Top[0] +6, clNearWhite, "CtlID");
		TextRender_string24(Lv.Grid.Left[0] + 286, Lv.Grid.Top[0] +6, clNearWhite, " Local");
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +44, clNearWhite, "Apply Mode");
		TextRender_string24(xRecover +30, Lv.Grid.Top[0] +44, clNearWhite, "Cover");
		TextRender_string24(xAvoid +30, Lv.Grid.Top[0] +44, clNearWhite, "Avoid");
		TextRender_string24(xType, Lv.Grid.Top[0] +44, clNearWhite, " Assign");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "Brie");
		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +40, clNearWhite, "Desc");
		TextRender_string24(Lv.Grid.Left[2] + 10, Lv.Grid.Top[2] +6, clNearWhite, "New Aux ID");
		TextRender_string24(Lv.Grid.Left[3] + 10, Lv.Grid.Top[3] +6, clNearWhite, "Mode");
		TextRender_string24(Lv.Grid.Left[3] + xInc +30, Lv.Grid.Top[3] +8, clNearWhite, "Inc ");
		//TextRender_string24(Lv.Grid.Left[3] + xDec +30, Lv.Grid.Top[3] +8, clNearWhite, "Dec ");
		TextRender_string24(Lv.Grid.Left[4] + 10, Lv.Grid.Top[4] +6, clNearWhite, "Opera");
		TRoundRect::sDrawBySize(xModify, 	Lv.Grid.Top[4] + 6, 76, 30, 7, clNearWhite, "View", 14, clNearBlack);
		TRoundRect::sDrawBySize(xSave, 	Lv.Grid.Top[4] + 6, 76, 30, 7, clNearWhite, "Save", 14, clNearBlack);
	}
}

void TUserCodeSetByArea::DrawSelf(void)
{
	RenderBackGround();
	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);
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);

	TextDigitRender2_24(Lv.Grid.Left[0] + 260, Lv.Grid.Top[0] +6, clNearWhite, MainCtl.fData.Split.MyNum);
	
	DrawFixText();
	
	IList->STextDType.Init(xType + 96 + 48 +4,  Lv.Grid.Top[0] +40, 286, 32, 0,0, clNearWhite, ItemColor);
	IList->STextDType.TextClear();
	IList->STextDType.Visible = 1;
	
	//Area Num
	IList->EditAreaAssign.Init(Lv.Grid.Left[0] + 86, Lv.Grid.Top[0] +4, 60, 30, 0,0,1,clNearWhite);
	IList->EditAreaAssign.Str.Clear();
	IList->EditAreaAssign.SetText("0001",24);	
	IList->EditAreaAssign.SetPstTail();
	IList->EditAreaAssign.SetMaxLen(4);
	IList->EditAreaAssign.Enable =1;
	
	//Assign Type
	IList->EditCtlNum.Init(xType + 96, Lv.Grid.Top[0] +40, 48, 30, 0,0,1,clNearWhite);
	IList->EditCtlNum.Str.Clear();
	IList->EditCtlNum.Str.FromStr("000");
	IList->EditCtlNum.SetMaxLen(3);
	IList->EditCtlNum.Enable =1;
	
	//Short Name
	IList->Edit[0].Init(Lv.Grid.Left[1] + 60, Lv.Grid.Top[1] +4, 		226, 30, 0,0,1,clNearWhite);
	IList->Edit[0].Str.Clear();
	IList->Edit[0].Enable =0;
	
	//Descp
	mlEdit.Init(Lv.Grid.Left[1] +60, Lv.Grid.Top[1] +36, 				226, 64, 0,0,1,clNearWhite);
	mlEdit.SetLineSpacing(4);
	mlEdit.Str.Clear();
	mlEdit.Enable =0;
	
	//New UserCode
	IList->EditUserCode.Init(Lv.Grid.Left[2] + 176, Lv.Grid.Top[2] +4, 		110, 30, 0,0,1,clNearWhite);
	IList->EditUserCode.SetMaxLen(8);
	IList->EditUserCode.Str.Clear();
	IList->EditUserCode.Enable =1;
	
	IList->EditCtlNum.Str.FromUInt3Dg(dType);
	IList->Edit[0].SetPstTail();
	IList->EditCtlNum.SetPstTail();
	
	IList->STextDType.Show();
	IList->Edit[0].Show();
	mlEdit.Show();
	
	IList->EditAreaAssign.Show();
	IList->EditCtlNum.Show();
	IList->EditUserCode.Show();
	
	DrawAssignTypeText();
	DrawRecover();
	DrawIncDec();
	
	LoadData();
	
	Check4Selected();
}

void TUserCodeSetByArea::Show(void)
{	
	IsShow = 1;
	RenderBackGround();
	DrawSelf();
}

void TUserCodeSetByArea::DrawRecover()
{
	if(IsRecover==0){
		TRoundSquare::sDrawBySize(xRecover, Lv.Grid.Top[0] + 44, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(xAvoid, Lv.Grid.Top[0] + 44, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
	}else{
		TRoundSquare::sDrawBySize(xRecover, Lv.Grid.Top[0] + 44, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		TRoundSquare::sDrawBySize(xAvoid, Lv.Grid.Top[0] + 44, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
	}	
}

void TUserCodeSetByArea::DrawIncDec()
{
	if(IncDec==0){
		TRoundSquare::sDrawBySize(xInc, Lv.Grid.Top[3] + 8, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		//TRoundSquare::sDrawBySize(xDec, Lv.Grid.Top[3] + 8, dWWidth, dWHeigh, dRoundR, dWdInvalidClr , 0);
	}else{
		TRoundSquare::sDrawBySize(xInc, Lv.Grid.Top[3] + 8, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		//TRoundSquare::sDrawBySize(xDec, Lv.Grid.Top[3] + 8, dWWidth, dWHeigh, dRoundR, dWdInvalidClr , 1);
	}
}

void TUserCodeSetByArea::FullRedraw(int Prm)
{	
	if(Prm == 0){
		RenderBackGround();
		DrawSelf();
		DrawWriteSta();
	}else
	if(Prm == 1){
		RectFillRender(GuiRedrawDataList[1][0], GuiRedrawDataList[1][1], GuiRedrawDataList[1][2], GuiRedrawDataList[1][3], ContentColor);
		for(int i=0; i<2; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
		if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
		TextDigitRender2_24(Lv.Grid.Left[0] + 260, Lv.Grid.Top[0] +6, clNearWhite, MainCtl.fData.Split.MyNum);
		DrawFixText();
		DrawRecover();
		IList->STextDType.Show();
		IList->EditAreaAssign.Show();
		IList->EditCtlNum.Show();
		IList->Edit[0].Show();
		mlEdit.Show();
		Check4Selected();
		if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
	}
}

//______________________________________________________________________________________________________________________________
void TUserCodeSetByArea::ClearSelected(void)
{
	char *tText;
	switch(CtlIndex){
		case 0:
			IList->EditAreaAssign.Selected =0;
			IList->EditAreaAssign.Show();
			break;
		case 1:
			TRoundSquare::sSelected(xRecover, Lv.Grid.Top[0]+44, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 2:
			TRoundSquare::sSelected(xAvoid, Lv.Grid.Top[0]+44, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 3:
			IList->EditCtlNum.Selected =0;
			IList->EditCtlNum.Show();
			break;
		case 4:
			IList->EditUserCode.Selected =0;
			IList->EditUserCode.Show();
			break;
		case 5:
			TRoundSquare::sSelected(xInc, Lv.Grid.Top[3]+8, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 6:
			TRoundSquare::sSelected(xDec, Lv.Grid.Top[3]+8, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 7:
			if(LanguageEnCn==0)tText="确定";else tText="View";
			TRoundRect::sDrawBySize(xModify, 	Lv.Grid.Top[4] + 6, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
		case 8:
			if(LanguageEnCn==0)tText="保存";else tText="Save";
			TRoundRect::sDrawBySize(xSave, 	Lv.Grid.Top[4] + 6, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
		default:

			break;
	}	
}

void TUserCodeSetByArea::Check4Selected(void)
{
	char *tText;
	switch(CtlIndex){
		case 0:
			IList->EditAreaAssign.Selected =1;
			IList->EditAreaAssign.SetPstTail();
			IList->EditAreaAssign.Show();
			break;
		case 1:
			TRoundSquare::sSelected(xRecover, Lv.Grid.Top[0]+44, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 2:
			TRoundSquare::sSelected(xAvoid, Lv.Grid.Top[0]+44, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 3:
			IList->EditCtlNum.Selected =1;
			IList->EditCtlNum.SetPstTail();
			IList->EditCtlNum.Show();
			break;
		case 4:
			IList->EditUserCode.Selected =1;
			IList->EditUserCode.SetPstTail();
			IList->EditUserCode.Show();
			break;
		case 5:
			TRoundSquare::sSelected(xInc, Lv.Grid.Top[3]+8, dWWidth, dWHeigh, 4, clNearWhite);
			//sDrawBySize(int x, int y, int aW, int aH, int RoundR, u32 aClr, int Active);
			break;
		case 6:
			TRoundSquare::sSelected(xDec, Lv.Grid.Top[3]+8, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 7:
			if(LanguageEnCn==0)tText="确定";else tText="View";
			TRoundRect::sDrawBySize(xModify, 	Lv.Grid.Top[4] + 6, 76, 30, 7, clBlue, tText, 14, clNearWhite);
			break;
		case 8:
			if(LanguageEnCn==0)tText="保存";else tText="Save";
			TRoundRect::sDrawBySize(xSave, 	Lv.Grid.Top[4] + 6, 76, 30, 7, clBlue, tText, 14, clNearWhite);
			break;
		default:

			break;
	}	
}

void TUserCodeSetByArea::PermissionCmdGO()
{
	int aResult;
	if(PermissionCmd == 1){
		aResult = Write();
		Record.ReadDevUserSet();
		Record.ReadDirectPadUserSet();
		if(aResult > 0){
			DrawWriteSta(aResult);
		}else{
			DrawWriteSta(aResult);
		}
		Check4Selected();
	}
}

void TUserCodeSetByArea::PermissionCmdReturnDraw()
{
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
}

//_____________________________________________________________________________________________________________________________
TGuiMsgReturn TUserCodeSetByArea::KeyIn(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	TGuiMsgReturn PmsRtnMsg = guiMsgNone;
	int iVal;
	int HadPrc;

	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 '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:
				HadPrc =0;
				if( (aKey == VK_LEFT) || (aKey == VK_RIGHT) ){
					if(CtlIndex == 1){
						if(aKey == VK_RIGHT){
							ClearSelected();
							CtlIndex++;
							Check4Selected();
							HadPrc =1;
					}
					}else
					if(CtlIndex == 2){
						if(aKey == VK_LEFT){
							ClearSelected();
							CtlIndex--;
							Check4Selected();
							HadPrc =1;
						}else
						if(aKey == VK_RIGHT){
							ClearSelected();
							CtlIndex++;
							Check4Selected();
							HadPrc =1;
						}
					}else
					if(CtlIndex == 3){
						if(aKey == VK_LEFT){
							if(IList->EditCtlNum.Pst <0){
								ClearSelected();
								CtlIndex--;
								Check4Selected();
								HadPrc =1;
							}
						}
					}else
					if(CtlIndex == 5){
						if(aKey == VK_RIGHT){
							ClearSelected();
							CtlIndex++;
							Check4Selected();
							HadPrc =1;
						}
					}else
					if(CtlIndex == 6){
						if(aKey == VK_LEFT){
							ClearSelected();
							CtlIndex--;
							Check4Selected();
							HadPrc =1;
						}
					}else
					if(CtlIndex == 7){
						if(aKey == VK_RIGHT){
							ClearSelected();
							CtlIndex++;
							Check4Selected();
							HadPrc =1;
						}
					}else
					if(CtlIndex == 8){
						if(aKey == VK_LEFT){
							ClearSelected();
							CtlIndex--;
							Check4Selected();
							HadPrc =1;
						}
					}
				}
				if(HadPrc == 0){
					if(CtlIndex == 0){
						IList->EditAreaAssign.KeyIn(aKey);
						int iVal;
						iVal = IList->EditAreaAssign.Str.ToInteger();
						if( (iVal <1) || (iVal > dAreaCountMax) ){
							AreaValid =0;
							IList->EditAreaAssign.SelectedColor = clRed;
						}else{
							AreaValid =1;
							IList->EditAreaAssign.SelectedColor = clBlue;
							iVal--;
							if(iVal != AreaNum){
								AreaNum = iVal;
								LoadData();
							}
						}
						IList->EditAreaAssign.Show();
					}else
					if(CtlIndex == 3){
						IList->EditCtlNum.KeyIn(aKey);
						int iVal;
						iVal = IList->EditCtlNum.Str.ToInteger();
						if( (iVal <0) || (iVal > 255) ){
							dTypeValid =0;
							IList->EditCtlNum.SelectedColor = clRed;
						}else{
							dTypeValid =1;
							IList->EditCtlNum.SelectedColor = clBlue;
							if(iVal != dType){
								dType = iVal;
							}
						}
						IList->EditCtlNum.Show();
						DrawAssignTypeText();
					}else
					if(CtlIndex == 4){
						IList->EditUserCode.KeyIn(aKey);
						IList->EditUserCode.Show();
					}
				}
				break;
			case dfKEY_ASTERISK:
				if(CtlIndex == 4){
					IList->EditUserCode.KeyIn(aKey);
					IList->EditUserCode.Show();
				}
				break;
			case VK_UP:
				if(CtlIndex >0){
					if( dTypeValid && AreaValid ){
						ClearSelected();
						CtlIndex--;
						if( (CtlIndex == 5) || (CtlIndex == 6) ){
							CtlIndex = 4;
						}
						Check4Selected();
					}
				}else{
					if( AreaValid && dTypeValid ){
						ClearSelected();
						CtlIndex =8;
						Check4Selected();
					}
				}
				break;
			case VK_DOWN:
				if(CtlIndex <8){
					if( AreaValid && dTypeValid ){
						ClearSelected();
						CtlIndex++;
						if( (CtlIndex == 5) || (CtlIndex == 6) ){
							CtlIndex = 7;
						}
						Check4Selected();
					}
				}else{
					ClearSelected();
					CtlIndex=0;
					Check4Selected();
				}
				break;
			case VK_TAB:
				//IsList = 1;
				//DrawList();
				//ClearSelected();
				break;				
			case dfKEY_SETUP:		//0x70		//  Key value for SETUP
				if( (CtlIndex == 1) || (CtlIndex == 2) ){
					IsRecover = IsRecover ? 0 :1;
					DrawRecover();
				}else
				if( (CtlIndex == 5) || (CtlIndex == 6) ){
					//IncDec = IncDec ? 0 :1;
					IncDec =0;
					DrawIncDec();
				}
				break;
			case VK_EXECUTE:
				if( (CtlIndex == 1) || (CtlIndex == 2) ){
					IsRecover = IsRecover ? 0 :1;
					DrawRecover();
				}else
				if( (CtlIndex == 5) || (CtlIndex == 6) ){
					//IncDec = IncDec ? 0 :1;
					IncDec =0;
					DrawIncDec();
				}else
				if(CtlIndex == 7){
					if(IsShowwingDetail){
						DrawDetailGoOn();
					}else{
						DrawDetailStart();
					}
				}else
				if(CtlIndex == 8){
					//Save Data Here
					PermissionCmd = 1;
					if(SystemPermission > 2){
						PermissionCmdGO();
					}else{
						IsPermission = 1;
						ClearSelected();
						PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -36 , 140, 3);
					}
				}
				break;
			case VK_RETURN:
				aMsg = guiMsgReturn;
				break;
			default :
				break;
		}
		
		if(VK_EXECUTE != aKey){
			IsShowwingDetail = 0;
			DrawWriteSta(0);
		}
	}
	
	return aMsg;	
}

void TUserCodeSetByArea::DrawAssignTypeText()
{	
	if(dTypeValid == 0){
		IList->STextDType.SetText("--------" ,24);
	}else{
		if(LanguageEnCn==0){
			if( dType ){
				IList->STextDType.SetText(StrTypeShortName[dType] ,24);
			}else{
				IList->STextDType.SetText("所有类型" ,24);
			}
		}else{
			if( dType ){
				IList->STextDType.SetText(StrTypeShortNameEn[dType] ,24);
			}else{
				IList->STextDType.SetText("All Types" ,24);
			}
		}
	}
	IList->STextDType.Show();
}

void TUserCodeSetByArea::LoadAUserCode()
{
	int i,x, Got =0;
	unsigned int tUc;
	for(i=0; i<dPORT_MAX_COUNT; i++){
		if(Got)break;
		for(x=0; x<dEP_MAX_COUNT_PER_PORT; x++){
			if(Port[i].UcList[x].Full != 0){
				Got =1;
				tUc = Port[i].UcList[x].Full;
				break;
			}
		}
	}
	for(i=0; i<dDIRECTCTL_MAX_COUNT; i++){
		if(Got)break;
		for(x=0; x<dDIRECTCTL_KEY_MAX_COUNT; x++){
			if(DirectCtlBoard[i].UcList[x].Full != 0){
				Got =1;
				tUc = DirectCtlBoard[i].UcList[x].Full;
				break;
			}
		}
	}
	
	if(Got){
		IList->EditUserCode.Str.FromUInt8Dg(tUc);
	}else{
		IList->EditUserCode.Str.FromStr("00000000");
	}
	IList->EditUserCode.Show();
}

void TUserCodeSetByArea::LoadShortName()
{
	unsigned int Idf, sAddr;

	if(AreaNum >= dAreaCountMax ){
		IList->Edit[0].Str.FromStr("------");
		IList->Edit[0].Show();
		return;
	}
	
	sAddr = dAddrSdRam_4Area + (AreaNum * 64);
	Idf = *(volatile unsigned int *)(sAddr);
	if(Idf == 0xA8A7A6A5){
		sAddr = dAddrSdRam_4Area + (AreaNum * 64) + 16;
		for(int i=0; i<16; i++){
			IList->Edit[0].Str.Text[i] = *(volatile unsigned char *)(sAddr +i);
		}
		IList->Edit[0].Str.Text[16] = '\0';
	}else{
		IList->Edit[0].Str.FromStr("------");
	}
	IList->Edit[0].Show();
}

void TUserCodeSetByArea::LoadDescp()
{
	unsigned int Idf, sAddr;
	
	if(AreaNum >= dAreaCountMax ){
		mlEdit.Str.FromStr("----");
		mlEdit.Show();
		return;
	}
	
	sAddr = dAddrSdRam_4Area + (AreaNum * 64);
	Idf = *(volatile unsigned int *)(sAddr);
	if(Idf == 0xA8A7A6A5){
		sAddr = dAddrSdRam_4Area + (AreaNum * 64) + 32;
		for(int i=0; i<32; i++){
			 mlEdit.Str.Text[i] = *(volatile unsigned char *)(sAddr +i);;
		}
		mlEdit.Str.Text[32] = '\0';
	}else{
		mlEdit.Str.FromStr("----");
	}	
	
	mlEdit.Show();
}

void TUserCodeSetByArea::LoadData()
{
	LoadAUserCode();
	LoadShortName();
	LoadDescp();
}

int TUserCodeSetByArea::DrawDetailStart()
{
	int x,y, Pst;
	char tText[16];
	unsigned int tUc, HadGotAsFinished;
	unsigned short AreaNumCmp;
	int AstStartPoint, AstEndPoint, AstLength, InputLength, Step;
	x = Lv.Panel.Left +4;
	y = Lv.Panel.Top +4;
	
	AreaNumCmp = AreaNum +1;
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	
	if(AreaNumCmp > dAreaCountMax){
		if(LanguageEnCn==0)TextRender_string24(x, y,  clNearWhite, 	"分区号错误");
		else TextRender_string24(x, y,  clNearWhite, 			"Zone Error");
		return -1;
	}
	if(dTypeValid == 0){
		if(LanguageEnCn==0)TextRender_string24(x, y,  clNearWhite, 	"指定类型超出范围     ");
		else TextRender_string24(x, y,  clNearWhite, 			"Assigned Type Invalid");
		return -1;
	}
	
	Detail.Erase.PortNum =0;;
	Detail.Erase.EpAddr =0;
	Detail.Erase.DirectPadNum =0;
	Detail.Erase.DirectKey =0;
	
	Detail.Write.PortNum =0;;
	Detail.Write.EpAddr =0;
	Detail.Write.DirectPadNum =0;
	Detail.Write.DirectKey =0;
	
	Detail.IsPortOrPad =0;
	Detail.IsWritting =0;

	Detail.Counts4ThisArea =0;
	for(int i=0; i<dPORT_MAX_COUNT; i++){
		for(int g=0; g<dEP_MAX_COUNT_PER_PORT; g++){
			if(Port[i].Area[g] == AreaNumCmp){
				int toCheck =0;
				if(dType == 0)toCheck =1;
				if(Port[i].AssignType[g]){
					if(Port[i].AssignType[g] == dType)toCheck =1;
				}else{
					if(Port[i].dTypeTable[g] == dType)toCheck =1;
				}							
				if(toCheck){
					Detail.Counts4ThisArea ++;
				}
			}
		}
	}
	for(int i=0; i<dDIRECTCTL_MAX_COUNT; i++){
		for(int g=0; g<dDIRECTCTL_KEY_MAX_COUNT; g++){
			if(DirectCtlBoard[i].Area[g] == AreaNumCmp){
				if((DirectCtlBoard[i].AssignType[g] == dType) || (dType == 0)){
					Detail.Counts4ThisArea ++;
				}
			}
		}
	}
	
	Step =0;
	GotAst = 0;
	HadGotAsFinished =0;
	for(int i=0; i<16; i++)tText[i] = '\0';
	for(Pst=0; Pst<8; Pst++){
		if(IList->EditUserCode.Str.Text[Pst] != '\0'){
			if(HadGotAsFinished == 1){
				if(IList->EditUserCode.Str.Text[Pst] == '*'){
					if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "通配二次码存在两段或以上的通配字段");
					else TextRender_string24(x, y, clNearWhite, "Invalid,Aux ID 2 Paragraphs Wildcard");
					return -1;
				}else{
					tText[Pst] = IList->EditUserCode.Str.Text[Pst];
					Step++;
				}
			}else{
				if(IList->EditUserCode.Str.Text[Pst] == '*'){
					tText[Pst] = '0';
					if(GotAst == 0)AstStartPoint = Pst;
					GotAst =1;
					AstEndPoint = Pst;
				}else{
					tText[Pst] = IList->EditUserCode.Str.Text[Pst];
					if(GotAst){
						HadGotAsFinished = 1;
						Step++;
					}
				}
			}
		}else{
			break;
		}
	}
	UserCodeItv = 1;
	for(int i=0; i< Step; i++){
		UserCodeItv *= 10;
	}
	AstLength = AstEndPoint - AstStartPoint +1;
	if(IList->EditUserCode.Str.Text[8] != '\0'){
		if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "新二次码长度超出范围");
		else TextRender_string24(x, y, clNearWhite, "New Aux ID Invalid");	//value out of range
		return -1;
	}
	
	UserCodeStart = TMyString::sToInteger(tText);
	
	if(GotAst){
		int tScope =1;
		for(int i=0, z=0; (i<8) && (z<AstLength); i++, z++){
			tScope = tScope * 10;
		}
		
		if(tScope < Detail.Counts4ThisArea){
			if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "新二次码长度超出通配字段长度");
			else TextRender_string24(x, y, clNearWhite, "Replacing Num Out Of Wildcard");
			x += 264;
			TextDigitRender8_24(x, y, clNearWhite, Detail.Counts4ThisArea);
			return -1;
		}
		
		if(IncDec == 0){
			if( (UserCodeStart + (UserCodeItv * tScope) ) > 99999999){
				if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, 	"通配字段递增溢出");
				else TextRender_string24(x, y, clNearWhite, 			"Invalid,Value Out Of Range");
				return -1;
			}
		}else{
			if( (UserCodeStart - (UserCodeItv * tScope) ) < 0){
				if(LanguageEnCn)TextRender_string24(x, y, clNearWhite, "通配字段递减溢出");
				else TextRender_string24(x, y, clNearWhite, 			"Invalid,Value Out Of Range");
				return -1;
			}
		}
		
		if(LanguageEnCn==0){
			TextRender_string24(x, y, clNearWhite, "使用通配字:");
			x += 132;
			TextRender_string24(x, y, clNearWhite, "开始");
			x += 48;
			TextDigitRender8_24(x, y, clNearWhite, UserCodeStart);
			x += 96;
			TextRender_string24(x, y, clNearWhite, "+");
			x += 12;
			TextDigitRender8_24(x, y, clNearWhite, UserCodeItv);
		}else{
			TextRender_string24(x, y, clNearWhite, 			"With Wildcard");
			x += 13 *12;
			TextRender_string24(x, y, clNearWhite, "Begin");
			x += 5*12;
			TextDigitRender8_24(x, y, clNearWhite, UserCodeStart);
			x += 96;
			TextRender_string24(x, y, clNearWhite, "+");
			x += 12;
			TextDigitRender8_24(x, y, clNearWhite, UserCodeItv);
		}
	}else{
		if(LanguageEnCn==0){
			TextRender_string24(x, y, clNearWhite, "无通配字 开始:");
			x += 170;
			TextDigitRender8_24(x, y, clNearWhite, UserCodeStart);
			x += 96;
			TextRender_string24(x, y, clNearWhite, "+");
			x += 12;
			TextDigitRender8_24(x, y, clNearWhite, 1);
		}else{
			TextRender_string24(x, y, clNearWhite, "Without Wildcard");
			x += 17*12;
			TextDigitRender8_24(x, y, clNearWhite, UserCodeStart);
			x += 96;
			TextRender_string24(x, y, clNearWhite, "+");
			x += 12;
			TextDigitRender8_24(x, y, clNearWhite, 1);
		}
	}
	
	IList->RealtimeData.Reset();
	x = Lv.Panel.Left +4;
	y+=28;
	if(LanguageEnCn==0){
		TextRender_string24(x, y, clNearWhite, "本区域设备数量:");
		x += 180;
	}else{
		TextRender_string24(x, y, clNearWhite, "Amount Of This Zone ");
		x += 20*12;
	}		
	TextDigitRender8_24(x, y, clNearWhite, Detail.Counts4ThisArea);
	
	UserCodeEnd = UserCodeStart + (UserCodeItv * Detail.Counts4ThisArea);
	UserCode = UserCodeStart;
	if(IsRecover) Detail.IsWritting =1;
	IsShowwingDetail = 1;

	x = Lv.Panel.Left +4;
	y+=28;
	if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "按确定键继续");
	else TextRender_string24(x, y, clNearWhite, "Press Key OK Continue");
	
	Detail.Counts4ThisArea =0;
	return 0;
}

void TUserCodeSetByArea::DrawDetailGoOn()
{
	int x,y, UcFound=0;
	int ThisPressDrawCount = 0;
	unsigned int AreaNumCmp;
	int LoadStartAddr;
	int LoadStartKey;
	x = Lv.Panel.Left +4;
	y = Lv.Panel.Top +4;
	
	AreaNumCmp = AreaNum+1;
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top+26, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	
	if(IsRecover){
		//Recover Mode
		//Showwing Erase Tntry
		if(Detail.IsWritting == 0){
			while(UserCode <= UserCodeEnd){
				for(; Detail.Erase.PortNum < dPORT_MAX_COUNT; Detail.Erase.PortNum++){
					int i=Detail.Erase.PortNum;
					if(ThisPressDrawCount > 7)break;
					for(; Detail.Erase.EpAddr <dEP_MAX_COUNT_PER_PORT; Detail.Erase.EpAddr++){
						if(ThisPressDrawCount > 7)break;
						int g=Detail.Erase.EpAddr;
						if( (Port[i].Area[g] == AreaNumCmp) && ((Port[i].AssignType[g] == dType) || (dType == 0) ) ) {
							if(UserCode == Port[i].UcList[g].Full){
								x = Lv.Panel.Left +4;
								y+=28;
								if(LanguageEnCn==0){
									TextRender_string24(x, y, clNearWhite, "删除 回路:");
									x += 120;
								}else{
									TextRender_string24(x, y, clNearWhite, "Del Loop: ");
									x += 120;
								}
								TextDigitRender2_24(x, y, clNearWhite, i+1);
								x += 36;
								if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "地址:");
								else TextRender_string24(x, y, clNearWhite, "Addr:");
								x += 60;
								TextDigitRender3_24(x, y, clNearWhite, g+1);
								x += 60;
								TextDigitRender8_24(x, y, clNearWhite, Port[i].UcList[g].Full );
								ThisPressDrawCount++;
							}
						}
						if(ThisPressDrawCount > 7)break;
					}
					if(ThisPressDrawCount > 7)break;
				}
				
				for(; Detail.Erase.DirectPadNum < dDIRECTCTL_MAX_COUNT; Detail.Erase.DirectPadNum++){
					int i=Detail.Erase.DirectPadNum;
					if(ThisPressDrawCount > 7)break;
					for(; Detail.Erase.DirectKey < dDIRECTCTL_KEY_MAX_COUNT; Detail.Erase.DirectKey++){
						int g=Detail.Erase.DirectKey;
						if(ThisPressDrawCount > 7)break;
						if( (DirectCtlBoard[i].Area[g] == AreaNumCmp) && ((DirectCtlBoard[i].AssignType[g] == dType) || (dType == 0) ) ) {
							if(UserCode == DirectCtlBoard[i].UcList[g].Full){
								x = Lv.Panel.Left +4;
								y+=28;
								if(LanguageEnCn==0){
									TextRender_string24(x, y, clNearWhite, "删除 多线盘号:");
									x += 168;
								}else{
									TextRender_string24(x, y, clNearWhite, "Del Direct Brd:");
									x += 15*12;
								}
								TextDigitRender2_24(x, y, clNearWhite, i+1);
								x += 36;
								if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "节点:");
								else TextRender_string24(x, y, clNearWhite, "Node:");
								x += 60;
								TextDigitRender3_24(x, y, clNearWhite, g+1);
								x += 60;
								TextDigitRender8_24(x, y, clNearWhite, DirectCtlBoard[i].UcList[g].Full );
								ThisPressDrawCount++;
							}
						}
						if(ThisPressDrawCount > 7)break;
					}
					if(ThisPressDrawCount > 7)break;
				}
				
				if(Detail.Erase.DirectPadNum >= dDIRECTCTL_MAX_COUNT){
					UserCode += UserCodeItv;
					Detail.Erase.PortNum =0;
					Detail.Erase.EpAddr =0;
					Detail.Erase.DirectPadNum =0;
					Detail.Erase.DirectKey =0;
				}
				
				if(ThisPressDrawCount > 7){
					x = Lv.Panel.Left +4;
					y+=28;
					if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "按确定键继续");
					else TextRender_string24(x, y, clNearWhite, "Press Key OK Continue");
					return;
				}
			}
			if(UserCode > UserCodeEnd){
				UserCode = UserCodeStart;
				Detail.IsWritting =1;
			}
		}
		//Show Write Entry
		if(Detail.IsWritting){
			LoadStartAddr =0;
			LoadStartKey =0;
			for(; Detail.Write.PortNum < dPORT_MAX_COUNT; Detail.Write.PortNum++){
				if(ThisPressDrawCount > 7)break;
				int i=Detail.Write.PortNum;
				if(LoadStartAddr == 1){
					Detail.Write.EpAddr =0;
				}
				LoadStartAddr =1;
				for(; Detail.Write.EpAddr < dEP_MAX_COUNT_PER_PORT; Detail.Write.EpAddr++){
					if(ThisPressDrawCount > 7)break;
					int g=Detail.Write.EpAddr;
					if(Port[i].Area[g] == AreaNumCmp){
						int toCheck =0;
						if(dType == 0)toCheck =1;
						if(Port[i].AssignType[g]){
							if(Port[i].AssignType[g] == dType)toCheck =1;
						}else{
							if(Port[i].dTypeTable[g] == dType)toCheck =1;
						}							
						if(toCheck){
							x = Lv.Panel.Left +4;
							y+=28;
							if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "回路:");
							else TextRender_string24(x, y, clNearWhite, "Loop:");
							x += 60;
							TextDigitRender2_24(x, y, clNearWhite, i+1);
							x += 36;
							if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "地址:");
							else TextRender_string24(x, y, clNearWhite, "Addr:");
							x += 60;
							TextDigitRender3_24(x, y, clNearWhite, g+1);
							x += 60;
							if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "原:");
							else TextRender_string24(x, y, clNearWhite, "   ");
							x += 36;
							TextDigitRender8_24(x, y, clNearWhite, Port[i].UcList[g].Full );
							x += 100;
							TextRender_string24(x, y, clNearWhite, "-->");
							x += 36;
							TextDigitRender8_24(x, y, clNearWhite, UserCode );
							ThisPressDrawCount++;
							UserCode += UserCodeItv;
							Detail.Counts4ThisArea++;
						}
					}
					if(ThisPressDrawCount > 7)break;
				}
				
				if(ThisPressDrawCount > 7)break;
			}
			
			for(; Detail.Write.DirectPadNum < dDIRECTCTL_MAX_COUNT; Detail.Write.DirectPadNum++){
				int i =Detail.Write.DirectPadNum;
				if(ThisPressDrawCount > 7)break;
				if(LoadStartKey == 1){
					Detail.Write.DirectKey =0;
				}
				LoadStartKey =1;
				for(; Detail.Write.DirectKey < dDIRECTCTL_KEY_MAX_COUNT; Detail.Write.DirectKey++){
					int g =Detail.Write.DirectKey;  
					if(ThisPressDrawCount > 7)break;
					if(DirectCtlBoard[i].Area[g] == AreaNumCmp){
						if( (dType == 0) || (DirectCtlBoard[i].AssignType[g] == dType) ){
							x = Lv.Panel.Left +4;
							y+=28;
							if(LanguageEnCn==0){
								TextRender_string24(x, y, clNearWhite, "多线盘号:");
								x += 108;
							}else{
								TextRender_string24(x, y, clNearWhite, "Direct Brd:");
								x += 11*12;
							}
							TextDigitRender2_24(x, y, clNearWhite, i+1);
							x += 36;
							if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "节点:");
							else TextRender_string24(x, y, clNearWhite, "Node:");
							x += 60;
							TextDigitRender2_24(x, y, clNearWhite, g+1);
							x += 48;
							if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "原");
							else TextRender_string24(x, y, clNearWhite, "  ");
							x += 24;
							TextDigitRender8_24(x, y, clNearWhite, DirectCtlBoard[i].UcList[g].Full );
							x += 96;
							TextRender_string24(x, y, clNearWhite, "->");
							x += 36;
							TextDigitRender8_24(x, y, clNearWhite, UserCode );
							
							ThisPressDrawCount++;
							UserCode += UserCodeItv;
							Detail.Counts4ThisArea++;
						}
					}
					if(ThisPressDrawCount > 7)break;
				}
				if(ThisPressDrawCount > 7)break;
			}
			if(ThisPressDrawCount > 7){
				x = Lv.Panel.Left +4;
				y+=28;
				if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "按确定键继续");
				else TextRender_string24(x, y, clNearWhite, "Press Key OK Continue");
				return;
			}
		}
		if(Detail.Write.DirectPadNum >= dDIRECTCTL_MAX_COUNT) {
			IsShowwingDetail = 0;
			x = Lv.Panel.Left +4;
			y+=28;
			if(LanguageEnCn==0){
				TextRender_string24(x, y, clNearWhite, "修改数量");
				TextDigitRender5_24(x+96, y, clNearWhite, Detail.Counts4ThisArea);
				TextRender_string24(x+156, y, clNearWhite, " 展示完毕");
			}else{
				TextRender_string24(x, y, clNearWhite, "To Be Modify");
				TextDigitRender5_24(x+12*12, y, clNearWhite, Detail.Counts4ThisArea);
				TextRender_string24(x+156, y, clNearWhite, " Completed");
			}
		}
	}else{
		//Avoid Mode
		while(Detail.Write.DirectPadNum < dDIRECTCTL_MAX_COUNT){	
			while(Detail.Write.PortNum <dPORT_MAX_COUNT){
				if(ThisPressDrawCount >7)break;
				int i= Detail.Write.PortNum;
				while(Detail.Write.EpAddr < dEP_MAX_COUNT_PER_PORT){
					if(ThisPressDrawCount >7)break;
					int g=Detail.Write.EpAddr;
					if(Port[i].Area[g] == AreaNumCmp){
						int toCheck =0;
						if(dType == 0)toCheck =1;
						if(Port[i].AssignType[g]){
							if(Port[i].AssignType[g] == dType)toCheck =1;
						}else{
							if(Port[i].dTypeTable[g] == dType)toCheck =1;
						}
						if(toCheck){
							int DoSkip;
							do{
									DoSkip =0;
									for(int i=0; i<dPORT_MAX_COUNT; i++){
										for(int g=0; g<dEP_MAX_COUNT_PER_PORT; g++){
											if(Port[i].Area[g] != AreaNumCmp){
												if(UserCode == Port[i].UcList[g].Full){
													UserCode += UserCodeItv;
													DoSkip =1;
													break;
												}
											}
										}
										if(DoSkip)break;
									}
									if(DoSkip)continue;
									for(int i=0; i<dDIRECTCTL_MAX_COUNT; i++){
										for(int g=0; g<dDIRECTCTL_KEY_MAX_COUNT; g++){
											if(DirectCtlBoard[i].Area[g] != AreaNumCmp){
												if(UserCode == DirectCtlBoard[i].UcList[g].Full){
													UserCode += UserCodeItv;
													DoSkip =1;
													break;
												}
											}
										}
										if(DoSkip)break;
									}
							}while(DoSkip);
							if(Port[i].UcList[g].Full != UserCode){
								x = Lv.Panel.Left +4;
								y+=28;
								if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "回路:");
								else TextRender_string24(x, y, clNearWhite, "Loop:");
								x += 60;
								TextDigitRender2_24(x, y, clNearWhite, i+1);
								x += 36;
								if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "地址:");
								else TextRender_string24(x, y, clNearWhite, "Addr:");
								x += 60;
								TextDigitRender3_24(x, y, clNearWhite, g+1);
								x += 60;
								if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "原:");
								else TextRender_string24(x, y, clNearWhite, "   ");
								x += 36;
								TextDigitRender8_24(x, y, clNearWhite, Port[i].UcList[g].Full );
								x += 100;
								TextRender_string24(x, y, clNearWhite, "-->");
								x += 36;			
								TextDigitRender8_24(x, y, clNearWhite, UserCode );

								ThisPressDrawCount++;
								UserCode += UserCodeItv;
								Detail.Counts4ThisArea++;
							}	
						}
					}
					Detail.Write.EpAddr++;
					if(Detail.Write.EpAddr >= dEP_MAX_COUNT_PER_PORT){
						Detail.Write.PortNum++;
						Detail.Write.EpAddr = 0;
						break;
					}
					if(ThisPressDrawCount >7)break;
				}
				if(ThisPressDrawCount > 7)break;
			}
			while(Detail.Write.DirectPadNum < dDIRECTCTL_MAX_COUNT){
				if(ThisPressDrawCount >7)break;
				int i=Detail.Write.DirectPadNum;
				while(Detail.Write.DirectKey < dDIRECTCTL_KEY_MAX_COUNT){
					if(ThisPressDrawCount >7)break;
					int g=Detail.Write.DirectKey;
					if(DirectCtlBoard[i].Area[g] == AreaNumCmp){
						if( (dType ==0) || (dType == DirectCtlBoard[i].AssignType[g]) ){
							int DoSkip;
							do{
									DoSkip =0;
									for(int i=0; i<dPORT_MAX_COUNT; i++){
										for(int g=0; g<dEP_MAX_COUNT_PER_PORT; g++){
											if(Port[i].Area[g] != AreaNumCmp){
												if(UserCode == Port[i].UcList[g].Full){
													UserCode += UserCodeItv;
													DoSkip =1;
													break;
												}
											}
										}
										if(DoSkip)break;
									}
									if(DoSkip)continue;
									for(int i=0; i<dDIRECTCTL_MAX_COUNT; i++){
										for(int g=0; g<dDIRECTCTL_KEY_MAX_COUNT; g++){
											if(DirectCtlBoard[i].Area[g] != AreaNumCmp){
												if(UserCode == DirectCtlBoard[i].UcList[g].Full){
													UserCode += UserCodeItv;
													DoSkip =1;
													break;
												}
											}
										}
										if(DoSkip)break;
									}
							}while(DoSkip);
							if(DirectCtlBoard[i].UcList[g].Full != UserCode){
								x = Lv.Panel.Left +4;
								y+=28;
								if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "多线盘号:");
								else TextRender_string24(x, y, clNearWhite, "Direct Brd:");
								x += 11*12;
								TextDigitRender2_24(x, y, clNearWhite, i+1);
								x += 36;
								if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "节点:");
								else TextRender_string24(x, y, clNearWhite, "Node:");
								x += 60;
								TextDigitRender2_24(x, y, clNearWhite, g+1);
								x += 48;
								if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "原");
								else TextRender_string24(x, y, clNearWhite, "  "); 
								x += 24;
								TextDigitRender8_24(x, y, clNearWhite, DirectCtlBoard[i].UcList[g].Full );
								x += 96;
								TextRender_string24(x, y, clNearWhite, "->");
								x += 36;
								TextDigitRender8_24(x, y, clNearWhite, UserCode );
								ThisPressDrawCount++;
								UserCode += UserCodeItv;
								Detail.Counts4ThisArea++;
							}
						}
					}
					Detail.Write.DirectKey++;
					if(Detail.Write.DirectKey >= dDIRECTCTL_KEY_MAX_COUNT){
						Detail.Write.DirectPadNum++;
						Detail.Write.DirectKey = 0;
						break;
					}
					if(ThisPressDrawCount >7)break;
				}
				if(ThisPressDrawCount > 7)break;
			}
			if(ThisPressDrawCount >7){
				x = Lv.Panel.Left +4;
				y+=28;
				if(LanguageEnCn==0)TextRender_string24(x, y, clNearWhite, "按确定键继续");
				else TextRender_string24(x, y, clNearWhite, "Press Key OK Continue");
				return;
			}
		}
		if( Detail.Write.DirectPadNum >= dDIRECTCTL_MAX_COUNT ){
			IsShowwingDetail = 0;
			x = Lv.Panel.Left +4;
			y+=28;
			if(LanguageEnCn==0){
				TextRender_string24(x, y, clNearWhite, "修改数量");
				TextDigitRender5_24(x+96, y, clNearWhite, Detail.Counts4ThisArea);
				TextRender_string24(x+156, y, clNearWhite, " 展示完毕");
			}else{
				TextDigitRender5_24(x, y, clNearWhite, Detail.Counts4ThisArea);
				TextRender_string24(x+6*12, y, clNearWhite, "Items To Be Modify,Completed");
			}
		}
	}	
}

void TUserCodeSetByArea::Write2Flash()
{
	/*unsigned int fAddr;
	unsigned int i;
	unsigned int aUcFull;
	volatile unsigned int x, GetSta;
	unsigned char wP1;
	int NotEqOcc =0;
	
	do{
		DelayMs(3);
		GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
	}while(GetSta);
	
	Record.ReadDevUserSet();

	if(NotEqOcc){
		//Error
	}else{
		//OK
	}*/
}

int TUserCodeSetByArea::WriteOnePort(unsigned int aP0)
{
	unsigned int fAddr;
	unsigned int i;
	unsigned int aUcFull;
	volatile unsigned int x, GetSta;
	unsigned char wP1;
	TDMix tCrc;
	
	do{
		DelayMs(3);
		GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
	}while(GetSta);
	
	//Erase 1 * 4K Blocks
	if( (aP0  < dPORT_MAX_COUNT) ){
		fAddr = dFlashAddrDevUserCode + (aP0 * 4096);
		nor_erase_sector_4k(dFlashAddrDevUserCodeChip,fAddr);
		DelayMs(100);
		
		do{
			DelayMs(10);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
		
		Crc32Reset();
		for(i=0; i<64; i++)IList->ReadWriteData.D32[i] = 0;
		for(i=0; i<4; i++){
			for(x=0;x<64;x++){
				IList->ReadWriteData.D32[x] = Port[aP0].UcList[i*64 + x].Full;
				if( (i<3) or (x< (dEP_MAX_COUNT_PER_PORT % 64))){
					Crc32Feed(IList->ReadWriteData.D32[x]);
				}
			}
			if(i==3){
				IList->ReadWriteData.D32[63] = Crc32GetResult();
			}
			fAddr = dFlashAddrDevUserCode + (aP0 * 4096) + (i * 256);
			nor_write_page(dFlashAddrDevUserCodeChip, fAddr, IList->ReadWriteData.D8);
			do{
				DelayMs(5);
				GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
			}while(GetSta);
		}
		
		for(x=0;x<dEP_MAX_COUNT_PER_PORT;x++){
			IList->ReadWriteData.D8[x] = Port[aP0].AssignType[x];
		}
		Crc32Reset();
		for(x=0; x<dEP_MAX_COUNT_PER_PORT; x++)Crc32Feed(static_cast<unsigned int>(IList->ReadWriteData.D8[x]));
		tCrc.D32 = Crc32GetResult();
		IList->ReadWriteData.D8[252] = tCrc.D8[0];
		IList->ReadWriteData.D8[253] = tCrc.D8[1];
		IList->ReadWriteData.D8[254] = tCrc.D8[2];
		IList->ReadWriteData.D8[255] = tCrc.D8[3];
		fAddr = dFlashAddrDevUserCode + (aP0 * 4096) + (4 * 256);
		nor_write_page(dFlashAddrDevUserCodeChip, fAddr, IList->ReadWriteData.D8);
		do{
			DelayMs(5);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
		
		//Signal Type
		for(x=0;x<256;x++){
			IList->ReadWriteData.D8[x] = Port[aP0].FuncSetByte[x];
		}
		Crc32Reset();
		for(x=0; x<dEP_MAX_COUNT_PER_PORT; x++)Crc32Feed(static_cast<unsigned int>(IList->ReadWriteData.D8[x]));
		tCrc.D32 = Crc32GetResult();
		IList->ReadWriteData.D8[252] = tCrc.D8[0];
		IList->ReadWriteData.D8[253] = tCrc.D8[1];
		IList->ReadWriteData.D8[254] = tCrc.D8[2];
		IList->ReadWriteData.D8[255] = tCrc.D8[3];
		fAddr = dFlashAddrDevUserCode + (aP0 * 4096) + (5 * 256);
		nor_write_page(dFlashAddrDevUserCodeChip, fAddr, IList->ReadWriteData.D8);
		do{
			DelayMs(5);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
	}
	
	//Check First 64 UserCode
	do{
		DelayMs(2);
		GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
	}while(GetSta);
	fAddr = dFlashAddrDevUserCode + (4096 * aP0) + (256 * 0);
	nor_read_byte(dFlashAddrDevUserCodeChip,fAddr,IList->ReadWriteData.D8,256);
	for(x=0; x<64; x++){
		if(Port[aP0].UcList[x].Full != IList->ReadWriteData.D32[x]){
			return -9;
		}
	}
	return 0;
}

int TUserCodeSetByArea::WriteOneDirectPad(unsigned char aP0)
{
	unsigned int fAddr;
	unsigned int i;
	volatile unsigned int x, GetSta;
	TDMix tCrc1, tCrc2;
	
	do{
		DelayMs(3);
		GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
	}while(GetSta);

	//Erase 1 * 4K Blocks
	if( aP0 < dDIRECTCTL_MAX_COUNT ){
		fAddr = dFlashAddrDirectPadUserCode + (aP0 * 4096);
		nor_erase_sector_4k(dFlashAddrDevUserCodeChip,fAddr);
		DelayMs(100);
		
		do{
			DelayMs(10);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
		
		for(x=0;x<dDIRECTCTL_KEY_MAX_COUNT;x++){
			IList->ReadWriteData.D32[x] = DirectCtlBoard[aP0].UcList[x].Full;
			IList->ReadWriteData.D8[x + 32] = DirectCtlBoard[aP0].AssignType[x];
		}
		Crc32Reset();
		for(x=0;x<dDIRECTCTL_KEY_MAX_COUNT;x++)Crc32Feed(IList->ReadWriteData.D32[x]);
		tCrc1.D32 = Crc32GetResult();
		Crc32Reset();
		for(x=0;x<dDIRECTCTL_KEY_MAX_COUNT;x++)Crc32Feed(IList->ReadWriteData.D8[x + 32]);
		tCrc2.D32 = Crc32GetResult();
		
		IList->ReadWriteData.D8[32+8 +0] = tCrc1.D8[0];
		IList->ReadWriteData.D8[32+8 +1] = tCrc1.D8[1];
		IList->ReadWriteData.D8[32+8 +2] = tCrc1.D8[2];
		IList->ReadWriteData.D8[32+8 +3] = tCrc1.D8[3];
		IList->ReadWriteData.D8[32+8 +4] = tCrc2.D8[0];
		IList->ReadWriteData.D8[32+8 +5] = tCrc2.D8[1];
		IList->ReadWriteData.D8[32+8 +6] = tCrc2.D8[2];
		IList->ReadWriteData.D8[32+8 +7] = tCrc2.D8[3];
		
		nor_write_page(dFlashAddrDevUserCodeChip, fAddr, IList->ReadWriteData.D8);
		do{
			DelayMs(5);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);

		do{
			DelayMs(5);
			GetSta = nor_get_busy_state(dFlashAddrDevUserCodeChip);
		}while(GetSta);
		
		nor_read_byte(dFlashAddrDevUserCodeChip,fAddr,IList->ReadWriteData.D8,256);
		for(x=0; x<dDIRECTCTL_KEY_MAX_COUNT;x++){
			if(IList->ReadWriteData.D32[x] != DirectCtlBoard[aP0].UcList[x].Full){
				//Direct Pad Write Error
				return -11;
			}
		}
		return 0;
	}
	//Direct Pad No Exist
	return -12;
}


int TUserCodeSetByArea::Write()
{
	int x,y, UcFound=0;
	int ProceduredCount = 0;
	int ToWriteThis;
	unsigned short AreaNumCmp;
	
	int Pst;
	char tText[16];
	unsigned int tUc, HadGotAsFinished;
	int AstStartPoint, AstEndPoint, AstLength, InputLength, Step;

	AreaNumCmp = AreaNum +1;
	
	if(AreaNumCmp > dAreaCountMax){
		//TextRender_string24(x, y,  clNearWhite, "分区号错误");
		return -1;
	}
	if(dTypeValid == 0){
		//TextRender_string24(x, y,  clNearWhite, "指定类型超出范围");
		return -2;
	}
	
	Writing.Erase.PortNum =0;;
	Writing.Erase.EpAddr =0;
	Writing.Erase.DirectPadNum =0;
	Writing.Erase.DirectKey =0;
	
	Writing.Write.PortNum =0;;
	Writing.Write.EpAddr =0;
	Writing.Write.DirectPadNum =0;
	Writing.Write.DirectKey =0;
	
	Writing.IsPortOrPad =0;
	Writing.IsWritting =0;

	//Get Items Count
	Writing.Counts4ThisArea =0;
	for(int i=0; i<dPORT_MAX_COUNT; i++){
		for(int g=0; g<dEP_MAX_COUNT_PER_PORT; g++){
			if(Port[i].Area[g] == AreaNumCmp){
				if( (Port[i].AssignType[g] == dType) || (dType == 0) ){
					Writing.Counts4ThisArea ++;
				}
			}
		}
	}
	for(int i=0; i<dDIRECTCTL_MAX_COUNT; i++){
		for(int g=0; g<dDIRECTCTL_KEY_MAX_COUNT; g++){
			if(DirectCtlBoard[i].Area[g] == AreaNumCmp){
				if((DirectCtlBoard[i].AssignType[g] == dType) || (dType == 0)){
					Writing.Counts4ThisArea ++;
				}
			}
		}
	}
	//__________________________Get Items Count <-
	
	//Get User Code 4 Start
	Step =0;
	GotAst = 0;
	HadGotAsFinished =0;
	for(int i=0; i<16; i++)tText[i] = '\0';
	for(Pst=0; Pst<8; Pst++){
		if(IList->EditUserCode.Str.Text[Pst] != '\0'){
			if(HadGotAsFinished == 1){
				if(IList->EditUserCode.Str.Text[Pst] == '*'){
					//TextRender_string24(x, y, clNearWhite, "通配二次码存在两段或以上的通配字段");
					return -4;
				}else{
					tText[Pst] = IList->EditUserCode.Str.Text[Pst];
					Step++;
				}
			}else{
				if(IList->EditUserCode.Str.Text[Pst] == '*'){
					tText[Pst] = '0';
					if(GotAst == 0)AstStartPoint = Pst;
					GotAst =1;
					AstEndPoint = Pst;
				}else{
					tText[Pst] = IList->EditUserCode.Str.Text[Pst];
					if(GotAst){
						HadGotAsFinished = 1;
						Step++;
					}
				}
			}
		}else{
			break;
		}
	}
	UserCodeItv = 1;
	for(int i=0; i< Step; i++){
		UserCodeItv *= 10;
	}
	AstLength = AstEndPoint - AstStartPoint +1;
	if(IList->EditUserCode.Str.Text[8] != '\0'){
		//TextRender_string24(x, y, clNearWhite, "新二次码长度超出范围");
		return -3;
	}
	UserCodeStart = TMyString::sToInteger(tText);
	//__________________________Get User Code 4 Start <-
	
	//Get User Code And The UserCodeItv=Inteval
	if(GotAst){
		int tScope =1;
		for(int i=0, z=0; (i<8) && (z<AstLength); i++, z++){
			tScope = tScope * 10;
		}
		
		if(tScope < Writing.Counts4ThisArea){
			//TextRender_string24(x, y, clNearWhite, "通配字段长度不足,需求:");
			return -5;
		}
		
		if(IncDec == 0){
			if( (UserCodeStart + (UserCodeItv * tScope) ) > 99999999){
				//TextRender_string24(x, y, clNearWhite, "通配字段递增溢出");
				return -6;
			}
		}else{
			if( (UserCodeStart - (UserCodeItv * tScope) ) < 0){
				//TextRender_string24(x, y, clNearWhite, "通配字段递减溢出");
				return -7;
			}
		}
	}else{
		//TextRender_string24(x, y, clNearWhite, "无通配字 开始:");
	}
	
	
	UserCodeEnd = UserCodeStart + (UserCodeItv * Writing.Counts4ThisArea);
	UserCode = UserCodeStart;
	if(IsRecover){
		//Recover Mode
		//Write Port
		for(x=0; x<dPORT_MAX_COUNT; x++){
			//if(MainCtl.fData.Split.ExistTablePort[x]){
				ToWriteThis = 0;
				for(y=0; y<dEP_MAX_COUNT_PER_PORT;y++)
				if(Port[x].Area[y] == AreaNumCmp){
					int toCheck =0;
					if(dType == 0)toCheck =1;
					if(Port[x].AssignType[y]){
						if(Port[x].AssignType[y] == dType)toCheck =1;
					}else{
						if(Port[x].dTypeTable[y] == dType)toCheck =1;
					}
					if( toCheck ){
						if(UserCode >99999999){
							//UserCode OverFlow
							return -10;
						}
						Port[x].UcList[y].Full = UserCode;
						UserCode += UserCodeItv;
						ToWriteThis =1;
						ProceduredCount++;
					}
				}
				if(ToWriteThis){
					//Write One Port Here
					if(WriteOnePort(x) !=0){
						//Write One Port Error
						return -8;
					}
				}
			//}
		}
		//Write Direct Pad
		for(x=0; x < dDIRECTCTL_MAX_COUNT; x++){
			ToWriteThis = 0;
			for(y=0; y < dDIRECTCTL_KEY_MAX_COUNT; y++){
				if(DirectCtlBoard[x].Area[y] == AreaNumCmp){
					if( (dType == 0) || (DirectCtlBoard[x].AssignType[y] == dType) ){
						if(UserCode >99999999){
							//UserCode OverFlow
							return -10;
						}
						DirectCtlBoard[x].UcList[y].Full = UserCode;
						UserCode += UserCodeItv;
						ToWriteThis = 1;
						ProceduredCount++;
					}
				}
			}
			if(ToWriteThis){
				////Write One Direct Pad Here
				if(WriteOneDirectPad(x) !=0){
					//Write One Direct Pad Error
					return -9;
				}
			}
		}
	}else{
		//Avoid Mode
		for(x=0; x<dPORT_MAX_COUNT; x++){
			//if(MainCtl.fData.Split.ExistTablePort[x]){
				ToWriteThis = 0;
				for(y=0; y<dEP_MAX_COUNT_PER_PORT;y++)
				if(Port[x].Area[y] == AreaNumCmp){
					int toCheck =0;
					if(dType == 0)toCheck =1;
					if(Port[x].AssignType[y]){
						if(Port[x].AssignType[y] == dType)toCheck =1;
					}else{
						if(Port[x].dTypeTable[y] == dType)toCheck =1;
					}
					if( toCheck ){
						int DoSkip;
						do{
								DoSkip =0;
								for(int i=0; i<dPORT_MAX_COUNT; i++){
									for(int g=0; g<dEP_MAX_COUNT_PER_PORT; g++){
										if(Port[i].Area[g] != AreaNumCmp){
											if(UserCode == Port[i].UcList[g].Full){
												UserCode += UserCodeItv;
												DoSkip =1;
												break;
											}
										}
									}
									if(DoSkip)break;
								}
								if(DoSkip)continue;
								for(int i=0; i<dDIRECTCTL_MAX_COUNT; i++){
									for(int g=0; g<dDIRECTCTL_KEY_MAX_COUNT; g++){
										if(DirectCtlBoard[i].Area[g] != AreaNumCmp){
											if(UserCode == DirectCtlBoard[i].UcList[g].Full){
												UserCode += UserCodeItv;
												DoSkip =1;
												break;
											}
										}
									}
									if(DoSkip)break;
								}
						}while(DoSkip);
						if(UserCode >99999999){
							//UserCode OverFlow
							return -10;
						}
						Port[x].UcList[y].Full = UserCode;
						UserCode += UserCodeItv;
						ToWriteThis =1;
						ProceduredCount++;
					}
				}
				if(ToWriteThis){
					//Write One Port Here
					if(WriteOnePort(x) !=0){
						//Write One Port Error
						return -8;
					}
				}
			//}
		}
		//Write Direct Pad
		for(x=0; x < dDIRECTCTL_MAX_COUNT; x++){
			ToWriteThis = 0;
			for(y=0; y < dDIRECTCTL_KEY_MAX_COUNT; y++){
				if(DirectCtlBoard[x].Area[y] == AreaNumCmp){
					if( (dType == 0) || (DirectCtlBoard[x].AssignType[y] == dType) ){
						int DoSkip;
						do{
								DoSkip =0;
								for(int i=0; i<dPORT_MAX_COUNT; i++){
									for(int g=0; g<dEP_MAX_COUNT_PER_PORT; g++){
										if(Port[i].Area[g] != AreaNumCmp){
											if(UserCode == Port[i].UcList[g].Full){
												UserCode += UserCodeItv;
												DoSkip =1;
												break;
											}
										}
									}
									if(DoSkip)break;
								}
								if(DoSkip)continue;
								for(int i=0; i<dDIRECTCTL_MAX_COUNT; i++){
									for(int g=0; g<dDIRECTCTL_KEY_MAX_COUNT; g++){
										if(DirectCtlBoard[i].Area[g] != AreaNumCmp){
											if(UserCode == DirectCtlBoard[i].UcList[g].Full){
												UserCode += UserCodeItv;
												DoSkip =1;
												break;
											}
										}
									}
									if(DoSkip)break;
								}
						}while(DoSkip);
						if(UserCode >99999999){
							//UserCode OverFlow
							return -10;
						}
						DirectCtlBoard[x].UcList[y].Full = UserCode;
						UserCode += UserCodeItv;
						ToWriteThis = 1;
						ProceduredCount++;
					}
				}
			}
			if(ToWriteThis){
				////Write One Direct Pad Here
				if(WriteOneDirectPad(x) !=0){
					//Write One Direct Pad Error
					return -9;
				}
			}
		}
	}
	if(ProceduredCount == 0){
		return -100;
	}
	return ProceduredCount;
}

void TUserCodeSetByArea::DrawWriteSta()
{
	int x,y;
	x = Lv.Grid.Left[5] +4;
	y = Lv.Grid.Top[5] +8;
	if(Sta >0){
		if(Sta>99999)Sta = 99999;
		if(LanguageEnCn==0){
			TextRender_string24(x, 		y,  clNearWhite, ItemColor, "保存了");
			TextDigitRender5_24(x+72, 	y,  clNearWhite, ItemColor,  Sta);
			TextRender_string24(x+132, 	y,  clNearWhite, ItemColor, "个更改   ");
		}else{
			TextDigitRender5_24(x, 	y,  clNearWhite, ItemColor,  Sta);
			TextRender_string24(x+72, 	y,  clNearWhite, ItemColor, 	"Items Been Saved");
		}
	}else{
		if(LanguageEnCn==0){
			switch(Sta){
				case -100:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"0 个更改            ");
					break;
				case -1:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"分区号错误          ");
				
					break;
				case -2:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"类型超出范围        ");
					break;
				case -3:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"新二次码长度超出范围");
					break;
				case -4:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"两段或以上的通配字段");
					break;
				case -5:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"通配字段长度不足    ");
					break;
				case -6:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"通配字段递增溢出    ");
					break;
				case -7:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"通配字段递减溢出    ");
					break;
				case -8:
					//Write One Port Error
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"写入回路错误        ");
					break;
				case -9:
					//Write One Direct Pad Error
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"写入多线盘错误      ");
					break;
				case -10:
					//UserCode OverFlow
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"二次码超出范围      ");
					break;
				default:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"                    ");
					break;
				
			}
		}else{
			switch(Sta){
				case -100:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"0 Items To Be Modify   ");
					break;
				case -1:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"Invalid Zone           ");
				
					break;
				case -2:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"Invalid Assigned Type  ");
					break;
				case -3:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"Invalid,New ID         ");
					break;
				case -4:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"Invalid,Wildcard Field ");
					break;
				case -5:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"Invalid,Wildcard Field ");
					break;
				case -6:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"Invalid,Out Of Range   ");
					break;
				case -7:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"Invalid,Out Of Range   ");
					break;
				case -8:
					//Write One Port Error
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"Failed To Write To Loop");
					break;
				case -9:
					//Write One Direct Pad Error
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"Failed To Write To DB  ");
					break;
				case -10:
					//UserCode OverFlow
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"AuxID Out Of Range     ");
					break;
				default:
					TextRender_string24(x, y,  clNearWhite,  ItemColor,"                       ");
					break;
				
			}
		}
	}
}

void TUserCodeSetByArea::DrawWriteSta(int aSta)
{
	Sta = aSta;
	DrawWriteSta();
}



