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

📄 checklose.pas

📁 物流管理系统是一个典型的数据库应用程序
💻 PAS
📖 第 1 页 / 共 2 页
字号:
        Grid.Visible := False;
        Application.MessageBox('该物资信息不存在.','提示',64);
        reg := True;
        Reginfo.Cells[storename,Row]:='';
        Reginfo.Col := storename;
      end;
    end;
    if (col = paymoney)and(Trim(Reginfo.Cells[paymoney,row])<>'') then
    begin
      StockTotal.Text := FloatToStr(CalculateMoney);
    end
    else if (col = paymoney)and(Trim(Reginfo.Cells[paymoney,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;
//自定义函数用于计算金额
function Tf_checklose.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[paymoney,i])<>'' then
      begin
        Result := Result+StrToFloat(Reginfo.Cells[paymoney,i]);
      end;
  end;
end;
//自定义函数判断当前行是否为空
function Tf_checklose.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;
//处理表格的按键事件,根据不同的按键实现不同的功能,例如按insert键添加新行,按delete键删除行
//按回车键控制焦点移动等
procedure Tf_checklose.ReginfoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  x,y: Integer;
begin
  inherited;
  Reg := False;
  if Key = VK_CONTROL then
  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
  begin
    Reg := True;
    Grid.SetFocus;
    Exit;
  end;
  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
  else if Key = vk_Delete then
  begin
    if Application.MessageBox('确实要删除当前行吗.','提示',mb_YesNo)= ID_Yes then
    begin
      Reg := True;
      ClearCurRow;
      if Reginfo.RowCount>2 then
      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;
    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);
          Grid.Hide;
        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_checklose.ClearCurRow;
var
  i: integer;
begin
  For i := 0 to Reginfo.ColCount-1 do
    Reginfo.Cells[i,row]:='';
end;
//自定义过程用于清空最后一行
procedure Tf_checklose.ClearEndRow;
var
  i: integer;
begin
  For i := 0 to Reginfo.ColCount-1 do
    Reginfo.Cells[i,Reginfo.RowCount-1]:='';
end;
//处理保存按钮的单击事件,完成报损处理
procedure Tf_checklose.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 //检测表格最后一行是否为空,如果是并且行数大于2则删除最后一行
  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_checklose  :principal,:operator,:storagename,:paymaney,:memo,:date ,:checkloseid output');
        Parameters.ParamByName('principal').Value := Trim(principal.Text);
        Parameters.ParamByName('operator').Value := Trim(operator.Text);
        Parameters.ParamByName('storagename').Value := Trim(Storagename.Text);
        Parameters.ParamByName('paymaney').Value := StrToFloat(stocktotal.Text);
        Parameters.ParamByName('memo').Value := (Memo.Text);
        Parameters.ParamByName('date').Value := Trunc(Date.DateTime);
        Parameters.ParamByName('checkloseid').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_checkloselist values(:checkloseid,:storename,:num,:paymoney)');
          Parameters.ParamByName('checkloseid').Value := Trim(query.Parameters.ParamByName('checkloseid').Value);
          Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,x]);
          Parameters.ParamByName('num').Value :=StrToFloat(Reginfo.Cells[num,x]);
          Parameters.ParamByName('paymoney').Value := StrToFloat(Reginfo.Cells[paymoney,x]);
          ExecSQL;
        end;
        With Query1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('update tb_comstorage set storesum = storesum - :num where storagename = :storagename and storename = :storename');
          Parameters.ParamByName('num').Value := StrToFloat(Reginfo.Cells[num,x]);
          Parameters.ParamByName('storagename').Value := Trim(Storagename.Text);
          Parameters.ParamByName('storename').Value := Trim(Reginfo.Cells[storename,x]);
          ExecSQL;
        end;
      end;
      Connect1.CommitTrans;//提交事务
      Application.MessageBox(Pchar('操作成功,票号为: '+Trim(query.Parameters.ParamByName('checkloseid').Value)),'提示',64);
      Cancel.Click;
    Except
      //产生异常则回滚事务
      Connect1.RollbackTrans;
      Application.MessageBox('操作失败.','提示',64);
    End;
  Finally
    Connect1.Free;
    Query.Free;
    Query1.Free;
  End;
end;
//自定义函数,判断编辑框是否为空
function Tf_checklose.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;
 { TODO : 没有完成 }
function Tf_checklose.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_checklose.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_checklose.CancelClick(Sender: TObject);
begin
  inherited;
  ClearEdit;
  principal.SetFocus;
  IniGrid;
  Date.DateTime := Now;

end;

procedure Tf_checklose.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;
  StockTotal.Text := '0.0';
  Memo.Text := '无';
end;

procedure Tf_checklose.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_checklose.QuitClick(Sender: TObject);
begin
  inherited;
  Close;
end;

end.

⌨️ 快捷键说明

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