Skip to content

Instantly share code, notes, and snippets.

/gist:5743504
Created Jun 9, 2013

Embed
What would you like to do?
Gestión de notas para el tutorial de programa de gestión desde 0
unit UNotas;
{$R BOTONERA.RES}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, IBDatabase,
MMSystem, //Para la botonera
NewPanelDB, //Para usar el NEwPanelDB
SPBBC, //Para TSpeedButtonBC
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
DBCBEXT, //Para usar el DbCombobox Extendido
GroupboxJL, //Para usar el CgoupBox especial
Dialogs, ComCtrls, ExtCtrls, Grids, DBGrids, StdCtrls, Spin, Buttons, DB, DBCtrls, ShellAPI,
DBneweditjl;
type
TFNotas = class(TForm)
PanelBotonera: TNewPanelDB;
SBBarraStatus: TStatusBar;
Panel1: TPanel;
Panel2: TPanel;
PanelDatos: TNewPanelDB;
Panel3: TPanel;
DBGNoEnable: TDBGrid;
PanelConfirmar: TNewPanelDB;
DsPrincipal: TDataSource;
SBPrimero: TSpeedButtonBC;
SBMenosx: TSpeedButtonBC;
SBMenos1: TSpeedButtonBC;
SBMas1: TSpeedButtonBC;
SBMasX: TSpeedButtonBC;
SBUltimo: TSpeedButtonBC;
SbNuevo: TSpeedButtonBC;
SbModificar: TSpeedButtonBC;
SbBorrar: TSpeedButtonBC;
SB_Salir: TSpeedButtonBC;
SBBuscar: TSpeedButtonBC;
SBConfirmar: TSpeedButtonBC;
SBCancelar: TSpeedButtonBC;
Label14: TLabel;
SEMobeByX: TSpinEdit;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
DBIBMemo1: TDBIBMemo;
DBNewEditJL2: TDBNewEditJL;
DBNewEditJL3: TDBNewEditJL;
DBNewEditJL1: TDBNewEditJL;
NewPanelDB1: TNewPanelDB;
SpeedButtonBC1: TSpeedButtonBC;
SpeedButtonBC2: TSpeedButtonBC;
SpeedButtonBC3: TSpeedButtonBC;
SpeedButtonBC4: TSpeedButtonBC;
SpeedButtonBC5: TSpeedButtonBC;
SpeedButtonBC6: TSpeedButtonBC;
SpeedButtonBC7: TSpeedButtonBC;
SpeedButtonBC8: TSpeedButtonBC;
SpeedButtonBC9: TSpeedButtonBC;
Label5: TLabel;
SpeedButtonBC10: TSpeedButtonBC;
SpeedButtonBC11: TSpeedButtonBC;
SpinEdit1: TSpinEdit;
GBBuscar: TGroupBoxJL;
Ebusqueda: TEdit;
BLimpiar: TButton;
BBuscar: TButton;
BCerrar: TButton;
SBImprimir: TSpeedButtonBC;
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 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 DBGNoEnableDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FNotas: TFNotas;
IBT:TIBTransaction;
implementation
{$R *.dfm}
uses UDM, Fun, FUN_DBGRID, UMENU, UArticulos;
procedure TFNotas.BBuscarClick(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ Buscar ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Locate('NOMBREMODULO;CODIGO;DESCRIPCION',VarArrayOf([VarSNomMod,VarsCod,Ebusqueda.Text]),[loCaseInsensitive,loPartialKey]);
end;
procedure TFNotas.BCerrarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*****************************************************[ Cerrar Busqueda ]******
//------------------------------------------------------------------------------
begin
BLimpiarClick(Sender);
GBBuscar.Visible:=False;
end;
procedure TFNotas.BLimpiarClick(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************[ Limpia la busqueda ]******
//------------------------------------------------------------------------------
begin
Ebusqueda.Text:='';
BBuscarClick(Sender);
Ebusqueda.SetFocus;
end;
procedure TFNotas.DBGNoEnableDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
//------------------------------------------------------------------------------
//*******************************************************[ ZEbaro del Grid ]****
//------------------------------------------------------------------------------
begin
Zebrado(DsPrincipal,DBGNoEnable, Rect, Column, State, COLOR1GRID,COLOR2GRID);
MemoGridB(DBGNoEnable,DsPrincipal.DataSet.FieldByName('NOTAS'), Rect, Column, State);
end;
procedure TFNotas.EbusquedaChange(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************[ Mientras se escribe en busqueda ]******
//------------------------------------------------------------------------------
begin
BBuscarClick(sender);
end;
procedure TFNotas.FormActivate(Sender: TObject);
//------------------------------------------------------------------------------
//********************************************[ Cuando se activa El form ]******
// Lo que queremos que haga nuestro Form Cuando se Actiba
//------------------------------------------------------------------------------
begin
//Carganmos las imagenes de los botones
SBPrimero.Glyph.Handle:=Loadbitmap(HInstance,'FIRST');
SBMenosx.Glyph.Handle:=Loadbitmap(HInstance,'RETROCEDER');
SBMenos1.Glyph.Handle:=Loadbitmap(HInstance,'PRIOR');
SBMas1.Glyph.Handle:=Loadbitmap(HInstance,'NEXT');
SBMasX.Glyph.Handle:=Loadbitmap(HInstance,'AVANZAR');
SBUltimo.Glyph.Handle:=Loadbitmap(HInstance,'LAST');
SbNuevo.Glyph.Handle:=Loadbitmap(HInstance,'NUEVO');
SbModificar.Glyph.Handle:=Loadbitmap(HInstance,'EDIT');
SbBorrar.Glyph.Handle:=Loadbitmap(HInstance,'BORRAR');
SB_Salir.Glyph.Handle:=Loadbitmap(HInstance,'SALIR');
SBBuscar.Glyph.Handle:=Loadbitmap(HInstance,'BUSCAR');
SBImprimir.Glyph.Handle:=Loadbitmap(HInstance,'IMPRIMIR');
SBConfirmar.Glyph.Handle:=Loadbitmap(HInstance,'CHECKROUND');
SBCancelar.Glyph.Handle:=Loadbitmap(HInstance,'CANCEL');
if Timer1.Enabled=false then Timer1.Enabled:=True;
//Ponemos el Juego de colores de mis NewPanelDB
PanelBotonera.ColorNotActive:=COLORPANELACT;
PanelBotonera.ActiveColor:=COLORPANELNOACT;
PanelDatos.ActiveColor:=COLORPANELACT;
PanelDatos.ColorNotActive:=COLORPANELNOACT;
PanelConfirmar.ActiveColor:=COLORPANELACT;
PanelConfirmar.ColorNotActive:=COLORPANELNOACT;
//Acondicionamos tamaños en el Grid
TStringGrid(DBGNoEnable).DefaultRowHeight :=40;
TStringGrid(DBGNoEnable).RowHeights[0]:=20;
end;
procedure TFNotas.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;
ActIbdataset(DM.IBDNOTAS,'select * from NOTAS');
//Retornos al modulo de llamada
if VarSNomMod='ARTICULOS' then FArticulos.SpeedButtonBC7Click(sender);
end;
procedure TFNotas.FormCreate(Sender: TObject);
//------------------------------------------------------------------------------
//***************************************************[ Al Crearse el Fom ]******
// Cosas que queremos que haga según se inicie el Form
//------------------------------------------------------------------------------
begin
IBT:=dm.IBTransaction1; // Aquí especificar el modulo y el IBTransaction a usar
{Cosas que queremos que haga según se inicie el Form}
end;
procedure TFNotas.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 TDBNewEditJL)
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 TFNotas.SbBorrarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*******************************************[ Borrar el Actual Registro ]******
//------------------------------------------------------------------------------
begin //Cambiar por el mensaje elegido
if (MessageBox(0, '¿Esta seguro de eliminar el registro actual?',
'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');
IBT.CommitRetaining;
end;
end;
procedure TFNotas.SBBuscarClick(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Abrir Busqueda ]******
//------------------------------------------------------------------------------
begin
GBBuscar.Visible:=True;
Ebusqueda.SetFocus;
end;
procedure TFNotas.SBCancelarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*****************************************************[ Cancelar Proceso]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Cancel;
IBT.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta
end;
procedure TFNotas.SBConfirmarClick(Sender: TObject);
//------------------------------------------------------------------------------
//********************************************************[ Grabar datos ]******
//------------------------------------------------------------------------------
begin
try
if (DBneweditjl3.text<>'') and (DBIBMemo1.lines.text<>'') then
begin
DSPrincipal.DataSet.Post;
IBT.CommitRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta
end else ShowMessage('Para poder grabar los datos, debe Rellenar los campos Descripción y Notas');
except
on E: Exception do
begin
MessageBeep(1000);
ShowMessage('Se ha producido un error y el proceso no se ha podido terminar Unidad:[ UNotas ] 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;
IBT.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta
end;
end;
end;
procedure TFNotas.SBMas1Click(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************************[ Avanzar un registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Next;
end;
procedure TFNotas.SBMasXClick(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************************[ Avanzar x Registros ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.MoveBy(SEMobeByX.Value);
end;
procedure TFNotas.SBMenos1Click(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************[ Retroceder 1 registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Prior;
end;
procedure TFNotas.SBMenosxClick(Sender: TObject);
//------------------------------------------------------------------------------
//**********************************************[ Retroceder x Registros ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.MoveBy(-SEMobeByX.Value);
end;
procedure TFNotas.SbModificarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*******************************************[ Editar el actual registro ]******
//------------------------------------------------------------------------------
begin
if DsPrincipal.DataSet.IsEmpty<>true then
begin
DSPrincipal.DataSet.Edit;
DBNewEditJL3.SetFocus;
end else ShowMessage('No hay tregistros disponibles para editar')
end;
procedure TFNotas.SbNuevoClick(Sender: TObject);
//------------------------------------------------------------------------------
//*******************************************[ Creamos un nuevo registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Insert;
DBIBMemo1.Lines.Clear;
DsPrincipal.DataSet.FieldByName('NOMBREMODULO').Value:=VarSNomMod;
DsPrincipal.DataSet.FieldByName('CODIGO').Value:=VarsCod;
if VarSNomMod='ARTICULOS' then DsPrincipal.DataSet.FieldByName('DESCRIPCION').Value:='NOTAS';
DBNewEditJL3.SetFocus;
end;
procedure TFNotas.SBPrimeroClick(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************[ Ir al Primer Registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.First;
end;
procedure TFNotas.SBUltimoClick(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************[ Ir al último registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Last;
end;
procedure TFNotas.SB_SalirClick(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Salir Del Form ]******
//------------------------------------------------------------------------------
begin
FNotas.Close;
end;
procedure TFNotas.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
You can’t perform that action at this time.