📄 storecancel.pas
字号:
CLose;
SQL.Clear;
SQL.Add('select * from tb_comstorage where storagename = :storagename and storename = :storename');
Parameters.ParamByName('storagename').Value := Trim(Reginfo.Cells[storagename,i]);
Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,i]) ;
Open;
end;
if t_data.Query1.RecordCount<1 then
begin
Result := False;
Application.MessageBox(Pchar('物资名称为: '+ Trim(Reginfo.Cells[storename,i])+' 的物资在库存中不存在.'),'提示',64);
Exit;
end;
end;
end;
//处理表格的OnSetEditText事件
procedure Tf_storecancel.ReginfoSetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
var
CellRect: TRect; //记录单元格区域,用于计算组合框出现的位置
begin
if Reg = false then
begin
Grid.Visible := False;
if (Acol = storename) then //匹配查询物资名称
begin
With t_data.Query1 do
begin
CLose;
SQL.Clear;
SQL.Add('select * from tb_storeinfo where storename Like :Storename or nameshort like :nameshort');
Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,ARow])+'%' ;
Parameters.ParamByName('nameshort').Value := Trim(Reginfo.Cells[storename,ARow])+'%' ;
Open;
end;
if t_data.Query1.RecordCount>0 then //如果存在匹配的数据,显示联想录入表格,供用户选择
begin
Regsource.DataSet := t_data.Query1;
if not Grid.Visible then
begin
CellRect := Reginfo.CellRect(ACol,ARow);
CellRect.Left := CellRect.Left+Reginfo.Left;
CellRect.Right := CellRect.Right+ Reginfo.Left;
CellRect.Top := Reginfo.Top+ CellRect.Top;
Grid.Left := CellRect.Right+1;
Grid.Top := CellRect.Top;
Grid.Visible := True;
end;
end
else //如果没有匹配的数据,进行提示
begin
RegSource.DataSet := Nil;
Grid.Visible := False;
Application.MessageBox('该物资信息不存在.','提示',64);
reg := True;
Reginfo.Cells[storename,Row]:='';
Reginfo.Col := storename;
end;
end
//如果正在编辑单价和数量,则自动合计金额
else if (ACol = unitprice)or(ACol= num) then
begin
if (Trim(Reginfo.Cells[unitprice,row])<>'')and(Trim(Reginfo.Cells[num,row])<>'')then
begin
Reginfo.Cells[money,Row]:= FloatToStr(StrToFloat(Reginfo.Cells[num,row])*StrToFloat(Reginfo.Cells[unitprice,row]));
end
else
Reginfo.Cells[money,Row]:= '';
Stocktotal.Text := FloatToStr(Calculatemoney);
end;
//如果当前行是最后一行,并且不为空则添加新行
if (row = Reginfo.RowCount-1)and(CurrentIsNull = False) then
begin
Reginfo.RowCount := Reginfo.RowCount+1;
end;
end;
end;
//处理录入表格的OnKeyDown事件,按Ctrl键将使下一行获得焦点,按Shift键将使联想录入表格
//获得焦点,按Insert键能够添加新行,按Delete键将删除当前行,按回车键能够检测录入信息是否合法,
//控制单元格焦点的移动
procedure Tf_storecancel.ReginfoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
x,y: Integer;
CellRect: TRect;
begin
Reg := False;
if Key = VK_CONTROL then //按Ctrl键,如果表格当前行没有处于最后一行,将使下一行获得焦点
begin
if row<>Reginfo.RowCount-1 then
begin
Reginfo.Row := Row+1;
Reginfo.Col := 0;
Reginfo.SetFocus;
end;
end;
if (Key = vk_Shift)and(Grid.Visible = True) then //按Shift键,如果联想录入表格可见,将使其获得焦点
begin
Reg := True;
Grid.SetFocus;
Exit;
end;
//按Insert键,如果当前行不为空,并且是最后一行,将添加新行
if (Key = vk_Insert)and(CurrentIsNull = False)and(Row = Reginfo.RowCount-1) then
begin
Reginfo.RowCount := Reginfo.RowCount+1;
Reginfo.Row := Reginfo.Row+1;
Reginfo.Col := Barcode;
end
//按Delete键将删除或清空(如果只有一行数据)当前行
else if Key = vk_Delete then
begin
//提示是否删除当前行
if Application.MessageBox('确实要删除当前行吗.','提示',mb_YesNo)= ID_Yes then
begin
Reg := True;
ClearCurRow; //清空当前行
if Reginfo.RowCount>2 then //如果行数>2,利用循环方式将下一行数据上移,并删除最后一行
begin
if row<>Reginfo.RowCount-1 then
begin
For x := row+1to (Reginfo.RowCount-1) do
For y:=0 to Reginfo.ColCount-1 do
Reginfo.Cells[y,x-1]:= Reginfo.Cells[y,x];
end;
ClearEndRow; //清空最后一行
Reginfo.RowCount := Reginfo.RowCount-1; //删除最后一行
end;
Reginfo.Col := 0;
Stocktotal.Text := FloatToStr(Calculatemoney);
end;
end
else if Key = vk_Return then
begin
reg := True; //修改录入表格信息时,防止触发OnSetEditText事件
Grid.Visible := False;
if (Trim(Reginfo.Cells[barcode,row])<>'')and(Trim(Reginfo.Cells[storename,row])='') then //检测物资是否存在
begin
with t_data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from tb_storeinfo where barcode = :barcode');
Parameters.ParamByName('barcode').Value := Trim(Reginfo.Cells[barcode,row]);
Open;
end;
if t_data.Query1.RecordCount>0 then
begin
with t_data.Query1 do
begin
Reginfo.Cells[storename,row]:= Trim(FieldByName('storename').AsString);
Reginfo.Cells[basicunit,row]:= Trim(FieldByName('basicunit').AsString);
Reginfo.Cells[unitprice,row]:= Trim(FieldByName('defaultprice').AsString);
end;
end
else
begin
Reginfo.Cells[barcode,row]:= '';
Application.MessageBox('该条形码不存在.','提示',64);
Exit;
end;
end
else if (Trim(Reginfo.Cells[storename,row])<>'')and(Trim(Reginfo.Cells[barcode,row])='') then //检测物资是否存在
begin
with t_data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from tb_storeinfo where storename = :storename or nameshort = :nameshort');
Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,row]);
Parameters.ParamByName('nameshort').Value := Trim(Reginfo.Cells[storename,row]);
Open;
end;
if t_data.Query1.RecordCount>0 then
begin
with t_data.Query1 do
begin
Reginfo.Cells[barcode,row]:= Trim(FieldByName('barcode').AsString);
Reginfo.Cells[basicunit,row]:= Trim(FieldByName('basicunit').AsString);
Reginfo.Cells[unitprice,row]:= Trim(FieldByName('Defaultprice').AsString);
end;
end
else
begin
Application.MessageBox('该物资不存在,请重新输入.','提示',64);
Reginfo.Cells[storename,row]:='';
end;
end;
if (Col = storagename )and(Comstorage.Visible = False) then //如果当前列为仓库名称,则显示组合框,供用户选择
begin
CellRect := Reginfo.CellRect(storagename,row);
CellRect.Left := CellRect.Left+Reginfo.Left;
CellRect.Top := CellRect.Top+Reginfo.Top;
Comstorage.Top := CellRect.Top;
ComStorage.Left := CellRect.Left;
ComStorage.ItemHeight := CellRect.Bottom-CellRect.Top;
ComStorage.Width :=CellRect.Right- CellRect.Left;
ComStorage.Visible := True;
ComStorage.SetFocus;
end;
if Reginfo.Col<>Reginfo.ColCount-1 then
Reginfo.Col := Reginfo.Col+1
else
Reginfo.Col := 0;
end;
end;
//窗体创建时初始化成员
procedure Tf_storecancel.FormCreate(Sender: TObject);
begin
inherited;
barcode := 0;
storename := 1;
basicunit := 2;
stockunit := 99;
convertions := 99;
unitprice := 3 ;
num := 4;
money := 5;
storagename := 6;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -