Skip to content

Instantly share code, notes, and snippets.

/gist:5743472
Created Jun 9, 2013

Embed
What would you like to do?
Gestión de artículos para el tutorial de programa de gestión desde 0
unit UArticulos;
{$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,
DBneweditjl, cbext, IBCustomDataSet, IBQuery;
const
Ean_izqA:array[0..9] of
pchar=('0001101','0011001','0010011','0111101','0100011','0110001','0101111','0111011','0110111','0001011');
Ean_izqB:array[0..9] of
pchar=('0100111','0110011','0011011','0100001','0011101','0111001','0000101','0010001','0001001','0010111');
Ean_dcha:array[0..9] of
pchar=('1110010','1100110','1101100','1000010','1011100','1001110','1010000','1000100','1001000','1110100');
Codificaizq:array[0..9] of
pchar=('AAAAA','ABABB','ABBAB','ABBBA','BAABB','BBAAB','BBBAA','BABAB','BABBA','BBABA');
//[ 1]----------------[ Para poder tener tabs del page control en color]--------
Type
TTabSheet = class(ComCtrls.TTabSheet)
private
FColor: TColor;
procedure SetColor(Value: TColor);
procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd);
message WM_ERASEBKGND;
public
constructor Create(aOwner: TComponent); override;
property Color: TColor read FColor write SetColor;
end;
//[ 1]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]--------
type
TFArticulos = 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;
SBImprimir: TSpeedButtonBC;
SBConfirmar: TSpeedButtonBC;
SBCancelar: TSpeedButtonBC;
Label14: TLabel;
SEMobeByX: TSpinEdit;
GBBuscar: TGroupBoxJL;
Ebusqueda: TEdit;
BLimpiar: TButton;
BBuscar: TButton;
BCerrar: TButton;
Panel4: TPanel;
PC: TPageControl;
Datos: TTabSheet;
Imagenes: TTabSheet;
Notas: TTabSheet;
Facturado: TTabSheet;
Label1: TLabel;
Label2: TLabel;
DBNewEditJL1: TDBNewEditJL;
DBNewEditJL2: TDBNewEditJL;
DBNewEditJL3: TDBNewEditJL;
DBNewEditJL5: TDBNewEditJL;
Label3: TLabel;
Label4: TLabel;
GroupBox1: TGroupBox;
Label5: TLabel;
DBNewEditJL7: TDBNewEditJL;
Label6: TLabel;
DBNewEditJL8: TDBNewEditJL;
Label7: TLabel;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Label12: TLabel;
Label13: TLabel;
Label15: TLabel;
Label16: TLabel;
GroupBox4: TGroupBox;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
Label29: TLabel;
Label30: TLabel;
Label31: TLabel;
Panel5: TPanel;
Label32: TLabel;
DBNewEditJL9: TDBNewEditJL;
DBText1: TDBText;
DBText2: TDBText;
Image2: TImage;
DBNewEditJL6: TDBNewEditJL;
DBNewEditJL11: TDBNewEditJL;
DBNewEditJL12: TDBNewEditJL;
DBIBCheckbox1: TDBIBCheckbox;
DBIBCheckbox2: TDBIBCheckbox;
DBIBCheckbox3: TDBIBCheckbox;
DBIBCheckbox4: TDBIBCheckbox;
DBNewEditJL10: TDBNewEditJL;
DBNewEditJL13: TDBNewEditJL;
DBNewEditJL14: TDBNewEditJL;
DBNewEditJL15: TDBNewEditJL;
DBNewEditJL16: TDBNewEditJL;
DBNewEditJL17: TDBNewEditJL;
DBNewEditJL18: TDBNewEditJL;
DBNewEditJL19: TDBNewEditJL;
DBNewEditJL20: TDBNewEditJL;
DBNewEditJL24: TDBNewEditJL;
DBNewEditJL25: TDBNewEditJL;
DBNewEditJL26: TDBNewEditJL;
DBNewEditJL27: TDBNewEditJL;
DBNewEditJL28: TDBNewEditJL;
DBNewEditJL29: TDBNewEditJL;
DbComboBoxExt2: TDbComboBoxExt;
Label8: TLabel;
DBNewEditJL4: TDBNewEditJL;
Label9: TLabel;
DBNewEditJL30: TDBNewEditJL;
GBImprimir: TGroupBoxJL;
CBVistaPrevia: TCheckBox;
CBVerDialogo: TCheckBox;
BCerrarIMP: TButton;
SpeedButtonBC1: TSpeedButtonBC;
Label10: TLabel;
Label11: TLabel;
Timer1: TTimer;
DsFamilias: TDataSource;
Label33: TLabel;
ComboBoxExt1: TComboBoxExt;
DBNewEditJL21: TDBNewEditJL;
Panel7: TPanel;
SpeedButtonBC2: TSpeedButtonBC;
SpeedButtonBC3: TSpeedButtonBC;
Panel8: TPanel;
Image1: TImage;
Panel9: TPanel;
SpeedButtonBC4: TSpeedButtonBC;
SpeedButtonBC5: TSpeedButtonBC;
Panel10: TPanel;
Image3: TImage;
IBQuery1: TIBQuery;
DBGrid1: TDBGrid;
Label34: TLabel;
DBNewEditJL22: TDBNewEditJL;
Label35: TLabel;
DBNewEditJL23: TDBNewEditJL;
Label36: TLabel;
DBNewEditJL31: TDBNewEditJL;
DBImage1: TDBImage;
Label37: TLabel;
DBNavigator1: TDBNavigator;
Label38: TLabel;
DBNewEditJL32: TDBNewEditJL;
Label39: TLabel;
DBNewEditJL33: TDBNewEditJL;
Label40: TLabel;
DBNewEditJL34: TDBNewEditJL;
DBIBMemo1: TDBIBMemo;
Label41: TLabel;
DBGrid2: TDBGrid;
Panel11: TPanel;
NewPanelDB1: TNewPanelDB;
SpeedButtonBC6: TSpeedButtonBC;
SpeedButtonBC8: TSpeedButtonBC;
SpeedButtonBC7: TSpeedButtonBC;
SpeedButtonBC9: TSpeedButtonBC; //LA fuente usada es Code39 la podeis bajar de http://es.fonts2u.com/code39-regular.fuente
//y echar un vistazo a http://www.delphifaq.com/faq/f643.shtml
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 FormPaint(Sender: TObject);
procedure DBNewEditJL7Change(Sender: TObject);
procedure DBNewEditJL8Exit(Sender: TObject);
Procedure Codifica(num:string;valor:integer);
Procedure Dibujar(matrix:string);
procedure DBNewEditJL8Change(Sender: TObject);
procedure ComboBoxExt1Exit(Sender: TObject);
procedure DBNewEditJL21Change(Sender: TObject);
procedure PCDrawTab(Control: TCustomTabControl; TabIndex: Integer;
const Rect: TRect; Active: Boolean);
procedure DSPrincipalDataChange(Sender: TObject; Field: TField);
procedure SpeedButtonBC5Click(Sender: TObject);
procedure SpeedButtonBC3Click(Sender: TObject);
procedure SpeedButtonBC6Click(Sender: TObject);
procedure SpeedButtonBC8Click(Sender: TObject);
procedure SpeedButtonBC7Click(Sender: TObject);
procedure SpeedButtonBC9Click(Sender: TObject);
procedure SpeedButtonBC4Click(Sender: TObject);
procedure SpeedButtonBC2Click(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FArticulos: TFArticulos;
IBT:TIBTransaction;
implementation
{$R *.dfm}
uses UDM, UMENU, Fun, Fun_Errores, FUN_DBGRID, UNotas, UImagenes;
//[ 2]----------------[ Para poder tener tabs del page control en color]--------
constructor TTabSheet.Create(aOwner: TComponent);
//------------------------------------------------------------------------------
//*************************************[ Crear nueva propiedad tabsheet ]*******
//------------------------------------------------------------------------------
begin
inherited;
FColor := clBtnFace;
end;
//[ 2]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]--------
//[ 3]----------------[ Para poder tener tabs del page control en color]--------
procedure TTabSheet.SetColor(Value: TColor);
//------------------------------------------------------------------------------
//**************************************************[ Seleción de color ]*******
//------------------------------------------------------------------------------
begin
if FColor <> Value then
begin
FColor := Value;
Invalidate;
end;
end;
//[ 3]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]--------
//[ 4]----------------[ Para poder tener tabs del page control en color]--------
procedure TTabSheet.WMEraseBkGnd(var Msg: TWMEraseBkGnd);
//------------------------------------------------------------------------------
//******************************************[ Dibujar en el pagecontrol ]*******
//------------------------------------------------------------------------------
begin
if FColor = clBtnFace then
inherited
else
begin
Brush.Color := FColor;
Windows.FillRect(Msg.dc, ClientRect, Brush.Handle);
Msg.Result := 1;
end;
end;
//[ 4]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]--------
procedure TFArticulos.BBuscarClick(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ Buscar ]******
//------------------------------------------------------------------------------
var Campo:string;
begin
Campo:='PRODUCTO'; {Dato a rellenar por el progrmador con el nombre del campo en la busqueda}
DSPrincipal.DataSet.Locate(Campo,Ebusqueda.Text,[loCaseInsensitive,loPartialKey]);
end;
procedure TFArticulos.BCerrarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*****************************************************[ Cerrar Busqueda ]******
//------------------------------------------------------------------------------
begin
BLimpiarClick(Sender);
GBBuscar.Visible:=False;
end;
procedure TFArticulos.BCerrarIMPClick(Sender: TObject);
//------------------------------------------------------------------------------
//****************************************************[ Cerrar Imrprimir ]******
//------------------------------------------------------------------------------
begin
GBImprimir.Visible:=False;
end;
procedure TFArticulos.BLimpiarClick(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************[ Limpia la busqueda ]******
//------------------------------------------------------------------------------
begin
Ebusqueda.Text:='';
BBuscarClick(Sender);
Ebusqueda.SetFocus;
end;
procedure TFArticulos.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
//------------------------------------------------------------------------------
//*******************************************************[ ZEbaro del Grid ]****
//------------------------------------------------------------------------------
begin
Zebrado(DsPrincipal,DBGrid1, Rect, Column, State, COLOR1GRID,COLOR2GRID);
GridImagen(DBGrid1, DM.DSImagenes.DataSet.Fields.FieldByName('IMAGENES'), Rect,Column,State);
end;
procedure TFArticulos.DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
//------------------------------------------------------------------------------
//*******************************************************[ ZEbaro del Grid ]****
//------------------------------------------------------------------------------
begin
Zebrado(DsPrincipal,DBGrid2, Rect, Column, State, COLOR1GRID,COLOR2GRID);
MemoGridB(DBGrid2,DM.DSNotas.DataSet.FieldByName('NOTAS'), Rect, Column, State);
end;
procedure TFArticulos.DBNewEditJL21Change(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************[ Change Tipo impuesto ]****
// Cambia el tipo de impuesto sin estar en edición o inserción de datos
//------------------------------------------------------------------------------
begin
if (not(DsPrincipal.DataSet.State in [dsEdit,dsInsert])) and (FArticulos.Active) then
begin
if DBNewEditJL21.Text='1' then ComboBoxExt1.Text:=DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO1').AsString;
if DBNewEditJL21.Text='2' then ComboBoxExt1.Text:=DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO2').AsString;
if DBNewEditJL21.Text='3' then ComboBoxExt1.Text:=DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO3').AsString;
if DBNewEditJL21.Text='4' then ComboBoxExt1.Text:=DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO4').AsString;
end;
end;
procedure TFArticulos.DBNewEditJL7Change(Sender: TObject);
//------------------------------------------------------------------------------
//*********************************************************[ Change Code39 ]****
// Mostramos el código de barras generado
//------------------------------------------------------------------------------
begin
Label33.Caption:=DBNewEditJL7.Text;
end;
Procedure TFArticulos.codifica(num:string;valor:integer);
//------------------------------------------------------------------------------
//**************************************************************[ codifica ]****
// Códifica el código de barras EAN13
//------------------------------------------------------------------------------
var
matrix:string;
I:integer;
begin
num:=DBNewEditJL8.text;
Matrix:='';
case length(num) of
13:begin
// EanCorrecto(num,valor);
DBNewEditJL8.text:=num;
matrix:=matrix+'x0x'; //Barra inicio
matrix:=matrix+EAN_izqA[Strtoint(num[2])];
for i:=3 to 7 do
if CodificaIzq[StrToInt(num[1])][i-3]='A' then
matrix:=matrix+EAN_izqA[StrToInt(num[i])]
else
matrix:=matrix+EAN_izqB[Strtoint(num[i])];
matrix:=matrix+'0x0x0'; //Barra de en medio
matrix:=matrix+Ean_dcha[StrToint(num[8])];
matrix:=matrix+Ean_dcha[StrToint(num[9])];
matrix:=matrix+Ean_dcha[StrToint(num[10])];
matrix:=matrix+Ean_dcha[StrToint(num[11])];
matrix:=matrix+Ean_dcha[StrToint(num[12])];
matrix:=matrix+Ean_dcha[StrToint(num[13])];
matrix:=matrix+'x0x'; //Barrafinal
Dibujar(matrix);
end;
8: begin
// EanCorrecto(num,valor);
DBNewEditJL8.text:=num;
matrix:=matrix+'x0x'; //Barra inicio
matrix:=matrix+EAN_izqA[Strtoint(num[1])];
matrix:=matrix+EAN_izqA[Strtoint(num[2])];
matrix:=matrix+EAN_izqA[Strtoint(num[3])];
matrix:=matrix+EAN_izqA[Strtoint(num[4])];
matrix:=matrix+'0x0x0'; //Barra del centro
matrix:=matrix+Ean_dcha[StrToint(num[5])];
matrix:=matrix+Ean_dcha[StrToint(num[6])];
matrix:=matrix+Ean_dcha[StrToint(num[7])];
matrix:=matrix+Ean_dcha[StrToint(num[8])];
matrix:=matrix+'x0x'; //Barrafinal
Dibujar(matrix);
end;
else
showmessage('Longitud del código no valida');
end;
end;
procedure TFArticulos.ComboBoxExt1Exit(Sender: TObject);
//------------------------------------------------------------------------------
//********************************************************[ Exit Impuestos ]****
// Salimos de elgir el tipo de impuesto pero elvalor que manda es el impuesto del cliente
//------------------------------------------------------------------------------
begin
if DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO1').AsString=ComboBoxExt1.Text then DBNewEditJL21.Field.Value:=1;
if DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO2').AsString=ComboBoxExt1.Text then DBNewEditJL21.Field.value:=2;
if DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO3').AsString=ComboBoxExt1.Text then DBNewEditJL21.Field.value:=3;
if DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO4').AsString=ComboBoxExt1.Text then DBNewEditJL21.Field.value:=4;
end;
Procedure TFArticulos.Dibujar(matrix:string);
//------------------------------------------------------------------------------
//***************************************************************[ Dibujar ]****
// Dibuja el código de barras
//------------------------------------------------------------------------------
var
i:integer;
begin
Image2.Canvas.Brush.Color:=clwhite;
Image2.Canvas.Fillrect(rect(0,0,Image2.width,Image2.Height));
Image2.Canvas.Pen.Color:=clBlack;
For i:=1 to length(matrix) do
if matrix[i]='1' then Image2.Canvas.Polyline([Point(10+i,10),Point(10+i,73)])
else
if matrix[i]='x' then
Image2.Canvas.Polyline([point(10+i,10),Point(10+i,78)]);
if length(DBNewEditJL8.text)=13 then
begin
//Camiar 70 por 50 si falla
Image2.Canvas.Font:=DBNewEditJL8.Font;
Image2.Canvas.TextOut(3,73,DBNewEditJL8.text[1]);
Image2.Canvas.TextOut(17,73,copy(DBNewEditJL8.Text,2,6));
Image2.Canvas.TextOut(63,73,copy(DBNewEditJL8.text,8,6));
end
else
if length(DBNewEditJL8.text)=8 then
begin
image2.Canvas.Font:=DBNewEditJL8.Font;
image2.Canvas.TextOut(16,70,copy(DBNewEditJL8.Text,1,4));
image2.Canvas.TextOut(48,70,copy(DBNewEditJL8.text,5,4));
end;
end;
procedure TFArticulos.DSPrincipalDataChange(Sender: TObject; Field: TField);
//------------------------------------------------------------------------------
//****************************************************[ Change DSPrincipal ]****
//------------------------------------------------------------------------------
begin
if (FArticulos.Active) and (not (DsPrincipal.DataSet.State in [dsEdit, dsInsert])) then
begin
if not dm.IBDSTOCK.IsEmpty then
begin
ActQuery(IBQuery1,'SELECT SUM(STOCK.EXISTENCIAS) AS FIELD_1 FROM STOCK WHERE'+
' (STOCK.CODPROD = '+QuotedStr(DBNewEditJL1.Text)+') AND ((STOCK.ACTIVO = '+QuotedStr('S')+')'+
' OR (STOCK.ACTIVO IS NULL)) AND (STOCK.EXISTENCIAS >= 1)');
if IBQuery1.FieldByName('FIELD_1').IsNull then Label11.Caption:='[ 0 ]'
else Label11.Caption:='[ ' +IBQuery1.FieldByName('FIELD_1').AsString+' ]';
end else Label11.Caption:='[ 0 ]';
if PC.ActivePageIndex=1 then SpeedButtonBC8Click(Sender);
if PC.ActivePageIndex=2 then SpeedButtonBC7Click(Sender);
Panel11.Caption:='Artículo: [ '+DBNewEditJL2.Text+' ]';
end else Panel11.Caption:='Artículo: [ '+'Tabla en ediciíon'+' ]';
end;
procedure TFArticulos.DBNewEditJL8Change(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Change de EAN 13 ]****
// Cuando canbia el Ean 13 y no esta en edición o inserción de datos
//------------------------------------------------------------------------------
begin
if (DBNewEditJL8.Text<>'') then
if FArticulos.Active then
if ( not (DsPrincipal.DataSet.State in [dsInsert, dsEdit])) then
begin
codifica(DBNewEditJL8.text,1);
end;
end;
procedure TFArticulos.DBNewEditJL8Exit(Sender: TObject);
//------------------------------------------------------------------------------
//********************************************************[ Exit de EAN 13 ]****
// Cuando sale del Ean 13
//------------------------------------------------------------------------------
begin
if (Length(DBNewEditJL8.Text)>=12) and (DBNewEditJL8.Text<>'') then
begin
//Funcion que comprueba el digito de control del EAM13 y lo cambia si es necesario
DBNewEditJL8.Text:=Copy(DBNewEditJL8.Text,1,12)+IntToStr(Calcula_digito_de_control_EAN13(DBNewEditJL8.Text));
//Cargamos la imagen con el código de barras
codifica(DBNewEditJL8.text,1);
end else ShowMessage('Debe contener como mínimo 12 digitos');
end;
procedure TFArticulos.EbusquedaChange(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************[ Mientras se escribe en busqueda ]******
//------------------------------------------------------------------------------
begin
BBuscarClick(sender);
end;
procedure TFArticulos.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;
//Nos aseguramos de cargar las Familias
DbComboBoxExt2.Items.Clear;
DsFamilias.DataSet.First;
while not DsFamilias.DataSet.Eof do
begin
DbComboBoxExt2.Items.AddObject(DsFamilias.DataSet.FieldByName('CODIGO').AsString,TObject(DsFamilias.DataSet.FieldByName('DESCRIPCION').AsString));//TObject(Clientescodigo.AsInteger));
DsFamilias.DataSet.Next;
end;
//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;
//Asignamos los colores de los ComboboxExt
ComboBoxExt1.ColorA:=COLOR1GRID;
ComboBoxExt1.ColorB:=COLOR2GRID;
DbComboBoxExt2.ColorA:=COLOR1GRID;
DbComboBoxExt2.ColorB:=COLOR2GRID;
if ComboBoxExt1.Items.Count=0 then
begin
if not DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO1').IsNull then ComboBoxExt1.Items.Add(DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO1').AsString);
if not DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO2').IsNull then ComboBoxExt1.Items.Add(DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO2').AsString);
if not DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO3').IsNull then ComboBoxExt1.Items.Add(DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO3').AsString);
if not DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO4').IsNull then ComboBoxExt1.Items.Add(DM.IBDCONFI.FieldByName('DESCRIPCIONIMPUESTO4').AsString);
end;
DBNewEditJL8Change(Sender);
DSPrincipalDataChange(Sender,DBNewEditJL1.Field);
end;
procedure TFArticulos.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 TFArticulos.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
//[ 5]----------------------------[ Tabs de page control en color ]-------------
Datos.Color:=clMoneyGreen; //verde pastel
Imagenes.Color:=clSkyBlue; //Azul Pastel
Notas.Color:=clInfoBk; //Amarillo pastel
Facturado.Color:=$0099CCFF; //Color naranja
//[ 5]----------------------------[ Tabs de page control en color ]-------------
{Cosas que queremos que haga según se inicie el Form}
PC.ActivePageIndex:=0;
end;
procedure TFArticulos.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 TDbComboBoxExt)
or (ActiveControl is TComboBoxExt)
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 TFArticulos.FormPaint(Sender: TObject);
//------------------------------------------------------------------------------
//***************************************************************[ OnPaint ]****
// Aseguramos que los DBIBCheckbox esten en negrita y que el panel que contiene
// el coste sólo se vea si el usuario tiene un nivel 7 o superior
//------------------------------------------------------------------------------
begin
DBIBCheckbox1.Font.Style:= [fsBold];
DBIBCheckbox2.Font.Style:= [fsBold];
DBIBCheckbox3.Font.Style:= [fsBold];
DBIBCheckbox4.Font.Style:= [fsBold];
if Nivel>=7 then Panel5.Visible:=true else Panel5.Visible:=False; //El nivel de acceoso al modulo es 6
end;
procedure TFArticulos.PCDrawTab(Control: TCustomTabControl; TabIndex: Integer;
const Rect: TRect; Active: Boolean);
//------------------------------------------------------------------------------
//************************************************[ COLORES PAGECONTROL ]*******
//------------------------------------------------------------------------------
var
//[ 6]----------------[ Para poder tener tabs del page control en color]--------
AText: string;
APoint: TPoint;
//[ 6]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]--------
begin
//[ 7]----------------[ Para poder tener tabs del page control en color]--------
with (Control as TPageControl).Canvas do
begin
case TabIndex of
0: brush.Color:=clMoneyGreen;
1: brush.Color:=clSkyBlue;
2: brush.Color:=clInfoBk;
3: Brush.Color:=$0099CCFF;
end;
PC.Canvas.Rectangle(Rect);
PC.Canvas.Brush.Color:=Control.Canvas.Brush.Color;
//Control.Canvas.TextOut(Rect.left+5,Rect.top+3,PageControl1.Pages[tabindex].Caption);
// pinta a parte interna (tabsheet)
PC.Pages[TabIndex].brush.Color := Control.Canvas.brush.Color;
PC.Pages[TabIndex].Repaint;
// Brush.Color := ClGreen;
FillRect(Rect);
AText := TPageControl(Control).Pages[TabIndex].Caption;
with Control.Canvas do
begin
APoint.x := (Rect.Right - Rect.Left) div 2 - TextWidth(AText) div 2;
APoint.y := (Rect.Bottom - Rect.Top) div 2 - TextHeight(AText) div 2;
TextRect(Rect, Rect.Left + APoint.x, Rect.Top + APoint.y, AText);
end;
end;
//[ 7]--FIN SECCIÓN---[ Para poder tener tabs del page control en color]--------
end;
procedure TFArticulos.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');
end;
end;
procedure TFArticulos.SBBuscarClick(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Abrir Busqueda ]******
//------------------------------------------------------------------------------
begin
GBBuscar.Visible:=True;
Ebusqueda.SetFocus;
end;
procedure TFArticulos.SBCancelarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*****************************************************[ Cancelar Proceso]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Cancel;
IBT.RollbackRetaining; //Donde IBT es el nombre de su Ibtrasaction, con ruta
end;
procedure TFArticulos.SBConfirmarClick(Sender: TObject);
//------------------------------------------------------------------------------
//********************************************************[ Grabar datos ]******
//------------------------------------------------------------------------------
begin
try
DSPrincipal.DataSet.Post;
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:[ UArticulos ] 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 TFArticulos.SBImprimirClick(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Abrir Imprimir ]******
//------------------------------------------------------------------------------
begin
GBImprimir.Visible:=True;
end;
procedure TFArticulos.SBMas1Click(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************************[ Avanzar un registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Next;
end;
procedure TFArticulos.SBMasXClick(Sender: TObject);
//------------------------------------------------------------------------------
//*************************************************[ Avanzar x Registros ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.MoveBy(SEMobeByX.Value);
end;
procedure TFArticulos.SBMenos1Click(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************[ Retroceder 1 registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Prior;
end;
procedure TFArticulos.SBMenosxClick(Sender: TObject);
//------------------------------------------------------------------------------
//**********************************************[ Retroceder x Registros ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.MoveBy(-SEMobeByX.Value);
end;
procedure TFArticulos.SbModificarClick(Sender: TObject);
//------------------------------------------------------------------------------
//*******************************************[ Editar el actual registro ]******
//------------------------------------------------------------------------------
begin
if DsPrincipal.DataSet.IsEmpty<>true then
begin
DSPrincipal.DataSet.Edit;
{ aquí posicionar en el primer control
---Ejemplo---
Dbedit.setfocus;}
end else ShowMessage('No hay tregistros disponibles para editar')
end;
procedure TFArticulos.SbNuevoClick(Sender: TObject);
//------------------------------------------------------------------------------
//*******************************************[ Creamos un nuevo registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Insert;
DBIBCheckbox1.Font.Style:= [fsBold];
DBIBCheckbox2.Font.Style:= [fsBold];
DBIBCheckbox3.Font.Style:= [fsBold];
DBIBCheckbox4.Font.Style:= [fsBold];
DBNewEditJL1.SetFocus;
end;
procedure TFArticulos.SBPrimeroClick(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************[ Ir al Primer Registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.First;
end;
procedure TFArticulos.SBUltimoClick(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************[ Ir al último registro ]******
//------------------------------------------------------------------------------
begin
DSPrincipal.DataSet.Last;
end;
procedure TFArticulos.SB_SalirClick(Sender: TObject);
//------------------------------------------------------------------------------
//******************************************************[ Salir Del Form ]******
//------------------------------------------------------------------------------
begin
FArticulos.Close;
end;
procedure TFArticulos.SpeedButtonBC2Click(Sender: TObject);
//------------------------------------------------------------------------------
//****************************************************[ Modificar Imagenes ]****
//------------------------------------------------------------------------------
begin
SpeedButtonBC8Click(sender);
if DBNewEditJL1.Text<>'' then
begin
VarSNomMod:='ARTICULOS';
VarsCod:=DBNewEditJL1.Field.Value;
ActIbdataset(DM.IBDIMAGENES,'SELECT * FROM IMAGENES WHERE (IMAGENES.NOMBREMODULO = '+QuotedStr('ARTICULOS')+') AND (IMAGENES.CODIGO = '+QuotedStr(DBNewEditJL1.Text)+')');
FImagenes.Show;
end else ShowMessage('Debe crear y seleccionar el artículo para poder modificar/borrar la imagen');
end;
procedure TFArticulos.SpeedButtonBC3Click(Sender: TObject);
//------------------------------------------------------------------------------
//**********************************************************[ Nueva Imagen ]****
//------------------------------------------------------------------------------
begin
SpeedButtonBC6Click(sender);
if DBNewEditJL1.Text<>'' then
begin
VarSNomMod:='ARTICULOS';
VarsCod:=DBNewEditJL1.Field.Value;
Fimagenes.Show;
Fimagenes.SbNuevoClick(Sender);
Fimagenes.DBNewEditJL3.SetFocus;
end else ShowMessage('Debe crear y seleccionar el cliente para poder crearle una nueva dirección');
end;
procedure TFArticulos.SpeedButtonBC4Click(Sender: TObject);
//------------------------------------------------------------------------------
//*******************************************************[ Modificar Notas ]****
//------------------------------------------------------------------------------
begin
SpeedButtonBC7Click(sender);
if DBNewEditJL1.Text<>'' then
begin
VarSNomMod:='ARTICULOS';
VarsCod:=DBNewEditJL1.Field.Value;
ActIbdataset(DM.IBDNOTAS,'SELECT * FROM NOTAS WHERE (NOTAS.NOMBREMODULO = '+QuotedStr('ARTICULOS')+') AND (NOTAS.CODIGO = '+QuotedStr(DBNewEditJL1.Text)+')');
FNotas.Show;
end else ShowMessage('Debe crear y seleccionar el artículo para poder modificar/borrar la nota');
end;
procedure TFArticulos.SpeedButtonBC5Click(Sender: TObject);
//------------------------------------------------------------------------------
//************************************************************[ Nueva Nota ]****
//------------------------------------------------------------------------------
begin
SpeedButtonBC7Click(sender);
if DBNewEditJL1.Text<>'' then
begin
VarSNomMod:='ARTICULOS';
VarsCod:=DBNewEditJL1.Field.Value;
FNotas.Show;
Fnotas.SbNuevoClick(Sender);
Fnotas.DBNewEditJL3.SetFocus;
end else ShowMessage('Debe crear y seleccionar el cliente para poder crearle una nueva dirección');
end;
procedure TFArticulos.SpeedButtonBC6Click(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ PC Datos ]****
//------------------------------------------------------------------------------
begin
PC.ActivePageIndex:=0;
DBNavigator1.Enabled:=False;
end;
procedure TFArticulos.SpeedButtonBC7Click(Sender: TObject);
//------------------------------------------------------------------------------
//**************************************************************[ PC Notas ]****
//------------------------------------------------------------------------------
begin
ActQuery(DM.IBQNOTAS,'SELECT * FROM NOTAS WHERE (NOTAS.NOMBREMODULO = '+QuotedStr('ARTICULOS')+') AND (NOTAS.CODIGO = '+QuotedStr(DBNewEditJL1.Text)+')');
if not DM.IBQNOTAS.IsEmpty then
begin
DBNavigator1.DataSource:=DM.DSNotas;
DBNavigator1.Enabled:=True;
//Gride de notas
TStringGrid(DBGrid2).DefaultRowHeight :=40;
TStringGrid(DBGrid2).RowHeights[0]:=20;
end else DM.IBQNOTAS.Active:=False;
PC.ActivePageIndex:=2;
end;
procedure TFArticulos.SpeedButtonBC8Click(Sender: TObject);
//------------------------------------------------------------------------------
//***********************************************************[ PC imagenes ]****
//------------------------------------------------------------------------------
begin
ActQuery(DM.IBQIMAGENES,'SELECT * FROM IMAGENES WHERE (IMAGENES.NOMBREMODULO = '+QuotedStr('ARTICULOS')+') AND (IMAGENES.CODIGO = '+QuotedStr(DBNewEditJL1.Text)+')');
if not DM.IBQIMAGENES.IsEmpty then
begin
DBNavigator1.DataSource:=DM.DSImagenes;
DBNavigator1.Enabled:=True;
//Gride de imagenes
TStringGrid(DBGrid1).DefaultRowHeight :=74;
TStringGrid(DBGrid1).RowHeights[0]:=20;
end else DM.IBQIMAGENES.Active:=False;
PC.ActivePageIndex:=1;
end;
procedure TFArticulos.SpeedButtonBC9Click(Sender: TObject);
//------------------------------------------------------------------------------
//**********************************************************[ PC facturado ]****
//------------------------------------------------------------------------------
begin
PC.ActivePageIndex:=3;
DBNavigator1.Enabled:=False;
end;
procedure TFArticulos.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.