unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
ComCtrls, StdCtrls, Types;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
ImageList1: TImageList;
ImageList2: TImageList;
ImageList3: TImageList;
ImageList4: TImageList;
MUESTRA_DATOS: TButton;
PageControl: TPageControl;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
VER_VENTAS: TTabSheet;
VER_TOTAL_VENTAS: TTabSheet;
procedure Button1Click(Sender: TObject);
procedure MUESTRA_DATOSClick(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
procedure StringGrid2DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
private
{ private declarations }
public
{ public declarations }
end;
type
eFicha = record
reg : Integer;
prod : Integer;
venta : Integer;
fpago : Integer;
end;
var
Form1: TForm1;
registros : array[1..10000] of eFicha;
ingresa: eFicha;
archivo1 : File of eFicha;
archivo2 : File of eFicha;
archivo3 : File of eFicha;
totalventa1 : Integer;
totalventa2 : Integer;
totalventaprod1 : Integer;
totalventaprod2 : Integer;
c : Integer;
d : Integer;
e : Integer;
x : Integer;
implementation
{$R *.lfm}
procedure cargadatos;
var
e : integer;
precios: array [1..10] of Integer = (1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000);
productos: array [1..10] of Integer = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
formapago: array [1..4] of Integer = (0, 1, 2, 3);
begin
randomize;
for e := 1 to 10000 do
begin
registros[e].reg := e;
registros[e].prod := (productos[low(productos) + random(length(productos))]);
registros[e].venta := (precios[low(precios) + random(length(precios))]);
registros[e].fpago := (formapago[low(formapago) + random(length(formapago))]);
end;
end;
procedure escribedatos;
var
x : integer;
begin
assignfile(archivo1,'registros.bin');
rewrite(archivo1);
for x := 1 to 10000 do
try
ingresa.reg:= registros[x].reg;
ingresa.prod:= registros[x].prod;
ingresa.venta:= registros[x].venta;
ingresa.fpago:= registros[x].fpago;
write(archivo1,ingresa);
except
writeLn('Error al escribir en archivo');
end;
close(archivo1);
end;
{ TForm1 }
procedure TForm1.MUESTRA_DATOSClick(Sender: TObject);
var
x : integer;
begin
assignfile(archivo2,'registros.bin');
c:=0;
x:=1;
reset(archivo2);
while NOT EOF(archivo2)do
begin
seek(archivo2,c);
BlockRead(archivo2,registros[x],1);
With Form1.StringGrid1 do
begin
RowCount:=RowCount+1;
Row:=RowCount;
Cells[0,Row]:= IntToStr(registros[x].reg);
Cells[1,Row]:= IntToStr(registros[x].prod);
Cells[2,Row]:= '$'+IntToStr(registros[x].venta);
Cells[3,Row]:= IntToStr(registros[x].fpago);
x:=x+1;
end;
c:=c+1;
end;
CloseFile(archivo2);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
for d := 1 to 10000 do
x:=1;
With Form1.StringGrid2 do
begin
Cells[1,1]:= IntToStr(registros[x].venta);
Cells[1,2]:= IntToStr(registros[x].venta);
Cells[1,3]:= IntToStr(totalventaprod1);
Cells[1,4]:= IntToStr(totalventaprod2);
x:=x+1;
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
begin
With Form1.StringGrid1 do
if (aCol = 3) then
begin
if cells[aCol,aRow] = '0' then
begin
ImageList1.Draw(Canvas, aRect.Left, aRect.Top,0);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '1' then
begin
ImageList1.Draw(Canvas, aRect.Left, aRect.Top,1);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '2' then
begin
ImageList1.Draw(Canvas, aRect.Left, aRect.Top,2);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '3' then
begin
ImageList1.Draw(Canvas, aRect.Left, aRect.Top,3);
end;
end;
With Form1.StringGrid1 do
if (aCol = 1) then
begin
if cells[aCol,aRow] = '1' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,0);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '2' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,1);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '3' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,2);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '4' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,3);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '5' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,4);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '6' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,5);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '7' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,6);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '8' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,7);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '9' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,8);
end;
With Form1.StringGrid1 do
if cells[aCol,aRow] = '10' then
begin
ImageList2.Draw(Canvas, aRect.Left, aRect.Top,9);
end;
end;
end;
procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer; aState: TGridDrawState);
var
ts: TTextStyle;
begin
if (ACol < 5) and (ARow = 0) then
begin
ts := StringGrid1.Canvas.TextStyle;
ts.Alignment := taCenter;
StringGrid1.Canvas.Font.Style := [fsBold];
StringGrid1.Canvas.TextStyle := ts;
end;
if (ACol = 2) and (ARow > 0) then
begin
ts := StringGrid1.Canvas.TextStyle;
ts.Alignment := taRightJustify;
StringGrid1.Canvas.Font.Style := [fsBold];
StringGrid1.Canvas.TextStyle := ts;
end;
if (ACol = 0) and (ARow > 0) then
begin
ts := StringGrid1.Canvas.TextStyle;
ts.Alignment := taCenter;
StringGrid1.Canvas.Font.Style := [fsBold];
StringGrid1.Canvas.TextStyle := ts;
end;
end;
procedure TForm1.StringGrid2DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
begin
With Form1.StringGrid2 do
if (ACol = 0) and (ARow > 0) then
begin
if cells[aCol,aRow] = '0' then
begin
ImageList3.Draw(Canvas, aRect.Left, aRect.Top,0);
end;
if cells[aCol,aRow] = '1' then
begin
ImageList3.Draw(Canvas, aRect.Left, aRect.Top,1);
end;
if cells[aCol,aRow] = '2' then
begin
ImageList3.Draw(Canvas, aRect.Left, aRect.Top,2);
end;
if cells[aCol,aRow] = '3' then
begin
ImageList3.Draw(Canvas, aRect.Left, aRect.Top,3);
end;
end;
With Form1.StringGrid2 do
if (ACol > 0) and (ARow = 0) then
begin
if cells[aCol,aRow] = '0' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,0);
end;
if cells[aCol,aRow] = '1' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,1);
end;
if cells[aCol,aRow] = '2' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,2);
end;
if cells[aCol,aRow] = '3' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,3);
end;
if cells[aCol,aRow] = '4' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,4);
end;
if cells[aCol,aRow] = '5' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,5);
end;
if cells[aCol,aRow] = '6' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,6);
end;
if cells[aCol,aRow] = '7' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,7);
end;
if cells[aCol,aRow] = '8' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,8);
end;
if cells[aCol,aRow] = '9' then
begin
ImageList4.Draw(Canvas, aRect.Left, aRect.Top,9);
end;
end;
end;
begin
cargadatos;
escribedatos;
end.