⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storescrap.pas

📁 物流管理系统是一个典型的数据库应用程序
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      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_storescrap.ClearCurRow;
var
  i: integer;
begin
  For i := 0 to Reginfo.ColCount-1 do
    Reginfo.Cells[i,row]:='';
end;
//自定义过程,用于清空最后一行
procedure Tf_storescrap.ClearEndRow;
var
  i: integer;
begin
  For i := 0 to Reginfo.ColCount-1 do
    Reginfo.Cells[i,Reginfo.RowCount-1]:='';
end;
//退出按钮的单击事件
function Tf_storescrap.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[scrapmoney,i])<>'' then
      begin
        Result := Result+StrToFloat(Reginfo.Cells[scrapmoney,i]);
      end;
  end;
end;
//处理取消按钮的单击事件
procedure Tf_storescrap.CancelClick(Sender: TObject);
begin
  inherited;
  ClearEdit; //清空编辑框信息
  principal.SetFocus;
  IniGrid; //清空录入表格信息
  Date.DateTime := Now; //重新设置时间
end;

procedure Tf_storescrap.QuitClick(Sender: TObject);
begin
  inherited;
  Close;
end;
//自定义函数,判断当前行是否为空
function Tf_storescrap.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;
//处理表格的OnSetEditText事件,完成物资信息的联想录入,计算总计金额
procedure Tf_storescrap.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;
    if (col = scrapmoney)and(Trim(Reginfo.Cells[scrapmoney,row])<>'') then  //如果用户正在编辑金额,自动合计总计
    begin
      StockTotal.Text := FloatToStr(CalculateMoney);
    end
    else if (col = scrapmoney)and(Trim(Reginfo.Cells[scrapmoney,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;
//自定义过程,用于清空编辑框信息
procedure Tf_storescrap.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;
  StockTotal.Text := '0.0';
end;
//自定义过程,用于初始化表格
procedure Tf_storescrap.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_storescrap.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_storescrap  :principal,:operator,:managemaney,:date ,:scrapid output');
        Parameters.ParamByName('principal').Value := Trim(principal.Text);
        Parameters.ParamByName('operator').Value := Trim(t_main.Operatorname);
        Parameters.ParamByName('managemaney').Value := StrToFloat(stocktotal.Text);
        Parameters.ParamByName('date').Value := Trunc(Date.DateTime);
        Parameters.ParamByName('scrapid').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_storescraplist values(:scrapid,:storename,:num,:managemoney,:memo)');
          Parameters.ParamByName('scrapid').Value := Trim(query.Parameters.ParamByName('scrapid').Value);
          Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,x]);
          Parameters.ParamByName('num').Value :=StrToFloat(Reginfo.Cells[num,x]);
          Parameters.ParamByName('managemoney').Value := StrToFloat(Reginfo.Cells[scrapmoney,x]);
          Parameters.ParamByName('memo').Value := Trim(Reginfo.Cells[memo,x]);
          ExecSQL;
        end;
     end;
      Connect1.CommitTrans;  //提交一个事务
      Application.MessageBox(Pchar('操作成功,票号为: '+Trim(query.Parameters.ParamByName('scrapid').Value)),'提示',64);
      Cancel.Click;
    Except
      Connect1.RollbackTrans; //产生异常则回滚事务
      Application.MessageBox('操作失败.','提示',64);
    End;
  Finally
    Connect1.Free;
    Query.Free;
    Query1.Free;
  End;
end;
//自定义函数,判断编辑框是否为空,如果为空,返回值为True,否则为False
function Tf_storescrap.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_storescrap.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_storescrap.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;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -