diff --git a/Project1.dpr b/Project1.dpr new file mode 100644 index 0000000..284ef77 --- /dev/null +++ b/Project1.dpr @@ -0,0 +1,21 @@ +program Project1; + +uses + Vcl.Forms, + UnitFormSplash in 'UnitFormSplash.pas' {FormSplash}, + UnitLista in 'UnitLista.pas', + UnitFormPadrao in 'UnitFormPadrao.pas' {FormPadrao}, + UnitFormCidade in 'UnitFormCidade.pas' {FormCidade}, + UnitFormEstado in 'UnitFormEstado.pas' {FormEstado}, + UnitFormPais in 'UnitFormPais.pas' {FormPais}, + UnitFormGrid in 'UnitFormGrid.pas' {FormGrid}, + UnitDados in 'UnitDados.pas'; + +{$R *.res} + +begin + Application.Initialize; + Application.MainFormOnTaskbar := True; + Application.CreateForm(TFormSplash, FormSplash); + Application.Run; +end. diff --git a/Project1.dproj.local b/Project1.dproj.local index 4598f7d..c7f551c 100644 --- a/Project1.dproj.local +++ b/Project1.dproj.local @@ -15,8 +15,8 @@ 2018/08/02 11:51:22.000.511,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Unit1.pas=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\UnitFormCidade.pas 2018/08/02 11:54:03.000.448,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj 2018/08/03 07:57:41.000.908,=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Unit1.pas - 2018/08/03 07:59:28.000.101,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Unit1.dfm=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\UnitFormEstado.dfm 2018/08/03 07:59:28.000.101,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Unit1.pas=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\UnitFormEstado.pas + 2018/08/03 07:59:28.000.101,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Unit1.dfm=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\UnitFormEstado.dfm 2018/08/03 09:19:04.000.339,=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Unit1.pas 2018/08/03 09:22:08.000.430,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\UnitFormPais.pas=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Unit1.pas 2018/08/03 09:22:08.000.430,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\UnitFormPais.dfm=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Unit1.dfm @@ -33,9 +33,11 @@ 2018/08/08 12:16:26.000.969,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj 2018/08/08 14:58:46.000.344,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj 2018/08/14 14:54:15.000.469,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj - 2018/08/15 09:42:05.729,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj - 2018/08/15 14:04:18.997,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj - 2018/08/15 15:04:40.526,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj + 2018/08/15 09:42:05.000.729,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj + 2018/08/15 14:04:18.000.997,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj + 2018/08/15 15:04:40.000.526,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj + 2018/08/16 11:06:43.000.602,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj + 2018/08/17 12:26:51.000,C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj=C:\Users\programacaounico38\Documents\Embarcadero\Studio\Projects\Ex_CRUD\Project1.dproj diff --git a/Project1.stat b/Project1.stat index b02e87f..38a0b16 100644 --- a/Project1.stat +++ b/Project1.stat @@ -1,10 +1,10 @@ [Stats] -EditorSecs=54967 -DesignerSecs=6268 -InspectorSecs=2075 -CompileSecs=317442 -OtherSecs=2376 +EditorSecs=55071 +DesignerSecs=6493 +InspectorSecs=2094 +CompileSecs=325150 +OtherSecs=2023 StartTime=03/08/2018 07:57:26 RealKeys=0 EffectiveKeys=0 -DebugSecs=23613 +DebugSecs=23790 diff --git a/UnitDados.pas b/UnitDados.pas new file mode 100644 index 0000000..306f98d --- /dev/null +++ b/UnitDados.pas @@ -0,0 +1,135 @@ +unit UnitDados; + +interface + +uses System.Classes, System.Contnrs, UnitLista, System.SysUtils, Dialogs; + +type + TDados = class + constructor Create(); + + private + + public + Dado: integer; + end; + + TDadoArmazenado = class + private + Dados: TStringList; + public + constructor Create(); + procedure saveToFile(Arquivo: string; Lista: TLista; Classe: TClass); + function loadFromFile(Arquivo: string; Classe: TClass): TLista; + property DadoArmazenado: TStringList read Dados write Dados; + end; + +implementation + uses UnitFormCidade, UnitFormEstado, unitFormPais; +constructor TDados.Create(); + begin + Dado := -1; + end; + +constructor TDadoArmazenado.Create; + begin + DadoArmazenado := TStringList.Create; + end; + +procedure TDadoArmazenado.saveToFile(Arquivo: string; Lista: TLista; Classe: TClass); +var + wDiretorio: string; + wObj: TObject; + wCont: integer; + begin + try + for wCont := 0 to Lista.Count-1 do + begin + wObj := Lista.getObjectByIndex(wCont); + if Classe = TCidade then + begin + with wObj as TCidade do + DadoArmazenado.Add(format('%d|%s|%s|%s',[wCod, wCidade, wPais, wUF])); + end; + if Classe = TEstado then + begin + with wObj as TEstado do + DadoArmazenado.Add(format('%d|%s|%s|%d',[wCod, wEstado, wPais, wAliquota])); + end; + if Classe = TPais then + begin + with wObj as TPais do + DadoArmazenado.Add(format('%d|%s|%s|%d',[wCod, wPais, wNacionalidade, wCodFed])); + end; + end; + finally + DadoArmazenado.savetofile(Arquivo); + ShowMessage('Exportação executada!'); + end; + end; + +function TDadoArmazenado.loadFromFile(Arquivo: string; Classe: TClass): TLista; +var + wStringList: TStringList; + wStringAux: TStringList; + wObj: TObject; + wCont: Integer; + FLista: TLista; + wIndex: integer; +begin + wStringList := TStringList.Create; + wStringList.LoadFromFile(Arquivo, TEncoding.UTF8); + wStringAux := TStringList.Create; + FLista := TLista.Create; + try + for wCont := 0 to wStringList.Count-1 do + begin + // condição de acordo com a classe recebida + wStringAux.Clear; + wStringAux.Delimiter := '|'; + wStringAux.DelimitedText := wStringList[wCont]; + wStringAux.StrictDelimiter := True; + if Classe = TCidade then + begin + wObj := TCidade.Create; + with wObj as TCidade do + begin + wCod := strtoint(wStringAux.Strings[0]); + wCidade := wStringAux.Strings[1]; + wPais := wStringAux.Strings[2]; + wUF := wStringAux.Strings[3]; + end; + FLista.Inserir(wObj, TCidade); + end; + if Classe = TEstado then + begin + wObj := TEstado.Create; + with wObj as TEstado do + begin + wCod := strtoint(wStringAux.Strings[0]); + wEstado := wStringAux.Strings[1]; + wPais := wStringAux.Strings[2]; + wAliquota := strtoint(wStringAux.Strings[3]); + end; + FLista.Inserir(wObj, TEstado); + end; + if Classe = TPais then + begin + wObj := TPais.Create; + with wObj as TPais do + begin + wCod := strtoint(wStringAux.Strings[0]); + wPais := wStringAux.Strings[1]; + wNacionalidade := wStringAux.Strings[2]; + wCodFed := strtoint(wStringAux.Strings[3]); + end; + FLista.Inserir(wObj, TPais); + end; + end; + finally + Result := FLista; + ShowMessage('Importação executada!'); + end; +end; + +end. diff --git a/UnitFormCidade.dfm b/UnitFormCidade.dfm new file mode 100644 index 0000000..27040f1 --- /dev/null +++ b/UnitFormCidade.dfm @@ -0,0 +1,130 @@ +inherited FormCidade: TFormCidade + Caption = 'Cadastro de cidade:' + ClientHeight = 312 + OnCreate = FormCreate + ExplicitHeight = 351 + PixelsPerInch = 96 + TextHeight = 15 + inherited ToolBar1: TToolBar + inherited btAnterior: TButton + TabOrder = 2 + OnClick = btAnteriorClick + end + inherited btProximo: TButton + OnClick = btProximoClick + end + inherited btBuscar: TButton + TabOrder = 0 + OnClick = btBuscarClick + end + inherited btInserir: TButton + Default = False + OnClick = btInserirClick + end + inherited btExcluir: TButton + OnClick = btExcluirClick + end + inherited btImportar: TButton + OnClick = btImportarClick + end + inherited btExportar: TButton + OnClick = btExportarClick + end + inherited btContar: TButton + OnClick = btContarClick + end + end + inherited Panel1: TPanel + Height = 264 + ExplicitHeight = 264 + inherited cbLimparCampos: TCheckBox + TabOrder = 1 + end + inherited Panel2: TPanel + Top = 6 + TabOrder = 0 + ExplicitLeft = 98 + object Label1: TLabel + Left = 52 + Top = 66 + Width = 42 + Height = 15 + Anchors = [] + Caption = 'C'#243'digo:' + end + object Label2: TLabel + Left = 54 + Top = 111 + Width = 40 + Height = 15 + Anchors = [] + Caption = 'Cidade:' + end + object Label3: TLabel + Left = 69 + Top = 161 + Width = 25 + Height = 15 + Anchors = [] + Caption = 'Pa'#237's:' + end + object Label4: TLabel + Left = 277 + Top = 161 + Width = 19 + Height = 15 + Anchors = [] + Caption = 'UF:' + end + object edCidade: TEdit + Tag = 1 + Left = 109 + Top = 108 + Width = 150 + Height = 23 + Anchors = [] + TabOrder = 0 + OnKeyPress = onKeyPress + end + object edCod: TEdit + Left = 110 + Top = 63 + Width = 75 + Height = 23 + Anchors = [] + TabOrder = 1 + OnExit = edCodExit + OnKeyPress = onKeyPress + end + object edPais: TEdit + Tag = 2 + Left = 109 + Top = 158 + Width = 150 + Height = 23 + Anchors = [] + TabOrder = 2 + OnKeyPress = onKeyPress + end + object edUF: TEdit + Tag = 3 + Left = 310 + Top = 158 + Width = 75 + Height = 23 + Anchors = [] + TabOrder = 3 + OnKeyPress = edFinalKeyPress + end + end + end + inherited StatusBar1: TStatusBar + Top = 293 + Panels = < + item + Text = 'Aguardando' + Width = 50 + end> + ExplicitTop = 293 + end +end diff --git a/UnitFormCidade.pas b/UnitFormCidade.pas new file mode 100644 index 0000000..f9c09f4 --- /dev/null +++ b/UnitFormCidade.pas @@ -0,0 +1,416 @@ +unit UnitFormCidade; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UnitFormPadrao, Vcl.StdCtrls, + Vcl.ToolWin, Vcl.ComCtrls, UnitLista, contnrs, Vcl.ExtCtrls, Vcl.Grids, UnitDados, + Vcl.ExtDlgs; + +type + TFormCidade = class(TFormPadrao) + edCod: TEdit; + edCidade: TEdit; + edUF: TEdit; + edPais: TEdit; + Label1: TLabel; + Label2: TLabel; + Label3: TLabel; + Label4: TLabel; + procedure btInserirClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure btExcluirClick(Sender: TObject); + procedure btAnteriorClick(Sender: TObject); + procedure btProximoClick(Sender: TObject); + procedure btBuscarClick(Sender: TObject); + procedure FormActivate(Sender: TObject); + procedure btExportarClick(Sender: TObject); + procedure btImportarClick(Sender: TObject); + procedure btContarClick(Sender: TObject); + procedure Button1Click(Sender: TObject); + procedure edCodExit(Sender: TObject); + procedure edFinalKeyPress(Sender: TObject; var Key: Char); + procedure limpaCampos(); + procedure cbLimparCamposClick(Sender: TObject); + private + { Private declarations } + strict private wLista: TLista; + wClear: boolean; + public + { Public declarations } + end; + + TCidade = class + private + wpCod: integer; + wpCidade: string; + wpPais: string; + wpUF: string; + public + property wCod: integer read wpCod write wpCod; + property wCidade: string read wpCidade write wpCidade; + property wPais: string read wpPais write wpPais; + property wUF: string read wpUF write wpUF; + end; + +var + FormCidade: TFormCidade; + wCidade: TCidade; + Dado1: TDados; + +implementation +{$R *.dfm} + +uses UnitFormGrid; + + +procedure TFormCidade.btAnteriorClick(Sender: TObject); +var + wObj: TObject; + wIndex: integer; + I: Integer; +begin + inherited; + if (trystrtoint(edCod.Text, wIndex)) then + begin + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TCidade do + begin + if wCod = strtoint(edCod.Text) then + wIndex := wLista.getIndexOfObj(wObj); + end; + end; + if wIndex-1 >= 0 then + begin + wObj := wLista.getObjectByIndex(wIndex-1); + with wObj as TCidade do + begin + edCod.Text := inttostr(wCod); + edCidade.Text := wCidade; + edPais.Text := wPais; + edUF.Text := wUF; + end; + end; + end; +end; + +procedure TFormCidade.btProximoClick(Sender: TObject); +var + wObj: TObject; + wIndex: integer; + I: integer; +begin + inherited; + if (trystrtoint(edCod.Text, wIndex)) then + begin + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TCidade do + if wCod = strtoint(edCod.Text) then + wIndex := wLista.getIndexOfObj(wObj); + end; + if wIndex+1 < wLista.Count then + begin + wObj := wLista.getObjectByIndex(wIndex+1); + with wObj as TCidade do + begin + edCod.Text := inttostr(wCod); + edCidade.Text := wCidade; + edPais.Text := wPais; + edUF.Text := wUF; + end; + end; + end; +end; + +procedure TFormCidade.Button1Click(Sender: TObject); +begin + inherited; + ShowMessage('teste'); +end; + +procedure TFormCidade.cbLimparCamposClick(Sender: TObject); +begin + inherited; + if wClear then + wClear := false + else + wClear := true; +end; + +procedure TFormCidade.limpaCampos(); +begin + if wClear then + begin + edCod.Clear; + edCidade.Clear; + edPais.Clear; + edUF.Clear; + end; +end; + +procedure TFormCidade.edFinalKeyPress(Sender: TObject; var Key: Char); +var + wObj: TCidade; + wObjGet: TObject; + wcont: Integer; + wIndex: integer; + wMaior: integer; + wNew: boolean; + wZero: boolean; +begin + inherited; + if (ord(key) = 13) or (ord(key) = 9) then + begin + wNew := true; + if (trystrtoint(edCod.Text, windex)) then + begin + wObj := TCidade.Create; + with wObj do + begin + wCod := strtoint(edCod.Text); + wCidade := edCidade.Text; + wPais := edPais.Text; + wUF := edUF.Text; + end; + for wCont := 0 to wLista.Count-1 do + begin + wObjGet := wLista.getObjectByIndex(wCont); + with wObjGet as TCidade do + if wCod = strtoint(edCod.Text) then + begin + wLista.Update(wCont, wObj); + wNew := false; + if wClear then + limpaCampos(); + break; + end; + end; + if wNew = true then + begin + wLista.Inserir(wObj, TCidade); + if wClear then + limpaCampos(); + end; + + end + else + if edCod.Text = '' then + begin + wZero := true; + for wCont := 0 to wLista.Count-1 do + begin + wObjGet := wLista.getObjectByIndex(wCont); + with wobjGet as TCidade do + begin + if wCod > wMaior then + wMaior := wCod; + wZero := false; + end; + + end; + wObj := TCidade.Create; + with wObj do + begin + if wZero then + wCod := 0 + else + wCod := wMaior+1; + wCidade := edCidade.Text; + wPais := edPais.Text; + wUF := edUF.Text; + end; + wLista.Inserir(wObj, TCidade); + if wClear then + limpaCampos(); + end; + // volta pro edit do inicio e altera status bar + for wCont := 0 to ComponentCount-1 do + if (Components[wCont].Tag = 0) and (Components[wCont] is TEdit) then + with Components[wCont] as TEdit do + begin + setFocus; + StatusBar1.Panels[0].Text := 'Aguardando'; + end; + end; +end; + +procedure TFormCidade.edCodExit(Sender: TObject); +var + wObj: TObject; + wCont: Integer; + wIndex: integer; + wNew: boolean; +begin + inherited; + if (trystrtoint(edCod.Text, wIndex)) then + begin + wNew := true; + for wCont := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(wCont); + with wObj as TCidade do + if wCod = strtoint(edCod.Text) then + begin + StatusBar1.Panels[0].Text := 'Alterando registro'; + edCod.Text := inttostr(wCod); + edCidade.Text := wCidade; + edPais.Text := wPais; + edUF.Text := wUF; + wNew := false; + exit; + end; + end; + if wNew then + StatusBar1.Panels[0].Text := 'Novo registro'; + end + else + if edCod.Text = '' then + StatusBar1.Panels[0].Text := 'Novo registro' + else + StatusBar1.Panels[0].Text := 'Aguardando'; +end; + +procedure TFormCidade.btExportarClick(Sender: TObject); +var + DadoArmazenado: TDadoArmazenado; + wDir: string; +begin + inherited; + DadoArmazenado := TDadoArmazenado.Create; + if SaveTextFileDialog1.Execute then + wDir := SaveTextFileDialog1.FileName; + DadoArmazenado.saveToFile(wDir, wLista, TCidade); +end; + +procedure TFormCidade.btBuscarClick(Sender: TObject); +var + FormGrid: TFormGrid; +begin + inherited; + if wLista.Count > 0 then + begin + FormGrid := TFormGrid.Create(nil); + FormGrid.geraGrid(wLista, TCidade); + FormGrid.Show; + end; +end; + +procedure TFormCidade.btContarClick(Sender: TObject); +begin + inherited; + ShowMessage(inttostr(wLista.Count)); +end; + +procedure TFormCidade.btExcluirClick(Sender: TObject); +var + wObj: TObject; + I: Integer; +begin + inherited; + try + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TCidade do + if wCod = strtoint(edCod.Text) then + begin + wLista.Excluir(I); + break; + end; + end; + finally + edCod.Clear; + edCidade.Clear; + edPais.Clear; + edUF.Clear; + end; +end; + +procedure TFormCidade.btImportarClick(Sender: TObject); +var + DadoArmazenado: TDadoArmazenado; + wDir: string; + begin + inherited; + DadoArmazenado := TDadoArmazenado.Create; + if OpenTextFileDialog1.Execute then + wDir := OpenTextFileDialog1.FileName; + wLista := DadoArmazenado.loadFromFile(wDir, TCidade); +end; + +procedure TFormCidade.btInserirClick(Sender: TObject); +var + Cidade: TCidade; + wObj: TObject; + wIndex: integer; + I: integer; + wAux: integer; +begin + inherited; + Cidade := TCidade.Create; + if (trystrtoint(edCod.Text, wIndex)) then + begin + with Cidade do + begin + wCod := strtoint(edCod.Text);wCidade := edCidade.Text;wPais := edPais.Text;wUF := edUF.Text; + end; + if wLista.Count >= 1 then + begin + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TCidade do + begin + if wCod = strtoint(edCod.Text) then + begin + wAux := 1; + wLista.Update(I, Cidade); + break; + end + else + wAux := 0; + end; + end; + if wAux =0 then + wLista.Inserir(Cidade, TCidade) + end + else + wLista.Inserir(Cidade, TCidade); + end; +end; + +procedure TFormCidade.FormActivate(Sender: TObject); +var + wObj: TObject; + wCont: Integer; +begin + inherited; + if Dado1.Dado > -1 then + begin + wObj := wLista.getObjectByIndex(Dado1.Dado); + with wObj as TCidade do + begin + edCod.Text := inttostr(wCod); + edCidade.Text := wCidade; + edPais.Text := wPais; + edUF.Text := wUF; + end; + end; +end; + +procedure TFormCidade.FormCreate(Sender: TObject); +begin + inherited; + wLista := TLista.Create; + Dado1 := TDados.Create; + wClear := false; +end; + +initialization + registerclass (TFormCidade); +end. diff --git a/UnitFormEstado.dfm b/UnitFormEstado.dfm new file mode 100644 index 0000000..b8a7eab --- /dev/null +++ b/UnitFormEstado.dfm @@ -0,0 +1,138 @@ +inherited FormEstado: TFormEstado + Caption = 'Cadastro de estado:' + ClientHeight = 313 + ClientWidth = 601 + OnCreate = FormCreate + ExplicitWidth = 617 + ExplicitHeight = 352 + PixelsPerInch = 96 + TextHeight = 15 + inherited ToolBar1: TToolBar + Width = 601 + Anchors = [] + ExplicitWidth = 601 + inherited btAnterior: TButton + OnClick = btAnteriorClick + end + inherited btProximo: TButton + OnClick = btProximoClick + end + inherited btBuscar: TButton + OnClick = btBuscarClick + end + inherited btInserir: TButton + Default = False + OnClick = btInserirClick + end + inherited btExcluir: TButton + OnClick = btExcluirClick + end + inherited btImportar: TButton + OnClick = btImportarClick + end + inherited btExportar: TButton + OnClick = btExportarClick + end + inherited btContar: TButton + OnClick = btContarClick + end + end + inherited Panel1: TPanel + Width = 601 + Height = 265 + ExplicitWidth = 601 + ExplicitHeight = 265 + inherited cbLimparCampos: TCheckBox + TabOrder = 1 + end + inherited Panel2: TPanel + Left = 102 + Top = 6 + TabOrder = 0 + ExplicitLeft = 102 + object Label1: TLabel + Left = 50 + Top = 65 + Width = 42 + Height = 15 + Anchors = [] + Caption = 'C'#243'digo:' + end + object Label2: TLabel + Left = 52 + Top = 108 + Width = 40 + Height = 15 + Anchors = [] + Caption = 'Estado:' + end + object Label3: TLabel + Left = 67 + Top = 153 + Width = 25 + Height = 15 + Anchors = [] + Caption = 'Pa'#237's:' + end + object Label4: TLabel + Left = 266 + Top = 153 + Width = 29 + Height = 15 + Anchors = [] + Caption = 'Al'#237'q.:' + end + object edAliquota: TEdit + Tag = 3 + Left = 306 + Top = 150 + Width = 75 + Height = 23 + Anchors = [] + TabOrder = 0 + OnKeyPress = edFinalKeyPress + end + object edCod: TEdit + Left = 110 + Top = 62 + Width = 75 + Height = 23 + Anchors = [] + TabOrder = 1 + OnExit = edCodExit + OnKeyPress = onKeyPress + end + object edEstado: TEdit + Tag = 1 + Left = 110 + Top = 105 + Width = 150 + Height = 23 + Anchors = [] + TabOrder = 2 + OnKeyPress = onKeyPress + end + object edPais: TEdit + Tag = 2 + Left = 110 + Top = 150 + Width = 150 + Height = 23 + Anchors = [] + TabOrder = 3 + OnKeyPress = onKeyPress + end + end + end + inherited StatusBar1: TStatusBar + Top = 294 + Width = 601 + Panels = < + item + Text = 'Aguardando' + Width = 50 + end> + ExplicitTop = 294 + ExplicitWidth = 601 + end +end diff --git a/UnitFormEstado.pas b/UnitFormEstado.pas new file mode 100644 index 0000000..3312bf1 --- /dev/null +++ b/UnitFormEstado.pas @@ -0,0 +1,407 @@ +unit UnitFormEstado; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UnitFormPadrao, Vcl.StdCtrls, UnitLista, UnitDados, + Vcl.ToolWin, Vcl.ComCtrls, System.Contnrs, Vcl.ExtDlgs, Vcl.ExtCtrls; + +type + TFormEstado = class(TFormPadrao) + edCod: TEdit; + edEstado: TEdit; + edPais: TEdit; + edAliquota: TEdit; + Label1: TLabel; + Label2: TLabel; + Label3: TLabel; + Label4: TLabel; + procedure btInserirClick(Sender: TObject); + procedure btExcluirClick(Sender: TObject); + procedure btContarClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure btAnteriorClick(Sender: TObject); + procedure btProximoClick(Sender: TObject); + procedure btBuscarClick(Sender: TObject); + procedure FormActivate(Sender: TObject); + procedure btExportarClick(Sender: TObject); + procedure btImportarClick(Sender: TObject); + procedure edFinalKeyPress(Sender: TObject; var Key: Char); + procedure limpaCampos(); + procedure edCodExit(Sender: TObject); + procedure cbLimparCamposClick(Sender: TObject); + private + { Private declarations } + strict private wLista: TLista; + wClear: boolean; + public + { Public declarations } + end; + + TEstado = class + private + wpCod: integer; + wpEstado: string; + wpPais: string; + wpAliquota: integer; + public + property wCod: integer read wpCod write wpCod; + property wEstado: string read wpEstado write wpEstado; + property wPais: string read wpPais write wpPais; + property wAliquota: integer read wpAliquota write wpAliquota; + end; + +var + FormEstado: TFormEstado; + wEstado: TEstado; + Dado2: TDados; + +implementation +{$R *.dfm} + +uses UnitFormGrid; + +procedure TFormEstado.edCodExit(Sender: TObject); +var + wObj: TObject; + wCont: Integer; + wIndex: integer; + wNew: boolean; +begin + inherited; + if (trystrtoint(edCod.Text, wIndex)) then + begin + wNew := true; + for wCont := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(wCont); + with wObj as TEstado do + if wCod = strtoint(edCod.Text) then + begin + StatusBar1.Panels[0].Text := 'Alterando registro'; + edCod.Text := inttostr(wCod); + edEstado.Text := wEstado; + edPais.Text := wPais; + edAliquota.Text := inttostr(wAliquota); + wNew := false; + exit; + end; + end; + if wNew then + StatusBar1.Panels[0].Text := 'Novo registro'; + end + else + if edCod.Text = '' then + StatusBar1.Panels[0].Text := 'Novo registro' + else + StatusBar1.Panels[0].Text := 'Aguardando'; +end; + +procedure TFormEstado.limpaCampos; +begin + if wClear then + begin + edCod.Clear; + edEstado.Clear; + edPais.Clear; + edAliquota.Clear; + end; +end; + +procedure TFormEstado.edFinalKeyPress(Sender: TObject; var Key: Char); +var + wObj: TEstado; + wObjGet: TObject; + wcont: Integer; + wIndex: integer; + wMaior: integer; + wNew: boolean; + wZero: boolean; +begin + inherited; + if (ord(key) = 13) or (ord(key) = 9) then + begin + wNew := true; + if (trystrtoint(edCod.Text, windex)) then + begin + wObj := TEstado.Create; + with wObj do + begin + wCod := strtoint(edCod.Text); + wEstado := edEstado.Text; + wPais := edPais.Text; + wAliquota := strtoint(edAliquota.Text); + end; + for wCont := 0 to wLista.Count-1 do + begin + wObjGet := wLista.getObjectByIndex(wCont); + with wObjGet as TEstado do + if wCod = strtoint(edCod.Text) then + begin + wLista.Update(wCont, wObj); + wNew := false; + if wClear then + limpaCampos(); + break; + end; + end; + if wNew = true then + begin + wLista.Inserir(wObj, TEstado); + if wClear then + limpaCampos(); + end; + + end + else + if edCod.Text = '' then + begin + wZero := true; + for wCont := 0 to wLista.Count-1 do + begin + wObjGet := wLista.getObjectByIndex(wCont); + with wobjGet as TEstado do + begin + if wCod > wMaior then + wMaior := wCod; + wZero := false; + end; + + end; + wObj := TEstado.Create; + with wObj do + begin + if wZero then + wCod := 0 + else + wCod := wMaior+1; + wEstado := edEstado.Text; + wPais := edPais.Text; + wAliquota := strtoint(edAliquota.Text); + end; + wLista.Inserir(wObj, TEstado); + if wClear then + limpaCampos(); + end; + // volta pro edit do inicio e altera status bar + for wCont := 0 to ComponentCount-1 do + if (Components[wCont].Tag = 0) and (Components[wCont] is TEdit) then + with Components[wCont] as TEdit do + begin + setFocus; + StatusBar1.Panels[0].Text := 'Aguardando'; + end; + end; +end; +procedure TFormEstado.btAnteriorClick(Sender: TObject); +var + wObj: TObject; + wObj2: TObject; + wIndex: integer; + I: Integer; +begin + inherited; + if (trystrtoint(edCod.Text, wIndex)) then + begin + for I := 1 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TEstado do + begin + if wCod = strtoint(edCod.Text) then + wIndex := wLista.getIndexOfObj(wObj); + end; + end; + if wIndex-1 >= 0 then + begin + wObj := wLista.getObjectByIndex(wIndex-1); + with wObj as TEstado do + begin + edCod.Text := inttostr(wCod); + edEstado.Text := wEstado; + edPais.Text := wPais; + edAliquota.Text := inttostr(wAliquota); + end; + end; + end; +end; + +procedure TFormEstado.btBuscarClick(Sender: TObject); +var + FormGrid: TFormGrid; +begin + inherited; + FormGrid := TFormGrid.Create(nil); + FormGrid.geraGrid(wLista, TEstado); + FormGrid.Show; +end; + +procedure TFormEstado.btContarClick(Sender: TObject); +begin + inherited; + ShowMessage(inttostr(wLista.Count)); +end; + +procedure TFormEstado.btExcluirClick(Sender: TObject); +var + wObj: TObject; + I: integer; +begin + inherited; + try + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TEstado do + if wCod = strtoint(edCod.Text) then + begin + wLista.Excluir(I); + break; + end; + end; + finally + edCod.Clear; + edEstado.Clear; + edPais.Clear; + edAliquota.Clear; + end; +end; + +procedure TFormEstado.btExportarClick(Sender: TObject); +var + DadoArmazenado: TDadoArmazenado; + wDir: string; +begin + inherited; + DadoArmazenado := TDadoArmazenado.Create; + if SaveTextFileDialog1.Execute then + wDir := SaveTextFileDialog1.FileName; + DadoArmazenado.saveToFile(wDir, wLista, TEstado); +end; + +procedure TFormEstado.btImportarClick(Sender: TObject); +var + DadoArmazenado: TDadoArmazenado; + wDir: string; + begin + inherited; + DadoArmazenado := TDadoArmazenado.Create; + if OpenTextFileDialog1.Execute then + wDir := OpenTextFileDialog1.FileName; + wLista := DadoArmazenado.loadFromFile(wDir, TEstado); +end; + +procedure TFormEstado.btInserirClick(Sender: TObject); +var + Estado: TEstado; + wObj: TObject; + wIndex: integer; + I: integer; + wAux: integer; +begin + inherited; + Estado := TEstado.Create; + if (trystrtoint(edCod.Text, wIndex)) then + begin + with Estado do + begin + wCod := strtoint(edCod.Text);wEstado := edEstado.Text;wPais := edPais.Text;wAliquota := strtoint(edAliquota.Text); + end; + if wLista.Count >= 1 then + begin + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TEstado do + begin + if wCod = strtoint(edCod.Text) then + begin + wAux := 1; + wLista.Update(I, Estado); + break; + end + else + wAux := 0; + end; + end; + if wAux =0 then + wLista.Inserir(Estado, TEstado) + end + else + wLista.Inserir(Estado, TEstado); + end; +end; + +procedure TFormEstado.btProximoClick(Sender: TObject); +var + wObj: TObject; + wIndex: integer; + I: integer; +begin + inherited; + if (trystrtoint(edCod.Text, wIndex)) then + begin + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TEstado do + begin + if wCod = strtoint(edCod.Text) then + wIndex := wLista.getIndexOfObj(wObj); + end; + end; + if wIndex+1 < wLista.Count then + begin + wObj := wLista.getObjectByIndex(wIndex+1); + with wObj as TEstado do + begin + edCod.Text := inttostr(wCod); + edEstado.Text := wEstado; + edPais.Text := wPais; + edAliquota.Text := inttostr(wAliquota); + end; + end; + end; +end; + +procedure TFormEstado.cbLimparCamposClick(Sender: TObject); +begin + inherited; + if wClear then + wClear := false + else + wClear := true; + +end; + +procedure TFormEstado.FormActivate(Sender: TObject); +var + wObj: TObject; +begin + inherited; + if Dado2.Dado > -1 then + begin + wObj := TEstado.Create; + wObj := wLista.getObjectByIndex(Dado2.Dado); + with wObj as TEstado do + begin + edCod.Text := inttostr(wCod); + edEstado.Text := wEstado; + edPais.Text := wPais; + edAliquota.Text := inttostr(wAliquota); + end; + end; +end; + +procedure TFormEstado.FormCreate(Sender: TObject); +begin + inherited; + wLista := TLista.Create; + Dado2 := TDados.Create; + wClear := false; +end; + +initialization + registerclass(TFormEstado); +end. diff --git a/UnitFormGrid.dfm b/UnitFormGrid.dfm new file mode 100644 index 0000000..af2e09a --- /dev/null +++ b/UnitFormGrid.dfm @@ -0,0 +1,61 @@ +object FormGrid: TFormGrid + Left = 0 + Top = 0 + Width = 365 + Height = 340 + AutoScroll = True + Caption = 'FormGrid' + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + FormStyle = fsMDIChild + OldCreateOrder = False + Visible = True + OnClose = FormClose + PixelsPerInch = 96 + TextHeight = 13 + object StringGrid1: TStringGrid + Left = 8 + Top = 35 + Width = 265 + Height = 184 + ColCount = 4 + FixedCols = 0 + FixedRows = 0 + Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSelect] + ParentShowHint = False + ShowHint = True + TabOrder = 0 + end + object ToolBar1: TToolBar + Left = 0 + Top = 0 + Width = 349 + Height = 29 + ButtonHeight = 25 + Caption = 'ToolBar1' + TabOrder = 1 + object btExcluir: TButton + Left = 0 + Top = 0 + Width = 70 + Height = 25 + Caption = 'Excluir' + TabOrder = 0 + OnClick = btExcluirClick + end + object btEscolher: TButton + Left = 70 + Top = 0 + Width = 70 + Height = 25 + Caption = 'Escolher' + Default = True + TabOrder = 1 + OnClick = btEscolherClick + end + end +end diff --git a/UnitFormGrid.pas b/UnitFormGrid.pas new file mode 100644 index 0000000..6b66ef3 --- /dev/null +++ b/UnitFormGrid.pas @@ -0,0 +1,112 @@ +unit UnitFormGrid; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, UnitLista, UnitFormEstado, UnitFormPais, + Vcl.ToolWin, Vcl.ComCtrls, Vcl.StdCtrls, UnitDados; + +type + TFormGrid = class(TForm) + StringGrid1: TStringGrid; + ToolBar1: TToolBar; + btExcluir: TButton; + btEscolher: TButton; + procedure geraGrid(wLista: TLista; wClass: TClass); + procedure FormClose(Sender: TObject; var Action: TCloseAction); + procedure btExcluirClick(Sender: TObject); + procedure btEscolherClick(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + FormGrid: TFormGrid; + FClass: TClass; + FLista: TLista; + +implementation +{$R *.dfm} +uses UnitFormCidade; +procedure TFormGrid.btEscolherClick(Sender: TObject); +var + wObj: TObject; + FormCidade: TFormCidade; +begin +try + if FClass = TCidade then + Dado1.Dado := StringGrid1.Row; + if FClass = TEstado then + Dado2.Dado := StringGrid1.Row; + if FClass = TPais then + Dado3.Dado := StringGrid1.Row; + finally + Self.Free; + end; +end; + +procedure TFormGrid.btExcluirClick(Sender: TObject); +var + Index: integer; + wObj: TObject; +begin + Index := StringGrid1.Row; + wObj := FClass.Create; + try + wObj := FLista.getObjectByIndex(Index); + FLista.Excluir(Index); + finally + Self.Free; + end; + +end; + +procedure TFormGrid.FormClose(Sender: TObject; var Action: TCloseAction); +begin + Action := caFree; +end; + +procedure TFormGrid.geraGrid(wLista: TLista; wClass: TClass); +var + wCont: integer; + wObj: TObject; +begin + FClass := wClass; + FLista := wLista; + wObj := FClass.Create; + StringGrid1.RowCount := FLista.Count; + for wCont := 0 to FLista.Count-1 do + begin + wObj := FLista.getObjectByIndex(wCont); + // fazer uma condição para cada tipo de Classe existente + if wObj.ClassType = TCidade then + with wObj as TCidade do + begin + StringGrid1.Cells[0, wCont] := inttostr(wCod); + StringGrid1.Cells[1, wCont] := wCidade; + StringGrid1.Cells[2, wCont] := wPais; + StringGrid1.Cells[3, wCont] := wUF; + end; + if wObj.ClassType = TEstado then + with wObj as TEstado do + begin + StringGrid1.Cells[0, wCont] := inttostr(wCod); + StringGrid1.Cells[1, wCont] := wEstado; + StringGrid1.Cells[2, wCont] := wPais; + StringGrid1.Cells[3, wCont] := inttostr(wAliquota); + end; + if wObj.ClassType = TPais then + with wObj as TPais do + begin + StringGrid1.Cells[0, wCont] := inttostr(wCod); + StringGrid1.Cells[1, wCont] := wPais; + StringGrid1.Cells[2, wCont] := wNacionalidade; + StringGrid1.Cells[3, wCont] := inttostr(wCodFed); + end; + end; +end; + +end. diff --git a/UnitFormPadrao.dfm b/UnitFormPadrao.dfm new file mode 100644 index 0000000..c95e1e4 --- /dev/null +++ b/UnitFormPadrao.dfm @@ -0,0 +1,148 @@ +object FormPadrao: TFormPadrao + Left = 0 + Top = 0 + Caption = 'FormPadrao' + ClientHeight = 332 + ClientWidth = 598 + Color = clBtnFace + Font.Charset = ANSI_CHARSET + Font.Color = clWindowText + Font.Height = -13 + Font.Name = 'Times New Roman' + Font.Style = [] + FormStyle = fsMDIChild + OldCreateOrder = False + Visible = True + OnActivate = FormActivate + OnClose = FormClose + PixelsPerInch = 96 + TextHeight = 15 + object ToolBar1: TToolBar + Left = 0 + Top = 0 + Width = 598 + Height = 29 + Caption = 'ToolBar1' + TabOrder = 0 + ExplicitWidth = 600 + object btAnterior: TButton + Left = 0 + Top = 0 + Width = 75 + Height = 22 + Caption = '<' + TabOrder = 0 + end + object btProximo: TButton + Left = 75 + Top = 0 + Width = 75 + Height = 22 + Caption = '>' + TabOrder = 1 + end + object btBuscar: TButton + Left = 150 + Top = 0 + Width = 75 + Height = 22 + Caption = 'Buscar' + TabOrder = 2 + end + object btInserir: TButton + Left = 225 + Top = 0 + Width = 75 + Height = 22 + Caption = 'Inserir' + Default = True + TabOrder = 3 + end + object btExcluir: TButton + Left = 300 + Top = 0 + Width = 75 + Height = 22 + Caption = 'Excluir' + TabOrder = 4 + end + object btImportar: TButton + Left = 375 + Top = 0 + Width = 75 + Height = 22 + Caption = 'Importar' + TabOrder = 5 + end + object btExportar: TButton + Left = 450 + Top = 0 + Width = 75 + Height = 22 + Caption = 'Exportar' + TabOrder = 6 + end + object btContar: TButton + Left = 525 + Top = 0 + Width = 75 + Height = 22 + Caption = 'Contar' + TabOrder = 7 + end + end + object Panel1: TPanel + Left = 0 + Top = 29 + Width = 598 + Height = 284 + Align = alClient + TabOrder = 1 + ExplicitWidth = 600 + ExplicitHeight = 263 + DesignSize = ( + 598 + 284) + object cbLimparCampos: TCheckBox + Left = 394 + Top = 227 + Width = 56 + Height = 17 + Caption = 'Limpar' + TabOrder = 0 + end + object Panel2: TPanel + Left = 98 + Top = 16 + Width = 400 + Height = 250 + Anchors = [] + TabOrder = 1 + ExplicitLeft = 99 + ExplicitTop = 6 + end + end + object StatusBar1: TStatusBar + Left = 0 + Top = 313 + Width = 598 + Height = 19 + Panels = < + item + BiDiMode = bdLeftToRight + ParentBiDiMode = False + Text = 'Aguardando' + Width = 50 + end> + ExplicitTop = 292 + ExplicitWidth = 600 + end + object SaveTextFileDialog1: TSaveTextFileDialog + Left = 552 + Top = 40 + end + object OpenTextFileDialog1: TOpenTextFileDialog + Left = 552 + Top = 77 + end +end diff --git a/UnitFormPadrao.pas b/UnitFormPadrao.pas new file mode 100644 index 0000000..0d716a3 --- /dev/null +++ b/UnitFormPadrao.pas @@ -0,0 +1,87 @@ +unit UnitFormPadrao; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ToolWin, Vcl.ComCtrls, UnitLista, + Vcl.ExtDlgs, Vcl.ExtCtrls; + +type + TFormPadrao = class(TForm) + ToolBar1: TToolBar; + btAnterior: TButton; + btProximo: TButton; + btBuscar: TButton; + btInserir: TButton; + btExcluir: TButton; + btImportar: TButton; + btExportar: TButton; + btContar: TButton; + SaveTextFileDialog1: TSaveTextFileDialog; + Panel1: TPanel; + OpenTextFileDialog1: TOpenTextFileDialog; + StatusBar1: TStatusBar; + cbLimparCampos: TCheckBox; + Panel2: TPanel; + procedure FormClose(Sender: TObject; var Action: TCloseAction); + procedure onKeyPress(Sender: TObject; var Key: Char); + procedure FormActivate(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + FormPadrao: TFormPadrao; + +implementation +{$R *.dfm} + +uses UnitFormCidade; + +procedure TFormPadrao.FormActivate(Sender: TObject); +var + wCont: integer; +begin + for wCont := 0 to ComponentCount-1 do + if (Components[wCont] is TEdit) and (Components[wCont].Tag = 0) then + with Components[wCont] as TEdit do + setFocus; +end; + +procedure TFormPadrao.FormClose(Sender: TObject; var Action: TCloseAction); +begin + Action := caFree; +end; + +procedure TFormPadrao.onKeyPress(Sender: TObject; var Key: Char); +var + wCont: integer; + wCont2: Integer; + maior: boolean; +begin + maior := false; + if ord(key) = VK_RETURN then + begin + for wCont := 0 to ComponentCount-1 do + if (Components[wCont] = Sender) then + for wCont2 := 0 to ComponentCount-1 do + if (Components[wCont2] is TEdit) and (Components[wCont2].Tag = Components[wCont].Tag+1) then + with Components[wCont2] as TEdit do + begin + setFocus; + maior := true; + break; + break; + end; + if maior = false then + for wCont := 0 to ComponentCount-1 do + if (Components[wCont].Tag = 0) and (Components[wCont] is TEdit) then + with Components[wCont] as TEdit do + setFocus; + end; +end; + +end. diff --git a/UnitFormPais.dfm b/UnitFormPais.dfm new file mode 100644 index 0000000..f5d82e4 --- /dev/null +++ b/UnitFormPais.dfm @@ -0,0 +1,138 @@ +inherited FormPais: TFormPais + Top = 17 + Caption = 'Cadastro de pa'#237's:' + ClientHeight = 314 + ClientWidth = 602 + Position = poDesigned + OnCreate = FormCreate + ExplicitWidth = 618 + ExplicitHeight = 353 + PixelsPerInch = 96 + TextHeight = 15 + inherited ToolBar1: TToolBar + Width = 602 + ExplicitWidth = 602 + inherited btAnterior: TButton + OnClick = btAnteriorClick + end + inherited btProximo: TButton + OnClick = btProximoClick + end + inherited btBuscar: TButton + OnClick = btBuscarClick + end + inherited btInserir: TButton + Default = False + OnClick = btInserirClick + end + inherited btExcluir: TButton + OnClick = btExcluirClick + end + inherited btImportar: TButton + OnClick = btImportarClick + end + inherited btExportar: TButton + OnClick = btExportarClick + end + end + inherited Panel1: TPanel + Width = 602 + Height = 266 + ExplicitWidth = 602 + ExplicitHeight = 266 + DesignSize = ( + 602 + 266) + inherited cbLimparCampos: TCheckBox + TabOrder = 1 + end + inherited Panel2: TPanel + Top = 6 + TabOrder = 0 + ExplicitLeft = 98 + object Label1: TLabel + Left = 49 + Top = 74 + Width = 42 + Height = 15 + Anchors = [] + Caption = 'C'#243'digo:' + end + object Label2: TLabel + Left = 66 + Top = 117 + Width = 25 + Height = 15 + Anchors = [] + Caption = 'Pa'#237's:' + end + object Label3: TLabel + Left = 12 + Top = 165 + Width = 79 + Height = 15 + Anchors = [] + Caption = 'Nacionalidade:' + end + object Label4: TLabel + Left = 268 + Top = 163 + Width = 51 + Height = 15 + Anchors = [] + Caption = 'C'#243'd.Fed.:' + end + object edCod: TEdit + Left = 110 + Top = 71 + Width = 75 + Height = 23 + Anchors = [] + TabOrder = 0 + OnExit = edCodExit + OnKeyPress = onKeyPress + end + object edCodFed: TEdit + Tag = 3 + Left = 325 + Top = 160 + Width = 75 + Height = 23 + Anchors = [] + TabOrder = 1 + OnKeyPress = edFinalKeyPress + end + object edNacionalidade: TEdit + Tag = 2 + Left = 110 + Top = 162 + Width = 150 + Height = 23 + Anchors = [] + TabOrder = 2 + OnKeyPress = onKeyPress + end + object edPais: TEdit + Tag = 1 + Left = 110 + Top = 114 + Width = 150 + Height = 23 + Anchors = [] + TabOrder = 3 + OnKeyPress = onKeyPress + end + end + end + inherited StatusBar1: TStatusBar + Top = 295 + Width = 602 + Panels = < + item + Text = 'Aguardando' + Width = 50 + end> + ExplicitTop = 295 + ExplicitWidth = 602 + end +end diff --git a/UnitFormPais.pas b/UnitFormPais.pas new file mode 100644 index 0000000..8c664df --- /dev/null +++ b/UnitFormPais.pas @@ -0,0 +1,408 @@ +unit UnitFormPais; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UnitFormPadrao, Vcl.StdCtrls, UnitDados, + Vcl.ToolWin, Vcl.ComCtrls, UnitLista, System.Contnrs, Vcl.ExtDlgs, + Vcl.ExtCtrls; + +type + TFormPais = class(TFormPadrao) + edCod: TEdit; + edPais: TEdit; + edNacionalidade: TEdit; + edCodFed: TEdit; + Label1: TLabel; + Label2: TLabel; + Label3: TLabel; + Label4: TLabel; + procedure FormCreate(Sender: TObject); + procedure btInserirClick(Sender: TObject); + procedure btContarClick(Sender: TObject); + procedure btExcluirClick(Sender: TObject); + procedure btAnteriorClick(Sender: TObject); + procedure btProximoClick(Sender: TObject); + procedure btBuscarClick(Sender: TObject); + procedure FormActivate(Sender: TObject); + procedure btExportarClick(Sender: TObject); + procedure btImportarClick(Sender: TObject); + procedure edCodExit(Sender: TObject); + procedure edFinalKeyPress(Sender: TObject; var Key: Char); + procedure limpaCampos(); + procedure cbLimparCamposClick(Sender: TObject); + private + { Private declarations } + strict private wLista: TLista; + wClear: boolean; + public + { Public declarations } + end; + + TPais = class + private + wpCod: integer; + wpPais: string; + wpNacionalidade: string; + wpCodFed: integer; + public + property wCod: integer read wpCod write wpCod; + property wPais: string read wpPais write wpPais; + property wNacionalidade: string read wpNacionalidade write wpNacionalidade; + property wCodFed: integer read wpCodFed write wpCodFed; + end; + +var + FormPais: TFormPais; + wPais: TPais; + Dado3: TDados; + +implementation +{$R *.dfm} +uses UnitFormGrid; + +procedure TFormPais.limpaCampos(); +begin + if wClear then + begin + edCod.Clear; + edPais.Clear; + edNacionalidade.Clear; + edCodFed.Clear; + end; + +end; + +procedure TFormPais.edFinalKeyPress(Sender: TObject; var Key: Char); +var + wObj: TPais; + wObjGet: TObject; + wcont: Integer; + wIndex: integer; + wMaior: integer; + wNew: boolean; + wZero: boolean; +begin + inherited; + if (ord(key) = 13) or (ord(key) = 9) then + begin + wNew := true; + if (trystrtoint(edCod.Text, windex)) then + begin + wObj := TPais.Create; + with wObj do + begin + wCod := strtoint(edCod.Text); + wPais := edPais.Text; + wNacionalidade := edNacionalidade.Text; + wCodFed := strtoint(edCodFed.Text); + end; + for wCont := 0 to wLista.Count-1 do + begin + wObjGet := wLista.getObjectByIndex(wCont); + with wObjGet as TPais do + if wCod = strtoint(edCod.Text) then + begin + wLista.Update(wCont, wObj); + wNew := false; + if wClear then + limpaCampos(); + break; + end; + end; + if wNew = true then + begin + wLista.Inserir(wObj, TPais); + if wClear then + limpaCampos(); + end; + + end + else + if edCod.Text = '' then + begin + wZero := true; + for wCont := 0 to wLista.Count-1 do + begin + wObjGet := wLista.getObjectByIndex(wCont); + with wobjGet as TPais do + begin + if wCod > wMaior then + wMaior := wCod; + wZero := false; + end; + + end; + wObj := TPais.Create; + with wObj do + begin + if wZero then + wCod := 0 + else + wCod := wMaior+1; + wPais := edPais.Text; + wNacionalidade := edNacionalidade.Text; + wCodFed := strtoint(edCodFed.Text); + end; + wLista.Inserir(wObj, TPais); + if wClear then + limpaCampos(); + end; + // volta pro edit do inicio e altera status bar + for wCont := 0 to ComponentCount-1 do + if (Components[wCont].Tag = 0) and (Components[wCont] is TEdit) then + with Components[wCont] as TEdit do + begin + setFocus; + StatusBar1.Panels[0].Text := 'Aguardando'; + end; + end; +end; + +procedure TFormPais.edCodExit(Sender: TObject); +var + wObj: TObject; + wCont: Integer; + wIndex: integer; + wNew: boolean; +begin + inherited; + if (trystrtoint(edCod.Text, wIndex)) then + begin + wNew := true; + for wCont := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(wCont); + with wObj as TPais do + if wCod = strtoint(edCod.Text) then + begin + StatusBar1.Panels[0].Text := 'Alterando registro'; + edCod.Text := inttostr(wCod); + edPais.Text := wPais; + edNacionalidade.Text := wNacionalidade; + edCodFed.Text := inttostr(wCodFed); + wNew := false; + exit; + end; + end; + if wNew then + StatusBar1.Panels[0].Text := 'Novo registro'; + end + else + if edCod.Text = '' then + StatusBar1.Panels[0].Text := 'Novo registro' + else + StatusBar1.Panels[0].Text := 'Aguardando'; +end; + +procedure TFormPais.btAnteriorClick(Sender: TObject); +var + wObj: TObject; + wObj2: TObject; + wIndex: integer; + I: Integer; +begin + inherited; + if (trystrtoint(edCod.Text, wIndex)) then + begin + for I := 1 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TPais do + begin + if wCod = strtoint(edCod.Text) then + wIndex := wLista.getIndexOfObj(wObj); + end; + end; + if wIndex-1 >= 0 then + begin + wObj := wLista.getObjectByIndex(wIndex-1); + with wObj as TPais do + begin + edCod.Text := inttostr(wCod); + edPais.Text := wPais; + edNacionalidade.Text := wNacionalidade; + edCodFed.Text := inttostr(wCodFed); + end; + end; + end; +end; + +procedure TFormPais.btBuscarClick(Sender: TObject); +var + FormGrid: TFormGrid; +begin + inherited; + FormGrid := TFormGrid.Create(nil); + FormGrid.geraGrid(wLista, TPais); + FormGrid.Show; +end; + +procedure TFormPais.btContarClick(Sender: TObject); +begin + inherited; + ShowMessage(inttostr(wLista.Count)); +end; + +procedure TFormPais.btExcluirClick(Sender: TObject); +var + wObj: TObject; + I: integer; +begin + inherited; + try + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TPais do + if wCod = strtoint(edCod.Text) then + begin + wLista.Excluir(I); + break; + end; + end; + finally + edCod.Clear; + edPais.Clear; + edNacionalidade.Clear; + edCodFed.Clear; + end; +end; + +procedure TFormPais.btExportarClick(Sender: TObject); +var + DadoArmazenado: TDadoArmazenado; + wDir: string; +begin + inherited; + DadoArmazenado := TDadoArmazenado.Create; + if SaveTextFileDialog1.Execute then + wDir := SaveTextFileDialog1.FileName; + DadoArmazenado.saveToFile(wDir, wLista, TPais); +end; + +procedure TFormPais.btImportarClick(Sender: TObject); +var + DadoArmazenado: TDadoArmazenado; + wDir: string; + begin + inherited; + DadoArmazenado := TDadoArmazenado.Create; + if OpenTextFileDialog1.Execute then + wDir := OpenTextFileDialog1.FileName; + wLista := DadoArmazenado.loadFromFile(wDir, TPais); +end; + +procedure TFormPais.btInserirClick(Sender: TObject); +var + Pais: TPais; + wObj: TObject; + wIndex: integer; + I: integer; + wAux: integer; +begin + inherited; + Pais := TPais.Create; + if (trystrtoint(edCod.Text, wIndex)) then + begin + with Pais do + begin + wCod := strtoint(edCod.Text);wPais := edPais.Text;wNacionalidade := edNacionalidade.Text;wCodFed := strtoint(edCodFed.Text); + end; + if wLista.Count >= 1 then + begin + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TPais do + begin + if wCod = strtoint(edCod.Text) then + begin + wAux := 1; + wLista.Update(I, Pais); + break; + end + else + wAux := 0; + end; + end; + if wAux =0 then + wLista.Inserir(Pais, TPais) + end + else + wLista.Inserir(Pais, TPais); + end; +end; + +procedure TFormPais.btProximoClick(Sender: TObject); +var + wObj: TObject; + wIndex: integer; + I: integer; +begin + inherited; + if (trystrtoint(edCod.Text, wIndex)) then + begin + for I := 0 to wLista.Count-1 do + begin + wObj := wLista.getObjectByIndex(I); + with wObj as TPais do + begin + if wCod = strtoint(edCod.Text) then + wIndex := wLista.getIndexOfObj(wObj); + end; + end; + if wIndex+1 < wLista.Count then + begin + wObj := wLista.getObjectByIndex(wIndex+1); + with wObj as TPais do + begin + edCod.Text := inttostr(wCod); + edPais.Text := wPais; + edNacionalidade.Text := wNacionalidade; + edCodFed.Text := inttostr(wCodFed); + end; + end; + end; +end; + +procedure TFormPais.cbLimparCamposClick(Sender: TObject); +begin + inherited; + if wClear then + wClear := false + else + wClear := true +end; + +procedure TFormPais.FormActivate(Sender: TObject); +var + wObj: TObject; +begin + inherited; + if Dado3.Dado > -1 then + begin + wObj := TPais.Create; + wObj := wLista.getObjectByIndex(Dado3.Dado); + with wObj as TPais do + begin + edCod.Text := inttostr(wCod); + edPais.Text := wPais; + edNacionalidade.Text := wNacionalidade; + edCodFed.Text := inttostr(wCodFed); + end; + end; +end; + +procedure TFormPais.FormCreate(Sender: TObject); +begin + inherited; + wLista := TLista.Create; + Dado3 := TDados.Create; + wClear := false; +end; + +initialization +registerclass(TFormPais); +end. diff --git a/UnitFormSplash.dfm b/UnitFormSplash.dfm new file mode 100644 index 0000000..77bc7c9 --- /dev/null +++ b/UnitFormSplash.dfm @@ -0,0 +1,38 @@ +object FormSplash: TFormSplash + Left = 0 + Top = 0 + Caption = 'FormSplash' + ClientHeight = 231 + ClientWidth = 505 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + FormStyle = fsMDIForm + Menu = MainMenu1 + OldCreateOrder = False + WindowState = wsMaximized + PixelsPerInch = 96 + TextHeight = 13 + object MainMenu1: TMainMenu + Left = 456 + Top = 184 + object Cadastrar1: TMenuItem + Caption = 'Cadastrar' + object TFormCidade: TMenuItem + Caption = 'Cidade' + OnClick = mmClick + end + object TFormEstado: TMenuItem + Caption = 'Estado' + OnClick = mmClick + end + object TFormPais: TMenuItem + Caption = 'Pa'#237's' + OnClick = mmClick + end + end + end +end diff --git a/UnitFormSplash.pas b/UnitFormSplash.pas new file mode 100644 index 0000000..4c7008c --- /dev/null +++ b/UnitFormSplash.pas @@ -0,0 +1,43 @@ +unit UnitFormSplash; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, UnitFormPadrao, UnitFormCidade; + +type + TFormSplash = class(TForm) + MainMenu1: TMainMenu; + Cadastrar1: TMenuItem; + TFormCidade: TMenuItem; + TFormEstado: TMenuItem; + TFormPais: TMenuItem; + procedure mmClick(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + FormSplash: TFormSplash; + +implementation + +{$R *.dfm} + +procedure TFormSplash.mmClick(Sender: TObject); +var + wNome: string; + wForm: TFormClass; + wF: TForm; +begin + with Sender as TMenuItem do + wNome := name; + wForm := TFormClass(FindClass(wNome)); + wF := wForm.Create(FormSplash); + wF.Show; +end; + +end. diff --git a/UnitLista.pas b/UnitLista.pas new file mode 100644 index 0000000..0de394e --- /dev/null +++ b/UnitLista.pas @@ -0,0 +1,90 @@ +unit UnitLista; + +interface + +uses Dialogs, Classes, Contnrs, System.Generics.Collections, SysUtils; + +type +TLista = class +private + strict private FListaClass: TClass; + strict private FLista: TObjectList; +public + constructor Create; + procedure Inserir(wObj: TObject; wClass: TClass); + procedure Update(Index: integer; wObj: TObject); + procedure Excluir(Index: integer); + procedure InserirPorIndex(Index: integer; wObj: TObject; wClass: TClass); + function Count: integer; + function getObjectByIndex(Index: integer): TObject; + function getObjectList: TObjectList; + function getIndexOfObj(wObj: TObject): integer; +end; + +implementation + constructor TLista.Create; + begin + FLista := TObjectList.Create; + end; + + function TLista.getObjectByIndex(Index: Integer): TObject; // retorna um objeto de acordo com o index passado por parametro + var + wObj: TObject; + begin + wObj := FListaClass.Create; + if Index < FLista.Count then + {if Index <> 0 then} + wObj := FLista.Items[Index]; + Result := wObj; + end; + + function TLista.Count: integer; + begin + Result := FLista.Count; + end; + + function TLista.getObjectList: TObjectList; + begin + Result := FLista; + end; + + function TLista.getIndexOfObj(wObj: TObject): integer; + begin + Result := FLista.IndexOf(wObj); + end; + + procedure TLista.Update(Index: integer; wObj: TObject); + begin + if FLista.Count > 0 then + FLista.Delete(Index); + FLista.Insert(Index, wObj); + end; + + procedure TLista.Inserir(wObj: TObject; wClass: TClass); + begin + FListaClass := wClass; // guarda o nome da classe pra poder instanciá-la em outras procedures + FLista.Add(wObj); + end; + + procedure TLista.InserirPorIndex(Index: integer; wObj: TObject; wClass: TClass); + begin + FListaClass := wClass; + FLista.Insert(Index, wObj); + end; + + procedure TLista.Excluir(Index: Integer); + var + wObj: TObject; + begin + wObj := FListaClass.Create; + + if FLista.Count > Index then + begin + FLista.Delete(Index); + ShowMessage('sucesso!'); + end + else + ShowMessage('Objeto não encontrado na lista!'); + end; + +end. diff --git a/UnitSharedVariables.pas b/UnitSharedVariables.pas new file mode 100644 index 0000000..746545f --- /dev/null +++ b/UnitSharedVariables.pas @@ -0,0 +1,14 @@ +unit UnitSharedVariables; + +interface + +type + TSharedVariables = class(TObject) + private + public + SetarDados: integer; + end; + +implementation + +end. diff --git a/Win32/Debug/Project1.exe b/Win32/Debug/Project1.exe index c003c60..cd5d32b 100644 Binary files a/Win32/Debug/Project1.exe and b/Win32/Debug/Project1.exe differ diff --git a/Win32/Debug/UnitFormCidade.dcu b/Win32/Debug/UnitFormCidade.dcu index 1105373..97b5905 100644 Binary files a/Win32/Debug/UnitFormCidade.dcu and b/Win32/Debug/UnitFormCidade.dcu differ diff --git a/Win32/Debug/UnitFormEstado.dcu b/Win32/Debug/UnitFormEstado.dcu index ed0e726..a107a93 100644 Binary files a/Win32/Debug/UnitFormEstado.dcu and b/Win32/Debug/UnitFormEstado.dcu differ diff --git a/Win32/Debug/UnitFormGrid.dcu b/Win32/Debug/UnitFormGrid.dcu index b05a413..d415206 100644 Binary files a/Win32/Debug/UnitFormGrid.dcu and b/Win32/Debug/UnitFormGrid.dcu differ diff --git a/Win32/Debug/UnitFormPadrao.dcu b/Win32/Debug/UnitFormPadrao.dcu index e4dd820..470832d 100644 Binary files a/Win32/Debug/UnitFormPadrao.dcu and b/Win32/Debug/UnitFormPadrao.dcu differ diff --git a/Win32/Debug/UnitFormPais.dcu b/Win32/Debug/UnitFormPais.dcu index 26936c7..884beb0 100644 Binary files a/Win32/Debug/UnitFormPais.dcu and b/Win32/Debug/UnitFormPais.dcu differ