Commit 39a85144 authored by Lucio Sandrini's avatar Lucio Sandrini

Implementação de cadastro de formulário (Dynamo)

parent 473fdaef
object itCadastrarFormulario: TitCadastrarFormulario
Left = 356
Height = 511
Height = 482
Top = 218
Width = 948
ClientHeight = 511
ClientWidth = 948
Width = 937
ClientHeight = 482
ClientWidth = 937
LCLVersion = '2.1.0.0'
object scrlbxTudo: TScrollBox
Left = 0
Height = 869
Height = 840
Top = 0
Width = 1666
HorzScrollBar.Page = 931
Width = 1655
HorzScrollBar.Page = 949
HorzScrollBar.Tracking = True
VertScrollBar.Page = 490
VertScrollBar.Page = 470
VertScrollBar.Tracking = True
Anchors = [akTop, akLeft, akRight, akBottom]
BorderStyle = bsNone
ClientHeight = 869
ClientWidth = 1666
ClientHeight = 840
ClientWidth = 1655
TabOrder = 0
object Panel1: TPanel
Left = 0
Height = 869
Height = 840
Top = 0
Width = 1666
Width = 1655
Align = alClient
ClientHeight = 869
ClientWidth = 1666
ClientHeight = 840
ClientWidth = 1655
TabOrder = 0
object edtCampo: TEdit
Left = 104
Height = 23
Top = 448
Top = 425
Width = 142
AutoSize = False
OnKeyPress = edtCampoKeyPress
TabOrder = 0
end
object btnCancelar: TButton
Left = 785
Left = 783
Height = 49
Top = 440
Width = 145
Top = 420
Width = 140
Caption = 'CANCELAR'
OnClick = btnCancelarClick
TabOrder = 1
end
object btnSalvar: TButton
Left = 641
Left = 634
Height = 49
Top = 440
Width = 145
Top = 420
Width = 140
Caption = 'SALVAR'
OnClick = btnSalvarClick
TabOrder = 2
......@@ -59,7 +59,7 @@ object itCadastrarFormulario: TitCadastrarFormulario
object lvCampos: TListView
Left = 16
Height = 300
Top = 130
Top = 107
Width = 604
Checkboxes = True
Columns = <
......@@ -93,19 +93,10 @@ object itCadastrarFormulario: TitCadastrarFormulario
OnClick = lvCamposClick
OnSelectItem = lvCamposSelectItem
end
object edtCodigo: TEdit
Left = 74
Height = 23
Top = 64
Width = 143
AutoSize = False
Enabled = False
TabOrder = 4
end
object btnAdd: TSpeedButton
Left = 253
Height = 25
Top = 448
Top = 425
Width = 70
Caption = 'Adicionar'
OnClick = btnAddClick
......@@ -113,7 +104,7 @@ object itCadastrarFormulario: TitCadastrarFormulario
object lblNovoCampo: TLabel
Left = 16
Height = 18
Top = 451
Top = 428
Width = 81
Caption = 'NOVO CAMPO:'
Font.Color = clWindowText
......@@ -122,23 +113,10 @@ object itCadastrarFormulario: TitCadastrarFormulario
ParentColor = False
ParentFont = False
end
object lblCodigo: TLabel
Left = 16
Height = 18
Top = 65
Width = 52
Caption = 'CÓDIGO:'
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Trebuchet MS'
Font.Style = [fsBold]
ParentColor = False
ParentFont = False
end
object lblExibirCampos: TLabel
Left = 16
Height = 18
Top = 106
Top = 83
Width = 55
Caption = 'CAMPOS:'
Font.Color = clWindowText
......@@ -148,12 +126,20 @@ object itCadastrarFormulario: TitCadastrarFormulario
ParentColor = False
ParentFont = False
end
object lblClasseName: TLabel
Left = 88
object Panel2: TPanel
Left = 0
Height = 72
Top = 0
Width = 948
ClientHeight = 72
ClientWidth = 948
TabOrder = 4
object lblCodigo: TLabel
Left = 232
Height = 18
Top = 24
Width = 65
Caption = 'ClassName'
Top = 16
Width = 157
Caption = 'CÓDIGO DO FORMULÁRIO:'
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Trebuchet MS'
......@@ -161,12 +147,12 @@ object itCadastrarFormulario: TitCadastrarFormulario
ParentColor = False
ParentFont = False
end
object lblClassIDO: TLabel
Left = 192
object lblClasseName: TLabel
Left = 16
Height = 18
Top = 24
Width = 52
Caption = 'ClassIDO'
Top = 16
Width = 107
Caption = 'NOME DA CLASSE:'
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Trebuchet MS'
......@@ -174,23 +160,34 @@ object itCadastrarFormulario: TitCadastrarFormulario
ParentColor = False
ParentFont = False
end
object lblTipoAtributo: TLabel
Left = 641
Height = 18
Top = 234
Width = 98
Caption = 'TIPO DO CAMPO: '
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Trebuchet MS'
object lblNomeClasse: TLabel
Left = 16
Height = 15
Top = 40
Width = 79
Caption = 'lblNomeClasse'
ParentColor = False
ParentFont = False
end
end
object lstAtributos: TValueListEditor
Left = 634
Height = 134
Top = 273
Width = 289
FixedCols = 0
RowCount = 2
TabOrder = 5
OnValidateEntry = lstAtributosValidateEntry
ColWidths = (
144
141
)
end
object cbbTipo: TComboBox
Left = 641
Left = 634
Height = 24
Hint = 'Tipo'
Top = 255
Top = 245
Width = 145
Font.Color = clWindowText
Font.Height = -11
......@@ -199,42 +196,40 @@ object itCadastrarFormulario: TitCadastrarFormulario
OnChange = cbbTipoChange
ParentFont = False
Style = csDropDownList
TabOrder = 5
end
object lstAtributos: TValueListEditor
Left = 641
Height = 145
Top = 285
Width = 289
FixedCols = 0
RowCount = 2
TabOrder = 6
OnValidate = lstAtributosValidate
ColWidths = (
144
141
)
end
object lblTipoAtributo: TLabel
Left = 634
Height = 18
Top = 226
Width = 98
Caption = 'TIPO DO CAMPO: '
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Trebuchet MS'
ParentColor = False
ParentFont = False
end
object btnUp: TSpeedButton
Left = 641
Height = 25
Top = 196
Left = 634
Height = 22
Top = 184
Width = 70
Caption = 'Sobe'
OnClick = btnUpClick
end
object btnDown: TSpeedButton
Left = 718
Height = 25
Top = 196
Left = 707
Height = 22
Top = 184
Width = 70
Caption = 'Desce'
OnClick = btnDownClick
end
object lblOrdem: TLabel
Left = 641
Left = 634
Height = 18
Top = 175
Top = 167
Width = 43
Caption = 'ORDEM:'
Font.Color = clWindowText
......@@ -244,27 +239,27 @@ object itCadastrarFormulario: TitCadastrarFormulario
ParentFont = False
end
object rbNao: TRadioButton
Left = 866
Left = 859
Height = 19
Top = 199
Top = 190
Width = 42
Caption = 'Não'
OnChange = rbNaoChange
TabOrder = 7
end
object rbSim: TRadioButton
Left = 820
Left = 813
Height = 19
Top = 199
Top = 190
Width = 40
Caption = 'Sim'
OnChange = rbSimChange
TabOrder = 8
end
object lblObrigatorio: TLabel
Left = 820
Left = 813
Height = 18
Top = 175
Top = 167
Width = 79
Caption = 'OBRIGATÓRIO:'
Font.Color = clWindowText
......@@ -273,6 +268,49 @@ object itCadastrarFormulario: TitCadastrarFormulario
ParentColor = False
ParentFont = False
end
object edtNome: TEdit
Left = 633
Height = 23
Top = 124
Width = 138
AutoSize = False
OnChange = edtNomeChange
TabOrder = 9
end
object edtDisplayNome: TEdit
Left = 785
Height = 23
Top = 124
Width = 138
AutoSize = False
OnChange = edtDisplayNomeChange
OnKeyPress = edtCampoKeyPress
TabOrder = 10
end
object lblNome: TLabel
Left = 634
Height = 18
Top = 106
Width = 37
Caption = 'NOME:'
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Trebuchet MS'
ParentColor = False
ParentFont = False
end
object lblDisplayNome: TLabel
Left = 785
Height = 18
Top = 106
Width = 83
Caption = 'DISPLAY NOME:'
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Trebuchet MS'
ParentColor = False
ParentFont = False
end
end
end
end
......@@ -8,27 +8,31 @@ uses
LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, StdCtrls, Dialogs, JvExControls, ComCtrls, ExtCtrls, Buttons,
MaskEdit, JvBaseEdits, JvCheckBox, utuMessage, Grids, ValEdit, StarUMLintf,
cxuCadastroDefinicaoClasse;
cxuCadastroDefinicaoClasse, IntegracaoDelphiSUML;
type
{ TitCadastrarFormulario }
TitCadastrarFormulario = class(TForm)
edtNome: TEdit;
edtDisplayNome: TEdit;
lblNomeClasse: TLabel;
lblCodigo: TLabel;
lblClasseName: TLabel;
lblClassIDO: TLabel;
lblOrdem: TLabel;
lblObrigatorio: TLabel;
lblNome: TLabel;
lblDisplayNome: TLabel;
lvCampos: TListView;
lblExibirCampos: TLabel;
btnUp: TSpeedButton;
btnDown: TSpeedButton;
edtCodigo: TEdit;
cbbTipo: TComboBox;
lblTipoAtributo: TLabel;
lstAtributos: TValueListEditor;
Panel1: TPanel;
Panel2: TPanel;
rbNao: TRadioButton;
rbSim: TRadioButton;
scrlbxTudo: TScrollBox;
......@@ -37,24 +41,26 @@ type
edtCampo: TEdit;
lblNovoCampo: TLabel;
btnAdd: TSpeedButton;
procedure lstAtributosClear;
procedure edtDisplayNomeChange(Sender: TObject);
procedure edtNomeChange(Sender: TObject);
procedure lstAtributosFill(piType: string);
procedure btnCancelarClick(Sender: TObject);
procedure btnUpClick(Sender: TObject);
procedure btnDownClick(Sender: TObject);
procedure lstAtributosValidateEntry(sender: TObject; aCol, aRow: Integer;
const OldValue: string; var NewValue: String);
procedure lvCamposSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure lvCamposClick(Sender: TObject);
procedure btnSalvarClick(Sender: TObject);
procedure cbbTipoChange(Sender: TObject);
procedure lstAtributosValidate(Sender: TObject; ACol, ARow: Integer;
const KeyName, KeyValue: string);
procedure btnAddClick(Sender: TObject);
procedure edtCampoKeyPress(Sender: TObject; var Key: Char);
procedure rbNaoChange(Sender: TObject);
procedure rbSimChange(Sender: TObject);
private
fUtil: TUtil;
fUMLClass: IUMLClass;
fcxCadastroDefinicaoClasse: cxCadastroDefinicaoClasse;
fClassPackage: IUMLPackage;
......@@ -74,26 +80,10 @@ type
property ClassPackage: IUMLPackage read fClassPackage write fClassPackage;
end;
//itCadastrarFormulario = class(itInterface)
//private
// fTypesField : utField;
// fFieldTypeList : utField;
// fIdCount : Integer;
//
// procedure ObterAtributosSuccess (piRequest : acRequest);
// procedure EditarSuccess (piRequest : acRequest);
// procedure IncluirSuccess (piRequest : acRequest);
// procedure SalvarSuccess (piRequest : acRequest);
// { Private declarations }
//public
// procedure Initialize; override;
// procedure Finalize; override;
//end;
implementation
uses
acuObject;
acuObject, acuFramework, acuModel;
const
__STRING = 1;
......@@ -111,16 +101,25 @@ const
{ itCadastrarCliente }
constructor TitCadastrarFormulario.Create(Sender: TComponent; piCadastroClasse: cxCadastroDefinicaoClasse; piUMLClass: IUMLCLass);
var lMetaModelGenOpt: TMetaModelGenerationOptions;
begin
inherited Create(sender);
if assigned(piUMLClass) then
begin
fUMLClass := piUMLClass;
lblClassIDO.Caption := fUMLClass.GetTaggedValueAsString('DBMappings', 'DBClassMap', 'DBIDO');
lblClasseName.Caption := fUMLClass.GetTaggedValueAsString('DBMappings', 'DBClassMap', 'Table');
lblNomeClasse.Caption := fUMLClass.Name;
//lblClassIDO.Caption := fUMLClass.GetTaggedValueAsString('DBMappings', 'DBClassMap', 'DBIDO');
//lblClasseName.Caption := fUMLClass.GetTaggedValueAsString('DBMappings', 'DBClassMap', 'Table');
end;
fcxCadastroDefinicaoClasse := piCadastroClasse;
lMetaModelGenOpt.CheckDBAttributeNameLength := false;
lMetaModelGenOpt.CheckDBTableNameLength := false;
fUtil := TUtil.Create;
fUtil.AlimentarMetamodel(lMetaModelGenOpt, nil);
self.Initialize;
end;
......@@ -130,6 +129,7 @@ begin
lField := utField.Create;
lResponseField := utField.Create;
fFieldTypeList := utField.Create;
fcxCadastroDefinicaoClasse.rmObtemContexto(lField, lResponseField);
SendToInterface(lResponseField);
lvCamposClick(nil);
......@@ -138,8 +138,10 @@ end;
procedure TitCadastrarFormulario.SendToInterface(piField: utField);
var
lFieldItem: utField;
lEnum : acEnumerator;
i : Integer;
lEnum: acEnumerator;
lClassCode, lRelationName: string;
lClass: acClassTicket;
i: Integer;
begin
inherited;
fTypesField := piField.FindField('FieldTypes');
......@@ -161,9 +163,24 @@ begin
end;
end;
for i:=0 to fUMLClass.GetAttributeCount - 1 do
lClassCode := fUMLClass.GetTaggedValueAsString('DBMappings', 'DBClassMap', 'Cod');
lClass := fUtil.MetaModel.ClassTicketByCode[lClassCode] as acClassTicket;
for i := 0 to lClass.Attributes.Count - 1 do
begin
AdicionarCampo(lClass.Attributes[i]);
end;
for i := 0 to lClass.RelationTicketsIn.Count - 1 do
begin
AdicionarCampo(fUMLClass.GetAttributeAt(i).Name);
lRelationName := acRelationTicket(lClass.RelationTicketsIn.Objects[i]).DestinationPropertyName;
if lRelationName <> '' then AdicionarCampo(lRelationName);
end;
for i := 0 to lClass.RelationTicketsOut.Count - 1 do
begin
lRelationName := acRelationTicket(lClass.RelationTicketsOut.Objects[i]).OriginPropertyName;
if lRelationName <> '' then AdicionarCampo(lRelationName);
end;
end;
......@@ -220,13 +237,33 @@ begin
Self.Close;
end;
procedure MoveListViewItem(ListView: TListView; IndexFrom, IndexTo: Integer);
var
Source, Target: TListItem;
begin
listview.Items.BeginUpdate;
try
Source := listview.Items[IndexFrom];
Target := listview.Items.Insert(IndexTo);
Target.Assign(Source);
Target.Checked := Source.Checked;
Source.Free;
finally
listview.Items.EndUpdate;
end;
end;
procedure TitCadastrarFormulario.btnDownClick(Sender: TObject);
var
lIndex : Integer;
begin
lIndex := lvCampos.Selected.Index;
//lvCampos.MoveDown(lIndex);
if lIndex <> lvCampos.Items.Count - 1 then
begin
MoveListViewItem(lvCampos, lIndex, lIndex + 2);
lvCampos.Selected := lvCampos.Items[lIndex + 1];
end;
lvCampos.SetFocus;
end;
procedure TitCadastrarFormulario.btnUpClick(Sender: TObject);
......@@ -234,7 +271,12 @@ var
lIndex : Integer;
begin
lIndex := lvCampos.Selected.Index;
//lvCampos.MoveUp(lIndex);
if lIndex <> 0 then
begin
MoveListViewItem(lvCampos, lIndex, lIndex - 1);
lvCampos.Selected := lvCampos.Items[lIndex - 1];
end;
lvCampos.SetFocus;
end;
......@@ -300,81 +342,62 @@ begin
end;
end;
procedure TitCadastrarFormulario.lstAtributosClear;
var
i : Integer;
procedure TitCadastrarFormulario.edtNomeChange(Sender: TObject);
begin
if lstAtributos.RowCount > 2 then
for i := lstAtributos.RowCount-1 downto 1 do
lstAtributos.DeleteRow(i)
else
lstAtributos.Values[lstAtributos.Keys[1]] := '';
lvCampos.Selected.Caption := edtNome.Text;
end;
procedure TitCadastrarFormulario.edtDisplayNomeChange(Sender: TObject);
begin
lvCampos.Selected.SubItems[__DISPLAY_NAME] := edtDisplayNome.Text;
end;
procedure TitCadastrarFormulario.lstAtributosValidate(Sender: TObject; ACol,
ARow: Integer; const KeyName, KeyValue: string);
procedure TitCadastrarFormulario.lstAtributosValidateEntry(sender: TObject;
aCol, aRow: Integer; const OldValue: string; var NewValue: String);
var
lField, lAttributeField, lTypeField : utField;
lOID, lAttributeType, lIntValue : Integer;
lOK, lBoolValue: Boolean;
lMessage : string;
begin
if (lvCampos.SelCount > 0) and (lvCampos.Selected.SubItems[__TIPO] <> '') then
lBoolValue: Boolean;
lKeyName : string;
begin
if NewValue <> OldValue then
begin
lKeyName := lstAtributos.Keys[aRow];
lTypeField := fTypesField.FieldByName(lvCampos.Selected.SubItems[__TIPO]);
lAttributeType := lTypeField.FieldByName('Attributes').FieldByName(KeyName).AttributeByName('type').AsInteger;
lAttributeType := lTypeField.FieldByName('Attributes').FieldByName(lKeyName).AttributeByName('type').AsInteger;
lOK := True;
if lAttributeType = __NUMBER then
if NewValue = '' then
begin
lOK := TryStrToInt(KeyValue, lIntValue);
lMessage := 'Atributo ' + KeyName + ' deve ser do tipo INTEGER';
end
else if lAttributeType = __BOOLEAN then
begin
lOK := TryStrToBool(KeyValue, lBoolValue);
lMessage := 'Atributo ''' + KeyName + ''' deve ser do tipo BOOLEAN';
lField := fFieldTypeList.FieldByName(lvCampos.Selected.SubItems[__ID]).FieldByName('Type');
if lField.HasField(lKeyName) then
lField.RemoveField(lField.FieldByName(lKeyName));
Exit;
end;
if KeyValue <> '' then
begin
if lOK then
begin
lOID := Integer(lstAtributos.Strings.Objects[lstAtributos.Strings.IndexOfName(KeyName)]);
if (lAttributeType = __NUMBER) and (TryStrToInt(NewValue, lIntValue) = False) then
raise Exception.Create('Atributo ' + lKeyName + ' deve ser do tipo INTEGER');
if (lAttributeType = __BOOLEAN) and (TryStrToBool(NewValue, lBoolValue) = False) then
raise Exception.Create('Atributo ''' + lKeyName + ''' deve ser do tipo BOOLEAN');
//caso os dados estejam validos:
lOID := Integer(lstAtributos.Strings.Objects[lstAtributos.Strings.IndexOfName(lKeyName)]);
lField := fFieldTypeList.FieldByName(lvCampos.Selected.SubItems[__ID]).FieldByName('Type');
if lField.HasField(KeyName) then
if lField.HasField(lKeyName) then
begin
lAttributeField := lField.FieldByName(KeyName);
lAttributeField := lField.FieldByName(lKeyName);
lAttributeField.AttributeByName('OID').AsInteger := lOID;
lAttributeField.AttributeByName('value').AsString := KeyValue;
lAttributeField.AttributeByName('value').AsString := NewValue;
end
else
begin
lAttributeField := lField.AddField(KeyName);
lAttributeField := lField.AddField(lKeyName);
lAttributeField.AddAttribute('OID').AsInteger := lOID;
lAttributeField.AddAttribute('value').AsString := KeyValue;
end;
end
else
begin
// lstAtributos.Col := ACol;
// lstAtributos.Row := ARow;
//lstAtributos.Values[KeyName] := '';
//MessageDlg(lMessage, mtError, [mbOK], 0);
raise Exception.Create(lMessage);
end;
end
else
begin
lField := fFieldTypeList.FieldByName(lvCampos.Selected.SubItems[__ID]).FieldByName('Type');
if lField.HasField(KeyName) then
lField.RemoveField(lField.FieldByName(KeyName));
lAttributeField.AddAttribute('value').AsString := NewValue;
end;
end;
end;
procedure TitCadastrarFormulario.rbNaoChange(Sender: TObject);
begin
lvCampos.Selected.SubItems[__OBRIGATORIO] := 'N';
......@@ -397,6 +420,10 @@ begin
lblOrdem.Enabled := False;
lblObrigatorio.Enabled := False;
lblTipoAtributo.Enabled := False;
lblNome.Enabled := False;
lblDisplayNome.Enabled := False;
edtNome.Enabled := False;
edtDisplayNome.Enabled := False;
lstAtributos.Enabled := False;
lstAtributos.Clear;
end
......@@ -410,6 +437,10 @@ begin
lblOrdem.Enabled := True;
lblObrigatorio.Enabled := True;
lblTipoAtributo.Enabled := True;
lblNome.Enabled := True;
lblDisplayNome.Enabled := True;
edtNome.Enabled := True;
edtDisplayNome.Enabled := True;
lstAtributos.Enabled := True;
end;
end;
......@@ -418,8 +449,8 @@ procedure TitCadastrarFormulario.lvCamposSelectItem(Sender: TObject; Item: TList
begin
if Selected then
begin
//edtNome.Text := Item.Caption;
//edtNomeDisplay.Text := Item.SubItems[__DISPLAY_NAME];
edtNome.Text := Item.Caption;
edtDisplayNome.Text := Item.SubItems[__DISPLAY_NAME];
if Item.SubItems[__OBRIGATORIO] = 'N' then
rbNao.Checked := True
......
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