Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
- Grids;
- type
- { TForm1 }
- TForm1 = class(TForm)
- btnagregar: TButton;
- btnsalir: TButton;
- btnprocesar: TButton;
- btnbuscar: TButton;
- betnvolver: TButton;
- combotipo: TComboBox;
- edtbuscar: TEdit;
- edtcodigo: TEdit;
- edtstock: TEdit;
- edtprecio: TEdit;
- Label1: TLabel;
- Label10: TLabel;
- Label11: TLabel;
- Label12: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- Label8: TLabel;
- Label9: TLabel;
- StringGrid1: TStringGrid;
- procedure btnagregarClick(Sender: TObject);
- procedure btnsalirClick(Sender: TObject);
- procedure btnprocesarClick(Sender: TObject);
- procedure btnbuscarClick(Sender: TObject);
- procedure betnvolverClick(Sender: TObject);
- procedure combotipoKeyPress(Sender: TObject; var Key: char);
- procedure edtcodigoKeyPress(Sender: TObject; var Key: char);
- procedure edtprecioKeyPress(Sender: TObject; var Key: char);
- procedure edtstockKeyPress(Sender: TObject; var Key: char);
- procedure FormCreate(Sender: TObject);
- private
- { private declarations }
- public
- { public declarations }
- end;
- TArticulo = record
- Codigo : integer;
- Precio_Unitario : real;
- Stock : integer;
- Tipo_Articulo:string;
- bus:integer
- end;
- TListaArticulos = array [1..100] of TArticulo;
- var
- Form1: TForm1;
- articulo:TArticulo;
- Lista_Articulos : TListaArticulos;
- Nro_Articulos : integer;
- valmin, countA, countB, countC:integer; // STOCK MINIMO
- function existeProducto(): integer;
- procedure leerproducto;
- function validar():boolean;
- procedure mostrarvehiculo;
- procedure agregarvehiculo;
- procedure sumar();
- procedure sumar2();
- procedure sumar3();
- procedure menorstock();
- implementation
- {$R *.lfm}
- { TForm1 }
- procedure leerproducto();
- var
- codigo1:integer;
- begin
- articulo.Tipo_Articulo:=form1.combotipo.text;
- val(Form1.edtcodigo.text,articulo.codigo,codigo1);
- val(Form1.edtstock.text,articulo.Stock,codigo1);
- val(Form1.edtprecio.text,articulo.Precio_Unitario,codigo1);
- val(form1.edtbuscar.text,articulo.bus,codigo1);
- end;
- function validar():boolean;
- begin
- if (form1.combotipo.text='')or(form1.edtcodigo.text='')or(form1.edtprecio.text='')or(form1.edtprecio.text='') then
- validar:=false;
- end;
- function existeProducto(): integer;
- var
- i,j: integer;
- existe: boolean;
- begin
- existe:=false;
- i:=1;
- j:=0;
- while (i<=Nro_Articulos) and Not existe do
- if Lista_Articulos[i].codigo=articulo.codigo then
- begin
- j:=1;
- existe:=true;
- end
- else
- i:=i+1;
- existeProducto := j;
- end;
- //NUEVA FUNCTION BUSCAR
- function buscarProducto(code:integer): integer;
- var
- i,j: integer;
- existe: boolean;
- begin
- existe:=false;
- i:=1;
- j:=-1;
- while (i<=Nro_Articulos) and Not existe do
- if Lista_Articulos[i].codigo=code then
- begin
- j:=i;
- existe:=true;
- end
- else
- i:=i+1;
- buscarProducto := j;
- end;
- procedure sumar();
- var
- i,contador:integer;
- begin
- contador:=0;
- for i:=1 to Nro_Articulos do
- if Lista_Articulos[i].Tipo_Articulo='A'then
- contador:=contador+1;
- form1.Label9.Caption:=inttostr(contador);
- end;
- procedure sumar2();
- var
- i,contador:integer;
- begin
- contador:=0;
- for i:=1 to Nro_Articulos do
- if Lista_Articulos[i].Tipo_Articulo='B'then
- contador:=contador+1;
- form1.Label10.Caption:=inttostr(contador);
- end;
- procedure sumar3();
- var
- i,contador:integer;
- begin
- contador:=0;
- for i:=1 to Nro_Articulos do
- if Lista_Articulos[i].Tipo_Articulo='C'then
- contador:=contador+1;
- form1.Label11.Caption:=inttostr(contador);
- end;
- procedure menorstock();
- var
- i:integer;
- minimo:TArticulo;
- stkstr:string;
- begin
- minimo:=Lista_Articulos[1];
- for i:=2 to Nro_Articulos do
- if Lista_Articulos[i].Stock < minimo.Stock then
- minimo:=Lista_Articulos[i];
- str(minimo.Stock,stkstr);
- form1.Label12.Caption:=stkstr;
- end;
- procedure agregarvehiculo();
- begin
- Nro_Articulos:=Nro_Articulos+1;
- Lista_Articulos[Nro_Articulos]:=articulo;
- if (valmin > articulo.Stock) then valmin:= articulo.Stock;
- form1.Label2.Caption:=IntToStr(valmin);
- if (articulo.Tipo_Articulo = 'A') then countA:= countA+1
- else if(articulo.Tipo_Articulo ='B') then countB:= countB+1
- else countC:= countC+1;
- form1.Label9.Caption := IntToStr(countA);
- form1.Label10.Caption:= IntToStr(countB);
- form1.Label11.Caption:= IntToStr(countC);
- form1.Label12.Caption:= IntToStr(valmin);
- end;
- procedure mostrarvehiculo();
- var
- i,fila:integer;
- preciostr,stkstr,codistr:string;
- begin
- form1.StringGrid1.RowCount:=1;
- for i:=1 to Nro_Articulos do
- begin
- Form1.StringGrid1.RowCount:= Form1.StringGrid1.RowCount+1;
- fila:=Form1.StringGrid1.RowCount;
- str(Lista_Articulos[i].codigo,codistr);
- str(Lista_Articulos[i].Stock,stkstr);
- str(Lista_Articulos[i].Precio_Unitario:7:2,preciostr);
- Form1.StringGrid1.Cells[1,fila - 1]:=codistr;
- Form1.StringGrid1.Cells[2,fila - 1]:=Lista_Articulos[i].Tipo_Articulo;
- Form1.StringGrid1.Cells[3,fila - 1]:=stkstr;
- Form1.StringGrid1.Cells[4,fila - 1]:=preciostr;
- end;
- end;
- procedure TForm1.btnagregarClick(Sender: TObject);
- var
- articulo:TArticulo;
- begin
- leerproducto();
- if validar()=true then
- if existeProducto()<>1 then
- begin
- agregarvehiculo();
- mostrarvehiculo();
- end
- else
- showmessage('se encuentra repetido el codigo')
- else
- showmessage('debe ingresar todos los valores');
- end;
- procedure TForm1.btnsalirClick(Sender: TObject);
- begin
- close;
- end;
- procedure TForm1.btnprocesarClick(Sender: TObject);
- begin
- form1.Label9.Visible:= true;
- form1.Label10.Visible:= true;
- form1.Label11.Visible:= true;
- form1.Label12.Visible:= true;
- end;
- procedure TForm1.btnbuscarClick(Sender: TObject);
- var
- i,fila:integer;
- stkstr,preciostr,codistr:string;
- begin
- leerproducto();
- i:= buscarProducto(articulo.bus);
- if i = -1 then ShowMessage('No encontrado')
- else
- begin
- Form1.StringGrid1.RowCount:= 1;
- Form1.StringGrid1.RowCount:= Form1.StringGrid1.RowCount+1;
- fila:= Form1.StringGrid1.RowCount;
- str(Lista_Articulos[i].codigo,codistr);
- str(Lista_Articulos[i].Stock,stkstr);
- str(Lista_Articulos[i].Precio_Unitario:7:2,preciostr);
- Form1.StringGrid1.Cells[1,fila - 1]:=codistr;
- Form1.StringGrid1.Cells[2,fila - 1]:=Lista_Articulos[i].Tipo_Articulo;
- Form1.StringGrid1.Cells[3,fila - 1]:=stkstr;
- Form1.StringGrid1.Cells[4,fila - 1]:=preciostr;
- end;
- form1.edtbuscar.Text:='';;
- end;
- procedure TForm1.betnvolverClick(Sender: TObject);
- begin
- mostrarvehiculo();
- end;
- procedure TForm1.combotipoKeyPress(Sender: TObject; var Key: char);
- begin
- if not(key in[#65,#66,#67,#8])then
- begin
- key:=#0;
- end;
- end;
- procedure TForm1.edtcodigoKeyPress(Sender: TObject; var Key: char);
- begin
- if not(key in['0'..'9',#8])then
- begin
- key:=#0;
- ShowMessage('solo se puede ingresar numeros');
- end;
- end;
- procedure TForm1.edtprecioKeyPress(Sender: TObject; var Key: char);
- begin
- if not(key in['0'..'9',#8,#46])then
- begin
- key:=#0;
- ShowMessage('solo se puede ingresar numeros');
- end;
- end;
- procedure TForm1.edtstockKeyPress(Sender: TObject; var Key: char);
- begin
- if not(key in['0'..'9',#8])then
- begin
- key:=#0;
- ShowMessage('solo se puede ingresar numeros');
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- valmin:=integer.MaxValue;
- countA:= 0;
- countB:= 0;
- countC:= 0;
- form1.Label9.Visible:= false;
- form1.Label10.Visible:= false;
- form1.Label11.Visible:= false;
- form1.Label12.Visible:= false;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement