📄 instore.pas
字号:
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;
//处理表格的OnSetEditText事件,实现数据的辅助例如功能及合计金额等信息
procedure Tf_instore.ReginfoSetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
var
CellRect: TRect; //记录单元格的区域,用于设置
begin
inherited;
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 = convertions)or(ACol= num) then //计算金额
begin
if (Trim(Reginfo.Cells[unitprice,row])<>'')and(Trim(Reginfo.Cells[convertions,row])<>'')and(Trim(Reginfo.Cells[num,row])<>'')then
begin
Reginfo.Cells[money,Row]:= FloatToStr(StrToFloat(Reginfo.Cells[convertions,row])*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;
procedure Tf_instore.GridExit(Sender: TObject);
begin
inherited;
Grid.Visible := False;
end;
procedure Tf_instore.GridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if Key = vk_Return then
Grid.OnDblClick(Sender);
end;
procedure Tf_instore.GridDblClick(Sender: TObject);
begin
inherited;
with t_data.Query1 do
begin
Reginfo.Cells[barcode,row]:= Trim(FieldByName('barcode').AsString);
Reginfo.Cells[storename,row]:= Trim(FieldByName('storename').AsString);
Reginfo.Cells[basicunit,row]:= Trim(FieldByName('basicunit').AsString);
Reginfo.Cells[stockunit,row]:= Trim(FieldByName('stockunit').AsString);
Reginfo.Cells[convertions,row]:= FloatToStr(FieldByName('conversion').AsCurrency);
Reginfo.Cells[unitprice,row]:= FloatToStr(FieldByName('defaultprice').AsCurrency);
end;
Reginfo.SetFocus;
Reginfo.Col := Reginfo.Col+1;
end;
procedure Tf_instore.ReginfoKeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if (col = unitprice)or(col = num)or(col = convertions) then
begin
if not (Key in ['0'..'9','.',#8]) then
Key := #0
end;
end;
//清空当前行
procedure Tf_instore.ClearCurRow;
var
i: integer;
begin
For i := 0 to Reginfo.ColCount-1 do
Reginfo.Cells[i,row]:='';
end;
//清空最后一行
procedure Tf_instore.ClearEndRow;
var
i: integer;
begin
For i := 0 to Reginfo.ColCount-1 do
Reginfo.Cells[i,Reginfo.RowCount-1]:='';
end;
//处理组合框的OnKeyDown事件,按回车键将组合框中的信息添加到表格中
procedure Tf_instore.ComstorageKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if key = vk_Return then
begin
Reginfo.Cells[storagename,row]:=Trim(ComStorage.Text);
ComStorage.Visible := False;
Reginfo.SetFocus;
if (row = Reginfo.RowCount-1)and(CurrentIsNull = False) then
begin
Reginfo.RowCount := Reginfo.RowCount+1;
end;
end;
end;
//组合框失去焦点时不可见
procedure Tf_instore.ComstorageExit(Sender: TObject);
begin
inherited;
Comstorage.Visible := False;
end;
//自定义函数,用于计算金额
function Tf_instore.CalculateMoney: Real;
var
i: Integer;
begin
Result := 0.0;
if Reginfo.RowCount>1 then
begin
For i := 1 to Reginfo.RowCount-1 do
if Trim(Reginfo.Cells[money,i])<>'' then
begin
Result := Result+StrToFloat(Reginfo.Cells[money,i]);
end;
end;
end;
procedure Tf_instore.StocktotalChange(Sender: TObject);
begin
inherited;
if (Trim(Rebate.Text)<>'')and(Trim(Stocktotal.Text)<>'')then
begin
Paymoney.Text := FloatToStr(StrToFloat(Stocktotal.Text)*StrToFloat(Rebate.Text));
end
else
Paymoney.Clear;
end;
procedure Tf_instore.QuitClick(Sender: TObject);
begin
inherited;
Close;
end;
procedure Tf_instore.ProvidernameEnter(Sender: TObject);
begin
inherited;
Grid.Visible := False;
end;
//处理取消按钮的单击事件,清空编辑框中的信息,初始化表格
procedure Tf_instore.CancelClick(Sender: TObject);
begin
inherited;
ClearEdit;
Rebate.Text := '1.0';
Stocktotal.Text := '0.0';
Paymoney.Text := '0.0';
Factmoney.Text := '0.0';
Date.DateTime := Now;
Providername.SetFocus;
IniGrid;
end;
//自定义过程,用于清空编辑框中的文本
procedure Tf_instore.ClearEdit;
var
i: Integer;
begin
For i := 0 to Panel2.ControlCount-1 do
if Panel2.Controls[i]is TEdit then
TEdit(Panel2.Controls[i]).Clear;
Operator.Text := t_main.Operatorname;
end;
//自定义过程,用于清空表格
procedure Tf_instore.IniGrid;
var
x,y: Integer;
begin
for x:=1 to Reginfo.RowCount-1 do
for y := 0 to reginfo.ColCount-1 do
Reginfo.Cells[y,x]:= '';
Reginfo.RowCount := 2;
end;
procedure Tf_instore.factmoneyKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if Key = vk_Return then
Save.SetFocus;
end;
//自定义函数,判断编辑框是否为空
function Tf_instore.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;
//处理保存按钮的单击事件,记录登记信息,修改库存及与供应商的账款信息
procedure Tf_instore.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
begin
ClearEndRow;
Reginfo.RowCount := Reginfo.RowCount-1;
end;
end;
if GridIsNull = True then //判断表格是否为空
begin
Application.MessageBox('表格中数据不能为空.','提示',64);
Exit;
end;
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_instoreinfo :providername,:principal,:operator,:stocktotal,:stockrebate,:paymoney,:factmoney,:date, :Instoreid output');
Parameters.ParamByName('providername').Value := Trim(Providername.Text);
Parameters.ParamByName('principal').Value := Trim(Principal.Text);
Parameters.ParamByName('operator').Value := Trim(Operator.Text);
Parameters.ParamByName('stocktotal').Value := StrToFloat(Stocktotal.Text);
Parameters.ParamByName('stockrebate').Value := StrToFloat(Rebate.Text);
Parameters.ParamByName('paymoney').Value := StrToFloat(paymoney.Text);
Parameters.ParamByName('factmoney').Value := StrToFloat(Factmoney.Text);
Parameters.ParamByName('date').Value := Trunc(Date.DateTime);
Parameters.ParamByName('instoreid').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_storelist values(:Regid,:storagename,:storename,:unitprice,:storesum,:Storemoney)');
Parameters.ParamByName('Regid').Value := Trim(query.Parameters.ParamByName('instoreid').Value);
Parameters.ParamByName('storagename').Value := Trim(Reginfo.Cells[storagename,x]);
Parameters.ParamByName('storesum').Value := StrToFloat(Reginfo.Cells[num,x])* StrToFloat(Reginfo.Cells[convertions,x]);
Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,x]);
Parameters.ParamByName('unitprice').Value := StrToFloat(Reginfo.Cells[unitprice,x]);
Parameters.ParamByName('storemoney').Value := StrToFloat(Reginfo.Cells[money,x]);
ExecSQL;
end;
With 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,x]);
Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,x]);
Open;
end;
if Query1.RecordCount>0 then
begin
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])*StrToFloat(Reginfo.Cells[ convertions,x]);
ExecSQL;
end;
end
else
begin
With Query1 do
begin
CLose;
SQL.Clear;
SQL.Add('insert into tb_comstorage values(:storagename,:storename,:storesum)');
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])*StrToFloat(Reginfo.Cells[convertions,x]);
ExecSQL;
end;
end;
end;
//修改供应商结款信息
With Query1 do
begin
CLose;
SQL.Clear;
SQL.Add('select * from tb_providerpayment where providername = :providername');
Parameters.ParamByName('providername').Value := Trim(Providername.Text);
Open;
end;
if Query1.RecordCount>0 then
begin
With query1 do
begin
CLose;
SQL.Clear;
SQL.Add('update tb_providerpayment set paymoney = paymoney +:paymoney where providername = :providername');
Parameters.ParamByName('paymoney').Value := StrToFloat(Paymoney.Text)-StrToFloat(Factmoney.Text);
Parameters.ParamByName('providername').Value := Trim(Providername.Text);
ExecSQL;
end;
end
else
begin
With query1 do
begin
CLose;
SQL.Clear;
SQL.Add('insert into tb_providerpayment values(:providername,:paymoney)');
Parameters.ParamByName('providername').Value := Trim(Providername.Text);
Parameters.ParamByName('paymoney').Value := StrToFloat(Paymoney.Text)-StrToFloat(Factmoney.Text);
ExecSQL;
end;
end;
Connect1.CommitTrans; //提交事务
Application.MessageBox(Pchar('操作成功,票号为: '+Trim(query.Parameters.ParamByName('instoreid').Value)),'提示',64);
Cancel.Click;
Except
Connect1.RollbackTrans; //回滚事务
Application.MessageBox('操作失败.','提示',64);
End;
Finally
Connect1.Free;
Query.Free;
Query1.Free;
End;
end;
//自定义函数,判断表格信息是否为空
function Tf_instore.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_instore.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;
//处理窗体显示时的事件
procedure Tf_instore.FormCreate(Sender: TObject);
begin
inherited;
barcode := 0;
storename := 1;
basicunit := 2;
stockunit := 3;
convertions := 4;
unitprice := 5 ;
num := 6;
money := 7;
storagename := 8;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -