bdtemporal.~pas.svn-base
来自「example delphi with database」· SVN-BASE 代码 · 共 305 行
SVN-BASE
305 行
unit BDTemporal;
interface
uses TDataConexion,ADODB,DB,SysUtils,Variants;
type
TTemporal = class
private
id:integer;
codBarra : string[100];
precio : real;
idusuario : integer;
fecha : string;
nomArticulo : string;
cantidad : integer;
idarticulo : integer;
Query : TADOQuery;
StoredProc: TADOStoredProc;
public
constructor Create;
destructor Destroy;override;
function Insertar():integer;
function Eliminar():integer;
function EliminarTabla():boolean;
function Listar():boolean;
function ActualizarPrecio():boolean;
function ActualizarCantidad():boolean;
function Total():real;
function RestaStock(idarticulo:integer):integer;
procedure setCodBarra(cod:string);
procedure setPrecio(precio:string);
procedure setIdUsuario(id:integer);
procedure setIdTemporal(id:integer);
procedure setFecha(fecha:string);
procedure setIdArticulo(id:integer);
procedure setNomArticulo(nombre:string);
procedure setCantidad(cant:integer);
function getIdTemporal():integer;
function getCodBarra():string;
function getPrecio():string;
function getIdUsuario():integer;
function getFecha():string;
function actualizarVentas():boolean;
function getIdArticulo():integer;
function getNomArticulo():string;
function getCantidad():integer;
end;
implementation
constructor TTemporal.Create();
begin
inherited Create;
Query:=TADOQuery.Create(nil);
Query.Connection:=Database.Conexion;
StoredProc:=TADOStoredProc.Create(nil) ;
StoredProc.Connection:=Database.Conexion;
codBarra:='';
precio:=0;
idusuario:=-1;
fecha:='';
end;
function TTemporal.Insertar():integer;
var resultado:integer;
begin
StoredProc.ProcedureName:='alta_temporal';
StoredProc.Parameters.CreateParameter('@ccod_barra',ftString,pdInput,100,codBarra);
StoredProc.Parameters.CreateParameter('@fprecio',ftFloat,pdInput,1,precio);
StoredProc.Parameters.CreateParameter('@ffecha',ftString,pdInput,10,fecha);
StoredProc.Parameters.CreateParameter('@isuaurio',ftInteger,pdInput,1,idusuario);
StoredProc.Parameters.CreateParameter('@cantidad',ftInteger,pdInput,1,cantidad);
StoredProc.Parameters.CreateParameter('@nom',ftString,pdInput,100,nomArticulo);
StoredProc.Parameters.CreateParameter('@idarticulo',ftInteger,pdInput,1,idarticulo);
StoredProc.Parameters.CreateParameter('@retorno',ftInteger,pdInputOutput,0,0);
StoredProc.Prepared:=True;
StoredProc.ExecProc;
resultado:=StoredProc.Parameters.ParamValues['@retorno'];
StoredProc.Parameters.Clear;
Insertar:=resultado;
end;
function TTemporal.Eliminar():integer;
var resultado:integer;
begin
StoredProc.ProcedureName:='baja_temporal_registro';
StoredProc.Parameters.CreateParameter('@iid',ftInteger,pdInput,1,id);
StoredProc.Parameters.CreateParameter('@retorno',ftInteger,pdInputOutput,0,0);
StoredProc.Prepared:=True;
StoredProc.ExecProc;
resultado:=StoredProc.Parameters.ParamValues['@retorno'];
StoredProc.Parameters.Clear;
Eliminar:=resultado;
end;
function TTemporal.EliminarTabla():boolean;
var resultado:integer;
begin
StoredProc.ProcedureName:='baja_temporal';
StoredProc.Parameters.CreateParameter('@retorno',ftInteger,pdInputOutput,0,0);
StoredProc.Prepared:=True;
StoredProc.ExecProc;
resultado:=StoredProc.Parameters.ParamValues['@retorno'];
StoredProc.Parameters.Clear;
if resultado = 0 then
EliminarTabla:=True
else
EliminarTabla := False;
end;
function TTemporal.Listar():boolean;
begin
Query.Close;
Query.SQL.Clear;
Query.Parameters.Clear;
Query.SQL.Add('select * from temporal');
Query.Prepared:=True;
Query.Open;
if not Query.IsEmpty then
begin
Query.Parameters.Clear;
Database.DSource.DataSet := Query; //no debo liberar el query
Listar:=True;
end
else
begin
Query.Parameters.Clear;
Listar:=False;
end;
end;
function TTemporal.Total():real;
begin
Query.Close;
Query.SQL.Clear;
Query.Parameters.Clear;
Query.SQL.Add('select sum(precio_venta*cantidad) as total from temporal');
Query.Prepared:=True;
Query.Open;
if not Query.IsEmpty then
begin
Query.Parameters.Clear;
Total:=Query.FieldValues['total'];
end
else
begin
Query.Parameters.Clear;
Total:=0;
end;
end;
function TTemporal.RestaStock(idarticulo:integer):integer;
begin
Query.Close;
Query.SQL.Clear;
Query.Parameters.Clear;
Query.Parameters.CreateParameter('idArticulo',ftInteger,pdInput,1,idarticulo);
Query.SQL.Add('select sum(cantidad) as resta from temporal where idarticulo=:idArticulo');
Query.Prepared:=True;
Query.Open;
if not Query.IsEmpty then
begin
Query.Parameters.Clear;
RestaStock:=Query.FieldValues['resta'];
end
else
begin
Query.Parameters.Clear;
RestaStock:=0;
end;
end;
function TTemporal.ActualizarPrecio():boolean;
var resultado:integer;
begin
StoredProc.ProcedureName:='actualizar_precio_temporal';
StoredProc.Parameters.CreateParameter('@id',ftInteger,pdInput,1,id);
StoredProc.Parameters.CreateParameter('@precio',ftFloat,pdInput,1,precio);
StoredProc.Parameters.CreateParameter('@retorno',ftInteger,pdInputOutput,0,0);
StoredProc.Prepared:=True;
StoredProc.ExecProc;
resultado:=StoredProc.Parameters.ParamValues['@retorno'];
StoredProc.Parameters.Clear;
if resultado <> 0 then
ActualizarPrecio:=False
else
ActualizarPrecio:=True;
end;
function TTemporal.ActualizarCantidad():boolean;
var resultado:integer;
begin
StoredProc.ProcedureName:='actualizar_cantidad_temporal';
StoredProc.Parameters.CreateParameter('@id',ftInteger,pdInput,1,id);
StoredProc.Parameters.CreateParameter('@cantidad',ftInteger,pdInput,1,cantidad);
StoredProc.Parameters.CreateParameter('@retorno',ftInteger,pdInputOutput,0,0);
StoredProc.Prepared:=True;
StoredProc.ExecProc;
resultado:=StoredProc.Parameters.ParamValues['@retorno'];
StoredProc.Parameters.Clear;
if resultado <> 0 then
ActualizarCantidad:=False
else
ActualizarCantidad:=True;
end;
procedure TTemporal.setCodBarra(cod:String);
begin
self.codBarra:=cod;
end;
procedure TTemporal.setPrecio(precio:String);
var code:integer;
begin
Val(precio,self.precio,code);
end;
procedure TTemporal.setIdUsuario(id:Integer);
begin
self.idusuario:=id;
end;
procedure TTemporal.setFecha(fecha:string);
begin
self.fecha:=fecha;
end;
procedure TTemporal.setIdArticulo(id:integer);
begin
self.idarticulo:=id;
end;
procedure TTemporal.setNomArticulo(nombre:string);
begin
self.nomArticulo:=nombre;
end;
procedure TTemporal.setCantidad(cant:integer);
begin
self.cantidad:=cant;
end;
procedure TTemporal.setIdTemporal(id:integer);
begin
self.id:=id;
end;
function TTemporal.getIdTemporal():integer;
begin
getIdTemporal:=self.id;
end;
function TTemporal.getCodBarra():String;
begin
getcodBarra:=self.codBarra;
end;
function TTemporal.getPrecio():String;
begin
getPrecio:=FloatToStr(self.precio);
end;
function TTemporal.getIdUsuario():Integer;
begin
getIdUsuario:=self.idusuario;
end;
function TTemporal.getFecha():string;
begin
getFecha:=self.fecha;
end;
function TTemporal.getIdArticulo():integer;
begin
getIdArticulo:=self.idarticulo;
end;
function TTemporal.getNomArticulo():string;
begin
getNomArticulo:=self.nomArticulo;
end;
function TTemporal.getCantidad():integer;
begin
getCantidad:=self.cantidad;
end;
function TTemporal.actualizarVentas():boolean;
var resultado:integer;
begin
StoredProc.ProcedureName:='actualizar_ventas';
StoredProc.Parameters.CreateParameter('@retorno',ftInteger,pdInputOutput,0,0);
StoredProc.Prepared:=True;
StoredProc.ExecProc;
resultado:=StoredProc.Parameters.ParamValues['@retorno'];
StoredProc.Parameters.Clear;
if (resultado = 0) then
actualizarVentas := True
else
actualizarVentas := False;
end;
destructor TTemporal.Destroy();
begin
StoredProc.Connection:=Nil;
StoredProc.Free;
inherited Destroy;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?