Skip to content

Instantly share code, notes, and snippets.

Created August 7, 2013 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6171304 to your computer and use it in GitHub Desktop.
Save anonymous/6171304 to your computer and use it in GitHub Desktop.
Módulo financiado de programa de Gestión desde 0
unit UFInanciado;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, IBDatabase,
NewPanelDB, //Para usar el NEwPanelDB
Lapelpanel, //Para paneles con solapa
MyDbIbMemo, //Para DbiMemo
TDbIbchkbox, //Para campos boolean en Firebird
Mask, DbEditDefault, //PAra usar los DbeditDefault en vez de los Dbedit normal
Dialogs, ComCtrls, ExtCtrls, Grids, DBGrids, StdCtrls, Spin, Buttons, DB, DBCtrls,
IBCustomDataSet, IBQuery, rpcompobase, rpvclreport, DBneweditjl;
type
TFFInanciado = class(TForm)
PanelBotonera: TNewPanelDB;
SBBarraStatus: TStatusBar;
Panel1: TPanel;
Panel2: TPanel;
PanelDatos: TNewPanelDB;
Panel3: TPanel;
DBGNoEnable: TDBGrid;
PanelConfirmar: TNewPanelDB;
DsPrincipal: TDataSource;
SBPrimero: TSpeedButton;
SBMenosx: TSpeedButton;
SBMenos1: TSpeedButton;
SBMas1: TSpeedButton;
SBMasX: TSpeedButton;
SBUltimo: TSpeedButton;
SbNuevo: TSpeedButton;
SbModificar: TSpeedButton;
SbBorrar: TSpeedButton;
SB_Salir: TSpeedButton;
SBBuscar: TSpeedButton;
SBImprimir: TSpeedButton;
SBConfirmar: TSpeedButton;
SBCancelar: TSpeedButton;
Label14: TLabel;
SEMobeByX: TSpinEdit;
GBBuscar: TGroupBox;
Ebusqueda: TEdit;
BLimpiar: TButton;
BBuscar: TButton;
BCerrar: TButton;
Timer1: TTimer;
NewPanelDB1: TNewPanelDB;
DBGrid1: TDBGrid;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
DBText1: TDBText;
DBText2: TDBText;
Label5: TLabel;
Label6: TLabel;
DsDetalle: TDataSource;
DSCLI: TDataSource;
IBQCLI: TIBQuery;
NewPanelDB2: TNewPanelDB;
NewPanelDB4: TNewPanelDB;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
NewPanelDB3: TNewPanelDB;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
NewPanelDB5: TNewPanelDB;
SpeedButton1: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton2: TSpeedButton;
Label11: TLabel;
GBImprimir: TGroupBox;
CBVistaPrevia: TCheckBox;
BCerrarIMP: TButton;
SpeedButton5: TSpeedButton;
DBNEFecha1: TDBNewEditJL;
DBNENumeroFinanciado2: TDBNewEditJL;
DBNEImporte3: TDBNewEditJL;
DBNEIntereses9: TDBNewEditJL;
DBNECodigoCliente4: TDBNewEditJL;
DBNEMininota: TDBNewEditJL;
DBNEDetalleImporte6: TDBNewEditJL;
DBNewEditJL1: TDBNewEditJL;
DBNEDetalleFormaPago: TDBNewEditJL;
DBNEDetalleFecha: TDBNewEditJL;
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure SBPrimeroClick(Sender: TObject);
procedure SBMenosxClick(Sender: TObject);
procedure SBMenos1Click(Sender: TObject);
procedure SBMas1Click(Sender: TObject);
procedure SBMasXClick(Sender: TObject);
procedure SBUltimoClick(Sender: TObject);
procedure SbNuevoClick(Sender: TObject);
procedure SbModificarClick(Sender: TObject);
procedure SbBorrarClick(Sender: TObject);
procedure SBBuscarClick(Sender: TObject);
procedure BLimpiarClick(Sender: TObject);
procedure BBuscarClick(Sender: TObject);
procedure BCerrarClick(Sender: TObject);
procedure EbusquedaChange(Sender: TObject);
procedure SBImprimirClick(Sender: TObject);
procedure BCerrarIMPClick(Sender: TObject);
procedure SB_SalirClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure SBCancelarClick(Sender: TObject);
procedure SBConfirmarClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton8Click(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure SpeedButton15Click(Sender: TObject);
procedure SpeedButton14Click(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure DBGNoEnableDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure SpeedButton5Click(Sender: TObject);
procedure DBNECodigoCliente4Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FFInanciado: TFFInanciado;
implementation
{$R *.dfm}
USes UDM,Fun, FUN_DBGRID, UCalCFinanciado, UMENU;
procedure TFFInanciado.BBuscarClick(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ Buscar ]******
//------------------------------------------------------------------------------
var Campo:string;
begin
Campo:='NUMEROFINANCIADO'; {Dato a rellenar por el progrmador con el nombre del campo en la busqueda}
DSPrincipal.DataSet.Locate(Campo,Ebusqueda.Text,[loCaseInsensitive,loPartialKey]);
end;
procedure TFFInanciado.BCerrarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*****************************************************[ Cerrar Busqueda ]******
//------------------------------------------------------------------------------
begin
BLimpiarClick(Sender);
GBBuscar.Visible:=False;
end;
procedure TFFInanciado.BCerrarIMPClick(Sender: TObject);
//------------------------------------------------------------------------------
//****************************************************[ Cerrar Imrprimir ]******
//------------------------------------------------------------------------------
begin
GBImprimir.Visible:=False;
end;
procedure TFFInanciado.BLimpiarClick(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************[ Limpia la busqueda ]******
//------------------------------------------------------------------------------
begin
Ebusqueda.Text:='';
BBuscarClick(Sender);
Ebusqueda.SetFocus;
end;
procedure TFFInanciado.DBGNoEnableDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
//------------------------------------------------------------------------------
//********************************************************[ Grid Agenda ]*******
// Dibujamos el zebrado
//------------------------------------------------------------------------------
begin
Zebrado(DsDetalle,DBGNoEnable,Rect, Column, State, COLOR1GRID,COLOR2GRID);
end;
procedure TFFInanciado.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
//------------------------------------------------------------------------------
//********************************************************[ Grid Agenda ]*******
// Dibujamos el zebrado
//------------------------------------------------------------------------------
begin
Zebrado(DsPrincipal,DBGrid1,Rect, Column, State, COLOR1GRID,COLOR2GRID);
end;
procedure TFFInanciado.DBNECodigoCliente4Change(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************************[ Cod Cliente ]****
//------------------------------------------------------------------------------
begin
if FFInanciado.Active then ActQuery(IBQCLI,'Select * From CLIENTES where UPPER(CODIGO)=UPPER('+QuotedStr(DBNECodigoCliente4.text)+')');
end;
procedure TFFInanciado.EbusquedaChange(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************[ Mientras se escribe en busqueda ]******
//------------------------------------------------------------------------------
begin
BBuscarClick(sender);
end;
procedure TFFInanciado.FormActivate(Sender: TObject);
//------------------------------------------------------------------------------
//********************************************[ Cuando se activa El form ]******
// Lo que queremos que haga nuestro Form Cuando se Actiba
//------------------------------------------------------------------------------
begin
if Timer1.Enabled=false then Timer1.Enabled:=True;
end;
procedure TFFInanciado.FormClose(Sender: TObject; var Action: TCloseAction);
//------------------------------------------------------------------------------
//*************************************************[ Al Cerrarse El Form ]******
// Cerramos todos los procesos para que no consuman memoria y posibles errores
//------------------------------------------------------------------------------
begin
if Timer1.Enabled=true then Timer1.Enabled:=False;
end;
procedure TFFInanciado.FormCreate(Sender: TObject);
//------------------------------------------------------------------------------
//***************************************************[ Al Crearse el Fom ]******
// Cosas que queremos que haga según se inicie el Form
//------------------------------------------------------------------------------
begin
//
end;
procedure TFFInanciado.FormKeyPress(Sender: TObject; var Key: Char);
//------------------------------------------------------------------------------
//************************************************[ Al pulsar una tecla ]******
// Al pulsar la tecla salta al foco del siguiente componente, si esta admitido
//------------------------------------------------------------------------------
begin
if (Key = #13) then {Si se ha pulsado enter }
if (ActiveControl is TEdit)
or (ActiveControl is TDBEdit)
or (ActiveControl is TDBComboBox) then
begin
Key := #0; { anula la puulsación }
Perform(WM_NEXTDLGCTL, 0, 0); { mueve al próximo control }
end
end;
procedure TFFInanciado.SbBorrarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*******************************************[ Borrar el Actual Registro ]******
//------------------------------------------------------------------------------
begin
if DsPrincipal.DataSet.IsEmpty<>true then
begin
if (MessageBox(0, '¿Esta seguro de eliminar el registro actual? ', //Aqui no se porque me manda la última comilla simple y la coma a la linea de abajo, por favor subir al final de la linea anterior
'Eliminar Registro', MB_ICONSTOP or MB_YESNO or MB_DEFBUTTON2) = ID_No) then abort
else begin
DSPrincipal.DataSet.Delete;
ShowMessage('El registro ha sido eliminado');
DM.IBTransaction1.CommitRetaining;
end;
end else ShowMessage('No hay registros disponibles para editar')
end;
procedure TFFInanciado.SBBuscarClick(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Abrir Busqueda ]******
//------------------------------------------------------------------------------
begin
GBBuscar.Visible:=True;
Ebusqueda.SetFocus;
end;
procedure TFFInanciado.SBCancelarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*****************************************************[ Cancelar Proceso]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Cancel;
DM.IBTransaction1.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta
end;
procedure TFFInanciado.SBConfirmarClick(Sender: TObject);
//------------------------------------------------------------------------------
//********************************************************[ Grabar datos ]******
//------------------------------------------------------------------------------
begin
try
if not (DsDetalle.DataSet.State in [dsEdit,dsInsert]) then
begin ShowMessage('Ojo detalle abierto');
DSPrincipal.DataSet.Post;
DM.IBTransaction1.CommitRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta
end else ShowMessage('Cierre el detalle primero');
except
on E: Exception do
begin
MessageBeep(1000);
ShowMessage('Se ha producido un error y el proceso no se ha podido terminar Unidad:[ UFInanciado ] Modulo:[ Grabar ]' + Chr(13) + Chr(13)
+ 'Clase de error: ' + E.ClassName + Chr(13) + Chr(13)
+ 'Mensaje del error:' + E.Message+Chr(13) + Chr(13)
+ ' '+Chr(13) + Chr(13)
+ 'El proceso ha quedado interrumpido');
DSPrincipal.DataSet.Cancel;
DM.IBTransaction1.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta
end;
end;
end;
procedure TFFInanciado.SBImprimirClick(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Abrir Imprimir ]******
//------------------------------------------------------------------------------
begin
GBImprimir.Visible:=True;
end;
procedure TFFInanciado.SBMas1Click(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************************[ Avanzar un registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Next;
end;
procedure TFFInanciado.SBMasXClick(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************************[ Avanzar x Registros ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.MoveBy(SEMobeByX.Value);
end;
procedure TFFInanciado.SBMenos1Click(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************[ Retroceder 1 registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Prior;
end;
procedure TFFInanciado.SBMenosxClick(Sender: TObject);
//------------------------------------------------------------------------------
//**********************************************[ Retroceder x Registros ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.MoveBy(-SEMobeByX.Value);
end;
procedure TFFInanciado.SbModificarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*******************************************[ Editar el actual registro ]******
//------------------------------------------------------------------------------
begin
if DsPrincipal.DataSet.IsEmpty<>true then
begin
DSPrincipal.DataSet.Edit;
DBNEFecha1.setfocus;
end else ShowMessage('No hay registros disponibles para editar')
end;
procedure TFFInanciado.SbNuevoClick(Sender: TObject);
//------------------------------------------------------------------------------
//*******************************************[ Creamos un nuevo registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Insert;
DBNEFecha1.setfocus;
end;
procedure TFFInanciado.SBPrimeroClick(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************[ Ir al Primer Registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.First;
end;
procedure TFFInanciado.SBUltimoClick(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************[ Ir al último registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Last;
end;
procedure TFFInanciado.SB_SalirClick(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Salir Del Form ]******
//------------------------------------------------------------------------------
begin
FFInanciado.Close;
end;
procedure TFFInanciado.SpeedButton14Click(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************************[ Canc. Deta. ]****
//------------------------------------------------------------------------------
begin
DsDetalle.DataSet.Cancel;
end;
procedure TFFInanciado.SpeedButton15Click(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************************[ Conf. Deta. ]****
//------------------------------------------------------------------------------
begin
DsDetalle.DataSet.Post;
end;
procedure TFFInanciado.SpeedButton1Click(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************[ Primer registro Det. ]****
//------------------------------------------------------------------------------
begin
DsDetalle.DataSet.First;
end;
procedure TFFInanciado.SpeedButton2Click(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************************[ Calc. Auto. ]****
//------------------------------------------------------------------------------
begin
if DsDetalle.DataSet.IsEmpty then
begin
if DsPrincipal.DataSet.State in [dsInsert] then
begin
DsPrincipal.DataSet.Post;
DsPrincipal.DataSet.Edit;
end;
FcalcFinanc.Show;
FcalcFinanc.MNEImporte3.Text:='';
FcalcFinanc.MNEFormadePago2.Text:='';
FcalcFinanc.DTPFecha.Date:=Now;
FcalcFinanc.NSEDividir.Value:=1;
FcalcFinanc.RadioGroup1.ItemIndex:=-1;
FcalcFinanc.MNEImporte.text:=DBNEImporte3.Text;
FcalcFinanc.MNENumeroFinanciado4.Text:=DBNENumeroFinanciado2.Text;
FcalcFinanc.CBIguales.Checked:=False;
FcalcFinanc.SetFocus;
end else ShowMessage('Este Nº de Financiado ya contiene detalles, no es posible usar el calculo automático');
end;
procedure TFFInanciado.SpeedButton3Click(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ -1 registro Det. ]****
//------------------------------------------------------------------------------
begin
DsDetalle.DataSet.Prior;
end;
procedure TFFInanciado.SpeedButton4Click(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************[ +1 registro Det. ]****
//------------------------------------------------------------------------------
begin
DsDetalle.DataSet.Next;
end;
procedure TFFInanciado.SpeedButton5Click(Sender: TObject);
//------------------------------------------------------------------------------
//************************************************************[ IMPRIME ]*******
// Muestra directamente este reporte
//------------------------------------------------------------------------------
begin
// código de impresión
end;
procedure TFFInanciado.SpeedButton6Click(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************[ Último registro Det. ]****
//------------------------------------------------------------------------------
begin
DsDetalle.DataSet.Last;
end;
procedure TFFInanciado.SpeedButton7Click(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************************[ Nuev. Deta. ]****
//------------------------------------------------------------------------------
begin
if DsPrincipal.DataSet.State in [dsInsert] then
begin
DsPrincipal.DataSet.Post;
DsPrincipal.DataSet.Edit
end;
DBNEDetalleImporte6.SetFocus;
end;
procedure TFFInanciado.SpeedButton8Click(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Editar detalle ]******
//------------------------------------------------------------------------------
begin
if DsDetalle.DataSet.IsEmpty<>true then
begin
DsDetalle.DataSet.Edit;
DBNEDetalleImporte6.SetFocus;
end else ShowMessage('No hay registros disponibles para editar')
end;
procedure TFFInanciado.SpeedButton9Click(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Borrar detalle ]******
//------------------------------------------------------------------------------
begin
if DsDetalle.DataSet.IsEmpty<>true then
begin
if (MessageBox(0, '¿Esta seguro de eliminar el registro actual? ', //Aqui no se porque me manda la última comilla simple y la coma a la linea de abajo, por favor subir al final de la linea anterior
'Eliminar Registro', MB_ICONSTOP or MB_YESNO or MB_DEFBUTTON2) = ID_No) then abort
else begin
DsDetalle.DataSet.Delete;
ShowMessage('El registro ha sido eliminado');
DM.IBTransaction1.CommitRetaining;
end;
end else ShowMessage('No hay registros disponibles para editar')
end;
procedure TFFInanciado.Timer1Timer(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************************[ El evento del Timer ]******
//------------------------------------------------------------------------------
begin
SBBarraStatus.Panels[2].Text:=TimeToStr(now);
if SBBarraStatus.Panels[1].Text<>DateToStr(Now) then SBBarraStatus.Panels[1].Text:=DateToStr(Now);
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment