unit ufrmEmpresas; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Data.DB, System.UITypes, Vcl.Grids, Vcl.DBGrids, Vcl.ComCtrls, Vcl.DBCtrls, Math, Vcl.Buttons, Vcl.ExtDlgs, Jpeg, Vcl.Mask, StrUtils, Types; type TfrmEmpresas = class(TForm) pnl_top: TPanel; pg_empresas: TPageControl; tab_dados: TTabSheet; tab_tblcalculos: TTabSheet; dbgrid_nomes: TDBGrid; grd_principal: TGridPanel; lbl_razao: TLabel; lbl_cnpj: TLabel; lbl_fantasia: TLabel; lbl_cidade: TLabel; lbl_bairro: TLabel; lbl_uf: TLabel; lbl_tel: TLabel; lbl_email: TLabel; lbl_end: TLabel; lbl_num: TLabel; lbl_compl: TLabel; lbl_cep: TLabel; lbl_inscriest: TLabel; lbl_inscrimuni: TLabel; lbl_website: TLabel; lbl_obs: TLabel; btn_clearmemo: TButton; grpb_logo: TGroupBox; pnl_img: TPanel; spdbtn_loadimg: TSpeedButton; spdbtn_clearimg: TSpeedButton; OpenPictureDialog1: TOpenPictureDialog; btn_criarcad: TButton; btn_removcad: TButton; dbmemo_obs: TDBMemo; dblucmbox_uf: TDBLookupComboBox; dblucmbox_cidade: TDBLookupComboBox; btn_altcad: TButton; dbedt_razao: TDBEdit; dbedt_fantasia: TDBEdit; dbedt_cnpj: TDBEdit; dbedt_inscriest: TDBEdit; dbedt_inscrimuni: TDBEdit; dbedt_bairro: TDBEdit; dbedt_cep: TDBEdit; dbedt_end: TDBEdit; dbedt_num: TDBEdit; dbedt_compl: TDBEdit; dbedt_tel: TDBEdit; dbedt_email: TDBEdit; dbedt_website: TDBEdit; img_logo: TImage; dblbl_nmfantasia: TDBText; dblbl_razaosocial: TDBText; grd_honorarios: TStringGrid; lbl_honorarios: TLabel; procedure Button1Click(Sender: TObject); procedure FormResize(Sender: TObject); procedure btn_clearmemoClick(Sender: TObject); procedure spdbtn_loadimgClick(Sender: TObject); procedure spdbtn_clearimgClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure dbgrid_nomesCellClick(Column: TColumn); procedure dbgrid_nomesKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); procedure btn_criarcadClick(Sender: TObject); procedure btn_removcadClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure btn_altcadClick(Sender: TObject); private { Private declarations } public img_path: string; mudou_img: boolean; { Public declarations } end; var frmEmpresas: TfrmEmpresas; implementation {$R *.dfm} uses udtmSystem; procedure TfrmEmpresas.btn_altcadClick(Sender: TObject); var selected, i: integer; honorarios: string; begin selected := MessageDlg ('Você está prestes a alterar o cadastro de uma Empresa.' + ' Tem certeza que deseja realizar tal ação?', mtConfirmation, [mbYes, mbNo], 0); if selected = mrYes then begin with udtmSystem.dtmSystem do begin tblEmpresa.Edit; tblEmpresaTX_NOME.AsString := dbedt_razao.Text; tblEmpresaTX_FANTASIA.AsString := dbedt_fantasia.Text; tblEmpresaTX_CNPJ.AsString := dbedt_cnpj.Text; tblEmpresaTX_IE.AsString := dbedt_inscriest.Text; tblEmpresaTX_IM.AsString := dbedt_inscrimuni.Text; tblEmpresaID_CIDADE.AsString := inttostr(dblucmbox_cidade.KeyValue); tblEmpresaID_ESTADO.AsString := inttostr(dblucmbox_uf.KeyValue); tblEmpresaTX_BAIRRO.AsString := dbedt_bairro.Text; tblEmpresaTX_CEP.AsString := dbedt_cep.Text; tblEmpresaTX_ENDERECO.AsString := dbedt_end.Text; tblEmpresaNR_NUMERO.AsString := dbedt_num.Text; tblEmpresaTX_COMPLEMENTO.AsString := dbedt_compl.Text; tblEmpresaTX_TELEFONE.AsString := dbedt_tel.Text; tblEmpresaTX_EMAIL.AsString := dbedt_email.Text; tblEmpresaTX_WEBSITE.AsString := dbedt_website.Text; tblEmpresaTL_OBSERVACOES.AsString := dbmemo_obs.Lines.Text; if (mudou_img) then begin tblEmpresaTX_LOGOMARCA.AsString := img_path; end; honorarios := ''; for i := 1 to grd_honorarios.RowCount - 1 do begin honorarios := honorarios + grd_honorarios.Cells[1, i] + '#'; end; tblEmpresaTX_HONORARIOS.AsString := honorarios; tblEmpresa.Post; end; end; end; procedure TfrmEmpresas.btn_clearmemoClick(Sender: TObject); begin dbmemo_obs.Lines.Clear; end; procedure TfrmEmpresas.btn_criarcadClick(Sender: TObject); var selected: integer; begin selected := MessageDlg ('Você está prestes a adicionar uma nova Empresa ao seu banco de dados.' + ' Tem certeza que deseja realizar tal ação?', mtConfirmation, [mbYes, mbNo], 0); // nome_emp := InputBox('Nova Empresa', 'Digite a razão social ou o nome fantasia da empresa. Ambos poderão ser alterados mais tarde.', ''); if selected = mrYes then begin with udtmSystem.dtmSystem do begin tblEmpresa.Append; end; end; end; procedure TfrmEmpresas.btn_removcadClick(Sender: TObject); begin if MessageDlg ('Deseja realmente apagar este registro? Não será possível recuperar os dados novamente.', mtConfirmation, [mbYes, mbNo], 0) = mrNo then begin abort; end; try begin udtmSystem.dtmSystem.tblEmpresa.Delete; end; finally begin abort; end; end; end; procedure TfrmEmpresas.Button1Click(Sender: TObject); begin Close; end; procedure TfrmEmpresas.dbgrid_nomesCellClick(Column: TColumn); var j: integer; list: Tstringdynarray; begin dblucmbox_uf.KeyValue := udtmSystem.dtmSystem.tblEmpresaID_ESTADO.AsInteger; dblucmbox_cidade.KeyValue := udtmSystem.dtmSystem.tblEmpresaID_CIDADE.AsInteger; if udtmSystem.dtmSystem.tblEmpresaTX_LOGOMARCA.AsString <> '' then begin img_logo.Picture.LoadFromFile (udtmSystem.dtmSystem.tblEmpresaTX_LOGOMARCA.AsString); end else begin img_logo.Picture := nil; end; if (not spdbtn_loadimg.Enabled) or (not spdbtn_clearimg.Enabled) then begin spdbtn_loadimg.Enabled := true; spdbtn_clearimg.Enabled := true; end; mudou_img := false; if udtmSystem.dtmSystem.tblEmpresaTX_HONORARIOS.AsString <> '' then begin list := SplitString(udtmSystem.dtmSystem.tblEmpresaTX_HONORARIOS. AsString, '#'); end else begin for j := 1 to 4 do begin grd_honorarios.Cells[1, j] := '0'; end; end; for j := 1 to length(list) do begin if list[j - 1] <> '' then begin grd_honorarios.Cells[1, j] := list[j - 1]; end; end; end; procedure TfrmEmpresas.dbgrid_nomesKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin dbgrid_nomes.OnCellClick(nil); end; procedure TfrmEmpresas.FormClose(Sender: TObject; var Action: TCloseAction); begin with udtmSystem.dtmSystem do begin tblEmpresa.Close; tblCidades.Close; tblEstados.Close; end; end; procedure TfrmEmpresas.FormCreate(Sender: TObject); var i, j, k: integer; list_open: Tstringdynarray; begin // abre as tabelas pra uso with udtmSystem.dtmSystem do begin tblEmpresa.Open; tblCidades.Open; tblEstados.Open; end; img_logo.Picture.LoadFromFile (udtmSystem.dtmSystem.tblEmpresaTX_LOGOMARCA.AsString); dblucmbox_uf.KeyValue := udtmSystem.dtmSystem.tblEmpresaID_ESTADO.AsInteger; dblucmbox_cidade.KeyValue := udtmSystem.dtmSystem.tblEmpresaID_CIDADE.AsInteger; mudou_img := false; grd_honorarios.Rows[1].Text := 'Juros'; grd_honorarios.Rows[2].Text := 'Multas'; grd_honorarios.Rows[3].Text := 'Encargos'; grd_honorarios.Rows[4].Text := 'Título'; for i := 0 to 4 do begin grd_honorarios.RowHeights[i] := 18; end; grd_honorarios.Height := 98; grd_honorarios.Width := (grd_honorarios.ColWidths[0] * 2) + 5; if udtmSystem.dtmSystem.tblEmpresaTX_HONORARIOS.AsString <> '' then begin list_open := SplitString(udtmSystem.dtmSystem.tblEmpresaTX_HONORARIOS. AsString, '#'); end else begin for k := 1 to 4 do begin grd_honorarios.Cells[1, k] := '0'; end; end; for j := 1 to length(list_open) do begin if list_open[j - 1] <> '' then begin grd_honorarios.Cells[1, j] := list_open[j - 1]; end; end; end; procedure TfrmEmpresas.FormResize(Sender: TObject); var i: integer; begin // setando o tamanho das linhas e colunas do grid grd_principal.RowCollection.BeginUpdate; grd_principal.RowCollection[0].SizeStyle := ssPercent; grd_principal.RowCollection[0].Value := 10; grd_principal.RowCollection[1].SizeStyle := ssPercent; grd_principal.RowCollection[1].Value := 30; grd_principal.RowCollection[2].SizeStyle := ssPercent; grd_principal.RowCollection[2].Value := 30; grd_principal.RowCollection[3].SizeStyle := ssPercent; grd_principal.RowCollection[3].Value := 30; grd_principal.RowCollection.EndUpdate; grd_principal.ColumnCollection.BeginUpdate; grd_principal.ColumnCollection[0].SizeStyle := ssPercent; grd_principal.ColumnCollection[0].Value := 25; grd_principal.ColumnCollection[1].SizeStyle := ssPercent; grd_principal.ColumnCollection[1].Value := 25; grd_principal.ColumnCollection[2].SizeStyle := ssPercent; grd_principal.ColumnCollection[2].Value := 25; grd_principal.ColumnCollection[3].SizeStyle := ssPercent; grd_principal.ColumnCollection[3].Value := 25; grd_principal.ColumnCollection.EndUpdate; // Seta tamanho das logos dblbl_razaosocial.Height := floor(pnl_top.Height / 2); dblbl_razaosocial.Font.Size := floor(dblbl_razaosocial.Height * 0.6); dblbl_nmfantasia.Height := floor(pnl_top.Height / 2); dblbl_nmfantasia.Font.Size := floor(dblbl_nmfantasia.Height * 0.6); // Seta o tamanho das colunas na tabela de seleção for i := 0 to (dbgrid_nomes.Columns.Count - 1) do begin dbgrid_nomes.Columns[i].Width := round(dbgrid_nomes.ClientWidth); end; // Posicionamento dinâmico dos objetos na janela lbl_razao.Left := 3; lbl_razao.Top := 3; dbedt_razao.Left := 3; dbedt_razao.Top := 18; dbedt_razao.Width := round(tab_dados.ClientWidth * 0.45); lbl_fantasia.Top := 3; lbl_fantasia.Left := dbedt_razao.Left + dbedt_razao.Width + round(tab_dados.ClientWidth * 0.02); dbedt_fantasia.Top := 18; dbedt_fantasia.Left := dbedt_razao.Left + dbedt_razao.Width + round(tab_dados.ClientWidth * 0.02); dbedt_fantasia.Width := round(tab_dados.ClientWidth * 0.45); lbl_cnpj.Top := 45; lbl_cnpj.Left := 3; dbedt_cnpj.Top := 60; dbedt_cnpj.Left := 3; lbl_cidade.Top := 87; lbl_cidade.Left := 3; dblucmbox_cidade.Top := 102; dblucmbox_cidade.Left := 3; dblucmbox_cidade.Width := round(tab_dados.ClientWidth * 0.2); lbl_inscriest.Top := 45; lbl_inscriest.Left := dblucmbox_cidade.Left + dblucmbox_cidade.Width + round(tab_dados.ClientWidth * 0.06); dbedt_inscriest.Top := 60; dbedt_inscriest.Left := dblucmbox_cidade.Left + dblucmbox_cidade.Width + round(tab_dados.ClientWidth * 0.06); lbl_inscrimuni.Top := 45; lbl_inscrimuni.Left := dbedt_razao.Left + dbedt_razao.Width - dbedt_inscrimuni.Width; dbedt_inscrimuni.Top := 60; dbedt_inscrimuni.Left := dbedt_razao.Left + dbedt_razao.Width - dbedt_inscrimuni.Width; lbl_bairro.Top := 84; lbl_bairro.Left := dblucmbox_cidade.Left + dblucmbox_cidade.Width + round(tab_dados.ClientWidth * 0.02); dbedt_bairro.Top := 102; dbedt_bairro.Left := dblucmbox_cidade.Left + dblucmbox_cidade.Width + round(tab_dados.ClientWidth * 0.02); dbedt_bairro.Width := round(tab_dados.ClientWidth * 0.23); lbl_uf.Top := 87; lbl_uf.Left := dbedt_razao.Left + dbedt_razao.Width + round(tab_dados.ClientWidth * 0.02); dblucmbox_uf.Top := 102; dblucmbox_uf.Left := dbedt_razao.Left + dbedt_razao.Width + round(tab_dados.ClientWidth * 0.02); lbl_cep.Top := 87; lbl_cep.Left := lbl_uf.Left + dblucmbox_uf.Width + round(tab_dados.ClientWidth * 0.03); dbedt_cep.Top := 102; dbedt_cep.Left := lbl_uf.Left + dblucmbox_uf.Width + round(tab_dados.ClientWidth * 0.03); lbl_honorarios.Top := 87; lbl_honorarios.Left := dbedt_cep.Left + dbedt_cep.Width + round(tab_dados.ClientWidth * 0.03); grd_honorarios.Top := 102; grd_honorarios.Left := lbl_honorarios.Left; lbl_end.Top := 129; lbl_end.Left := 3; dbedt_end.Top := 144; dbedt_end.Left := 3; dbedt_end.Width := round(tab_dados.ClientWidth * 0.45); lbl_num.Top := 129; lbl_num.Left := dbedt_razao.Left + dbedt_razao.Width + round(tab_dados.ClientWidth * 0.02); dbedt_num.Top := 144; dbedt_num.Left := dbedt_razao.Left + dbedt_razao.Width + round(tab_dados.ClientWidth * 0.02); lbl_compl.Top := 129; lbl_compl.Left := lbl_uf.Left + dblucmbox_uf.Width + round(tab_dados.ClientWidth * 0.03); dbedt_compl.Top := 144; dbedt_compl.Left := lbl_uf.Left + dblucmbox_uf.Width + round(tab_dados.ClientWidth * 0.03); lbl_tel.Top := 171; lbl_tel.Left := 3; dbedt_tel.Top := 186; dbedt_tel.Left := 3; // dbedt_tel.Width := round(tab_dados.ClientWidth*0.2); dbedt_email.Top := 186; dbedt_email.Width := round(tab_dados.ClientWidth * 0.23); dbedt_email.Left := dbedt_end.Left + dbedt_end.Width - dbedt_email.Width; lbl_email.Top := 171; lbl_email.Left := dbedt_email.Left; lbl_website.Top := 213; lbl_website.Left := 3; dbedt_website.Top := 228; dbedt_website.Left := 3; dbedt_website.Width := round(tab_dados.ClientWidth * 0.45); dbmemo_obs.Height := round(tab_dados.ClientHeight * 0.5); dbmemo_obs.Top := tab_dados.ClientHeight - dbmemo_obs.Height; dbmemo_obs.Width := round(tab_dados.ClientWidth * 0.45); btn_clearmemo.Left := dbmemo_obs.Left + dbmemo_obs.Width - btn_clearmemo.Width; btn_clearmemo.Top := dbmemo_obs.Top - btn_clearmemo.Height - 3; lbl_obs.Top := dbmemo_obs.Top - lbl_obs.Height - 3; grpb_logo.Left := tab_dados.ClientWidth - grpb_logo.Width - round(tab_dados.ClientHeight * 0.25); grpb_logo.Top := tab_dados.ClientHeight - grpb_logo.Height - 30; btn_criarcad.Top := dbedt_website.Top - 2; btn_removcad.Top := btn_criarcad.Top; btn_criarcad.Left := dbedt_razao.Left + dbedt_razao.Width + round(tab_dados.ClientWidth * 0.02); btn_removcad.Left := btn_criarcad.Left + btn_criarcad.Width + round(tab_dados.ClientWidth * 0.02); btn_altcad.Top := btn_criarcad.Top; btn_altcad.Left := btn_removcad.Left + btn_removcad.Width + round(tab_dados.ClientWidth * 0.02); end; procedure TfrmEmpresas.spdbtn_clearimgClick(Sender: TObject); begin img_logo.Picture := nil; end; procedure TfrmEmpresas.spdbtn_loadimgClick(Sender: TObject); begin if OpenPictureDialog1.Execute then begin if FileExists(OpenPictureDialog1.FileName) then begin CreateDir(GetCurrentDir + '\LOGOMARCAS'); img_logo.Picture.LoadFromFile(OpenPictureDialog1.FileName); img_path := GetCurrentDir + '\LOGOMARCAS\' + udtmSystem.dtmSystem.tblEmpresaTX_NOME.AsString + ExtractFileExt(OpenPictureDialog1.FileName); img_logo.Picture.SaveToFile(img_path); img_logo.Visible := true; mudou_img := true; end else begin raise Exception.Create('Arquivo não existe.'); end; end; end; end.