📄 storeservice.pas
字号:
end;
end
else //如果没有匹配的数据,进行提示
begin
RegSource.DataSet := Nil;
Grid.Visible := False;
Application.MessageBox('该物资信息不存在.','提示',64);
reg := True;
Reginfo.Cells[storename,Row]:='';
Reginfo.Col := storename;
end;
end;
if (col = servicemoney)and(Trim(Reginfo.Cells[servicemoney,row])<>'') then //如果用户正在编辑金额,自动合计总计
begin
StockTotal.Text := FloatToStr(CalculateMoney);
end
else if (col = servicemoney)and(Trim(Reginfo.Cells[servicemoney,row])='') then
begin
StockTotal.Text :='0.0';
end;
if (row = Reginfo.RowCount-1)and(CurrentIsNull = False) then //如果当前行是最后一行,并且不为空则添加新行
begin
Reginfo.RowCount := Reginfo.RowCount+1;
end;
end;
end;
//自定义函数,判断当前行是否为空,如果为空,返回值为True,否则为False
function Tf_storeservice.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;
//自定义函数,用户合计金额
function Tf_storeservice.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[servicemoney,i])<>'' then
begin
Result := Result+StrToFloat(Reginfo.Cells[servicemoney,i]);
end;
end;
end;
//处理录入表格的OnKeyDown事件,按Ctrl键将使下一行获得焦点,按Shift键将使联想录入表格
//获得焦点,按Insert键能够添加新行,按Delete键将删除当前行,按回车键能够检测录入信息是否合法,
//控制单元格焦点的移动
procedure Tf_storeservice.ReginfoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
x,y: Integer;
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 := storename;
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[storename,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[storename,row]:= Trim(FieldByName('storename').AsString);
end;
end
else //物资不存在,进行提示并清空物资名称
begin
Application.MessageBox('该物资不存在,请重新输入.','提示',64);
Reginfo.Cells[storename,row]:='';
end;
end;
if Reginfo.Col<>Reginfo.ColCount-1 then
Reginfo.Col := Reginfo.Col+1
else
Reginfo.Col := 0;
end;
end;
//自定义过程,用于清空当前行
procedure Tf_storeservice.ClearCurRow;
var
i: integer;
begin
For i := 0 to Reginfo.ColCount-1 do
Reginfo.Cells[i,row]:='';
end;
//自定义过程,用于清空最后一行
procedure Tf_storeservice.ClearEndRow;
var
i: integer;
begin
For i := 0 to Reginfo.ColCount-1 do
Reginfo.Cells[i,Reginfo.RowCount-1]:='';
end;
//退出按钮的单击事件
procedure Tf_storeservice.QuitClick(Sender: TObject);
begin
inherited;
Close;
end;
//处理取消按钮的单击事件
procedure Tf_storeservice.CancelClick(Sender: TObject);
begin
inherited;
ClearEdit;//清空编辑框信息
principal.SetFocus;
IniGrid;//清空录入表格信息
Date.DateTime := Now;//重新设置时间
end;
//自定义过程,用于清空编辑框信息
procedure Tf_storeservice.ClearEdit;
var
i: Integer;
begin
For i := 0 to Panel1.ControlCount-1 do
if Panel1.Controls[i]is TEdit then
TEdit(Panel1.Controls[i]).Clear;
Operator.Text := t_main.Operatorname;
StockTotal.Text := '0.0';
Factmoney.Text := '0.0';
end;
//自定义过程,用于初始化表格
procedure Tf_storeservice.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_storeservice.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_storeservice :principal,:operator,:serviceman,:paymaney,:factmaney,:date ,:serviceid output');
Parameters.ParamByName('principal').Value := Trim(principal.Text);
Parameters.ParamByName('operator').Value := Trim(operator.Text);
Parameters.ParamByName('serviceman').Value := Trim(serviceman.Text);
Parameters.ParamByName('paymaney').Value := StrToFloat(stocktotal.Text);
Parameters.ParamByName('factmaney').Value := StrToFloat(factmoney.Text);
Parameters.ParamByName('date').Value := Trunc(Date.DateTime);
Parameters.ParamByName('serviceid').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_storeservicelist values(:serviceid,:storename,:num,:servicemoney,:memo)');
Parameters.ParamByName('serviceid').Value := Trim(query.Parameters.ParamByName('serviceid').Value);
Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,x]);
Parameters.ParamByName('num').Value :=StrToFloat(Reginfo.Cells[num,x]);
Parameters.ParamByName('servicemoney').Value := StrToFloat(Reginfo.Cells[servicemoney,x]);
Parameters.ParamByName('memo').Value := Trim(Reginfo.Cells[memo,x]);
ExecSQL;
end;
end;
Connect1.CommitTrans;//提交一个事务
Application.MessageBox(Pchar('操作成功,票号为: '+Trim(query.Parameters.ParamByName('serviceid').Value)),'提示',64);
Cancel.Click;
Except
Connect1.RollbackTrans; //产生异常则回滚事务
Application.MessageBox('操作失败.','提示',64);
End;
Finally
Connect1.Free;
Query.Free;
Query1.Free;
End;
end;
//自定义函数,判断编辑框是否为空,如果为空,返回值为True,否则为False
function Tf_storeservice.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 Panel1.ControlCount-1 do
if Panel1.Controls[i]is TEdit then
if Trim(TEdit(Panel1.Controls[i]).Text)='' then
begin
Result := True;
Exit;
end;
end;
//自定义函数,判断最后一行是否为空,如果为空,返回值为True,否则为False
function Tf_storeservice.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;
//自定义函数判断表格信息是否为空,如果为空,返回值为True,否则为False
function Tf_storeservice.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;
procedure Tf_storeservice.ServicemanKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if key = vk_return then
Findnext(True);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -