做销售,用stringgrid做临时的过渡性商品录入界面具体如下:
把在其它EDIT中录入的数据转到stringgrid中相应的单元格中如下
商品名称 单价 数量 小计
文具 0.2 3 0.6(通过计算得出)
...
...
...
总计 ...(通过计算得出) *最后一行*行应该能自动增加
某行录入错了可以按一个热键删除当前选中行,计算结果相应改变.然后再把这些数据写入到相应的数据库中
最后清空所有stringgrid 中的数据等待下次销售.
把在其它EDIT中录入的数据转到stringgrid中相应的单元格中如下
商品名称 单价 数量 小计
文具 0.2 3 0.6(通过计算得出)
...
...
...
总计 ...(通过计算得出) *最后一行*行应该能自动增加
某行录入错了可以按一个热键删除当前选中行,计算结果相应改变.然后再把这些数据写入到相应的数据库中
最后清空所有stringgrid 中的数据等待下次销售.
if stringgrid>stringgrid.rowcount-2 then
stringgrid.row:=stringgrid.row+1;
stringgrid.cells[0,stringgrid.row]:=.....
删除,
if key=#.. then
stringgrid.rows[stringgrid.row].clear;
写表你就自己看吧,估计要做循环。
清空:
for i:=1 to stringgrid.rowcount do
stringgrid.rows[i].clear;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DB, ADODB;type
TForm1 = class(TForm)
strgCost: TStringGrid;
adsCost: TADOQuery;
procedure strgCostKeyPress(Sender: TObject; var Key: Char);
procedure strgCostKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure strgCostDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure strgCostSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
private
{ Private declarations }
procedure CalcCell(ARow : integer);
procedure DelRow(ARow : integer);
procedure InsertData;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.strgCostKeyPress(Sender: TObject; var Key: Char);
begin
with TStringGrid(Sender) do
if (Col in [2, 3]) then
if not (key in ['1','2','3','4','5','6','7','8','9','0',#8,#13,#37,#39,#46]) then
key:=#0;
end;procedure TForm1.strgCostKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key=13) then begin
if (strgCost.Row=strgCost.RowCount-1) and
((strgCost.Col=strgCost.ColCount-2) or (strgCost.Col=strgCost.ColCount-1)) then begin
strgCost.RowCount:= strgCost.RowCount+1;
// Exit;
end;
// ji suan
CalcCell(strgCost.Row); if (strgCost.Col=strgCost.ColCount-2) or (strgCost.Col=strgCost.ColCount-1) then begin
strgCost.Row:=strgCost.Row+1;
strgCost.Col:=1;
end
else
strgCost.Col:=strgCost.Col+1;
end
else if (key=VK_F2) then
DelRow(strgCost.Row);
end;procedure TForm1.strgCostDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
str: string;
begin
str := TStringGrid(Sender).Cells[ACol,Arow];
with TStringGrid(Sender).Canvas do begin
if (ACol<>1) then
TextRect(Rect,Rect.Right-TextWidth(str)-3,Rect.Top+3,str)
else
TextRect(Rect,Rect.Left+3,Rect.Top+3,str);
end;
end;procedure TForm1.strgCostSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if (ACol = 4) then
strgCost.Options:=strgCost.Options-[goEditing]
else
strgCost.Options:=strgCost.Options+[goEditing];
end;procedure TForm1.CalcCell(ARow: integer);
var
vPrice, vQty : real;
begin
if Trim(strgCost.Cells[2, ARow])='' then
vPrice:=0
else
vPrice:=StrToFloat(strgCost.Cells[2, ARow]);
if Trim(strgCost.Cells[3, ARow])='' then
vQty:=0
else
vQty:=StrToFloat(strgCost.Cells[3, ARow]); strgCost.Cells[4, ARow]:=FloatToStr(vPrice*vQty);
end;procedure TForm1.DelRow(ARow : integer);
var
i, j : integer;
begin
if strgCost.RowCount=2 then
for j:=1 to strgCost.ColCount-1 do
strgCost.Cells[j, 1]:=''
else begin
for i:=ARow to strgCost.RowCount-2 do
for j:=1 to strgCost.ColCount-1 do
strgCost.Cells[j, i]:=strgCost.Cells[j, i+1];
strgCost.RowCount:=strgCost.RowCount-1;
end;
end;procedure TForm1.InsertData;
var
i : integer;
begin
for i:=1 to strgCost.RowCount-1 do begin
adsCost.Close;
adsCost.SQL.Clear;
adsCost.SQL.Add('insert into table (fName, fPrice, fQuantity, fSum) ');
adsCost.SQL.Add('values('+QuotedStr(strgCost.Cells[1, i]));
adsCost.SQL.Add(', '+strgCost.Cells[2, i]+', '+strgCost.Cells[3, i]);
adsCost.SQL.Add(', '+strgCost.Cells[4, i]+')');
adsCost.ExecSQL;
end;
end;end.
procedure TTFrmChgRatio.ClearPara;
var
iRow, iCol: Integer; //清空SGDisp的循环变量
begin
for iRow := 1 to SGPara.RowCount - 1 do
for iCol := 0 to SGPara.ColCount - 1 do
SGPara.Cells[iCol, iRow] := '';
SGPara.RowCount := 2;end; //删除
if SGPara.RowCount=2 then
for j:=1 to SGPara.ColCount-1 do
SGPara.Cells[j, 1]:='';
if SGPara.RowCount=2 then
for I:=SGPara.Row to SGPara.RowCount do
for J:=0 to SGPara.ColCount-1 do
SGPara.Cells[J,I]:=SGPara.Cells[J,I+1];