#include "Gui.h"
#include "DevProperty.h"

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

#define dWdClr		clSkyBlue
#define dWdDisabelClr	clNearWhite

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

void TDevProperty::DrawFixTextNoType()
{
	if(LanguageEnCn == 0){
		TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, "定义类型");
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, "保存", 14, clNearBlack);
	
		TextRender_string24(Lv.Grid.Left[3] +10, ModuleRectLv3.Top + 6, clNearWhite, ItemColor, "输入信号");
		TextRender_string24(Lv.Grid.Left[3] +42, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "反馈");
		TextRender_string24(Lv.Grid.Left[3] +140, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "报警");
		TextRender_string24(Lv.Grid.Left[3] +236, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "监管");
		TextRender_string24(Lv.Grid.Left[3] +42, ModuleRectLv3.Top + 72, clNearWhite, ItemColor, "点动");
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +120, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, "读取", 14, clNearBlack);
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +210, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, "保存", 14, clNearBlack);
	}else{
		TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, "DEF TYPE");
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, "Save", 14, clNearBlack);
	
		TextRender_string24(Lv.Grid.Left[3] +10, ModuleRectLv3.Top + 6, clNearWhite, ItemColor, "Signal");
		TextRender_string24(Lv.Grid.Left[3] +42, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "FBCK");
		TextRender_string24(Lv.Grid.Left[3] +140, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "Fire");
		TextRender_string24(Lv.Grid.Left[3] +236, ModuleRectLv3.Top + 36, clNearWhite, ItemColor, "SUPV");
		TextRender_string24(Lv.Grid.Left[3] +42, ModuleRectLv3.Top + 72, clNearWhite, ItemColor, "Pulse");
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +120, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, "Read", 14, clNearBlack);
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +210, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, "Save", 14, clNearBlack);
	}	
}

void TDevProperty::FullRedrawNoType(int Prm)
{
	if(Prm == 0){
		for(int i=2; i<Lv.Grid.UsingCount; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
		RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
		RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
		ReDrawCommonInf();
		DrawFixTextNoType();

		IList->Edit[0].Show();
		IList->STextModuleInDefineType.Show();
		
		if(EdittingDescp){
			CnInput.FullRedraw();
		}else{
			ClearSelectedNoType();
		}
	}else{
		for(int i=2; i<3; 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);
		ReDrawCommonInf();
		if(LanguageEnCn == 0){
			TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, "定义类型");
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, "保存", 14, clNearBlack);
		}else{
			TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, "DEF TYPE");
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, "Save", 14, clNearBlack);
		}
		IList->Edit[0].Show();
		IList->STextModuleInDefineType.Show();
		if(EdittingDescp){
			CnInput.FullRedraw();
		}else{
			Check4SelectedNoType();
		}
		if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
	}
	
	Redraw4NoTypeSmallPanelWithNoData();
}

void TDevProperty::InitNoType()
{
	PanelIsUsingText = 1;
	
	for(int i=2; i<3; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	RectFillRender(Lv.Grid.Left[3], ModuleRectLv3.Top, Lv.Grid.Right[3], ModuleRectLv3.Bottom, ItemColor);
	RectFillRender(Lv.Grid.Left[4], ModuleRectLv4.Top, Lv.Grid.Right[4], ModuleRectLv4.Bottom, ItemColor);
	DrawFixTextNoType();
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
	
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);
	
	IList->Edit[0].Init(Lv.Grid.Left[2] +110, Lv.Grid.Top[2] + 4, 48,30,0,0,1,clNearBlack);
	IList->Edit[0].SetMaxLen(3);
	IList->Edit[0].Str.Clear();
	IList->STextModuleInDefineType.Init(Lv.Grid.Left[2] +4, Lv.Grid.Top[2] + 40, 196,30,0,0,clNearWhite,ItemColor);
	unsigned char tType = Port[Path0-1].AssignType[Path1-1];
	IList->Edit[0].Str.FromUInt3Dg(tType);
	if(LanguageEnCn==0){
		if(tType == 0){
			IList->STextModuleInDefineType.SetText("未指派类型" , 24);
		}else{
			IList->STextModuleInDefineType.SetText(StrTypeShortName[tType] , 24);
		}
	}else{
		if(tType == 0){
			IList->STextModuleInDefineType.SetText("NONE TYPE" , 24);
		}else{
			IList->STextModuleInDefineType.SetText(StrTypeShortNameEn[tType] , 24);
		}
	}
	IList->Edit[0].Show(); 
	IList->STextModuleInDefineType.Show();

	Data.NoTypeSignalInOutType = Port[Path0-1].FuncSetByte[Path1-1];
	RedrawNoTypeSignalType();
	
	Redraw4NoTypeSmallPanelWithNoData();
}


void TDevProperty::EditDescpReturnHtNoType()
{
	PanelIsUsingText = 1;
	
	for(int i=2; i<3; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	RectFillRender(Lv.Grid.Left[3], ModuleRectLv3.Top, Lv.Grid.Right[3], ModuleRectLv3.Bottom, ItemColor);
	
	DrawFixTextNoType();
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
	
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);
	
	IList->Edit[0].Show();
	IList->STextModuleInDefineType.Show();
	
	RedrawNoTypeSignalType(); 
	
	ReDrawPanel();
}

void TDevProperty::Redraw4NoTypeNewLoad()
{
	unsigned char tType = Port[Path0-1].AssignType[Path1-1];
	IList->Edit[0].Str.FromUInt3Dg(tType);
	if(LanguageEnCn==0){
		if(tType == 0){
			IList->STextModuleInDefineType.SetText("未指派类型" , 24);
		}else{
			IList->STextModuleInDefineType.SetText(StrTypeShortName[tType] , 24);
		}
	}else{
		if(tType == 0){
			IList->STextModuleInDefineType.SetText("NONE TYPE" , 24);
		}else{
			IList->STextModuleInDefineType.SetText(StrTypeShortNameEn[tType] , 24);
		}
	}
	IList->Edit[0].SetPstTail();
	IList->Edit[0].Show();
	IList->STextModuleInDefineType.Show();
	
	Data.NoTypeSignalInOutType = Port[Path0-1].FuncSetByte[Path1-1];
	RedrawNoTypeSignalType();
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
}

void TDevProperty::RedrawNoTypeDefineType()
{
	int iVal;
	iVal =IList->Edit[0].Str.ToInteger();
	if(LanguageEnCn==0){
		if( (iVal <0) || (iVal > 255) ){
			IList->Edit[0].SelectedColor = clRed;
			IList->STextModuleInDefineType.SetText("未指派类型",24);
		}else{
			IList->Edit[0].SelectedColor = clBlue;
			IList->STextModuleInDefineType.SetText(StrTypeShortName[iVal],24);
		}
	}else{
		if( (iVal <0) || (iVal > 255) ){
			IList->Edit[0].SelectedColor = clRed;
			IList->STextModuleInDefineType.SetText("NONE TYPE",24);
		}else{
			IList->Edit[0].SelectedColor = clBlue;
			IList->STextModuleInDefineType.SetText(StrTypeShortNameEn[iVal],24);
		}
	}
	IList->Edit[0].SetPstTail();
	IList->Edit[0].Show();
	IList->STextModuleInDefineType.Show();
}

void TDevProperty::RedrawNoTypeSignalType()
{
	if((Data.NoTypeSignalInOutType & 0x07) == 1){
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
	}else
	if((Data.NoTypeSignalInOutType & 0x07) == 2){
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);		
	}else
	if((Data.NoTypeSignalInOutType & 0x07) == 4){
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
	}else{
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
	}
	
	if(Data.NoTypeSignalInOutType & 0x08){
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 72, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
	}else{
		TRoundSquare::sDrawBySize(Lv.Grid.Left[1] + 12, ModuleRectLv3.Top + 72, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
	}
}

void TDevProperty::ClearSelectedNoType()
{
	unsigned int aClr;
	char *tText;
	switch(Tag.Inx){
		case 0:
			
			break;
		case 1:
			IList->EditPortNum.Selected = 0;
			IList->EditPortNum.Show();
			break;
		case 2:
			IList->EditAddrNum.Selected = 0;
			IList->EditAddrNum.Show();
			break;
		case 3:
			IList->EditDescpShow.Selected = 0;
			IList->EditDescpShow.Show();
			break;
		case 4:
			IList->EditUserCode.Selected = 0;
			IList->EditUserCode.Show();
			break;
		case 5:
			IList->EditAreaAssign.Selected = 0;
			IList->EditAreaAssign.Show();
			break;
		case 6:
			IList->Edit[0].Selected = 0;
			IList->Edit[0].Show();
			break;
		case 7:
			if(LanguageEnCn == 0)tText = "保存\0"; else tText="Save\0";
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
		case 8:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 9:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 10:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 11:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +12, ModuleRectLv3.Top + 72, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 12:
			if(LanguageEnCn == 0)tText = "读取\0"; else tText="Read\0";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +120, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
		case 13:
			if(LanguageEnCn == 0)tText = "保存\0"; else tText="Save\0";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +210, ModuleRectLv3.Top + 72, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
	}
}
void TDevProperty::Check4SelectedNoType()
{
	unsigned int aClr;
	char *tText;
	switch(Tag.Inx){
		case 0:
			
			break;
		case 1:
			IList->EditPortNum.Selected = 1;
			IList->EditPortNum.SetPstTail();
			IList->EditPortNum.Show();
			IList->EditPortNum.ShowCursor();
			break;
		case 2:
			IList->EditAddrNum.Selected = 1;
			IList->EditAddrNum.SetPstTail();
			IList->EditAddrNum.Show();
			IList->EditAddrNum.ShowCursor();
			break;
		case 3:
			IList->EditDescpShow.Selected = 1;
			IList->EditDescpShow.Show();
			break;
		case 4:
			IList->EditUserCode.Selected = 1;
			IList->EditUserCode.SetPstTail();
			IList->EditUserCode.Show();
			IList->EditUserCode.ShowCursor();
			break;
		case 5:
			IList->EditAreaAssign.Selected = 1;
			IList->EditAreaAssign.SetPstTail();
			IList->EditAreaAssign.Show();
			IList->EditAreaAssign.ShowCursor();
			break;
		case 6:
			IList->Edit[0].Selected = 1;
			IList->Edit[0].SetPstTail();
			IList->Edit[0].Show();
			IList->Edit[0].ShowCursor();
			break;
		case 7:
			if(LanguageEnCn == 0)tText = "保存"; else tText="Save";
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +210, Lv.Grid.Top[2] + 40, 76, 30, 7, clDeepBlue, tText, 14, clNearWhite);
			break;
		case 8:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +12, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 9:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +110, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 10:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +206, ModuleRectLv3.Top + 36, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 11:
			TRoundSquare::sSelected(Lv.Grid.Left[3] +12, ModuleRectLv3.Top + 72, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 12:
			if(LanguageEnCn == 0)tText = "读取\0"; else tText="Read\0";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +120, ModuleRectLv3.Top + 72, 76, 30, 7, clDeepBlue, tText, 14, clNearWhite);
			break;
		case 13:
			if(LanguageEnCn == 0)tText = "保存\0"; else tText="Save\0";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +210, ModuleRectLv3.Top + 72, 76, 30, 7, clDeepBlue, tText, 14, clNearWhite);
			break;
	}		
}


