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

📄 bookmove.pas

📁 1、系统环境要求:WindowsXP/2000 2、DELPHI7.0企业版 3、如果数据库为SQL Server数据库
💻 PAS
📖 第 1 页 / 共 2 页
字号:

function Tf_bookmove.DetailIsNull: Boolean;
var
  i: Integer;
begin
  Result := False;
  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;
        Break;
      end;
end;

procedure Tf_bookmove.Grid1DblClick(Sender: TObject);
begin
  inherited;
  Barcode.Text := Trim(Source1.DataSet.FieldByName('barcode').AsString);
  Bookname.Text := Trim(Source1.DataSet.FieldByName('bookname').AsString);
  Grid1.Visible := False;
  Num.SetFocus;
end;

procedure Tf_bookmove.Grid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if Key = vk_Return then
    Grid1.OnDblClick(Sender);
end;

procedure Tf_bookmove.GridSelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
begin
  inherited;
  x := ARow;
  y := ACol;
end;

procedure Tf_bookmove.GridKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  i,j: Integer;
begin
  inherited;
  if Key = vk_delete then
  begin
    if x <> Grid.RowCount-1 then //因为最后一行始终为空,不能够删除
    begin
      if Application.MessageBox('确实要删除当前行数据吗?','提示',mb_yesno)= ID_Yes then
      begin
        For i := x to Grid.RowCount-2 do
        begin
          For j := 0 to Grid.ColCount-1 do
            Grid.Cells[j,i]:= Grid.Cells[j,i+1];
        end;
        Grid.RowCount := Grid.RowCount-1;
      end;
    end;
  end
end;

procedure Tf_bookmove.StorageKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if Key = Vk_Return then
    FindNext(True);
end;

procedure Tf_bookmove.StorageEnter(Sender: TObject);
begin
  inherited;
  Grid1.Visible := False;
end;

procedure Tf_bookmove.Grid1Exit(Sender: TObject);
begin
  inherited;
  Grid1.Visible := False;
end;

procedure Tf_bookmove.SaveClick(Sender: TObject);
var
  Connect: TADOConnection;
  Query1,Query2: TADOQuery;
  row: Integer;
  inid: String;
begin
  inherited;
  Connect := Nil;
  Query1 := Nil;
  Query2 := Nil;
  Try
    Connect := TADOConnection.Create(nil);
    Connect.LoginPrompt := False;
    Connect.ConnectionString := t_data.Connection1.ConnectionString;
    Connect.Open;
    Query1 := TADOQuery.Create(nil);
    Query2 := TADOQuery.Create(nil);
    Query1.Connection := Connect;
    Query2.Connection := Connect;
    if MasterIsNull = False then
    begin
      if GridIsNull = False then
      begin
        if StorageAndCounterIsValid = True then
        begin
          Try
            Connect.BeginTrans;
            With Query1 do
            begin
              Close;
              SQL.Clear;
              SQL.Add('Exec Add_MoveID :depot,:counter,:Operator,:data,:id output');
              Parameters.ParamByName('depot').Value := Trim(Storage.Text);
              Parameters.ParamByName('counter').Value := Trim(Counter.Text);
              Parameters.ParamByName('operator').Value := Trim(Operator.Text);
              Parameters.ParamByName('data').Value := Picker1.Date;
              Parameters.ParamByName('id').Value := 'temp';
              ExecSQL;
            end;
            inid := Trim(Query1.Parameters.ParamByName('id').Value);
            For Row := 1 to Grid.RowCount-2 do
            begin
              With Query2 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('insert into tb_depotmovedetail Values(:id,:barcode,:num)');
                Parameters.ParamByName('id').Value := Trim(inid);
                Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[c_barcode,row]);
                Parameters.ParamByName('num').Value := StrToFloat(Grid.Cells[c_num,row]);
                ExecSQL;
              end;
              With Query1 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('select * from tb_bookcounter where counter = :counter and barcode = :barcode');
                Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[c_barcode,row]);
                Parameters.ParamByName('counter').Value := Trim(Counter.Text);
                Open;
              end;
              if Query1.RecordCount>0 then
              begin
                With Query2 do
                begin
                  Close;
                  SQL.Clear;
                  SQL.Add('update tb_bookcounter set num = num+:sum where barcode = :bar and counter = :counter');
                  Parameters.ParamByName('sum').Value := StrToFloat(Grid.Cells[c_num,row]);
                  Parameters.ParamByName('bar').Value := Trim(Grid.Cells[c_barcode,row]);
                  Parameters.ParamByName('counter').Value := Trim(Counter.Text);
                  ExecSQL;
                end;
              end
              else
              begin
                With Query2 do
                begin
                  Close;
                  SQL.Clear;
                  SQL.Add('insert into tb_bookcounter Values(:counter,:barcode,:sum)');
                  Parameters.ParamByName('sum').Value := StrToFloat(Grid.Cells[c_num,row]);
                  Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[c_barcode,row]);
                  Parameters.ParamByName('counter').Value := Trim(Counter.Text);
                  ExecSQL;
                end;
              end;
              With Query2 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('Update tb_bookdepot set num = num - :sum where depot = :depot and barcode =:barcode');
                Parameters.ParamByName('sum').Value := StrToFloat(Grid.Cells[c_num,row]);
                Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[c_barcode,row]);
                Parameters.ParamByName('depot').Value := Trim(Storage.Text);
                ExecSQL;
              end;
            end;
            Connect.CommitTrans;
            Application.MessageBox(Pchar('操作成功,票号为: '+ inid),'提示',64);
            Cancel.Click;
          Except
            Connect.RollbackTrans;
            Application.MessageBox('操作失败.','提示',64);
          End;
        end
        else
          Application.MessageBox('供应商不存在.','提示',64);
      end
      else
       Application.MessageBox('表格信息不能为空.','提示',64);
    end
    else
      Application.MessageBox('标题信息不能为空.','提示',64);
  Finally
    Query1.Free;
    Query2.Free;
    Connect.Free;
  End;
end;

function Tf_bookmove.MasterIsNull: Boolean;
var
  i: Integer;
begin
  Result := False;
  For i := 0 to Panel1.ControlCount-1 do
    if Panel1.Controls[i]is TComboBox then
      if Trim(TComboBox(Panel1.Controls[i]).Text)='' then
      begin
        Result := True;
        Break;
      end;
end;

function Tf_bookmove.StorageAndCounterIsValid: Boolean;
begin
  Result := True;
  With t_data.Query1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('Select * from tb_depotinfo where depotname =:depotname');
    Parameters.ParamByName('depotname').Value := Trim(Storage.Text);
    Open;
  end;
  if t_data.Query1.RecordCount<1 then
  begin
    Result := False;
  end
  else
  begin
    With t_data.Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('Select * from tb_counter where counter = :counter');
      Parameters.ParamByName('counter').Value := Trim(Counter.Text);
      Open;
    end;
    if t_data.Query1.RecordCount<1 then
      Result := False;
  end;
end;

function Tf_bookmove.GridIsNull: Boolean;
var
  i,j: Integer;
begin
  Result := False;
  if Grid.RowCount =2 then
  begin
    Result := True;
    Exit;
  end;
  For i := 1 to Grid.RowCount-2 do
  begin
    For j := 0 to Grid.ColCount-1 do
      if Trim(Grid.Cells[j,i])= '' then
      begin
        Result := True;
        Break;
      end;
  end;
end;


end.

⌨️ 快捷键说明

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