#ifndef DUPLICATECHECK_H_
#define DUPLICATECHECK_H_

#include "gType.h" 
#include "GraphBase.h"
#include "string.h"
#include "my_string.h"
#include "Device.h"
#include "EpDevice.h"
#include "StaticText.h"
#include "CtlPanel1.h"
#include "ProtoInnerCan.h"

class TDuplicateCheck{
	public:
		static constexpr unsigned short hList[12] = {72,102,72,72,	42,72,34,34,	34,34,34,34};
		static constexpr unsigned short wList[12] = {800,290,290,290,	290,290,290,290,	290,290,290,290};
		static constexpr TLv Lv = {
			.Caption.Left = 0,
			.Caption.Top = 36,
			.Caption.Width = 800,
			.Caption.Heigh = 32,
			.Caption.Right = 800 -0 -1,
			.Caption.Bottom = 36 + 32,
			
			.Grid.Left = {0,0,0,0,	0,0,0,0,	0,0,0,0},
			.Grid.Right = {wList[0]-1,wList[1]-1,wList[2]-1,wList[3]-1,	wList[4]-1,wList[5]-1,wList[6]-1,wList[7]-1,	wList[8]-1,wList[9]-1,wList[10]-1,wList[11]-1},
			.Grid.Top[0] = (36 + 32 +2),
			.Grid.Top[1] = (36 + 32 +2) + (2 + hList[0]),
			.Grid.Top[2] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]),
			.Grid.Top[3] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]),
			.Grid.Top[4] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]),
			.Grid.Top[5] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]),
			.Grid.Top[6] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]),
			.Grid.Top[7] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]),
			.Grid.Top[8] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]),
			.Grid.Top[9] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]),
			.Grid.Top[10] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]),
			.Grid.Top[11] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]) + (2 + hList[10]),
				
			.Grid.Bottom[0] = (36 + 32 +2) + hList[0],
			.Grid.Bottom[1] = (36 + 32 +2) + (2 + hList[0]) + hList[1],
			.Grid.Bottom[2] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + hList[2],
			.Grid.Bottom[3] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + hList[3],
			.Grid.Bottom[4] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + hList[4],
			.Grid.Bottom[5] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + hList[5],
			.Grid.Bottom[6] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + hList[6],
			.Grid.Bottom[7] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + hList[7],
			.Grid.Bottom[8] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + hList[8],
			.Grid.Bottom[9] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + hList[9],
			.Grid.Bottom[10] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]) + hList[10],
			.Grid.Bottom[11] = (36 + 32 +2) + (2 + hList[0]) + (2 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]) + (2 + hList[10]) + hList[11],
			
			.Grid.UsingCount = 5,
			
			.Panel.Active = 1,
			.Panel.ItemType = piMemo,
			.Panel.Left = wList[1] + 6,
			.Panel.Top = (36 + 32 +2) + hList[0] +6,
			.Panel.Width = 502,
			.Panel.Heigh = 250,
			.Panel.Right = wList[1] + 6 + 502 -1,
			.Panel.Bottom = (36 + 32 +2) + hList[0] +6 + 250 -1,
			
			.PanelSmall.Active = 1,
			.PanelSmall.Left = wList[1] + 6,
			.PanelSmall.Top = (36 + 32 +2) + hList[0] +6 + 250 -1 + 1,
			.PanelSmall.Width = 502,
			.PanelSmall.Heigh = 42,
			.PanelSmall.Right = wList[1] + 6 + 502 -1,
			.PanelSmall.Bottom = (36 + 32 +2) + hList[0] +6 + 250 -1 + 1 + 42 -1,
		};
		static constexpr unsigned int MaxCount = 1024;
		static constexpr int LinesCount = 8;
	public:
		class TItemList	*IList;
	
		void (*KeepOnMeJustEnter)(void);
		void (*KeepUiOnMe)(void);
		u32 Color;
	
		int IsShow;
	
		unsigned char CtlNum;
		unsigned char PortNum;
		unsigned char CtlNumAvalble;
		unsigned char PortNumAvalble;
	
		TRect Bound;	
		TMyString Str;
	
		struct{
			unsigned char InxMin;
			unsigned char InxMax;
			unsigned char Inx;
			void Reset(){
				Inx = 0;
				InxMin = 0;
				InxMax =11;
			}
		}Tag;
		unsigned char IsPermission;
		unsigned char PermissionCmd;
		
		union{
			unsigned short sVal[4];
			unsigned char  cVal[8];
		}RecData;
		unsigned short Scaling[4];
		int IsFastCmd;
		unsigned char Data[8];
		
		unsigned char IsChecking;
		unsigned char IsTransmiting;
		unsigned char IsTransmitingFinish;
		unsigned char IsOnNetwork;
		unsigned char CheckWhat;
		unsigned char CheckTick;
		unsigned char PortCnt;
		unsigned char Percent;
		unsigned char OldPercent;
		unsigned char P0;
		unsigned char IsShowDetail;
		unsigned char IsProgressUpdata;
		unsigned char IsDetailUpdata;
		
		unsigned int WastingTime;
		
		struct{
			unsigned char PagesCount;
			unsigned char PageX;
		}Details;
		char Text[4];
		
	private:
	public:
		TDuplicateCheck(){};
		void Init();
	
		void SetAndShowCaption(unsigned char aType);
		
		void RenderBackGround(void);
		void RenderBackGround(unsigned int aClr);
		void DrawSelf(void);
		void DrawCommonByExReturn();
		void DrawFixText();
		
		void Show(void);
		void ReDraw(void);
		void FullRedraw(int Prm);
		void PanelCanvasOut();
		void DrawProgress();
		void DrawDetailOutline();
		int  TryDrawDetail();
		void DrawDetail();
		
		TGuiMsgReturn KeyIn(unsigned char aKey);
		void ClearSelected(void);
		void Check4Selected(void);
		
		void PermissionCmdReturnDraw();
		void SendCmd();
		void SendFastCmd();
		void SendEndCmd();
		
		void CheckResult();
		void ResetBackEndData();
		
		void InnerCanPushData(unsigned char aCmd, unsigned char *pData);
			
		void PermissionCmdGO();
		void SetData(unsigned char aPort, unsigned char aAddr, unsigned char aCnt);
		unsigned char GetData(unsigned char aPort, unsigned char aAddr);
		
		void Task1000Ms();
		
		int ExtRequst(unsigned char Prm);//{IsShow =0; SendEndCmd(); return 0;}
};



#endif