TGuiMsgReturn TDevProperty::KeyInHtNoType(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	char *tText;
	unsigned char aBits; 
	int HasPrc = 0;
	switch(aKey){
		case VK_0:
		case VK_1:
		case VK_2:
		case VK_3:
		case VK_4:
		case VK_5:
		case VK_6:
		case VK_7:
		case VK_8:
		case VK_9:
		case VK_DELETE:
		case VK_LEFT:
		case VK_RIGHT:
			if(Tag.Inx < 6){
				KeyInCommonEdit(aKey);
			}else{
				if(Tag.Inx == 6){
					//Change Define Type
					IList->Edit[0].KeyIn(aKey);
					RedrawNoTypeDefineType();
				}else
				if(Tag.Inx == 7){
					//Save Define Type
				}else
				if(Tag.Inx == 8){
					//Set As Feed Back
					if(aKey == VK_RIGHT){
						ClearSelectedNoType();
						Tag.Inx = 9;
						Check4SelectedNoType();
					}
				}else
				if(Tag.Inx == 9){
					//Set As Alram
					if(aKey == VK_LEFT){
						ClearSelectedNoType();
						Tag.Inx = 8;
						Check4SelectedNoType();
					}else
					if(aKey == VK_RIGHT){
						ClearSelectedNoType();
						Tag.Inx = 10;
						Check4SelectedNoType();
					}
				}else
				if(Tag.Inx == 10){
					//Set As Sv
					if(aKey == VK_LEFT){
						ClearSelectedNoType();
						Tag.Inx = 9;
						Check4SelectedNoType();
					}
				}
				if(Tag.Inx == 11){
					//Set Output type
					if(aKey == VK_RIGHT){
						ClearSelectedNoType();
						Tag.Inx = 12;
						Check4SelectedNoType();
					}
				}else
				if(Tag.Inx == 12){
					//Read Input Type
					if(aKey == VK_LEFT){
						ClearSelectedNoType();
						Tag.Inx = 11;
						Check4SelectedNoType();
					}else
					if(aKey == VK_RIGHT){
						ClearSelectedNoType();
						Tag.Inx = 13;
						Check4SelectedNoType();
					}
				}else
				if(Tag.Inx == 13){
					//Save Input Type
					if(aKey == VK_LEFT){
						ClearSelectedNoType();
						Tag.Inx = 12;
						Check4SelectedNoType();
					}
				}
			}
			break;
		case VK_UP:
			if(PortNumValid && AddrNumValid){
				ClearSelectedNoType();
				Tag.Inx > Tag.InxMin ? Tag.Inx-- : Tag.Inx = 13;
				Check4SelectedNoType();
			}
			break;
		case VK_DOWN:
			if(PortNumValid && AddrNumValid){
				ClearSelectedNoType();
				Tag.Inx < 13 ? Tag.Inx++ : Tag.Inx = Tag.InxMin;
				Check4SelectedNoType();
			}
			break;
		case VK_TAB:
			//PanelIsUsingText = PanelIsUsingText ? 0 : 1;
			break;
		case dfKEY_SETUP:
			if(Tag.Inx == 8){
				aBits = Data.NoTypeSignalInOutType;
				if( (aBits & 0x07) == 0){
					Data.NoTypeSignalInOutType |= 0x01;
				}else
				if( (aBits & 0x07) == 1){
					Data.NoTypeSignalInOutType &= ~0x07;
				}else{
					Data.NoTypeSignalInOutType &= ~0x07;
					Data.NoTypeSignalInOutType |= 0x01;
				}
				RedrawNoTypeSignalType();
			}else
			if(Tag.Inx == 9){
				aBits = Data.NoTypeSignalInOutType;
				if( (aBits & 0x07) == 0){
					Data.NoTypeSignalInOutType |= 0x02;
				}else
				if( (aBits & 0x07) == 2){
					Data.NoTypeSignalInOutType &= ~0x07;
				}else{
					Data.NoTypeSignalInOutType &= ~0x07;
					Data.NoTypeSignalInOutType |= 0x02;
				}
				RedrawNoTypeSignalType();
			}else
			if(Tag.Inx == 10){
				aBits = Data.NoTypeSignalInOutType;
				if( (aBits & 0x07) == 0){
					Data.NoTypeSignalInOutType |= 0x04;
				}else
				if( (aBits & 0x07) == 4){
					Data.NoTypeSignalInOutType &= ~0x07;
				}else{
					Data.NoTypeSignalInOutType &= ~0x07;
					Data.NoTypeSignalInOutType |= 0x04;
				}
				RedrawNoTypeSignalType();
			}else
			if(Tag.Inx == 11){
				aBits = Data.NoTypeSignalInOutType;
				if( (aBits & 0x08) == 0){
					Data.NoTypeSignalInOutType |= 0x08;
				}else{
					Data.NoTypeSignalInOutType &= ~0x08;
				}
				RedrawNoTypeSignalType();
			}
			break;
		case dfKEY_QUERY:
			//PanelDrawData.DesertTextHex = PanelDrawData.DesertTextHex ? 0: 1;
			break;
		case dfKEY_ENCN:
			//SendReqMac();
			break;
		case VK_EXECUTE:
			if(PortNumValid && AddrNumValid){
				if(Tag.Inx <6){
					KeyInCommonEnter(aKey);
				}else{
					if(Tag.Inx == 6){
						//Change Define Type
					}else
					if(Tag.Inx == 7){
						//Save Define Type And Add Record
						if( (Path0 >0) && (Path0 <= dPORT_MAX_COUNT) && (Path1 >0) && (Path1 <= dEP_MAX_COUNT_PER_PORT) ){
							HasPrc = IList->Edit[0].Str.ToInteger();
							if( (HasPrc >-1) && (HasPrc < 256) ){
								AssignTypeSetting = HasPrc;
								PermissionCmd = pcWriteAssignType;
								if(SystemPermission >2){
									PermissionCmdGO();
								}else{
									IsPermission = 1;
									PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
								}
							}
						}
					}else
					if(Tag.Inx == 8){
						aBits = Data.NoTypeSignalInOutType;
						if( (aBits & 0x07) == 0){
							Data.NoTypeSignalInOutType |= 0x01;
						}else
						if( (aBits & 0x07) == 1){
							Data.NoTypeSignalInOutType &= ~0x07;
						}else{
							Data.NoTypeSignalInOutType &= ~0x07;
							Data.NoTypeSignalInOutType |= 0x01;
						}
						RedrawNoTypeSignalType();
					}else
					if(Tag.Inx == 9){
						aBits = Data.NoTypeSignalInOutType;
						if( (aBits & 0x07) == 0){
							Data.NoTypeSignalInOutType |= 0x02;
						}else
						if( (aBits & 0x07) == 2){
							Data.NoTypeSignalInOutType &= ~0x07;
						}else{
							Data.NoTypeSignalInOutType &= ~0x07;
							Data.NoTypeSignalInOutType |= 0x02;
						}
						RedrawNoTypeSignalType();
					}else
					if(Tag.Inx == 10){
						aBits = Data.NoTypeSignalInOutType;
						if( (aBits & 0x07) == 0){
							Data.NoTypeSignalInOutType |= 0x04;
						}else
						if( (aBits & 0x07) == 4){
							Data.NoTypeSignalInOutType &= ~0x07;
						}else{
							Data.NoTypeSignalInOutType &= ~0x07;
							Data.NoTypeSignalInOutType |= 0x04;
						}
						RedrawNoTypeSignalType();
					}else
					if(Tag.Inx == 11){
						aBits = Data.NoTypeSignalInOutType;
						if( (aBits & 0x08) == 0){
							Data.NoTypeSignalInOutType |= 0x08;
						}else{
							Data.NoTypeSignalInOutType &= ~0x08;
						}
						RedrawNoTypeSignalType();
					}else
					if(Tag.Inx == 12){
						if( (Path0) && (Path1) && (Path0 <= dPORT_MAX_COUNT) && (Path1 <= dEP_MAX_COUNT_PER_PORT) ){
							Data.NoTypeSignalInOutType = Port[Path0-1].FuncSetByte[Path1-1];
						}
						RedrawNoTypeSignalType();
					}else
					if(Tag.Inx == 13){
						//Write Signal In Type
						PermissionCmd = pcWriteNoTypeSignalInOutType;
						if(SystemPermission >2){
							PermissionCmdGO();
						}else{
							IsPermission = 1;
							PermissionCmd = pcWriteNoTypeSignalInOutType;
							PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
						}
					}
				}
			}
			break;
		case VK_RETURN:
			IsShow = 0;
			RealTimeSendCmdAbort();
			aMsg = guiMsgReturn;
			break;
	}
	
	return aMsg;
}

void TDevProperty::WriteNoTypeInOutSignal()
{
	unsigned int fAddr;
	unsigned int i;
	unsigned int aUcFull;
	volatile unsigned int x, GetSta;
	unsigned char aP0, aP1, wP1;
	if( (Path0) && (Path0<=dPORT_MAX_COUNT) && (Path1) ){
		aP0 = Path0 -1;
		aP1 = Path1 -1;
		Port[aP0].FuncSetByte[aP1] = Data.NoTypeSignalInOutType;
		sIList = IList;
		sWriteAuxIdAssignTypeSignalType(Path0);

		Record.ReadDevUserSet();
		Data.NoTypeSignalInOutType = Port[aP0].FuncSetByte[aP1];
		RedrawNoTypeSignalType();
	}
}

void TDevProperty::Redraw4NoTypeSmallPanelWithNoData()
{
	//RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);
}

void TDevProperty::Task1000MsNoType()
{

}


