(CODE)
/
PROMPT Creating Primary Key on 'SUBSTANCE'
ALTER TABLE SUBSTANCE
ADD CONSTRAINT SUBSTANCE_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'PERIOD'
ALTER TABLE PERIOD
ADD CONSTRAINT ПЕРИОДИЧН_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'ECOLOGY_NUMBER'
ALTER TABLE ECOLOGY_NUMBER
ADD CONSTRAINT ЭКОЛОГ_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'GROUP_PARAMETR'
ALTER TABLE GROUP_PARAMETR
ADD CONSTRAINT ГРУППА_ПАР_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'TYPE_ECOLOGY_NUMBER'
ALTER TABLE TYPE_ECOLOGY_NUMBER
ADD CONSTRAINT ТИП_ЭВ_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'ZAGRAZN_VV'
ALTER TABLE ZAGRAZN_VV
ADD CONSTRAINT ЗАГР_ВВ_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'SMES'
ALTER TABLE SMES
ADD CONSTRAINT СМЕСИ_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'ECOLOGY_PARAM'
ALTER TABLE ECOLOGY_PARAM
ADD CONSTRAINT PARAM_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'NORMATIV_PARAM'
ALTER TABLE NORMATIV_PARAM
ADD CONSTRAINT НОРМАТИВ_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'TERRITORIES'
ALTER TABLE TERRITORIES
ADD CONSTRAINT TER3_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'OBJECT_EM'
ALTER TABLE OBJECT_EM
ADD CONSTRAINT ОБЪЕКТ_ЭМ_PK PRIMARY KEY
(CODE)
/
PROMPT Creating Primary Key on 'UNITMEASURE'
ALTER TABLE UNITMEASURE
ADD CONSTRAINT UNI1_PK PRIMARY KEY
(UNITMEAS)
/
PROMPT Creating Primary Key on 'ISOTOPE'
ALTER TABLE ISOTOPE
ADD CONSTRAINT ISO_PK PRIMARY KEY
(SHORTNAME)
/
PROMPT Creating Unique Keys on 'ORGANIZATION'
ALTER TABLE ORGANIZATION
ADD ( CONSTRAINT ORG_SYS_C002890_UK UNIQUE
(NAME))
ADD ( CONSTRAINT ORG_SYS_C002891_UK UNIQUE
(SHORTNAME))
/
PROMPT Creating Unique Keys on 'TERRITORIES'
ALTER TABLE TERRITORIES
ADD ( CONSTRAINT TER3_SYS_C0027487_UK UNIQUE
(NAME))
/
PROMPT Creating Foreign Keys on 'OTCHETNOST'
ALTER TABLE OTCHETNOST ADD CONSTRAINT
ОТЧЕТНОСТЬ_ПЕРИОДИЧН_FK FOREIGN KEY
(ПЕРИОДИЧН_CODE) REFERENCES PERIOD
(CODE) ADD CONSTRAINT
ОТЧЕТНОСТЬ_PARAM_FK FOREIGN KEY
(PARAM_CODE) REFERENCES ECOLOGY_PARAM
(CODE) ADD CONSTRAINT
ОТЧЕТНОСТЬ_НОРМАТИВ_FK FOREIGN KEY
(НОРМАТИВ_CODE) REFERENCES NORMATIV_PARAM
(CODE) ADD CONSTRAINT
ОТЧЕТНОСТЬ_НОРМАТИВ_ЯВЛЯЕТС_FK FOREIGN KEY
(НОРМАТИВ_CODE_ЯВЛЯЕТСЯ) REFERENCES NORMATIV_PARAM
(CODE) ADD CONSTRAINT
ОТЧЕТНОСТЬ_UNI1_FK FOREIGN KEY
(UNI1_UNITMEAS) REFERENCES UNITMEASURE
(UNITMEAS) ADD CONSTRAINT
ОТЧЕТНОСТЬ_ОБЪЕКТ_ЭМ_FK FOREIGN KEY
(ОБЪЕКТ_ЭМ_CODE) REFERENCES OBJECT_EM
(CODE)
/
PROMPT Creating Foreign Keys on 'FORMA_OTCHETNOSTI'
ALTER TABLE FORMA_OTCHETNOSTI ADD CONSTRAINT
ФОРМА_ФОРМА_FK FOREIGN KEY
(ФОРМА_CODE) REFERENCES FORMA_OTCHETNOSTI
(CODE) ADD CONSTRAINT
ФОРМА_ORG_УТВЕРЖДЕНА_FK FOREIGN KEY
(ORG_CODE_УТВЕРЖДЕНА) REFERENCES ORGANIZATION
(CODE) ADD CONSTRAINT
ФОРМА_ПЕРИОДИЧН_FK FOREIGN KEY
(ПЕРИОДИЧН_CODE) REFERENCES PERIOD
(CODE)
/
PROMPT Creating Foreign Keys on 'ECOLOGY_NUMBER'
ALTER TABLE ECOLOGY_NUMBER ADD CONSTRAINT
ЭКОЛОГ_UNI1_FK FOREIGN KEY
(UNI1_UNITMEAS) REFERENCES UNITMEASURE
(UNITMEAS) ADD CONSTRAINT
ЭКОЛОГ_ТИП_ЭВ_FK FOREIGN KEY
(ТИП_ЭВ_CODE) REFERENCES TYPE_ECOLOGY_NUMBER
(CODE) ADD CONSTRAINT
ЭКОЛОГ_ГРУППА_ПАР_FK FOREIGN KEY
(ГРУППА_ПАР_CODE) REFERENCES GROUP_PARAMETR
(CODE)
/
PROMPT Creating Foreign Keys on 'GROUP_PARAMETR'
ALTER TABLE GROUP_PARAMETR ADD CONSTRAINT
ГРУППА_ПАР_ГРУППА_ПАР_FK FOREIGN KEY
(ГРУППА_ПАР) REFERENCES GROUP_PARAMETR
(CODE)
/
PROMPT Creating Foreign Keys on 'TYPE_ECOLOGY_NUMBER'
ALTER TABLE TYPE_ECOLOGY_NUMBER ADD CONSTRAINT
ТИП_ЭВ_FK FOREIGN KEY
(ТИП_ЭВ) REFERENCES TYPE_ECOLOGY_NUMBER
(CODE)
/
PROMPT Creating Foreign Keys on 'ZAGRAZN_VV'
ALTER TABLE ZAGRAZN_VV ADD CONSTRAINT
ЗАГР_ВВ_СМЕСИ_FK FOREIGN KEY
(СМЕСИ_CODE) REFERENCES SMES
(CODE) ADD CONSTRAINT
ЗАГР_ВВ_ISO_FK FOREIGN KEY
(ISO_SHORTNAME) REFERENCES ISOTOPE
(SHORTNAME) ADD CONSTRAINT
ЗАГР_ВВ_SUBSTANCE_FK FOREIGN KEY
(SUBSTANCE_CODE) REFERENCES SUBSTANCE
(CODE)
/
PROMPT Creating Foreign Keys on 'ECOLOGY_PARAM'
ALTER TABLE ECOLOGY_PARAM ADD CONSTRAINT
PARAM_UNI1_FK FOREIGN KEY
(UNI1_UNITMEAS) REFERENCES UNITMEASURE
(UNITMEAS) ADD CONSTRAINT
PARAM_ЭКОЛОГ_FK FOREIGN KEY
(ЭКОЛОГ_CODE) REFERENCES ECOLOGY_NUMBER
(CODE) ADD CONSTRAINT
PARAM_ЗАГР_ВВ_FK FOREIGN KEY
(ЗАГР_ВВ_CODE) REFERENCES ZAGRAZN_VV
(CODE) ADD CONSTRAINT
PARAM_ФОРМА_FK FOREIGN KEY
(ФОРМА_CODE) REFERENCES FORMA_OTCHETNOSTI
(CODE) ADD CONSTRAINT
PARAM_ПЕРИОДИЧН_FK FOREIGN KEY
(ПЕРИОДИЧН_CODE) REFERENCES PERIOD
(CODE)
/
PROMPT Creating Foreign Keys on 'VALUE'
ALTER TABLE VALUE ADD CONSTRAINT
VALUE_ORG_FK FOREIGN KEY
(ORG_CODE) REFERENCES ORGANIZATION
(CODE) ADD CONSTRAINT
VALUE_ОТЧЕТНОСТЬ_FK FOREIGN KEY
(ОТЧЕТНОСТЬ_CODE) REFERENCES OTCHETNOST
(CODE)
/
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "main.h"
#include "basic.h"
#include "unislct.h"
#include "filter.h"
#include "fieldsN.h"
#include "fieldText.h"
#include "fieldList.h"
#include "fieldValue.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "tbltmpl"
#pragma resource "*.dfm"
void __fastcall UploadMetaInfo(TformDescription *t_desc, AnsiString formname)
{
TADOQuery *mrT = new TADOQuery(NULL);
try
{
mrT->Connection = frmMain->cnncMetaInfo;
t_desc->formname = formname;
if (SELECT(mrT, "select * from forms where name = '" + t_desc->formname + "'"))
{
t_desc->title = mrT->FieldByName("title")->AsString;
t_desc->edittitle = mrT->FieldByName("edittitle")->AsString;
t_desc->accepttitle = mrT->FieldByName("accepttitle")->AsString;
t_desc->table = mrT->FieldByName("table")->AsString;
t_desc->keyfield = mrT->FieldByName("keyfield")->AsString;
t_desc->namefield = mrT->FieldByName("namefield")->AsString;
t_desc->listfield = mrT->FieldByName("listfield")->AsString;
t_desc->shortnamefield = mrT->FieldByName("shortnamefield")->AsString;
t_desc->sortfield = mrT->FieldByName("sortfield")->AsString;
t_desc->sequencename = mrT->FieldByName("sequencename")->AsString;
t_desc->readonly = mrT->FieldByName("readonly")->AsBoolean;
t_desc->takefieldsfrom = mrT->FieldByName("takefieldsfrom")->AsString;
t_desc->type = mrT->FieldByName("type")->AsString;
t_desc->hideonaccept = mrT->FieldByName("hideonaccept")->AsBoolean;
t_desc->parentfield = mrT->FieldByName("parentfield")->AsString;
} else
{
throw Exception("Ошибка: Форма {" + t_desc->formname + "} отсутствует");
}
} __finally
{
delete mrT;
}
}
//---------------------------------------------------------------------------
__fastcall TfrmUniForm::TfrmUniForm(TComponent* Owner, TMenuItem* itm, AnsiString formname)
: TForm(Owner)
{
this->itm = itm;
uid = "";
link = false;
desc = new TformDescription();
slv = NULL; lnk = NULL;
desc->formname = formname;
form->dsc = desc;
parentform = NULL;
if (itm) itm->Enabled = false;
accept = false;
btnlst = new TList();
fltlst = new TList();
fldlst = new TList();
UploadInfo();
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::UploadInfo()
{
UploadMetaInfo(desc, desc->formname);
this->Caption = desc->title;
form->editpanel->Caption = desc->edittitle;
form->dbgBrowse->Columns->Items[0]->FieldName = desc->listfield;
form->dbgBrowse->Columns->Items[0]->Title->Caption = "Название";
if (desc->readonly) { form->tblBrowse->ReadOnly = true; }
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::ReorderFilters()
{
for (int r=0; r<fltlst->Count; r++)
{
TfrmFilter* fr = ((TfrmFilter*)((TfltAddInfo*)fltlst->Items[r])->pntr);
fr->Align = alNone;
fr->Visible = false;
}
for (int r=0; r<fltlst->Count; r++)
{
TfrmFilter* fr = ((TfrmFilter*)((TfltAddInfo*)fltlst->Items[r])->pntr);
fr->Visible = true;
fr->Align = alTop;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::Execute()
{
if (link)
{
form->Go();
// запомним мета-информацию по полям
int cnt = form->tblBrowse->Fields->Count;
TField **flms = new TField*[cnt];
for(int i = 0; i < cnt; i++)
{
TFieldType dtype = form->tblBrowse->Fields->Fields[i]->DataType;
if (dtype == ftInteger) flms[i] = new TIntegerField(this);
if (dtype == ftString) flms[i] = new TStringField(this);
if (dtype == ftFloat) flms[i] = new TFloatField(this);
if (dtype == ftDate) flms[i] = new TDateField(this);
if (dtype == ftDateTime) flms[i] = new TDateTimeField(this);
if (dtype == ftTime) flms[i] = new TTimeField(this);
flms[i]->Required = form->tblBrowse->Fields->Fields[i]->Required;
flms[i]->ReadOnly = form->tblBrowse->Fields->Fields[i]->ReadOnly;
flms[i]->FieldName = form->tblBrowse->Fields->Fields[i]->FieldName;
flms[i]->Size = form->tblBrowse->Fields->Fields[i]->Size;
flms[i]->Tag = (int)dtype;
}
form->tblBrowse->Close();
for(int i = 0; i < cnt; i++) flms[i]->DataSet = form->tblBrowse;
// добавим lookup-поле
TStringField *fld = new TStringField(form->tblBrowse);
fld->ReadOnly = true;
fld->FieldName = desc->listfield;
fld->FieldKind = fkLookup;
AnsiString tmp;
tmp = lnk->linktofield; StrRpl(tmp, ",", ";");
fld->KeyFields = tmp;
tmp = slv->keyfield; StrRpl(tmp, ",", ";");
fld->LookupKeyFields = tmp;
fld->LookupDataSet = form->tblAdd;
fld->LookupResultField = slv->listfield;
fld->Lookup = true;
if (form->tblAdd->Active)
fld->Size = form->tblAdd->FieldByName(slv->listfield)->Size;
fld->DataSet = form->tblBrowse;
form->dbgBrowse->Columns->Items[0]->FieldName = fld->FieldName;
form->dbgBrowse->Columns->Items[0]->Title->Caption = "Название";
}
AnsiString strw;
if (!accept || !desc->hideonaccept)
{
strw = "select * from buttons where parentform = '" + desc->formname + "' ";
if (!desc->takefieldsfrom.IsEmpty()) strw += "or parentform = '" + desc->takefieldsfrom + "' ";
strw += "order by sortorder desc";
if (SELECT(mqrA, strw))
{
do
{
TToolButton* btn = form->AddLinkBtn(mqrA->FieldByName("title")->AsString, CommonButtonClick);
TbtnAddInfo *inf = new TbtnAddInfo();
inf->childform = mqrA->FieldByName("childform")->AsString;
inf->childtitle = mqrA->FieldByName("childtitle")->AsString;
inf->linkform = mqrA->FieldByName("linkform")->AsString;
inf->linktofield = mqrA->FieldByName("linktofield")->AsString;
inf->linkfromfield = mqrA->FieldByName("linkfromfield")->AsString;
inf->type = mqrA->FieldByName("type")->AsString;
inf->sql = mqrA->FieldByName("sql")->AsString;
btn->Tag = btnlst->Add(inf);
mqrA->Next();
} while (!mqrA->Eof);
}
}
strw = "select * from filters where parentform = '" + desc->formname + "' ";
if (!desc->takefieldsfrom.IsEmpty()) strw += "or parentform = '" + desc->takefieldsfrom + "' ";
strw += "order by sortorder desc";
if (SELECT(mqrA, strw))
{
do
{
TfrmFilter* flt = form->AddFilter(mqrA->FieldByName("title")->AsString, CommonFilterChange, CommonFilterClear);
TfltAddInfo *inf = new TfltAddInfo();
inf->childform = mqrA->FieldByName("childform")->AsString;
inf->filtersql = mqrA->FieldByName("filtersql")->AsString;
inf->sql = mqrA->FieldByName("sql")->AsString;
inf->type = mqrA->FieldByName("type")->AsString;
inf->name = mqrA->FieldByName("name")->AsString;
inf->code = mqrA->FieldByName("code")->AsInteger;
inf->logic = mqrA->FieldByName("logic")->AsInteger;
inf->pntr = flt;
inf->retid = "";
if (inf->logic == 1) form->FilterBy("a" + IntToStr(inf->code), "(1=0)");
if (lnk)
if (inf->childform == lnk->parentform)
{
inf->retid = lnk->linkvalue;
inf->rettitle = lnk->linktitle;
flt->edt->Text = lnk->linktitle;
// в uid возвращается выбранный код
AnsiString str = inf->filtersql;
if (retid.IsEmpty()) str="";
else StrRpl(str, "%1", lnk->linkvalue);
form->FilterBy("a" + IntToStr(inf->code), str);
flt->btn->Enabled = false;
flt->btnclr->Enabled = false;
flt->Enabled = false;
}
flt->Tag = fltlst->Add(inf);
mqrA->Next();
} while (!mqrA->Eof);
}
if (!accept || !desc->hideonaccept)
{
// подгрузка полей БД из имеющейся метаинформации
strw = "select * from fields where parentform = '" + desc->formname + "' ";
if (!desc->takefieldsfrom.IsEmpty()) strw += "or parentform = '" + desc->takefieldsfrom + "' ";
strw += "order by sortorder";
if (SELECT(mqrA, strw))
{
do
{
// сразу создадим все формы полей, инициализируем их, а также оставим ВСЮ семантику в этих формах
TfieldAddInfo *inf = new TfieldAddInfo();
inf->fieldname = mqrA->FieldByName("fieldname")->AsString;
inf->title = mqrA->FieldByName("title")->AsString;
inf->type = mqrA->FieldByName("type")->AsString;
inf->childform = mqrA->FieldByName("childform")->AsString;
inf->sql = mqrA->FieldByName("sql")->AsString;