Commit d7ffe4a3 authored by Lucio Sandrini's avatar Lucio Sandrini

Implementação de Cadastro de Formulário (Dynamo) finalizada.

parent 3cf47eb1
...@@ -43,7 +43,7 @@ procedure cxCadastroDefinicaoClasse.rmSalvaObjeto(piField: utField; const piResp ...@@ -43,7 +43,7 @@ procedure cxCadastroDefinicaoClasse.rmSalvaObjeto(piField: utField; const piResp
var lRequestMessage: mxRequestMessage; var lRequestMessage: mxRequestMessage;
lResponseMessage: mxAnswerMessage; lResponseMessage: mxAnswerMessage;
begin begin
lRequestMessage := self.NewRequest('RM_SALVA_OBJETO', piField); lRequestMessage := self.NewRequest('RM_SALVAR', piField);
try try
lResponseMessage := self.Session.SendRequest(lRequestMessage); lResponseMessage := self.Session.SendRequest(lRequestMessage);
try try
...@@ -60,7 +60,7 @@ procedure cxCadastroDefinicaoClasse.rmExcluiObjeto(piField: utField; const piRes ...@@ -60,7 +60,7 @@ procedure cxCadastroDefinicaoClasse.rmExcluiObjeto(piField: utField; const piRes
var lRequestMessage: mxRequestMessage; var lRequestMessage: mxRequestMessage;
lResponseMessage: mxAnswerMessage; lResponseMessage: mxAnswerMessage;
begin begin
lRequestMessage := self.NewRequest('RM_EXCLUI_OBJETO', piField); lRequestMessage := self.NewRequest('RM_EXCLUIR', piField);
try try
lResponseMessage := self.Session.SendRequest(lRequestMessage); lResponseMessage := self.Session.SendRequest(lRequestMessage);
try try
......
...@@ -184,7 +184,7 @@ object itCadastrarFormulario: TitCadastrarFormulario ...@@ -184,7 +184,7 @@ object itCadastrarFormulario: TitCadastrarFormulario
TabOrder = 0 TabOrder = 0
end end
object lblNomeForm: TLabel object lblNomeForm: TLabel
Left = 467 Left = 466
Height = 18 Height = 18
Top = 16 Top = 16
Width = 145 Width = 145
...@@ -196,8 +196,8 @@ object itCadastrarFormulario: TitCadastrarFormulario ...@@ -196,8 +196,8 @@ object itCadastrarFormulario: TitCadastrarFormulario
ParentColor = False ParentColor = False
ParentFont = False ParentFont = False
end end
object edtNome1: TEdit object edtNomeForm: TEdit
Left = 632 Left = 631
Height = 23 Height = 23
Top = 13 Top = 13
Width = 140 Width = 140
...@@ -205,7 +205,7 @@ object itCadastrarFormulario: TitCadastrarFormulario ...@@ -205,7 +205,7 @@ object itCadastrarFormulario: TitCadastrarFormulario
TabOrder = 1 TabOrder = 1
end end
object lblCodigoForm: TLabel object lblCodigoForm: TLabel
Left = 467 Left = 466
Height = 18 Height = 18
Top = 40 Top = 40
Width = 157 Width = 157
...@@ -218,13 +218,22 @@ object itCadastrarFormulario: TitCadastrarFormulario ...@@ -218,13 +218,22 @@ object itCadastrarFormulario: TitCadastrarFormulario
ParentFont = False ParentFont = False
end end
object lblCodigoForm2: TLabel object lblCodigoForm2: TLabel
Left = 632 Left = 631
Height = 15 Height = 15
Top = 40 Top = 40
Width = 80 Width = 80
Caption = 'lblCodigoForm' Caption = 'lblCodigoForm'
ParentColor = False ParentColor = False
end end
object btnExcluir: TButton
Left = 784
Height = 49
Top = 8
Width = 140
Caption = 'EXCLUIR'
OnClick = btnExcluirClick
TabOrder = 2
end
end end
object lstAtributos: TValueListEditor object lstAtributos: TValueListEditor
Left = 634 Left = 634
......
...@@ -8,17 +8,18 @@ uses ...@@ -8,17 +8,18 @@ uses
LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics, LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, StdCtrls, Dialogs, JvExControls, ComCtrls, ExtCtrls, Buttons, Controls, Forms, StdCtrls, Dialogs, JvExControls, ComCtrls, ExtCtrls, Buttons,
MaskEdit, JvBaseEdits, JvCheckBox, utuMessage, Grids, ValEdit, StarUMLintf, MaskEdit, JvBaseEdits, JvCheckBox, utuMessage, Grids, ValEdit, StarUMLintf,
cxuCadastroDefinicaoClasse, IntegracaoDelphiSUML; cxuCadastroDefinicaoClasse, IntegracaoDelphiSUML, acuModel;
type type
{ TitCadastrarFormulario } { TitCadastrarFormulario }
TitCadastrarFormulario = class(TForm) TitCadastrarFormulario = class(TForm)
btnExcluir: TButton;
cbbForm: TComboBox; cbbForm: TComboBox;
edtNome: TEdit; edtNome: TEdit;
edtDisplayNome: TEdit; edtDisplayNome: TEdit;
edtNome1: TEdit; edtNomeForm: TEdit;
lblCodigoForm: TLabel; lblCodigoForm: TLabel;
lblCodigoForm2: TLabel; lblCodigoForm2: TLabel;
lblNomeForm: TLabel; lblNomeForm: TLabel;
...@@ -46,6 +47,7 @@ type ...@@ -46,6 +47,7 @@ type
edtCampo: TEdit; edtCampo: TEdit;
lblNovoCampo: TLabel; lblNovoCampo: TLabel;
btnAdd: TSpeedButton; btnAdd: TSpeedButton;
procedure btnExcluirClick(Sender: TObject);
procedure cbbFormSelect(Sender: TObject); procedure cbbFormSelect(Sender: TObject);
procedure edtDisplayNomeChange(Sender: TObject); procedure edtDisplayNomeChange(Sender: TObject);
procedure edtNomeChange(Sender: TObject); procedure edtNomeChange(Sender: TObject);
...@@ -79,6 +81,7 @@ type ...@@ -79,6 +81,7 @@ type
procedure Initialize; procedure Initialize;
procedure SendToInterface(piField: utField); procedure SendToInterface(piField: utField);
procedure FillListViewClassData(piClass: acClassTicket);
function AdicionarCampo (piName : string) : TListItem; function AdicionarCampo (piName : string) : TListItem;
public public
Constructor Create(Sender: TComponent; piCadastroClasse: cxCadastroDefinicaoClasse; piUMLClass: IUMLClass); reintroduce; Constructor Create(Sender: TComponent; piCadastroClasse: cxCadastroDefinicaoClasse; piUMLClass: IUMLClass); reintroduce;
...@@ -91,7 +94,7 @@ type ...@@ -91,7 +94,7 @@ type
implementation implementation
uses uses
acuObject, acuFramework, acuModel; acuObject, acuFramework;
const const
__STRING = 1; __STRING = 1;
...@@ -185,7 +188,11 @@ begin ...@@ -185,7 +188,11 @@ begin
begin begin
lFieldItem := lEnum.Current as utField; lFieldItem := lEnum.Current as utField;
lFieldItem.Name := lFieldItem.AttributeByName('OID').AsString; lFieldItem.Name := lFieldItem.AttributeByName('OID').AsString;
cbbForm.AddItem(lFieldItem.AttributeByName('code').AsString, Pointer(lFieldItem.AttributeByName('OID').AsInteger));
if lFieldItem.HasAttribute('name') then
cbbForm.AddItem(lFieldItem.AttributeByName('name').AsString, Pointer(lFieldItem.AttributeByName('OID').AsInteger))
else
cbbForm.AddItem(lFieldItem.AttributeByName('code').AsString, Pointer(lFieldItem.AttributeByName('OID').AsInteger));
lEnum.MoveNext; lEnum.MoveNext;
end; end;
finally finally
...@@ -198,31 +205,119 @@ begin ...@@ -198,31 +205,119 @@ begin
{preenche a listview com os atributos e relaes da classe} {preenche a listview com os atributos e relaes da classe}
lClass := fUtil.MetaModel.ClassTicketByCode[fClassCode] as acClassTicket; //lClass := fUtil.MetaModel.ClassTicketByCode[fClassCode] as acClassTicket;
//FillListViewClassData(lClass);
end;
for i := 0 to lClass.Attributes.Count - 1 do procedure TitCadastrarFormulario.FillListViewClassData(piClass: acClassTicket);
var
lRelationName: string;
i: Integer;
begin
for i := 0 to piClass.Attributes.Count - 1 do
begin begin
AdicionarCampo(lClass.Attributes[i]); AdicionarCampo(piClass.Attributes[i]);
end; end;
for i := 0 to lClass.RelationTicketsIn.Count - 1 do for i := 0 to piClass.RelationTicketsIn.Count - 1 do
begin begin
lRelationName := acRelationTicket(lClass.RelationTicketsIn.Objects[i]).DestinationPropertyName; lRelationName := acRelationTicket(piClass.RelationTicketsIn.Objects[i]).DestinationPropertyName;
if lRelationName <> '' then AdicionarCampo(lRelationName); if lRelationName <> '' then AdicionarCampo(lRelationName);
end; end;
for i := 0 to lClass.RelationTicketsOut.Count - 1 do for i := 0 to piClass.RelationTicketsOut.Count - 1 do
begin begin
lRelationName := acRelationTicket(lClass.RelationTicketsOut.Objects[i]).OriginPropertyName; lRelationName := acRelationTicket(piClass.RelationTicketsOut.Objects[i]).OriginPropertyName;
if lRelationName <> '' then AdicionarCampo(lRelationName); if lRelationName <> '' then AdicionarCampo(lRelationName);
end; end;
lvCampos.Selected := nil;
end; end;
procedure TitCadastrarFormulario.btnSalvarClick(Sender: TObject); procedure TitCadastrarFormulario.btnSalvarClick(Sender: TObject);
var
lField, lResponseField, lFormField, lFields, lNewForm,
lFieldField, lTypeField, lTypeSelectRelation: utField;
lOrder, lFormOID: Integer;
lItem: TListItem;
begin begin
lField := utField.Create;
lFormField := lField.AddField('Form');
if cbbForm.Text <> 'Novo' then lFormField.AddAttribute('OID').AsInteger := Integer(cbbForm.Items.Objects[cbbForm.ItemIndex]);
if edtNomeForm.Text <> '' then lFormField.AddAttribute('name').AsString := edtNomeForm.Text;
lFields := lFormField.AddField('Fields');
lOrder := 0;
for lItem in lvCampos.Items do
begin
if lItem.Checked then
begin
if (lItem.Caption = '') or (lItem.SubItems[__DISPLAY_NAME] = '')then
raise Exception.Create('Todos os campos devem possuir um nome e um display nome');
if lItem.SubItems[__TIPO] = '' then
raise Exception.Create('O campo ''' + lItem.Caption + ''' deve possuir um tipo');
if lItem.SubItems[__TIPO] = 'ftSelectRelation' then
begin
lTypeSelectRelation := fFormFields.FieldByName(lItem.SubItems[__ID]).FieldByName('Type');
if not lTypeSelectRelation.HasField('labelAttribute') then
begin
raise Exception.Create('O campo ''' + lItem.Caption + ''' deve preencher o valor da Key: ''labelAttribute''');
end
end;
lFieldField := lFields.AddField('Field');
lFieldField.AddAttribute('name').AsString := lItem.Caption;
lFieldField.AddAttribute('displayName').AsString := lItem.SubItems[__DISPLAY_NAME];
lFieldField.AddAttribute('order').AsInteger := lOrder;
lFieldField.AddAttribute('required').AsBoolean := (lItem.SubItems[__OBRIGATORIO] = 'S');
lFieldField.AddAttribute('id').AsInteger := StrToInt(lItem.SubItems[__ID]);
lTypeField := lFieldField.AddField('Type');
lTypeField.Assign(fFormFields.FieldByName(lItem.SubItems[__ID]).FieldByName('Type'));
lOrder := lOrder + 1;
end;
end;
if not lFields.HasField('Field') then
raise Exception.Create('O formulrio deve possuir pelo menos um campo, use as CheckBoxes para escolhe-los.');
lResponseField := utField.Create;
fcxCadastroDefinicaoClasse.rmSalvaObjeto(lField, lResponseField);
{caso tenha sido salvo com sucesso}
if lResponseField.HasField('Form') then
begin
lFormOID := lResponseField.FieldByName('Form').AttributeByName('OID').AsInteger;
if cbbForm.Text = 'Novo' then
begin
lblCodigoForm2.Caption := IntToStr(lFormOID);
cbbForm.Items.Objects[cbbForm.ItemIndex] := Pointer(lFormOID);
cbbForm.Items[cbbForm.ItemIndex] := IntToStr(lFormOID); {mudar para o nome depois---------------------}
cbbForm.AddItem('Novo', nil);
lNewForm := fForms.AddField('Form');
lNewForm.Assign(lResponseField.FieldByName('Form'));
lNewForm.Name := IntToStr(lFormOID);
end
else
begin
//cbbForm.Text := IntToStr(lFormOID); {mudar para o nome depois---------------------}
fForms.FieldByName(IntToStr(lFormOID)).Assign(lResponseField.FieldByName('Form'));
fForms.FieldByName('Form').Name := IntToStr(lFormOID);
end;
if lResponseField.FieldByName('Form').HasAttribute('name') then
begin
cbbForm.Items[cbbForm.ItemIndex] := lResponseField.FieldByName('Form').AttributeByName('name').AsString;
edtNomeForm.Text := lResponseField.FieldByName('Form').AttributeByName('name').AsString;
end;
application.MessageBox('Formulrio salvo com sucesso.','StarUML', MB_ICONASTERISK + MB_OK);
end
else raise Exception.Create('Erro ao salvar formulrio.');
end; end;
function TitCadastrarFormulario.AdicionarCampo (piName : string) : TListItem; function TitCadastrarFormulario.AdicionarCampo (piName : string) : TListItem;
...@@ -318,69 +413,52 @@ end; ...@@ -318,69 +413,52 @@ end;
procedure TitCadastrarFormulario.cbbFormSelect(Sender: TObject); procedure TitCadastrarFormulario.cbbFormSelect(Sender: TObject);
var var
lField, lResponseField, lFieldItem : utField; lFieldItem : utField;
lCode, lFieldName, lFormOID, teste: string; lFieldName, lFormOID: string;
lEnum : acEnumerator; lEnum : acEnumerator;
lItem: TListItem; lItem: TListItem;
lPosition, lIndex, lId : Integer; lId : Integer;
lClass: acClassTicket;
begin begin
lvCampos.Clear;
lblCodigoForm2.Caption := '';
edtNomeForm.Clear;
fIdCount := 0;
if cbbForm.Text = 'Novo' then if cbbForm.Text = 'Novo' then
begin begin
if not fForms.HasField('Novo') then if not fForms.HasField('Novo') then fForms.AddField('Novo');
begin if fFormFields <> nil then fFormFields.Free;
fForms.AddField('Novo');
lField := utField.Create;
lResponseField := utField.Create;
fcxCadastroDefinicaoClasse.rmIncluiObjeto(lField, lResponseField);
cbbForm.Items.Objects[cbbForm.ItemIndex] := Pointer(lResponseField.FieldByName('Form').AttributeByName('OID').AsInteger);
end;
fFormFields := utField.Create; fFormFields := utField.Create;
lblCodigoForm2.Caption := IntToStr(Integer(cbbForm.Items.Objects[cbbForm.ItemIndex]));
end end
else else
begin begin
lFormOID := IntToStr(Integer(cbbForm.Items.Objects[cbbForm.ItemIndex])); lFormOID := IntToStr(Integer(cbbForm.Items.Objects[cbbForm.ItemIndex]));
lblCodigoForm2.Caption := fForms.FieldByName(lFormOID).AttributeByName('OID').AsString;//lFormOID; lblCodigoForm2.Caption := lFormOID;
fFormFIelds := utField.Create;
fFormFields.Assign(fForms.FieldByName(lFormOID).FieldByName('Fields')); fFormFields.Assign(fForms.FieldByName(lFormOID).FieldByName('Fields'));
if fForms.FieldByName(lFormOID).HasAttribute('name') then
edtNomeForm.Text := fForms.FieldByName(lFormOID).AttributeByName('name').AsString;
lEnum := fFormFields.GetFieldsEnumerator; lEnum := fFormFields.GetFieldsEnumerator;
try try
while not lEnum.EOL do while not lEnum.EOL do
begin begin
lFieldItem := lEnum.Current as utField; lFieldItem := lEnum.Current as utField;
teste := lFieldItem.GetXMLString;
if lFieldItem.Name <> 'Field' then Break; if lFieldItem.Name <> 'Field' then Break;
lFieldName := lFieldItem.AttributeByName('name').AsString; lFieldName := lFieldItem.AttributeByName('name').AsString;
lId := lFieldItem.AttributeByName('id').AsInteger; lId := lFieldItem.AttributeByName('id').AsInteger;
if lId > fIdCount then fIdCount := lId; if lId > fIdCount then fIdCount := lId - 1;
lItem := AdicionarCampo(lFieldName); lItem := AdicionarCampo(lFieldName);
lItem.Checked := True; lItem.Checked := True;
lItem.SubItems[__DISPLAY_NAME] := lFieldItem.AttributeByName('displayName').AsString; lItem.SubItems[__DISPLAY_NAME] := lFieldItem.AttributeByName('displayName').AsString;
lItem.SubItems[__OBRIGATORIO] := lFieldItem.AttributeByName('required').AsString; lItem.SubItems[__OBRIGATORIO] := lFieldItem.AttributeByName('required').AsString;
lItem.SubItems[__ID] := lFieldItem.AttributeByName('id').AsString;
lItem.SubItems[__TIPO] := lFieldItem.FieldByName('Type').AttributeByName('name').AsString; lItem.SubItems[__TIPO] := lFieldItem.FieldByName('Type').AttributeByName('name').AsString;
//lPosition := lFieldItem.AttributeByName('order').AsInteger;
//lIndex := lItem.Index;
//
//while lIndex > lPosition do
//begin
// lvCampos.MoveUp(lIndex, False);
// lIndex := lIndex - 1;
//end;
//
//while lIndex < lPosition do
//begin
// lvCampos.MoveDown(lIndex, False);
// lIndex := lIndex + 1;
//end;
//
lFieldItem.Name := IntToStr(lId); lFieldItem.Name := IntToStr(lId);
//fFormFields.AddField(IntToStr(lId));
//fFormFields.FieldByName(IntToStr(lId)).Assign(lFieldItem);
lEnum.MoveNext; lEnum.MoveNext;
end; end;
...@@ -388,6 +466,37 @@ begin ...@@ -388,6 +466,37 @@ begin
lEnum.Free; lEnum.Free;
end; end;
end; end;
lClass := fUtil.MetaModel.ClassTicketByCode[fClassCode] as acClassTicket;
FillListViewClassData(lClass);
lvCampos.Selected := nil;
lvCamposClick(nil);
end;
procedure TitCadastrarFormulario.btnExcluirClick(Sender: TObject);
var
lField, lResponseField, lFormField: utField;
lClass: acClassTicket;
begin
if cbbForm.Text = 'Novo' then
begin
lvCampos.Clear;
cbbFormSelect(nil);
end
else
begin
lField := utField.Create;
lResponseField := utField.Create;
lFormField := lField.AddField('Form');
lFormField.AddAttribute('OID').AsInteger := Integer(cbbForm.Items.Objects[cbbForm.ItemIndex]);
fcxCadastroDefinicaoClasse.rmExcluiObjeto(lField, lResponseField);
cbbForm.Items.Delete(cbbForm.ItemIndex);
cbbForm.ItemIndex := 0;
cbbFormSelect(nil);
end;
end; end;
procedure TitCadastrarFormulario.cbbTipoChange(Sender: TObject); procedure TitCadastrarFormulario.cbbTipoChange(Sender: TObject);
...@@ -454,12 +563,14 @@ end; ...@@ -454,12 +563,14 @@ end;
procedure TitCadastrarFormulario.edtNomeChange(Sender: TObject); procedure TitCadastrarFormulario.edtNomeChange(Sender: TObject);
begin begin
lvCampos.Selected.Caption := edtNome.Text; if lvCampos.SelCount <> 0 then
lvCampos.Selected.Caption := edtNome.Text;
end; end;
procedure TitCadastrarFormulario.edtDisplayNomeChange(Sender: TObject); procedure TitCadastrarFormulario.edtDisplayNomeChange(Sender: TObject);
begin begin
lvCampos.Selected.SubItems[__DISPLAY_NAME] := edtDisplayNome.Text; if lvCampos.SelCount <> 0 then
lvCampos.Selected.SubItems[__DISPLAY_NAME] := edtDisplayNome.Text;
end; end;
procedure TitCadastrarFormulario.lstAtributosValidateEntry(sender: TObject; procedure TitCadastrarFormulario.lstAtributosValidateEntry(sender: TObject;
...@@ -510,12 +621,14 @@ end; ...@@ -510,12 +621,14 @@ end;
procedure TitCadastrarFormulario.rbNaoChange(Sender: TObject); procedure TitCadastrarFormulario.rbNaoChange(Sender: TObject);
begin begin
lvCampos.Selected.SubItems[__OBRIGATORIO] := 'N'; if lvCampos.SelCount <> 0 then
lvCampos.Selected.SubItems[__OBRIGATORIO] := 'N';
end; end;
procedure TitCadastrarFormulario.rbSimChange(Sender: TObject); procedure TitCadastrarFormulario.rbSimChange(Sender: TObject);
begin begin
lvCampos.Selected.SubItems[__OBRIGATORIO] := 'S'; if lvCampos.SelCount <> 0 then
lvCampos.Selected.SubItems[__OBRIGATORIO] := 'S';
end; end;
procedure TitCadastrarFormulario.lvCamposClick(Sender: TObject); procedure TitCadastrarFormulario.lvCamposClick(Sender: TObject);
...@@ -532,6 +645,8 @@ begin ...@@ -532,6 +645,8 @@ begin
lblTipoAtributo.Enabled := False; lblTipoAtributo.Enabled := False;
lblNome.Enabled := False; lblNome.Enabled := False;
lblDisplayNome.Enabled := False; lblDisplayNome.Enabled := False;
edtNome.Clear;
edtDisplayNome.Clear;
edtNome.Enabled := False; edtNome.Enabled := False;
edtDisplayNome.Enabled := False; edtDisplayNome.Enabled := False;
lstAtributos.Enabled := False; lstAtributos.Enabled := False;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment