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

📄 outdepot.~pas

📁 1、系统环境要求:WindowsXP/2000 2、DELPHI7.0企业版 3、如果数据库为SQL Server数据库
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
begin
  inherited;
  if Not (Key in ['0'..'9','.',#8])then
    Key := #0
  else if (key = '.') then
    Key := #0;
end;

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

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

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

procedure Tf_outdepot.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
        Summoney.Text := FloatToStr(StrToFloat(Summoney.Text)-StrToFloat(Grid.Cells[sumprice,x]));
        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
end;

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

procedure Tf_outdepot.QuitClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure Tf_outdepot.CancelClick(Sender: TObject);
var
  i: Integer;
begin
  inherited;
  For i :=0 to ComponentCount-1 do
    if Components[i]is TEdit then
      TEdit(Components[i]).Clear
    else if Components[i]is TComboBox then
      TComboBox(Components[i]).ItemIndex := -1
    else if Components[i]is TDateTimePicker then
      TDateTimePicker(Components[i]).Date := Now
    else if Components[i]is TStringGrid then
    begin
      ClearGrid;
    end;
  Operator.Text := Username;
end;

procedure Tf_outdepot.FormShow(Sender: TObject);
begin
  inherited;
  Picker.DateTime := Now;
  Grid.Cells[bar,0]:= '条形码';
  Grid.Cells[book,0]:='书籍名称';
  Grid.Cells[unitprice,0]:= '单价';
  Grid.Cells[amount,0]:= '数量';
  Grid.Cells[sumprice,0]:= '金额';
  Grid.Cells[depot,0]:='仓库';
  With t_data.Query1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select providername from tb_providerinfo');
    Open;
  end;
  if t_data.Query1.RecordCount>0 then
  begin
    while Not t_data.Query1.Eof do
    begin
      Provider.Items.Add(Trim(t_data.Query1.Fields[0].Value));
      t_data.Query1.Next;
    end;
  end;
  With t_data.Query1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select depotname from tb_depotinfo');
    Open;
  end;
  if t_data.Query1.RecordCount>0 then
  begin
    while Not t_data.Query1.Eof do
    begin
      Storage.Items.Add(Trim(t_data.Query1.Fields[0].Value));
      t_data.Query1.Next;
    end;
  end;
  Cancel.Click;
end;

procedure Tf_outdepot.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 ProviderIsValid = True then
        begin
          Try
            Connect.BeginTrans;
            With Query1 do
            begin
              Close;
              SQL.Clear;
              SQL.Add('Exec add_bookout :provider,:principal,:Operator,:data,:id output');
              Parameters.ParamByName('provider').Value := Trim(Provider.Text);
              Parameters.ParamByName('principal').Value := Trim(Principal.Text);
              Parameters.ParamByName('operator').Value := Trim(Operator.Text);
              Parameters.ParamByName('data').Value := Picker.Date;
              Parameters.ParamByName('id').Value := 'temp';
              ExecSQL;
            end;
            With Query2 do
            begin
              Close;
              SQL.Clear;
              SQL.Add('select * from tb_provideracount where provider = :provider');
              Parameters.ParamByName('provider').Value := Trim(Provider.Text);
              Open;
            end;
            if Query2.RecordCount>0 then
            begin
              With Query2 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('update tb_provideracount set money = money - :money where provider = :provider');
                Parameters.ParamByName('provider').Value := Trim(Provider.Text);
                Parameters.ParamByName('money').Value := StrToFloat(Summoney.Text);
                ExecSQL;
              end;
            end
            else
            begin
              Raise EPrividerIsValid.Create('没有与当前供应商建立往来账目关系');
            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_bookoutdetail Values(:id,:barcode,:price,:num,:money,:depot)');
                Parameters.ParamByName('id').Value := Trim(inid);
                Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[bar,row]);
                Parameters.ParamByName('price').Value := StrToFloat(Grid.Cells[unitprice,row]);
                Parameters.ParamByName('num').Value := StrToFloat(Grid.Cells[amount,row]);
                Parameters.ParamByName('money').Value := StrToFloat(Grid.Cells[sumprice,Row]);
                Parameters.ParamByName('depot').Value := Trim(Grid.Cells[depot,row]);
                ExecSQL;
              end;
              With Query1 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('select * from tb_bookdepot where barcode = :bar and depot = :depot');
                Parameters.ParamByName('bar').Value := Trim(Grid.Cells[bar,row]);
                Parameters.ParamByName('depot').Value := Trim(Grid.Cells[depot,row]);
                Open;
              end;
              if Query1.RecordCount>0 then
              begin
                With Query2 do
                begin
                  Close;
                  SQL.Clear;
                  SQL.Add('update tb_bookdepot set num = num-:sum where barcode = :bar and depot = :depot');
                  Parameters.ParamByName('sum').Value := StrToFloat(Grid.Cells[amount,row]);
                  Parameters.ParamByName('bar').Value := Trim(Grid.Cells[bar,row]);
                  Parameters.ParamByName('depot').Value := Trim(Grid.Cells[depot,row]);
                  ExecSQL;
                end;
              end
              else
              begin
                Raise EBookinfoIsValid.Create('图书退货信息有误.');
              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;

{ EPrividerIsValid }

constructor EPrividerIsValid.Create(const Msg: string);
begin
  Inherited;
  Application.MessageBox('没有与当前供应商建立往来账目关系.','提示',64);
end;

{ EBookinfoIsValid }

constructor EBookinfoIsValid.Create(const Msg: string);
begin
  Inherited;
  Application.MessageBox('图书退货信息有误.','提示',64);
end;

procedure Tf_outdepot.BooknameChange(Sender: TObject);
begin
  inherited;
  If Trim(Bookname.Text)<>'' then
  begin
    With t_data.Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from tb_bookinfo where bookname like :name');
      Parameters.ParamByName('name').Value := Trim(Bookname.Text)+'%';
      Open;
    end;
    if t_data.Query1.RecordCount>0 then
    begin
      Source1.DataSet := t_data.Query1;
      Grid1.Visible := True;
    end
    else
    begin
      t_data.Query1.Close;
      Grid1.Visible := False;
    end;
  end;
end;

procedure Tf_outdepot.priceChange(Sender: TObject);
begin
  inherited;
  if (Trim(Price.Text)<>'')and(Trim(sum.Text)<>'') then
    Money.Text := FloatToStr(StrToFloat(Price.Text)*StrToFloat(sum.Text))
  else
    Money.Clear;
end;

end.

⌨️ 快捷键说明

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