inf->ReadOnly = mqrA->FieldByName("readonly")->AsBoolean;
inf->isqbe = mqrA->FieldByName("isqbe")->AsBoolean;
inf->value = mqrA->FieldByName("value")->AsString.Trim();
inf->code = mqrA->FieldByName("code")->AsInteger;
if (inf->type == (AnsiString)"T")
{
TfrmeFT *fr = new TfrmeFT(this, form->dsrcBrowse, inf);
fr->Parent = form->editarea; fr->Name = ""; fr->Align = alTop; inf->form = fr;
}
if ((inf->type == (AnsiString)"I") || (inf->type == (AnsiString)"S"))
{
TfrmeFV *fr = new TfrmeFV(this, form->dsrcBrowse, inf);
fr->Parent = form->editarea; fr->Name = ""; fr->Align = alTop; inf->form = fr;
}
if (inf->type == (AnsiString)"C")
{
TfrmeFieldsN *fr = new TfrmeFieldsN(this, form->dsrcBrowse, inf);
fr->Parent = form->editarea; fr->Name = ""; fr->Align = alTop; inf->form = fr;
}
if (inf->type == (AnsiString)"F") // поле интерпетируется на этапе подстановки при New,
{ // а также для фильтрации (т.е. используется для
// реализации ограниченных наборов)
form->FilterBy("flt_" + inf->fieldname, inf->sql);
}
if (inf->type == (AnsiString)"L")
{
TfrmeList *fr = new TfrmeList(this, form->dsrcBrowse, inf);
if (SELECT(mqrB, "select * from fieldelements where parentfield = " +
mqrA->FieldByName("code")->AsString + " order by sortorder"))
{
do
{
fr->AddElement(mqrB->FieldByName("title")->AsString, mqrB->FieldByName("value")->AsString);
mqrB->Next();
} while (!mqrB->Eof);
fr->Go();
mqrB->Close();
}
fr->Parent = form->editarea; fr->Name = ""; fr->Align = alTop; inf->form = fr;
}
fldlst->Add(inf);
mqrA->Next();
} while (!mqrA->Eof);
}
mqrA->Close();
}
bool f = ((desc->type == (AnsiString)"T") && (!desc->parentfield.Trim().IsEmpty()));
form->spbTree->Visible = f;
form->dbnPlus->Visible = f;
form->SetTreeMode(f);
TuneFilters();
form->Go();
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::TuneFromBtn(TbtnAddInfo *lnkinfo, AnsiString linkvalue, AnsiString linktitle, AnsiString parentform)
{
if (!lnk) lnk = new TlnkFromBtn();
form->lnkb = lnk;
lnk->linkform = lnkinfo->linkform;
lnk->linktofield = lnkinfo->linktofield;
lnk->linkfromfield = lnkinfo->linkfromfield;
lnk->linkvalue = linkvalue;
lnk->linktitle = linktitle;
lnk->parentform = parentform;
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::TuneForLink()
{
link = true;
slv = new TformDescription();
UploadMetaInfo(slv, lnk->linkform);
form->slv = slv;
form->link = link;
desc->listfield = "add_lnkform_nam";
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::InitTblAdd()
{
// инициализация tblAdd
AnsiString str;
str = "select " + slv->listfield + ", " + slv->keyfield + " from " + slv->table;
form->tblAdd->SQL->Clear();
form->tblAdd->SQL->Add(str);
try
{
form->tblAdd->Close();
form->tblAdd->Open();
} catch(EOracleError &E)
{
ShowMessage(E.Message + ", запрос: '" + str + "'");
return;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::TuneFilters()
{
if (!parentform) return;
TList* patfrm_fltlst = ((TfrmUniForm*)parentform)->fltlst;
TList* patfrm_fldlst = ((TfrmUniForm*)parentform)->fldlst;
if (patfrm_fltlst)
{
for (int r=0; r<fltlst->Count; r++)
for (int i=0; i<patfrm_fltlst->Count; i++)
{
TfltAddInfo* tm_r = ((TfltAddInfo*)(fltlst->Items[r]));
TfltAddInfo* tm_i = ((TfltAddInfo*)(patfrm_fltlst->Items[i]));
if (tm_r->name == tm_i->name)
{
tm_r->retid = tm_i->retid;
tm_r->rettitle = tm_i->rettitle;
TfrmFilter* src = ((TfrmFilter*)tm_r->pntr);
src->edt->Text = tm_i->rettitle;
// в uid возвращается выбранный код
AnsiString str = tm_r->filtersql;
if (retid.IsEmpty()) str="";
else StrRpl(str, "%1", retid);
form->FilterBy("a" + IntToStr(tm_r->code), str);
}
}
}
if (accept && patfrm_fldlst)
{
TfrmUniForm* uni = ((TfrmUniForm*)parentform);
if (!uni->form->tblBrowse->IsEmpty())
{
for (int r=0; r<patfrm_fldlst->Count; r++)
for (int i=0; i<fltlst->Count; i++)
{
TfieldAddInfo *fl = ((TfieldAddInfo*)patfrm_fldlst->Items[r]);
TfrmeFieldsN *tm_i = ((TfrmeFieldsN*)(fl->form));
TfltAddInfo *tm_r = ((TfltAddInfo*)(fltlst->Items[i]));
if ((fl->type == (AnsiString)"C") && (fl->fieldname == tm_r->name))
if (!uni->form->tblBrowse->FieldByName(fl->fieldname)->IsNull)
{
tm_r->retid = uni->form->tblBrowse->FieldByName(fl->fieldname)->AsString;
tm_r->rettitle = tm_i->name->Text;
TfrmFilter* src = ((TfrmFilter*)tm_r->pntr);
src->edt->Text = tm_i->name->Text;
// в uid возвращается выбранный код
AnsiString str = tm_r->filtersql;
if (retid.IsEmpty()) str="";
else StrRpl(str, "%1", retid);
form->FilterBy("a" + IntToStr(tm_r->code), str);
}
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::CommonButtonClick(TObject *Sender)
{
TbtnAddInfo* tm = ((TbtnAddInfo*)btnlst->Items[((TToolButton*)Sender)->Tag]);
if (form->tblBrowse->IsEmpty()) return;
// обработка настройки дочерней формы по нажатию кнопки контекстного перехода
AnsiString _title = tm->childtitle, _filter = tm->sql;
UseReplaces(_title, _filter);
bool s = (tm->type == (AnsiString)"S"), l = (tm->type == (AnsiString)"L");
if (!s && !l) return;
try
{
TfrmUniForm *frm = new TfrmUniForm(frmMain, NULL, tm->childform);
frm->parentform = this;
if (!_filter.Trim().IsEmpty()) frm->form->FilterBy("parent", _filter);
if (!_title.Trim().IsEmpty()) frm->Caption = _title;
if (s || l) frm->TuneFromBtn(tm, form->tblBrowse->FieldByName(desc->keyfield)->AsString, form->tblBrowse->FieldByName(desc->listfield)->AsString, desc->formname);
if (l) frm->TuneForLink();
if (l) frm->InitTblAdd();
frm->Execute();
frm->FormStyle = fsMDIChild;
frm->Show();
} catch (Exception &E)
{
ShowMessage(E.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::CommonFilterChange(TObject *Sender)
{
// обработка вызова дочерней формы по нажатию кнопки фильтра
TfrmFilter* src = ((TfrmFilter*)Sender);
TfltAddInfo* tm = ((TfltAddInfo*)fltlst->Items[src->Tag]);
int i = CallOtherForm(tm->childform, "", tm->sql, true, true);
if (i == mrOk)
{
tm->retid = retid;
tm->rettitle = rettitle;
src->edt->Text = rettitle;
// в uid возвращается выбранный код
AnsiString str = tm->filtersql;
if (retid.IsEmpty()) { CommonFilterClear(Sender); return; }
else StrRpl(str, "%1", retid);
form->FilterBy("a" + IntToStr(tm->code), str);
form->Go();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::CommonFilterClear(TObject *Sender)
{
// обработка вызова дочерней формы по нажатию кнопки фильтра
TfrmFilter* src = ((TfrmFilter*)Sender);
TfltAddInfo* tm = ((TfltAddInfo*)fltlst->Items[src->Tag]);
tm->retid = "";
src->edt->Text = "";
AnsiString str = "";
if (tm->logic == 1) str = "(1=0)";
form->FilterBy("a" + IntToStr(tm->code), str);
form->Go();
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::CommonFltSlctChange(TObject *Sender)
{
// обработка вызова дочерней формы по выбору из списка
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::FormClose(TObject *Sender,
TCloseAction &Action)
{
Action = caFree;
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::formbtbtnCancelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::formbtbtnOKClick(TObject *Sender)
{
if (!form->tblBrowse->IsEmpty())
{
this->uid = form->tblBrowse->FieldByName(desc->keyfield)->AsString;
this->rettitle = form->tblBrowse->FieldByName(desc->listfield)->AsString;
this->ModalResult = mrOk;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::TuneForAccept()
{
if (form) form->TuneForAccept();
accept = true;
if (!desc->accepttitle.IsEmpty()) this->Caption = desc->accepttitle;
if (desc->hideonaccept) this->Width = 500;
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::FormDestroy(TObject *Sender)
{
if (desc) delete desc;
if (slv) delete slv;
if (lnk) delete lnk;
for (int r=0; r<btnlst->Count; r++)
delete ((TbtnAddInfo*)(btnlst->Items[r]));
delete btnlst;
for (int r=0; r<fltlst->Count; r++)
delete ((TfltAddInfo*)(fltlst->Items[r]));
delete fltlst;
for (int r=0; r<fldlst->Count; r++)
delete ((TfieldAddInfo*)(fldlst->Items[r]));
delete fldlst;
if (itm) itm->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::UseReplaces(AnsiString &title, AnsiString &filter)
{
if (!form->tblBrowse->IsEmpty() && !form->tblBrowse->FieldByName(desc->keyfield )->IsNull)
{
StrRpl(title, "%1", form->tblBrowse->FieldByName(desc->listfield)->AsString);
StrRpl(filter, "%1", form->tblBrowse->FieldByName(desc->keyfield )->AsString);
}
StrRpl(filter, "<<", "|%%");
StrRpl(filter, ">>", "%%|");
// учтём подстановки полей вида <field>, а также их возможные NULL
filter = TranslateString(filter, FieldValue);
StrRpl(filter, "|%%", "<");
StrRpl(filter, "%%|", ">");
// учтём (ссылки на другие фильтры) подстаноки вида <<flt_value>>, а также их возможные NULL
filter = TranslateString(filter, FilterValue);
StrRpl(filter, "'NULL'", "NULL");
}
//---------------------------------------------------------------------------
int __fastcall TfrmUniForm::CallOtherForm(AnsiString _form, AnsiString _title, AnsiString _filter,
bool _modal, bool _accept)
{
UseReplaces(_title, _filter);
int res = 0;
try
{
TfrmUniForm *frm = new TfrmUniForm(((_modal)?(TForm*)Owner:(TForm*)frmMain), NULL, _form);
frm->parentform = this;
if (!_filter.Trim().IsEmpty()) frm->form->FilterBy("parent", _filter);
if (_accept) { frm->TuneForAccept(); frm->parentform = this; }
if (!_title.Trim().IsEmpty()) frm->Caption = _title;
frm->Execute();
if (_modal)
{
frm->FormStyle = fsNormal;
res = frm->ShowModal();
retid = frm->uid;
rettitle = frm->rettitle;
} else
{
frm->FormStyle = fsMDIChild;
frm->Show();
}
} catch (Exception &E)
{
ShowMessage(E.Message);
}
return res;
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::formdbgBrowseDblClick(TObject *Sender)
{
if (accept && form->btbtnOK->Visible && form->pnlLCOK->Visible)
formbtbtnOKClick(this);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmUniForm::FieldValue(AnsiString valname)
{
AnsiString tmp;
if (!form->tblBrowse->FieldByName(valname.Trim())->IsNull)
tmp= form->tblBrowse->FieldByName(valname.Trim())->AsString;
else
tmp= "NULL";
return tmp;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmUniForm::FilterValue(AnsiString valname)
{
AnsiString tmp;
// выясним текущее значение указанного фильтра
for (int r=0; r<fltlst->Count; r++)
{
TfltAddInfo* tm = ((TfltAddInfo*)(fltlst->Items[r]));
if (tm->name == valname.Trim())
{
if (!tm->retid.IsEmpty())
tmp= tm->retid;
else
tmp= "NULL";
}
}
return tmp;
}
//---------------------------------------------------------------------------
// ф-ция разбора строки
AnsiString __fastcall TfrmUniForm::TranslateString(AnsiString str, TGetValueEvent evt)
{
AnsiString tmp, filter, _filter = str;
tmp = "";
filter = "";
bool b = false;
for(int r=1; r<=_filter.Length(); r++)
{
if (_filter[r] == '<' && !b) { b = true; tmp = ""; }
else
if (_filter[r] == '>' && b && (!tmp.Trim().IsEmpty())) { b = false; filter+=evt(tmp); }
else
if (_filter[r] != '<' && b) { tmp += _filter[r]; }
else
if (!b) { filter+= _filter[r]; }
}
return filter;
}
//---------------------------------------------------------------------------
void __fastcall TfrmUniForm::FormShow(TObject *Sender)
{
if (accept) ReorderFilters();
}
//---------------------------------------------------------------------------