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

📄 tempfile.tmp

📁 example delphi with database
💻 TMP
字号:
unit BDArticulo;

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

type
      TArticulo = class 
      private
        codBarra : string[100];
        nombre : string[100];
        descripcion : string[200];
<<<<<<< .mine
        precio : real;
        estado : char;
=======
        precio : real;
        estado : string;
>>>>>>> .r29
        idarticulo : integer;
        Query : TADOQuery;
        StoredProc: TADOStoredProc;
      public
      constructor Create;
      destructor Destroy;override;
      function Insertar():integer;
      function Eliminar():integer;
      function Modificar():integer;
      function Buscar():boolean;
      function Listar():boolean;
      procedure setCodBarra(cod:string);
      procedure setNombre(nombre:string);
      procedure setDescripcion(desc:string);
      procedure setPrecio(precio:string);
      procedure setEstado(estado:char);
      procedure setIdArticulo(id:integer);
      function getNombre():string;
      function getCodBarra():string;
      function getPrecio():string;
      function getDescripcion():string;
      function getEstado():string;
      function getIdArticulo():integer;
      end;

implementation

constructor TArticulo.Create();
begin
   inherited Create;
   Query:=TADOQuery.Create(nil);
   Query.Connection:=Database.Conexion;
   StoredProc:=TADOStoredProc.Create(nil) ;
   StoredProc.Connection:=Database.Conexion;
   codBarra:='';
   nombre:='';
   descripcion:='';
   precio:=0;
   estado:=' '; //chequear estado
   idarticulo:=-1;
end;

function TArticulo.Insertar():integer;
var resultado:integer;
begin
      StoredProc.ProcedureName:='alta_articulo';
      StoredProc.Parameters.CreateParameter('@cnombre',ftString,pdInput,100,nombre);
      StoredProc.Parameters.CreateParameter('@ccod_barra',ftString,pdInput,100,codBarra);
      StoredProc.Parameters.CreateParameter('@tdescripcion',ftString,pdInput,100,descripcion);
      StoredProc.Parameters.CreateParameter('@fprecio',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;
      Insertar:=resultado;
end;
function TArticulo.Eliminar():integer;
var resultado:integer;
begin
      StoredProc.ProcedureName:='baja_articulo';
      StoredProc.Parameters.CreateParameter('@ccod_barra',ftString,pdInput,100,codbarra);
      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 TArticulo.Modificar():integer;
var resultado:integer;
begin
      StoredProc.ProcedureName:='modificar_articulo';
      StoredProc.Parameters.CreateParameter('@cnombre',ftString,pdInput,100,nombre);
      StoredProc.Parameters.CreateParameter('@ccod_barra',ftString,pdInput,100,codBarra);
      StoredProc.Parameters.CreateParameter('@tdescripcion',ftString,pdInput,100,descripcion);
      StoredProc.Parameters.CreateParameter('@fprecio',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;
      Modificar:=resultado;
end;

function TArticulo.Buscar():boolean;
begin
      Query.Close;
      Query.SQL.Clear;
      Query.Parameters.CreateParameter('codigoBarra',ftString,pdInput,100,CodBarra);
      Query.SQL.Add('select nombre,descripcion,precio from articulo where cod_barra=:codigoBarra');
      Query.Prepared:=True;
      Query.Open;
       if not Query.IsEmpty then
       begin
        self.nombre:=Query.FieldValues['nombre'];
        self.descripcion:=Query.FieldValues['descripcion'];
        self.precio:=Query.FieldValues['precio'];
//        estado:=Query.FieldValues['estado']; //hay que pasar el esta a un char
        Query.Parameters.Free;
        Buscar:=True;
        end
        else
                Buscar:=False;
end;

function TArticulo.Listar():boolean;
begin
      Query.Close;
      Query.SQL.Clear;
      Query.Parameters.Clear;
      Query.SQL.Add('select cod_barra,nombre,descripcion from articulo and estado=''A'''); //agregarle que estado sea igual a A
      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;

procedure TArticulo.setCodBarra(cod:string);
begin
      self.CodBarra := cod;

end;

procedure TArticulo.setNombre(nombre:string);
begin
         self.Nombre := nombre;
end;

procedure TArticulo.setDescripcion(desc:string);
begin
       self.Descripcion := desc;
end;

procedure TArticulo.setPrecio(precio:string);
var code:integer;
begin
      Val(precio,self.precio,code);
end;

procedure TArticulo.setEstado(estado:char);
begin
     self.estado := estado;
end;

procedure TArticulo.setIdArticulo(id:integer);
begin
     self.idarticulo := id;
end;

function TArticulo.getNombre():string;
begin
       getNombre := self.Nombre;
end;

function TArticulo.getCodBarra():string;
begin
       getCodBarra := self.CodBarra;
end;

function TArticulo.getPrecio():string;
begin
       getPrecio := FloatToStr(self.precio);
end;

function TArticulo.getDescripcion():string;
begin
       getDescripcion := self.Descripcion;
end;

function TArticulo.getEstado():string;
begin
       getEstado := self.estado;
end;

function TArticulo.getIdArticulo():integer;
begin
      getIdArticulo := self.idarticulo;
end;
destructor TArticulo.Destroy();
begin
       StoredProc.Connection:=Nil;
       StoredProc.Free;
     //  Query.Connection:=Nil;
      // Query.Free;
       inherited Destroy;
end;

end.

⌨️ 快捷键说明

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