Advertisement
WallHero

Retroalimentacion Taller01-02

Sep 10th, 2020
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 8.10 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   Grids;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     btnagregar: TButton;
  17.     btnsalir: TButton;
  18.     btnprocesar: TButton;
  19.     btnbuscar: TButton;
  20.     betnvolver: TButton;
  21.     combotipo: TComboBox;
  22.     edtbuscar: TEdit;
  23.     edtcodigo: TEdit;
  24.     edtstock: TEdit;
  25.     edtprecio: TEdit;
  26.     Label1: TLabel;
  27.     Label10: TLabel;
  28.     Label11: TLabel;
  29.     Label12: TLabel;
  30.     Label2: TLabel;
  31.     Label3: TLabel;
  32.     Label4: TLabel;
  33.     Label5: TLabel;
  34.     Label6: TLabel;
  35.     Label7: TLabel;
  36.     Label8: TLabel;
  37.     Label9: TLabel;
  38.     StringGrid1: TStringGrid;
  39.     procedure btnagregarClick(Sender: TObject);
  40.     procedure btnsalirClick(Sender: TObject);
  41.     procedure btnprocesarClick(Sender: TObject);
  42.     procedure btnbuscarClick(Sender: TObject);
  43.     procedure betnvolverClick(Sender: TObject);
  44.     procedure combotipoKeyPress(Sender: TObject; var Key: char);
  45.     procedure edtcodigoKeyPress(Sender: TObject; var Key: char);
  46.     procedure edtprecioKeyPress(Sender: TObject; var Key: char);
  47.     procedure edtstockKeyPress(Sender: TObject; var Key: char);
  48.     procedure FormCreate(Sender: TObject);
  49.   private
  50.     { private declarations }
  51.   public
  52.     { public declarations }
  53.   end;
  54.   TArticulo = record
  55.     Codigo : integer;
  56.     Precio_Unitario : real;
  57.     Stock : integer;
  58.     Tipo_Articulo:string;
  59.     bus:integer
  60.  
  61.  end;
  62.   TListaArticulos = array [1..100] of TArticulo;
  63.  
  64. var
  65.   Form1: TForm1;
  66.    articulo:TArticulo;
  67.   Lista_Articulos : TListaArticulos;
  68.     Nro_Articulos : integer;
  69.   valmin, countA, countB, countC:integer; // STOCK MINIMO
  70.   function existeProducto(): integer;
  71.   procedure leerproducto;
  72.   function validar():boolean;
  73.   procedure mostrarvehiculo;
  74.   procedure agregarvehiculo;
  75.   procedure sumar();
  76.   procedure sumar2();
  77.   procedure sumar3();
  78.   procedure menorstock();
  79. implementation
  80.  
  81. {$R *.lfm}
  82.  
  83. { TForm1 }
  84.  
  85.  
  86. procedure leerproducto();
  87. var
  88.  codigo1:integer;
  89. begin
  90.   articulo.Tipo_Articulo:=form1.combotipo.text;
  91.   val(Form1.edtcodigo.text,articulo.codigo,codigo1);
  92.    val(Form1.edtstock.text,articulo.Stock,codigo1);
  93.     val(Form1.edtprecio.text,articulo.Precio_Unitario,codigo1);
  94.     val(form1.edtbuscar.text,articulo.bus,codigo1);
  95. end;
  96. function validar():boolean;
  97. begin
  98.   if (form1.combotipo.text='')or(form1.edtcodigo.text='')or(form1.edtprecio.text='')or(form1.edtprecio.text='') then
  99.     validar:=false;
  100. end;
  101.  
  102. function existeProducto(): integer;
  103. var
  104.   i,j: integer;
  105.   existe: boolean;
  106. begin
  107.   existe:=false;
  108.   i:=1;
  109.   j:=0;
  110.   while (i<=Nro_Articulos) and Not existe do
  111.     if Lista_Articulos[i].codigo=articulo.codigo then
  112.       begin
  113.        j:=1;
  114.        existe:=true;
  115.       end
  116.     else
  117.       i:=i+1;
  118.  
  119.   existeProducto := j;
  120. end;
  121.  
  122. //NUEVA FUNCTION BUSCAR
  123. function buscarProducto(code:integer): integer;
  124. var
  125.   i,j: integer;
  126.   existe: boolean;
  127. begin
  128.   existe:=false;
  129.   i:=1;
  130.   j:=-1;
  131.   while (i<=Nro_Articulos) and Not existe do
  132.     if Lista_Articulos[i].codigo=code then
  133.       begin
  134.        j:=i;
  135.        existe:=true;
  136.       end
  137.     else
  138.       i:=i+1;
  139.  
  140.   buscarProducto := j;
  141. end;
  142.  
  143.  
  144. procedure sumar();
  145. var
  146. i,contador:integer;
  147. begin
  148. contador:=0;
  149.   for i:=1 to Nro_Articulos do
  150.      if Lista_Articulos[i].Tipo_Articulo='A'then
  151.        contador:=contador+1;
  152.   form1.Label9.Caption:=inttostr(contador);
  153. end;
  154. procedure sumar2();
  155. var
  156. i,contador:integer;
  157. begin
  158. contador:=0;
  159.   for i:=1 to Nro_Articulos do
  160.      if Lista_Articulos[i].Tipo_Articulo='B'then
  161.        contador:=contador+1;
  162.   form1.Label10.Caption:=inttostr(contador);
  163. end;
  164. procedure sumar3();
  165. var
  166. i,contador:integer;
  167. begin
  168. contador:=0;
  169.   for i:=1 to Nro_Articulos do
  170.      if Lista_Articulos[i].Tipo_Articulo='C'then
  171.        contador:=contador+1;
  172.   form1.Label11.Caption:=inttostr(contador);
  173. end;
  174. procedure menorstock();
  175. var
  176. i:integer;
  177. minimo:TArticulo;
  178. stkstr:string;
  179. begin
  180. minimo:=Lista_Articulos[1];
  181.      for i:=2 to Nro_Articulos do
  182.           if Lista_Articulos[i].Stock < minimo.Stock then
  183.             minimo:=Lista_Articulos[i];
  184.           str(minimo.Stock,stkstr);
  185.            form1.Label12.Caption:=stkstr;
  186. end;
  187.  
  188. procedure agregarvehiculo();
  189. begin
  190.    Nro_Articulos:=Nro_Articulos+1;
  191.    Lista_Articulos[Nro_Articulos]:=articulo;
  192.    if (valmin > articulo.Stock) then valmin:= articulo.Stock;
  193.    form1.Label2.Caption:=IntToStr(valmin);
  194.    if (articulo.Tipo_Articulo = 'A') then countA:= countA+1
  195.    else if(articulo.Tipo_Articulo ='B') then countB:= countB+1
  196.    else countC:= countC+1;
  197.    form1.Label9.Caption := IntToStr(countA);
  198.    form1.Label10.Caption:= IntToStr(countB);
  199.    form1.Label11.Caption:= IntToStr(countC);
  200.    form1.Label12.Caption:= IntToStr(valmin);
  201.  
  202. end;
  203. procedure mostrarvehiculo();
  204. var
  205.  i,fila:integer;
  206.  preciostr,stkstr,codistr:string;
  207. begin
  208. form1.StringGrid1.RowCount:=1;
  209.   for i:=1 to Nro_Articulos do
  210.    begin
  211.      Form1.StringGrid1.RowCount:=  Form1.StringGrid1.RowCount+1;
  212.      fila:=Form1.StringGrid1.RowCount;
  213.      str(Lista_Articulos[i].codigo,codistr);
  214.      str(Lista_Articulos[i].Stock,stkstr);
  215.      str(Lista_Articulos[i].Precio_Unitario:7:2,preciostr);
  216.      Form1.StringGrid1.Cells[1,fila - 1]:=codistr;
  217.      Form1.StringGrid1.Cells[2,fila - 1]:=Lista_Articulos[i].Tipo_Articulo;
  218.      Form1.StringGrid1.Cells[3,fila - 1]:=stkstr;
  219.      Form1.StringGrid1.Cells[4,fila - 1]:=preciostr;
  220.    end;
  221. end;
  222. procedure TForm1.btnagregarClick(Sender: TObject);
  223. var
  224.   articulo:TArticulo;
  225. begin
  226.   leerproducto();
  227.    if validar()=true then
  228.      if  existeProducto()<>1 then
  229.        begin
  230.         agregarvehiculo();
  231.         mostrarvehiculo();
  232.        end
  233.      else
  234.        showmessage('se encuentra repetido el codigo')
  235.    else
  236.       showmessage('debe ingresar todos los valores');
  237. end;
  238.  
  239. procedure TForm1.btnsalirClick(Sender: TObject);
  240. begin
  241.   close;
  242. end;
  243.  
  244. procedure TForm1.btnprocesarClick(Sender: TObject);
  245. begin
  246.      form1.Label9.Visible:= true;
  247.   form1.Label10.Visible:= true;
  248.   form1.Label11.Visible:= true;
  249.   form1.Label12.Visible:= true;
  250. end;
  251.  
  252. procedure TForm1.btnbuscarClick(Sender: TObject);
  253. var
  254. i,fila:integer;
  255. stkstr,preciostr,codistr:string;
  256. begin
  257.   leerproducto();
  258.  
  259.       i:= buscarProducto(articulo.bus);
  260.       if i = -1 then ShowMessage('No encontrado')
  261.       else
  262.         begin
  263.              Form1.StringGrid1.RowCount:= 1;
  264.              Form1.StringGrid1.RowCount:=  Form1.StringGrid1.RowCount+1;
  265.             fila:=  Form1.StringGrid1.RowCount;
  266.             str(Lista_Articulos[i].codigo,codistr);
  267.             str(Lista_Articulos[i].Stock,stkstr);
  268.             str(Lista_Articulos[i].Precio_Unitario:7:2,preciostr);
  269.             Form1.StringGrid1.Cells[1,fila - 1]:=codistr;
  270.             Form1.StringGrid1.Cells[2,fila - 1]:=Lista_Articulos[i].Tipo_Articulo;
  271.             Form1.StringGrid1.Cells[3,fila - 1]:=stkstr;
  272.             Form1.StringGrid1.Cells[4,fila - 1]:=preciostr;
  273.         end;
  274.        form1.edtbuscar.Text:='';;
  275. end;
  276.  
  277. procedure TForm1.betnvolverClick(Sender: TObject);
  278. begin
  279.      mostrarvehiculo();
  280. end;
  281.  
  282. procedure TForm1.combotipoKeyPress(Sender: TObject; var Key: char);
  283. begin
  284.     if not(key in[#65,#66,#67,#8])then
  285.      begin
  286.      key:=#0;
  287.      end;
  288. end;
  289.  
  290. procedure TForm1.edtcodigoKeyPress(Sender: TObject; var Key: char);
  291. begin
  292.   if not(key in['0'..'9',#8])then
  293.      begin
  294.      key:=#0;
  295.      ShowMessage('solo se puede ingresar numeros');
  296.      end;
  297. end;
  298.  
  299. procedure TForm1.edtprecioKeyPress(Sender: TObject; var Key: char);
  300. begin
  301.   if not(key in['0'..'9',#8,#46])then
  302.      begin
  303.      key:=#0;
  304.      ShowMessage('solo se puede ingresar numeros');
  305.      end;
  306. end;
  307.  
  308. procedure TForm1.edtstockKeyPress(Sender: TObject; var Key: char);
  309. begin
  310.   if not(key in['0'..'9',#8])then
  311.      begin
  312.      key:=#0;
  313.      ShowMessage('solo se puede ingresar numeros');
  314.      end;
  315. end;
  316.  
  317. procedure TForm1.FormCreate(Sender: TObject);
  318. begin
  319.   valmin:=integer.MaxValue;
  320.   countA:= 0;
  321.   countB:= 0;
  322.   countC:= 0;
  323.   form1.Label9.Visible:= false;
  324.   form1.Label10.Visible:= false;
  325.   form1.Label11.Visible:= false;
  326.   form1.Label12.Visible:= false;
  327. end;
  328.  
  329.  
  330. end.
  331.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement