#ifndef __ML8300_H
#define __ML8300_H

#define DB_MAXFIELD_COUNT 		16
#define DB_MAXFIELD_NAME		16
#define		VALUETYPE_INT1		0
#define		VALUETYPE_INT2		1
#define		VALUETYPE_INT4		2
#define		VALUETYPE_UINT1		3
#define		VALUETYPE_UINT2		4
#define		VALUETYPE_UINT4		5
#define		VALUETYPE_DOUBLE2	0
#define		VALUETYPE_DOUBLE3	1
#define		VALUETYPE_UDOUBLE2	2
#define		VALUETYPE_UDOUBLE3	3
#define		SOURCETYPE_KEYBOARD	0
#define		SOURCETYPE_SCANER	1
#define		SOURCETYPE_KEYANDSCAN	2
#define		SOURCETYPE_UNALLOW	3
#define	CONTROL_TYPE_NONE		0
#define CONTROL_TYPE_FORM		1
#define CONTROL_TYPE_BUTTON		2
#define CONTROL_TYPE_STATIC		3
#define CONTROL_TYPE_INT1		4
#define CONTROL_TYPE_INT2		5
#define CONTROL_TYPE_INT4		6
#define CONTROL_TYPE_DOUBLE		7
#define	CONTROL_TYPE_STRING		8
#define	CONTROL_TYPE_NULL		9
#define	FM_CLICK		1
#define	FM_CANCEL		2
#define FM_UP			3
#define FM_DOWN			4
#define KEY_ENTER		13
#define ICON_CLEAR_ALL		0
#define ICON_UP			1
#define ICON_DOWN		2
#define ICON_SELECTION		3
#define ICON_NOSELECTION	4
#define MB_NONE			0
#define MB_OK			1
#define MB_YESNO		2
#define MBYES			1
#define MBNO			2
#define MB_ICONEXCLAMATION	512
#define MB_ICONQUESTION		1024
#define HOTKEY_FORMSELECTION	0
#define HOTKEY_FORMSELECTION1	1
#define HOTKEY_FORMSELECTION2	2
#define HOTKEY_FORMSELECTION3	3
#define HOTKEY_CALCULATOR	4

#define DBTYPE_STRING	0
#define DBTYPE_INT	1
#define	DBTYPE_UINT	2
#define	DBTYPE_FLOAT	3
#define DBTYPE_UFLOAT	4
#define DBTYPE_INCR	5	
#define DBERROR_NOERROR			0
#define DBERROR_UNKNOWNERROR		-1
#define DBERROR_TABLEALREADYEXIST	-2
#define DBERROR_TABLENOTEXIST		-3
#define DBERROR_STRUCTOFTABLENOTFOUND 	-4
#define DBERROR_OTHERTABLEALREADYOPEN	-5
#define DBERROR_ILLEGALFIELDNUM		-6
#define DBERROR_TABLENOTOPEN		-7
#define DBERROR_NOFREEKEY		-8
#define DBERROR_KEYALREADYUSEINFIELD	-9
#define DBERROR_NOKEYAVAILABLE		-10
#define DBERROR_FILENAMEISNULL		-11
#define DBERROR_FILENOTEXIST		-12
#define DBERROR_FILENOTDBF		-13
#define DBERROR_FILEALREADYOPEN		-14
#define DBERROR_MAXIMUMFILESEXCEED	-15
#define	DBERROR_INALIDFILEHANDLE	-16
#define	DBERROR_ILLEGALKEYNUMBER	-17
#define DBERROR_ILLEGALARGUMENTS	-18
#define DBERROR_DBFNOTEMPTY		-19
#define DBERROR_KEYALREADYEXIST		-20
#define DBERROR_NOMOREFREESPACE		-21
#define DBERROR_MAXNUMFIELDSEXCEED	-22
#define	DBERROR_DBFEMPTY		-23
#define DBERROR_ENDOFFILE		-24
#define DBERROR_NEEDPREPARE		-25
#define DBERROR_CRITICAL_NOMEMORY	-26
#define DBERROR_RECORDNOTFOUND		-27
#define DBERROR_CHECKFAIL		-28

