⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bdtemporal.pas.svn-base

📁 example delphi with database
💻 SVN-BASE
字号:
unit BDTemporal;

interface
uses TDataConexion,ADODB,DB,SysUtils,Variants;
type

    TTemporal = class
      private
        id:integer;
        codBarra : string[100];
        precio : real;
        idusuario : integer;
        fecha : string;
        hora : 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 ActualizarMovimientos():boolean;
      function InformeMovimientos(fecha:string):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 setHora(hora: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('@cfecha',ftString,pdInput,10,fecha);
      StoredProc.Parameters.CreateParameter('@chora',ftString,pdInput,8,hora);
      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;

function TTemporal.ActualizarMovimientos():boolean;
var resultado: integer;
begin
      StoredProc.ProcedureName:='alta_movimiento';
      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
          ActualizarMovimientos:=False
      else
          ActualizarMovimientos:=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.setHora(hora:string);
begin
    self.hora:=hora;
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;

function TTemporal.InformeMovimientos(fecha:string) : boolean;
begin
      Query.Close;
      Query.SQL.Clear;
      Query.Parameters.Clear;
      Query.Parameters.CreateParameter('fecha',ftString,pdInput,10,fecha);
      Query.SQL.Add('select cod_barra from movimiento');
      //Query.SQL.Add('select movimiento.cod_barra, movimiento.precio_venta,movimiento.hora,articulo.nombre as articulo,movimiento.cantidad,articulo.nombre as usuario');
      //Query.SQL.Add(' from articulo,movimiento,usuario where movimiento.fecha=:fecha');
      //Query.SQL.Add(' and articulo.cod_barra = movimiento.cod_barra and movimiento.idusuario = usuario.idusuario order by movimiento.hora');
      Query.Prepared:=True;
      Query.Open;
      Query.SQL.Text;
       if not Query.IsEmpty then
       begin
                Query.Parameters.Clear;
                InformeMovimientos:=True;
       end
       else
       begin
                Query.Parameters.Clear;
                InformeMovimientos:=False;
       end;
end;

destructor TTemporal.Destroy();
begin
       StoredProc.Connection:=Nil;
       StoredProc.Free;
       inherited Destroy;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -