📄 storeout.pas
字号:
Reginfo.Col := storename;
end;
end;
if (row = Reginfo.RowCount-1)and(CurrentIsNull = False) then //如果当前行是最后一行,并且不为空则添加新行
begin
Reginfo.RowCount := Reginfo.RowCount+1;
end;
end;
end;
//自定义函数,判断当前行是否为空
function Tf_storeout.CurrentIsNull: Boolean;
var
i: integer;
begin
Result := False;
For i := 0 to Reginfo.ColCount-1 do
if Trim(Reginfo.Cells[i,Row])= '' then
begin
Result := True;
Break;
end;
end;
//处理录入表格的OnKeyDown事件,按Ctrl键将使下一行获得焦点,按Shift键将使联想录入表格
//获得焦点,按Insert键能够添加新行,按Delete键将删除当前行,按回车键能够检测录入信息是否合法,
//控制单元格焦点的移动
procedure Tf_storeout.ReginfoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
x,y: Integer;
CellRect: TRect;
begin
inherited;
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;
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);
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[storename,row]:= Trim(FieldByName('storename').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+2;
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_storeout.ClearCurRow;
var
i: integer;
begin
For i := 0 to Reginfo.ColCount-1 do
Reginfo.Cells[i,row]:='';
end;
//自定义过程,用于清空最后一行
procedure Tf_storeout.ClearEndRow;
var
i: integer;
begin
For i := 0 to Reginfo.ColCount-1 do
Reginfo.Cells[i,Reginfo.RowCount-1]:='';
end;
procedure Tf_storeout.DateKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if Key = vk_Return then
Reginfo.SetFocus;
end;
//处理保存按钮的单击事件,保存出库登记信息,修改库存
procedure Tf_storeout.SaveClick(Sender: TObject);
var
Connect1: TADOConnection;
Query,Query1: TADOQuery;
x: Integer;
begin
inherited;
Connect1 := nil;
Query := nil;
Query1 := nil;
if EditIsNull = True then //判断编辑框信息是否为空
begin
Application.MessageBox('信息不能为空.','提示',64);
Exit;
end;
if EndRowIsNull= True then //判断最后一行是否为空
begin
if Reginfo.RowCount>2 then //如果行数>2,清空并删除最后一行
begin
ClearEndRow;
Reginfo.RowCount := Reginfo.RowCount-1;
end;
end;
if GridIsNull = True then //表格是否为空
begin
Application.MessageBox('表格中数据不能为空.','提示',64);
Exit;
end;
if StoreIsExis = True then //验证物资是否存在
begin
if CheckStoreEnough = True then //判断物资是否有足够库存
begin
Try
//动态创建TADOConnection组件,用于进行事务控制
Connect1 := TADOConnection.Create(nil);
Connect1.ConnectionString := Trim(t_data.Connection1.ConnectionString);
Connect1.LoginPrompt := False; //取消登录对话框
Connect1.Connected := True;
Query := TADOQuery.Create(nil);
Query.Connection := Connect1;
Query1 := TADOQuery.Create(nil);
Query1.Connection := Connect1;
Try
Connect1.BeginTrans; //开始一个事务
With Query do
begin
CLose;
SQL.Clear;
//利用存储过程生成出库票号,保存主表信息
SQL.Add('Exec Add_outstoreinfo :storemanager,:outperson,:operator,:memo,:date,:outstoreid output');
Parameters.ParamByName('storemanager').Value := Trim(Storemanager.Text);
Parameters.ParamByName('outperson').Value := Trim(Outperson.Text);
Parameters.ParamByName('operator').Value := Trim(Operator.Text);
Parameters.ParamByName('Memo').Value := Trim(Memo.Text);
Parameters.ParamByName('date').Value := Trunc(Date.DateTime);
Parameters.ParamByName('outstoreid').Value := 'temporary';
ExecSQL;
end;
for x := 1 to Reginfo.RowCount-1 do //利用循环向明细表中插入数据,修改物资库存
begin
With Query1 do
begin
CLose;
SQL.Clear;
SQL.Add('insert into tb_storeoutlist values(:outid,:storename,:num,:storagename )');
Parameters.ParamByName('outid').Value := Trim(query.Parameters.ParamByName('outstoreid').Value);
Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,x]);
Parameters.ParamByName('num').Value := StrToFloat(Reginfo.Cells[num,x]);
Parameters.ParamByName('storagename').Value := Trim(Reginfo.Cells[storagename,x]);
ExecSQL;
end;
With Query1 do //修改物资库存
begin
CLose;
SQL.Clear;
SQL.Add('update tb_comstorage set storesum = storesum - :storesum where storagename = :storagename and storename = :storename');
Parameters.ParamByName('storagename').Value := Trim(Reginfo.Cells[storagename,x]);
Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,x]);
Parameters.ParamByName('storesum').Value := StrToFloat(Reginfo.Cells[num,x]);
ExecSQL;
end;
end;
Connect1.CommitTrans; //提交事务
Application.MessageBox(Pchar('操作成功,票号为: '+Trim(query.Parameters.ParamByName('outstoreid').Value)),'提示',64);
Cancel.Click;
Except
Connect1.RollbackTrans;//产生异常则回滚事务
Application.MessageBox('操作失败.','提示',64);
End;
Finally
Connect1.Free;
Query.Free;
Query1.Free;
End;
end;
end;
end;
//自定义函数,判断编辑框文本是否为空
function Tf_storeout.EditIsNull: Boolean;
var
i: Integer;
begin
Result := False;
For i := 0 to Panel2.ControlCount-1 do
if Panel2.Controls[i]is TEdit then
if Trim(TEdit(Panel2.Controls[i]).Text)='' then
begin
Result := True;
Exit;
end;
For i := 0 to Panel3.ControlCount-1 do
if Panel3.Controls[i]is TEdit then
if Trim(TEdit(Panel3.Controls[i]).Text)='' then
begin
Result := True;
Exit;
end;
end;
//自定义函数,判断最后一行是否为空
function Tf_storeout.EndRowIsNull: Boolean;
var
i: Integer;
begin
Result := False;
For i := 0 to Reginfo.ColCount-1 do
if Trim(Reginfo.Cells[i,Reginfo.RowCount-1])='' then
begin
Result := True;
Break;
end;
end;
//自定义函数,判断表格是否为空
function Tf_storeout.GridIsNull: Boolean;
var
x,y: Integer;
begin
Result := False;
for x := 1 to Reginfo.RowCount-1 do
for y := 0 to Reginfo.ColCount-1 do
begin
if Trim(Reginfo.Cells[y,x])='' then
begin
Result := True;
Break;
end;
end;
end;
//自定义函数,判断库存中是否有足够的物资
function Tf_storeout.CheckStoreEnough: Boolean;
var
i,j,m: Integer;
Storenum: Real;
begin
Storenum := 0;
Result := True;
for i := 1 to Reginfo.RowCount-1 do
begin
if CurIsExit(i)= False then //如果当前行在其后面的行中不存在
begin
Storenum := Calculatenum(i); //在当前行统计物资数量
with t_data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select storesum 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(Reginfo.Cells[storename,i]+' 在库存中没有足够的数量.'),'提示',64);
Exit;
end;
if t_data.Query1.Fields[0].Value < Storenum then
begin
Result := False;
Application.MessageBox(Pchar(Reginfo.Cells[storename,i]+' 在库存中没有足够的数量.'),'提示',64);
Exit;
end;
end;
end;
end;
//自定义函数,判断当前行在其后的行中是否存在
function Tf_storeout.CurIsExit(index: Integer): Boolean;
var
i: Integer;
begin
Result := False;
if index = Reginfo.RowCount-1 then
begin
Result := False;
Exit;
end;
For i := index+1 to Reginfo.RowCount-1 do
begin
if (Trim(Reginfo.Cells[storename,index])= Trim(Reginfo.Cells[storename,i]))and(Trim(Reginfo.Cells[storagename,index])=Trim(Reginfo.Cells[storagename,i]))then
begin
Result := True;
Break;
end;
end;
end;
//统计从首行到当前行的同一种物资的数量
function Tf_storeout.Calculatenum(index: Integer): Real;
var
i: integer;
begin
Result := 0.0;
for i := 1 to Index do
begin
if (Trim(Reginfo.Cells[storename,index])= Trim(Reginfo.Cells[storename,i]))and(Trim(Reginfo.Cells[storagename,index])=Trim(Reginfo.Cells[storagename,i]))then
Result := Result + StrToFloat(Reginfo.Cells[num,i]);
end;
end;
//自定义函数,判断物资是否存在
function Tf_storeout.StoreIsExis: Boolean;
var
i: Integer;
begin
Result := True;
for i := 1 to Reginfo.RowCount-1 do
begin
with t_data.Query1 do
begin
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;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -