//---------------------------------------------------------------------------


#pragma hdrstop

#include "udmFireDACInsertData.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma classgroup "FMX.Controls.TControl"
#pragma resource "*.dfm"
TDataModule1 *DataModule1;

const String Numeric[10] = {"0","1","2","3","4","5","6","7","8","9"};
const String sSurName[31] = {"»¯","¿ú","®]","§õ","©P","§d","¾G","¤ý","¶¾","³¯","»u","½Ã","½±","¨H","Áú","·¨","¦¶","¯³","¤×","³\","¦ó","§f","¬I","±i","¤Õ","±ä","ÄY","µØ","ª÷","ÃQ","³³"};
const String sRName[16]  =  {"¹s","³ü","¶L","°Ñ","¸v","¥î","³°","¬m","®Ã","¨h","¬B","¨Õ","¥a","¸U","»õ","¥ü"};
const String sRName1[11] =  {"¢¯", "¤@","¤G","¤T","¥|","¤­","¤»","¤C","¤K","¤E","¤Q"};

//---------------------------------------------------------------------------
__fastcall TDataModule1::TDataModule1(TComponent* Owner)
	: TDataModule(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TDataModule1::DataModuleCreate(TObject *Sender)
{
  Randomize();
}
//---------------------------------------------------------------------------

String TDataModule1::GetRandomName()
{
  int iIndex;
  int iPos;

  String sResult = "";
  sResult = sSurName[Random(31)];
  for (iIndex = 1; iIndex <= 9; iIndex++)
  {
	iPos = Random(2);
	if (iPos == 0)
	{
	  sResult = sResult + sRName[Random(16)];
	}
	else
	{
	  sResult = sResult + sRName1[Random(11)];
	}
  }

  return sResult;
}

String TDataModule1::GetRandomPhone()
{
  int iIndex;
  int iPos;

  String sResult = "";
  for (iIndex = 1; iIndex <= 15; iIndex++)
  {
	iPos = Random(10);
	sResult = sResult + Numeric[iPos];
  }

  return sResult;
}

String TDataModule1::GetRandomDateTime(const TDateTime dt)
{
  Word iYear, iMonth, iDay;
  Word iHour, iMin, iSec, iMSec;

  DecodeDate(dt, iYear, iMonth, iDay);
  DecodeTime(dt, iHour, iMin, iSec, iMSec);
  String sResult = IntToStr(iYear) + IntToStr(iMonth) + IntToStr(iDay) + IntToStr(iHour) + IntToStr(iMin) + IntToStr(iSec);
  return sResult;
}

String TDataModule1::GetRandomDivision()
{
  int iRecord = Random(SQLQuery1->RecordCount);
  SQLQuery1->First();
  SQLQuery1->MoveBy(iRecord);
  String sResult = SQLQuery1->FieldByName("DIVISIONNAME")->Value;
  return sResult;
}

void TDataModule1::InsertDataWithQuery(const int iRecord)
{
  cdsData->DisableControls();
  for (int iIndex = 1; iIndex <= iRecord; iIndex++)
  {
	cdsData->Insert();
	cdsData->FieldByName("ADDDT")->Value = Now();
	cdsData->FieldByName("ADDDATETIME")->Value = GetRandomDateTime(Now());
	cdsData->FieldByName("RNAME")->Value = GetRandomName();
	cdsData->FieldByName("FAKEPHONE")->Value = GetRandomPhone();
	cdsData->FieldByName("DIVISION")->Value = GetRandomDivision();
	cdsData->Post();
	cdsData->ApplyUpdates(0);
  }
  cdsData->EnableControls();
}

