You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
192 lines
4.5 KiB
192 lines
4.5 KiB
unit umstCadastro;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
|
Grids, DBGrids, StdCtrls, DBCtrls, ExtCtrls, Buttons, ComCtrls, DB, Menus,
|
|
Vcl.Mask, System.UITypes;
|
|
|
|
type
|
|
TmstCadastro = class(TForm)
|
|
GroupBox2: TGroupBox;
|
|
pcClientes: TPageControl;
|
|
tabCadastro: TTabSheet;
|
|
dtsDB: TDataSource;
|
|
stbStatus: TStatusBar;
|
|
navPrincipal: TDBNavigator;
|
|
grpDescricao: TGroupBox;
|
|
Nome: TLabel;
|
|
DBEdit1: TDBEdit;
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
|
procedure FormCreate(Sender: TObject);
|
|
procedure FormShow(Sender: TObject);
|
|
procedure navPrincipalBeforeAction(Sender: TObject; Button: TNavigateBtn);
|
|
procedure dtsDBStateChange(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
AcaoRealizada: String;
|
|
end;
|
|
|
|
var
|
|
mstCadastro: TmstCadastro;
|
|
|
|
implementation
|
|
|
|
uses udtmSystem;
|
|
|
|
{$R *.DFM}
|
|
|
|
procedure TmstCadastro.FormKeyDown(Sender: TObject; var Key: Word;
|
|
Shift: TShiftState);
|
|
begin
|
|
|
|
if (ActiveControl is TDBGrid) or
|
|
// ((ActiveControl is TDBLookupCombo) and (ActiveControl.Tag = 1)) or
|
|
((ActiveControl is TDBComboBox) and (ActiveControl.Tag = 1)) or
|
|
// ((ActiveControl is TDBDateTimePicker) and (ActiveControl.Tag = 1)) or
|
|
((ActiveControl is TDBEdit) and (ActiveControl.Tag = 1)) or
|
|
(ActiveControl is TDBMemo) or (ActiveControl is TDBRichEdit) // or
|
|
// (ActiveControl is TDBWPRichText)
|
|
or (ActiveControl is TMemo) or (ActiveControl is TDBMemo)
|
|
then
|
|
exit;
|
|
|
|
case Key of
|
|
|
|
VK_RETURN:
|
|
begin
|
|
SelectNext(ActiveControl as tWinControl, True, True);
|
|
Key := 0;
|
|
end;
|
|
{
|
|
VK_UP:
|
|
begin
|
|
SelectNext(ActiveControl as tWinControl, False, True );
|
|
Key := 0;
|
|
end;
|
|
|
|
VK_DOWN:
|
|
begin
|
|
SelectNext(ActiveControl as tWinControl, True, True );
|
|
Key := 0;
|
|
end;
|
|
}
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TmstCadastro.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
|
begin
|
|
|
|
if navPrincipal.DataSource <> nil then
|
|
if navPrincipal.DataSource.State in [dsInsert, dsEdit] then
|
|
begin
|
|
MessageDlg
|
|
('Existem alterações pendentes, clique em CONFIRMAR ou CANCELAR.',
|
|
mtConfirmation, [mbOK], 0);
|
|
CanClose := False;
|
|
end;
|
|
|
|
end;
|
|
|
|
procedure TmstCadastro.dtsDBStateChange(Sender: TObject);
|
|
begin
|
|
|
|
grpDescricao.Enabled := dtsDB.State in [dsEdit, dsInsert];
|
|
tabCadastro.Enabled := grpDescricao.Enabled;
|
|
|
|
end;
|
|
|
|
procedure TmstCadastro.FormClose(Sender: TObject; var Action: TCloseAction);
|
|
begin
|
|
|
|
if dtsDB.DataSet <> nil then
|
|
begin
|
|
|
|
dtsDB.DataSet.Filtered := False;
|
|
|
|
if dtsDB.DataSet.State in [dsInsert, dsEdit] then
|
|
dtsDB.DataSet.Cancel;
|
|
|
|
end;
|
|
|
|
// Envia as alterações para o banco
|
|
|
|
// if dtsDB.DataSet.State in [dsInsert, dsEdit] then
|
|
|
|
// RegistraSaida;
|
|
|
|
// Volta o cursor para o estado normal
|
|
|
|
Screen.Cursor := crDefault;
|
|
|
|
// Libera a memória
|
|
|
|
Action := caFree;
|
|
|
|
end;
|
|
|
|
procedure TmstCadastro.FormCreate(Sender: TObject);
|
|
begin
|
|
|
|
|
|
dtmSystem.tx_formulario := TForm(Sender).Name;
|
|
|
|
|
|
dtsDB.DataSet.Open;
|
|
|
|
pcClientes.ActivePage := tabCadastro;
|
|
|
|
end;
|
|
|
|
procedure TmstCadastro.FormShow(Sender: TObject);
|
|
begin
|
|
|
|
pcClientes.ActivePageIndex := 0
|
|
|
|
end;
|
|
|
|
procedure TmstCadastro.navPrincipalBeforeAction(Sender: TObject;
|
|
Button: TNavigateBtn);
|
|
begin
|
|
|
|
case Button of
|
|
nbFirst, nbPrior, nbNext, nbLast, nbInsert, nbRefresh:
|
|
if navPrincipal.DataSource.State in [dsInsert, dsEdit] then
|
|
begin
|
|
MessageDlg('Existem alterações pendentes, clique em CONFIRMAR ou CANCELAR.', mtConfirmation, [mbOK], 0);
|
|
Abort;
|
|
end;
|
|
|
|
nbPost: SelectNext(ActiveControl as tWinControl, True, True);
|
|
|
|
nbDelete:
|
|
begin
|
|
if navPrincipal.DataSource.State in [dsInsert, dsEdit] then
|
|
begin
|
|
MessageDlg('Existem alterações pendentes, clique em CONFIRMAR ou CANCELAR.', mtConfirmation, [mbOK], 0);
|
|
Abort;
|
|
end;
|
|
|
|
if MessageDlg('Deseja apagar este registro?', mtConfirmation, [mbYes, mbNo], 0) = mrNo then Abort;
|
|
|
|
try
|
|
dtsDB.DataSet.Delete;
|
|
except
|
|
ShowMessage('Este registro está sendo utilizado pelo sistema ou contém dependências e não pode ser apagado');
|
|
end;
|
|
|
|
Abort;
|
|
end;
|
|
|
|
nbCancel: if MessageDlg('Deseja cancelar as modificações?', mtConfirmation, [mbYes, mbNo], 0) = mrNo then Abort;
|
|
end;
|
|
|
|
end;
|
|
|
|
end.
|