typedef struct SMenuHeader
{
	char	*HeaderTitle;
	char	HeaderFont;
	char	fShowHeader;
	char	Font;
	char	fInverse;
	int	NumOfItems;
	int	CurrentItem;
	char	Offset;
} MenuHeader;

typedef struct SMenuItem
{
	char	*Title;
	char	HotKey;
} MenuItem;

typedef struct SForm
{
	char 	Type;
	char	Offset;
	long 	ID;
	int	CurrentChild;
} Form;

typedef struct SButton
{
	char 	Type;
	char	XPos;
	char	YPos;
	char	Font;
	char	AutoEnter;
	long	ID;
	char	*Caption;
	char	HotKey;
} Button;

typedef struct SStatic
{
	char 	Type;
	char	XPos;
	char	YPos;
	char	Font;
	char	AutoEnter;
	char	*Caption;
	char	fInverse;
} Static;


typedef struct SIntValue1
{
	char 	Type;
	char	XPos;
	char	YPos;
	char	Font;
	char	AutoEnter;
	char	Skip;
	char	Inverse;
	char	Invisible;
	long	ID;
	char	ValueType;
	unsigned char Lenght;
	char	Source;
	union	{
		char		Int1;
		unsigned char	UInt1;
	} Value;
} IntValue1;

typedef struct SIntValue2
{
	char 	Type;
	char	XPos;
	char	YPos;
	char	Font;
	char	AutoEnter;
	char	Skip;
	char	Inverse;
	char	Invisible;
	long	ID;
	char	ValueType;
	unsigned char Lenght;
	char	Source;
	union	{
		int				Int2;
		unsigned int	UInt2;
	} Value;
} IntValue2;

typedef struct SIntValue4
{
	char 	Type;
	char	XPos;
	char	YPos;
	char	Font;
	char	AutoEnter;
	char	Skip;
	char	Inverse;
	char	Invisible;
	long	ID;
	char	ValueType;
	unsigned char Lenght;
	char	Source;
	union	{
		long			Int4;
		unsigned long	UInt4;
	} Value;
} IntValue4;

typedef struct SDoubleValue
{
	char 	Type;
	char	XPos;
	char	YPos;
	char	Font;
	char	AutoEnter;
	char	Skip;
	char	Inverse;
	char	Invisible;
	long	ID;
	char	ValueType;
	unsigned char Lenght;
	char	Source;
	double	Value;
} DoubleValue;

typedef struct SString
{
	char 	Type;
	char	XPos;
	char	YPos;
	char	Font;
	char	AutoEnter;
	char	Skip;
	char	Inverse;
	char	Invisible;
	long	ID;
	char	ValueType;
	unsigned char Lenght;
	char	Source;	
	char 	*Value;	
} String;

typedef struct SNullValue
{
	char Type;
} NullValue;

typedef struct SWeightBarcode
{
	unsigned char	code_st;
	unsigned char	code_end;
	unsigned char	col_st;
	unsigned char	col_end;
	char	pr[8];
	long	divisor;
} WeightBarcode;


typedef struct STR_TABLEINFO
{
	char		Name[9];
	unsigned	TotalLen;
	long		RecordCount;
	unsigned	FieldCount;
	unsigned	FieldLen[DB_MAXFIELD_COUNT];
	unsigned	FieldType[DB_MAXFIELD_COUNT];
	char		FieldFilter[DB_MAXFIELD_COUNT];
	char		FieldName[DB_MAXFIELD_COUNT][DB_MAXFIELD_NAME];
	unsigned	KeyCount;
	unsigned	Keys[8];
} TableInfo;

typedef struct STR_WDATA
{
	int	KeyNumber;
	int	FileHandle;
	char 	*CurrentRecord;
	char	*Fields[DB_MAXFIELD_COUNT];
	char	fPrepare;
	int	FilterField;
	char	*CurrentFilter;
	unsigned long	MaxIncr;
} WData;


void	ShowForm (Form *form, char **controls, long *lparam, long *wparam);
void	ShowMenu (MenuHeader *MenuHdr, MenuItem *MenuItm, long *lparam, long *wparam);
int	MessageBox (char *Text, long flags, long param);
void	SetPasswordOnEdit (unsigned long l);
void	SetPasswordOnView (unsigned long l);
void	SetPasswordOnSetup (unsigned long l);
void	SetPasswordOnDelete (unsigned long l);
void	SetWeightBarcode (unsigned char, unsigned char, unsigned char, unsigned char, char*, long);
void	MoveToNextChild (Form *MainForm, char **controls);
void	MoveToPrevChild (Form *MainForm, char **controls);
void	ShowIcon (int iconID);
char*	DoubleToStr (double dbl, char type);
void	SetHotKey (char type, char key);
void	SetRemoveLeadNull (char remove);
void	MainMenu (void);
char	CheckPasswordOnEdit ();
char	CheckPasswordOnView ();
char	CheckPasswordOnSetup ();
char	CheckPasswordOnDelete ();
char	GetPassword (char *pas);
void	SaveToFlash ();
void 	ReadFromFlash ();
int	StripWeightBarcode (char *code, double *dbl);
long	DoubleToLong (double dbl);
char	FormSelection (char* ctrl, char key);
void	AbleFormSelection (char *ctrl);
void	RemoveParentTables();
void	AddParentTable (char, char , char); 

char	ActionReplaceStr (char, char, char *);
char	ActionAddStr (char, char, char *);
char	ActionAdd (char, char, char *);
char	ActionSub (char, char, char *);
char	ActionRecordAdd (char);
char	ActionRecordEdit (char);
char	ActionRecordDel (char);
char	ActionRecordAddEdit (char, char);
char	ActionRecordLocate (char, char, char *);
char	ActionCalc (char *, char *, char*, char);
char	ActionFilterOff (char);
char	ActionFilterOn (char, char *);
char	ActionRecordNext (char);
char	ActionRecordPrev (char);
char	ActionRecordFirst (char);
char	ActionRecordLast (char);
char	ActionRecordDeleteAll (char);
char	ActionShowMessage (char *);
void	ActionBeep (char);
char	ActionSet (char *, char *);
char	ActionFieldSetDouble (char *, double);
char	ActionTableSetDouble (char, char, char, double);
char	ActionCopy (char *FormField1, char *FormField2);
char	ActionClearCurrentRecord (char TableIndex);
double	Any2Double (char*);

void	TransmitPrepare(int params, int type);
void	TransmitFinish ();
void	ProceedRecivedData ();

int	PrepareToCreateTable (char *);
int	CreateField (char *, unsigned, unsigned, char);
int	CreateKey (unsigned, unsigned);
int	CreateTable ();
int	CloseTable  ();
int	CloseAllTables ();
int	OpenTable	(char *);
int	ChangeTable (char *);
int	GetTableCount ();
int	GetTableInfo (char *, TableInfo *);
int	GetCurrentTable (TableInfo *);
int	ClearTableByName (char *);
int	DeleteTableByName (char *);
int	AddRecord ();
int	DeleteRecord ();
int	ClearCurrentRecord ();
int	SaveRecord ();
int	LoadRecord ();
int	SetFieldValue (unsigned, char *);
int	GetFieldValue (unsigned, char *);
int	SetFieldValueWithAction (unsigned, char *, char);
int	CheckFieldValueWithAction (unsigned, char *, char);
int	SetRecordValue (char *);
int	ClearTable ();
int	MoveFirst();
int	MoveLast();
int	MovePrior();
int	MoveNext();
int	LocateRecordByKeyNumber(unsigned, char *);
long	GetCurrentPosition();
int	SetCurrentPosition (long);
long	GetRecordCount ();
int	ChangeKeyNumber (unsigned);
unsigned GetKeyNumberWithFilter (unsigned);
int	GetFieldCount ();
int	GetFieldLen (unsigned);
int	GetFieldName (unsigned, char *);
int	GetFieldType (unsigned);
int	GetFieldFilter (unsigned);
int	SetFilter (unsigned, char *);
int	RemoveFilter ();
int	GetFilter ();
char*	GetFilterValue();
int	SetFilterToRecord ();

void	CreateTableStructure ();
void	ViewTable (long);
char	GetFormSelection (long, long, char *, char *,char *, char *, char *);
char	GetAvailableFormSelection (long, long, char*, char*, char*, char*);
char	GetAvailableCalculator (long, long);


#endif
