Created
March 1, 2015 13:15
Demo video Club UNIDADES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit UUnidades; | |
interface | |
uses | |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | |
Dialogs, ComCtrls, StdCtrls, DBCtrls, Grids, DBGrids, Mask, Buttons, ExtCtrls, | |
DB, IBCustomDataSet, IBQuery, ExtDlgs; | |
type | |
TFunidades = class(TForm) | |
Panelcontenedor: TPanel; | |
PanelDatos: TPanel; | |
Label10: TLabel; | |
Label1: TLabel; | |
PanelOculto: TPanel; | |
SpeedButton8: TSpeedButton; | |
SpeedButton9: TSpeedButton; | |
DbeCodigo: TDBEdit; | |
DBGrid1: TDBGrid; | |
Botonera1: TPanel; | |
SBNuevo: TSpeedButton; | |
SBEditar: TSpeedButton; | |
SBBorrar: TSpeedButton; | |
SBSalir: TSpeedButton; | |
SBRecuperada: TSpeedButton; | |
DBNavigator1: TDBNavigator; | |
Botonera2: TPanel; | |
Label9: TLabel; | |
SpeedButton16: TSpeedButton; | |
SBBuscarnormal: TSpeedButton; | |
Edit1: TEdit; | |
StatusBar1: TStatusBar; | |
Label2: TLabel; | |
DBETitulo: TDBEdit; | |
DSPrincipal: TDataSource; | |
Label3: TLabel; | |
Label4: TLabel; | |
Label5: TLabel; | |
Label7: TLabel; | |
DBEFechaAlta: TDBEdit; | |
Label8: TLabel; | |
DBEFechaBaja: TDBEdit; | |
Label13: TLabel; | |
DBEDisponible: TDBEdit; | |
Label14: TLabel; | |
DBEVendida: TDBEdit; | |
Label15: TLabel; | |
DBEPErdida: TDBEdit; | |
Label16: TLabel; | |
DBENumeroAlquileres: TDBEdit; | |
Label17: TLabel; | |
DBImage1: TDBImage; | |
Label18: TLabel; | |
DBECodigoBarras: TDBEdit; | |
DBLBGenero: TDBLookupComboBox; | |
DBLBValor: TDBLookupComboBox; | |
DBLBFormato: TDBLookupComboBox; | |
Label6: TLabel; | |
Memo1: TMemo; | |
PAnelNivel: TPanel; | |
DBERendimiento: TDBEdit; | |
Label12: TLabel; | |
DBECoste: TDBEdit; | |
Label11: TLabel; | |
SBCargar: TSpeedButton; | |
SBcopiar: TSpeedButton; | |
SpeedButton12: TSpeedButton; | |
SBEditMemo: TSpeedButton; | |
SpeedButton10: TSpeedButton; | |
DSGenero: TDataSource; | |
DSValor: TDataSource; | |
DSFormato: TDataSource; | |
DBText1: TDBText; | |
DBText2: TDBText; | |
DBText3: TDBText; | |
DSIBQValor: TDataSource; | |
DSIBQFormatos: TDataSource; | |
DSIBQGeneros: TDataSource; | |
IBQValor: TIBQuery; | |
IBQFormatos: TIBQuery; | |
IBQGeneros: TIBQuery; | |
OpenPictureDialog1: TOpenPictureDialog; | |
SBVendida: TSpeedButton; | |
sbBaja: TSpeedButton; | |
SpeedButton3: TSpeedButton; | |
SBEtiqueta: TSpeedButton; | |
SBPErdida: TSpeedButton; | |
procedure SBNuevoClick(Sender: TObject); | |
procedure SBEditarClick(Sender: TObject); | |
procedure SBBorrarClick(Sender: TObject); | |
procedure SBBuscarClick(Sender: TObject); | |
procedure SBSalirClick(Sender: TObject); | |
procedure SpeedButton9Click(Sender: TObject); | |
procedure SpeedButton8Click(Sender: TObject); | |
procedure SBBuscarnormalClick(Sender: TObject); | |
procedure SpeedButton16Click(Sender: TObject); | |
procedure FormKeyPress(Sender: TObject; var Key: Char); | |
procedure SBCargarClick(Sender: TObject); | |
procedure SBcopiarClick(Sender: TObject); | |
procedure SBEditMemoClick(Sender: TObject); | |
procedure FormShow(Sender: TObject); | |
procedure DBLBGeneroEnter(Sender: TObject); | |
procedure DBLBValorEnter(Sender: TObject); | |
procedure DBLBFormatoEnter(Sender: TObject); | |
procedure comprobar; | |
procedure DSPrincipalDataChange(Sender: TObject; Field: TField); | |
procedure FormActivate(Sender: TObject); | |
procedure DBLBGeneroExit(Sender: TObject); | |
procedure DBLBValorExit(Sender: TObject); | |
procedure DBLBFormatoExit(Sender: TObject); | |
private | |
{ Private declarations } | |
public | |
{ Public declarations } | |
end; | |
var | |
Funidades: TFunidades; | |
implementation | |
{$R *.dfm} | |
uses UDM,Funciones, UEditor; | |
procedure TFunidades.comprobar; | |
//------------------------------------------------------------------------------ | |
//************************************************************[ comprobar ]***** | |
//------------------------------------------------------------------------------ | |
begin | |
if Funidades.Active then | |
begin | |
if not (DsPrincipal.DataSet.State in [dsEdit,dsInsert]) then | |
begin | |
if not (DM.IBDUnidades.IsEmpty) then | |
begin | |
if DsPrincipal.DataSet.FieldByName('NOTAS').Value<>'' then Memo1.Lines.Text:=DsPrincipal.DataSet.FieldByName('NOTAS').AsString | |
else Memo1.Lines.Clear; | |
if DBLBFormato.Text<>'' then ActQuery(IBQFormatos,'select * from FORMATOS WHERE (FORMATOS.CODIGO = '+QuotedStr(DBLBFormato.Text)+')'); | |
if DBLBGenero.Text<>'' then ActQuery(IBQGeneros,'select * from GENEROS WHERE (GENEROS.CODIGO = '+QuotedStr(DBLBGenero.Text)+')'); | |
if DBLBValor.Text<>'' then ActQuery(IBQValor,'select * from VALOR_ALQUILER WHERE (VALOR_ALQUILER.CODIGO = '+QuotedStr(DBLBValor.Text)+')'); | |
if (DM.IBDUnidadesDISPONIBLE.value='S') and (DM.IBDUnidadesPERDIDA.value='N') and (DM.IBDUnidadesVENDIDA.value='N') then PanelDatos.Color:=StringToColor(DM.IBDConfiguracionCOLOR_DISPONIBLE.Value); | |
if (DM.IBDUnidadesDISPONIBLE.value='N') and (DM.IBDUnidadesPERDIDA.value='N') and (DM.IBDUnidadesVENDIDA.value='N') then PanelDatos.Color:=StringToColor(DM.IBDConfiguracionCOLOR_NO_DISPONIBLE.Value); | |
if (DM.IBDUnidadesDISPONIBLE.value='N') and ((DM.IBDUnidadesPERDIDA.value='S') or (DM.IBDUnidadesVENDIDA.value='S')) then PanelDatos.Color:=StringToColor(DM.IBDConfiguracionCOLOR_BLOQUEADA.Value); | |
end; | |
end; | |
end; | |
end; | |
procedure TFunidades.DBLBFormatoEnter(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Entrar en formato ]***** | |
// Abre el dialogo | |
//------------------------------------------------------------------------------ | |
begin | |
DM.IBDFormatos.Last; | |
DBLBFormato.perform(CB_SHOWDROPDOWN,1,0); | |
end; | |
procedure TFunidades.DBLBFormatoExit(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************[ Salir del DBLoockupCombobox ]***** | |
// Actualizamos datos | |
//------------------------------------------------------------------------------ | |
begin | |
if DBLBFormato.Text<>'' then ActQuery(IBQFormatos,'select * from FORMATOS WHERE (FORMATOS.CODIGO = '+QuotedStr(DBLBFormato.Text)+')'); | |
end; | |
procedure TFunidades.DBLBGeneroEnter(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Entrar en genero ]***** | |
// Abre el dialogo | |
//------------------------------------------------------------------------------ | |
begin | |
DM.IBDGeneros.Last; | |
DBLBGenero.perform(CB_SHOWDROPDOWN,1,0); | |
end; | |
procedure TFunidades.DBLBGeneroExit(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************[ Salir del DBLoockupCombobox ]***** | |
// Actualizamos datos | |
//------------------------------------------------------------------------------ | |
begin | |
if DBLBGenero.Text<>'' then ActQuery(IBQGeneros,'select * from GENEROS WHERE (GENEROS.CODIGO = '+QuotedStr(DBLBGenero.Text)+')'); | |
end; | |
procedure TFunidades.DBLBValorEnter(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************[ Entrar en Valor de alquiler ]***** | |
// Abre el dialogo | |
//------------------------------------------------------------------------------ | |
begin | |
DM.IBDValorAlquiler.Last; | |
DBLBValor.perform(CB_SHOWDROPDOWN,1,0); | |
end; | |
procedure TFunidades.DBLBValorExit(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************[ Salir del DBLoockupCombobox ]***** | |
// Actualizamos datos | |
//------------------------------------------------------------------------------ | |
begin | |
if DBLBValor.Text<>'' then ActQuery(IBQValor,'select * from VALOR_ALQUILER WHERE (VALOR_ALQUILER.CODIGO = '+QuotedStr(DBLBValor.Text)+')'); | |
end; | |
procedure TFunidades.DSPrincipalDataChange(Sender: TObject; Field: TField); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Cambia de datos ]***** | |
//------------------------------------------------------------------------------ | |
begin | |
comprobar; | |
end; | |
procedure TFunidades.FormActivate(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**********************************************************[ On Activate ]***** | |
//------------------------------------------------------------------------------ | |
begin | |
comprobar; | |
end; | |
procedure TFunidades.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 TDBLookupComboBox) | |
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 TFunidades.FormShow(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***************************************************************[ OnShow ]***** | |
// Cuando muestra la pantalla | |
//------------------------------------------------------------------------------ | |
begin | |
if VarINivelUSuario<8 then PAnelNivel.Visible:=False | |
else PAnelNivel.Visible:=True; | |
end; | |
procedure TFunidades.SBBorrarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Borrar el Actual Registro ]****** | |
//------------------------------------------------------------------------------ | |
begin //Cambiar por el mensaje elegido | |
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; | |
DM.IBT.CommitRetaining; | |
ShowMessage('El registro ha sido eliminado'); | |
end; | |
end; | |
procedure TFunidades.SBBuscarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Abrir Búsqueda ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
Botonera2.Visible:=True; | |
Edit1.SetFocus; | |
end; | |
procedure TFunidades.SBBuscarnormalClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//***********************************************[ ejecutamos la búsqueda ]***** | |
//------------------------------------------------------------------------------ | |
begin | |
DSPrincipal.DataSet.Locate('TITULO',Edit1.Text,[loCaseInsensitive,loPartialKey]); | |
end; | |
procedure TFunidades.SBCargarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*********************************************************[ Cargar imagen ]**** | |
//------------------------------------------------------------------------------ | |
begin | |
CargaIimagenADBImagen(OpenPictureDialog1,DBImage1); | |
end; | |
procedure TFunidades.SBcopiarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**********************************************[ Copiar del portapapeles ]***** | |
//------------------------------------------------------------------------------ | |
begin | |
PEgarImagen(DBImage1,'Unidades'); | |
end; | |
procedure TFunidades.SBEditarClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*******************************************[ Editar el actual registro ]****** | |
//------------------------------------------------------------------------------ | |
begin | |
if DsPrincipal.DataSet.IsEmpty<>true then | |
begin | |
DSPrincipal.DataSet.Edit; | |
PanelDatos.Enabled:=True; | |
PanelOculto.Visible:=True; | |
Botonera1.Enabled:=false; | |
DBECodigoBarras.SetFocus; | |
end else ShowMessage('No hay tregistros disponibles para editar') | |
end; | |
procedure TFunidades.SBEditMemoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//******************************************************[ Editor del memo ]***** | |
//------------------------------------------------------------------------------ | |
begin | |
VarSUnidad:='UUNIDADES'; | |
VarSMEMO:=MEmo1.Lines.Text; | |
Feditor.Memo1.Lines:=MEmo1.Lines; | |
Feditor.Show; | |
end; | |
procedure TFunidades.SBNuevoClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************************[ SBnuevo ]***** | |
//------------------------------------------------------------------------------ | |
var VarIRegistro:Integer; | |
begin | |
DsPrincipal.DataSet.Insert; | |
VarIRegistro:=DM.IBDConfiguracionNUMERADOR_UNIDAD.Value; | |
VarIRegistro:=VarIRegistro+1; | |
DBECodigo.Field.Value:=IntToStr(VarIRegistro); | |
PanelDatos.Enabled:=True; | |
PanelOculto.Visible:=True; | |
Botonera1.Enabled:=false; | |
VarIModoApertura:=0; | |
Memo1.Lines.Clear; | |
DBEDisponible.Field.Value:='S'; | |
DBEPErdida.Field.Value:='N'; | |
DBEVendida.Field.Value:='N'; | |
DBEFechaAlta.Field.Value:=Now; | |
DBECodigoBarras.SetFocus; | |
end; | |
procedure TFunidades.SBSalirClick(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//**************************************************************[ SBSalir ]***** | |
//------------------------------------------------------------------------------ | |
begin | |
if IBQValor.Active then IBQValor.Active:=False; | |
if IBQFormatos.Active then IBQFormatos.Active:=False; | |
if IBQGeneros.Active then IBQGeneros.Active:=False; | |
Close; | |
end; | |
procedure TFunidades.SpeedButton16Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//****************************************************[ Salir de búsqueda ]***** | |
//------------------------------------------------------------------------------ | |
begin | |
Edit1.Text:=''; | |
Botonera2.Visible:=False; | |
end; | |
procedure TFunidades.SpeedButton8Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//*****************************************************[ Cancelar Proceso]****** | |
//------------------------------------------------------------------------------ | |
begin | |
if DsPrincipal.DataSet.State in [dsEdit,dsInsert] then DSPrincipal.DataSet.Cancel; | |
DM.IBT.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta | |
PanelOculto.Visible:=False; | |
Botonera1.Enabled:=True; | |
PanelDatos.Enabled:=False; | |
end; | |
procedure TFunidades.SpeedButton9Click(Sender: TObject); | |
//------------------------------------------------------------------------------ | |
//********************************************************[ Grabar datos ]****** | |
//------------------------------------------------------------------------------ | |
var VarIFase:Integer; | |
begin | |
try | |
VarIFase:=1; | |
if DsPrincipal.DataSet.State in [dsInsert] then VarBGrabarNumerador:=True else VarBGrabarNumerador:=False; | |
if DsPrincipal.DataSet.State in [dsEdit,dsInsert] then | |
begin | |
if Memo1.Lines.Text<>DM.IBDUnidadesNOTAS.value then DM.IBDUnidadesNOTAS.value:=Memo1.Lines.Text; | |
DSPrincipal.DataSet.Post; | |
end; | |
if VarBGrabarNumerador=true then | |
begin | |
VarIFase:=2; | |
DM.IBDConfiguracion.Edit; | |
DM.IBDConfiguracionNUMERADOR_UNIDAD.Value:=StrToInt(DBECodigo.Field.Value); | |
DM.IBDConfiguracion.Post; | |
VarBGrabarNumerador:=False; | |
end; | |
DM.IBT.CommitRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta | |
except | |
on E: Exception do | |
begin | |
MessageBeep(1000); | |
ShowMessage('Se ha producido un error y el proceso no se ha podido terminar Unidad:[ UunidadesGeneros ] Modulo:[ Grabar ]' + Chr(13) + Chr(13) | |
+ 'Fase del error [ '+IntToStr(VarIFase)+' ]'+ 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'); | |
if DsPrincipal.DataSet.State in [dsEdit,dsInsert] then DSPrincipal.DataSet.Cancel; | |
DM.IBT.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta | |
end; | |
end; | |
PanelOculto.Visible:=False; | |
PanelDatos.Enabled:=False; | |
Botonera1.Enabled:=True; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment