Advertisement
FacundoCruz

Principal

Oct 16th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.47 KB | None | 0 0
  1. unit u_ABMProductos;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, u_Global, utiles;
  9.  
  10. type
  11.  
  12.   { TfrmABM }
  13.  
  14.   TfrmABM = class(TForm)
  15.     btnSalir: TButton;
  16.     btnABM: TButton;
  17.     edtStock: TEdit;
  18.     edtPrecio: TEdit;
  19.     edtDescripcion: TEdit;
  20.     edtCodigo: TEdit;
  21.     Label1: TLabel;
  22.     Label2: TLabel;
  23.     Label3: TLabel;
  24.     Label4: TLabel;
  25.     lblTitulo: TLabel;
  26.     procedure btnABMClick(Sender: TObject);
  27.     procedure btnSalirClick(Sender: TObject);
  28.     procedure FormClick(Sender: TObject);
  29.   private
  30.  
  31.   public
  32.     procedure inicializarComponentes();
  33.     procedure leerRegistro(var P:TProducto);
  34.   end;
  35.  
  36. var
  37.   frmABM: TfrmABM;
  38.  
  39. implementation
  40.  
  41. {$R *.lfm}
  42.  
  43.  
  44. { TfrmABM }
  45.  
  46. procedure TfrmABM.inicializarComponentes();
  47. begin
  48.   edtCodigo.Text := '';
  49.   edtDescripcion.Text := '';
  50.   edtPrecio.Text := '';
  51.   edtStock.Text := '';
  52. end;
  53.  
  54. procedure TfrmABM.leerRegistro(var P: TProducto);
  55. begin
  56.   try
  57.     p.codigo:= StrToInt(edtCodigo.Text);
  58.     p.precio:= StringToFloat(edtPrecio.Text);
  59.     p.stock := StrToInt(edtStock.Text);
  60.     if edtDescripcion.Text = '' then
  61.         Raise EConvertError.Create('Debe ingresar la descripción');
  62.     P.descripcion := edtDescripcion.Text;
  63.   except
  64.     on e: EConvertError do
  65.        Raise EConvertError.Create('Datos incorrectos ' + e.Message);
  66.     on e: Exception do
  67.        Raise Exception.Create('Error inesperado ' + e.Message);
  68.    end;
  69. end;
  70.  
  71. procedure TfrmABM.btnABMClick(Sender: TObject);
  72. var
  73.   producto : TProducto;
  74.   posicion : longInt;
  75. begin
  76.   try
  77.       leerRegistro(producto);
  78.       posicion := buscarProducto(f,producto.codigo);
  79.  
  80.       if btnABM.Caption='Alta' then
  81.          if (posicion = NO_ENCONTRADO) then
  82.            begin
  83.              altaProducto(f,producto);
  84.            end
  85.          else
  86.            ShowMessage('El producto ya existe…')
  87.       else
  88.         if btnABM.Caption='Modificar' then
  89.            begin
  90.              modificarProducto(f,producto,posicion);
  91.              close;
  92.            end
  93.         else
  94.             ShowMessage('Operación inválida...');
  95.       inicializarComponentes();
  96.   except
  97.     on e: EConvertError do
  98.        showMessage(e.Message);
  99.     on e: Exception do
  100.        showMessage('Error inesperado: ' +  E.ClassName + #13#10 + e.Message);
  101.   end;
  102. end;
  103.  
  104. procedure TfrmABM.btnSalirClick(Sender: TObject);
  105. begin
  106.   close;
  107. end;
  108.  
  109.  
  110. end.
  111.                                                      
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement