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

📄 booksell.pas

📁 1、系统环境要求:WindowsXP/2000 2、DELPHI7.0企业版 3、如果数据库为SQL Server数据库
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      Sumprice.Text := Money.Text
    else
      Sumprice.Text := FloatToStr(StrToFloat(Sumprice.Text)+ StrToFloat(Money.Text));
    ClearDetail;
    Barcode.SetFocus;
  end
  else if Key =vk_escape then
  begin
    ClearDetail;
  end;
end;

function Tf_booksell.DetailIsNull: 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;
        Break;
      end;
end;

procedure Tf_booksell.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;

procedure Tf_booksell.RebateExit(Sender: TObject);
begin
  inherited;
  if StrToFloat(Rebate.Text)>1 then
  begin
    Application.MessageBox('折扣不能大于1.','提示',64);
    Rebate.Text := '1.0';
  end;
end;

procedure Tf_booksell.RebateChange(Sender: TObject);
begin
  inherited;
  if (Trim(Rebate.Text)<>'')and(Trim(sumprice.Text)<>'')and(StrToFloat(Rebate.Text)<=1) then
  begin
    Paymoney.Text := FloatToStr(StrToFloat(Sumprice.Text)* StrToFloat(Rebate.Text));
  end
  else
    Paymoney.Clear;
end;

procedure Tf_booksell.PaymoneyChange(Sender: TObject);
begin
  inherited;
  if (Trim(Paymoney.Text)<>'')and(Trim(Factmoney.Text)<>'') then
    Change.Text := FloatToStr(StrToFloat(Factmoney.Text)-StrToFloat(Paymoney.Text))
  else
    Change.Clear;
end;

procedure Tf_booksell.ClearGrid;
var
  x,y: Integer;
begin
  For x := 1 to Grid.RowCount-1 do
    For y := 0 to Grid.ColCount-1 do
      Grid.Cells[y,x]:='';
  Grid.RowCount := 2;
end;

procedure Tf_booksell.ClearDetail;
var
  i: Integer;
begin
  For i:= 0 to Panel2.ControlCount-1 do
    if Panel2.Controls[i]is TEdit then
      TEdit(Panel2.Controls[i]).Clear;
end;

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

procedure Tf_booksell.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
        Sumprice.Text := FloatToStr(StrToFloat(Sumprice.Text)-StrToFloat(Grid.Cells[c_money,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_booksell.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]).DateTime := Now
    else if (Components[i]is TStringGrid) then
      ClearGrid;
  Operator.Text := Username;
  Rebate.Text := '1.0';
end;

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

procedure Tf_booksell.SaveClick(Sender: TObject);
var
  Connect: TADOConnection;
  Query1: TADOQuery;
  row: Integer;
  inid: String;
begin
  inherited;
  Connect:= Nil;
  Query1 := Nil;
  if MasterIsValid then
  begin
    if AccountIsNull = False then
    begin
      if StrToFloat(Change.Text)>=0 then
      begin
        Try
          Connect := TADOConnection.Create(nil);
          Connect.LoginPrompt := False;
          Connect.ConnectionString := t_data.Connection1.ConnectionString;
          Connect.Open;
          Query1 := TADOQuery.Create(nil);
          Query1.Connection := Connect;
          Try
            Connect.BeginTrans;
            With Query1 do
            begin
              Close;
              SQL.Clear;
              SQL.Add('Exec Add_SellID :counter,:operator,:rebate,:paymoney,:factmoney,:change,:date,:sellid output');
              Parameters.ParamByName('counter').Value := Trim(Counter.Text);
              Parameters.ParamByName('operator').Value := Trim(Operator.Text);
              Parameters.ParamByName('rebate').Value := StrToFloat(Rebate.Text);
              Parameters.ParamByName('paymoney').Value := StrToFloat(Paymoney.Text);
              Parameters.ParamByName('factmoney').Value := StrToFloat(Factmoney.Text);
              Parameters.ParamByName('change').Value := StrToFloat(Change.Text);
              Parameters.ParamByName('date').Value := Picker.DateTime;
              Parameters.ParamByName('sellid').Value := 'temp';
              ExecSQL;
            end;
            inid := Trim(Query1.Parameters.ParamByName('sellid').Value);
            For Row := 1 to Grid.RowCount-2 do
            begin
              With Query1 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('insert into tb_selldetail values (:sellid,:barcode,:unitprice,:num,:money)');
                Parameters.ParamByName('sellid').Value := Trim(inid);
                Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[c_barcode,Row]);
                Parameters.ParamByName('unitprice').Value := StrToFloat(Grid.Cells[c_price,Row]);
                Parameters.ParamByName('num').Value := StrToFloat(Grid.Cells[c_sum,Row]);
                Parameters.ParamByName('money').Value := StrToFloat(Grid.Cells[c_money,Row]);
                ExecSQL;
              end;
              With Query1 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('update tb_bookcounter set num = num- :sum where barcode = :barcode and counter = :counter');
                Parameters.ParamByName('sum').Value := StrToFloat(Grid.Cells[c_sum,Row]);
                Parameters.ParamByName('barcode').Value := StrToFloat(Grid.Cells[c_barcode,Row]);
                Parameters.ParamByName('counter').Value := Trim(Counter.Text);
                ExecSQL;
              end;
            end;
           Connect.CommitTrans;
           Application.MessageBox(Pchar('操作成功,票号为: '+ inid),'提示',64);
           Cancel.Click;
          Except
            Connect.RollbackTrans;
            Application.MessageBox('操作失败.','');
          End;
        Finally
          Query1.Free;
          Connect.Free;
        End;
      end
      else
        Application.MessageBox('找零不能为负数.','提示',64);
    end
    else
      Application.MessageBox('账目信息不能为空.','提示',64);
  end
  else
    Application.MessageBox('标题信息有误,请检查标题信息是否为空或柜台名称是否正确.','提示',64);
end;

function Tf_booksell.MasterIsValid: Boolean;
begin
  Result := True;
  if Trim(Counter.Text)='' then
  begin
    Result := False;
    Exit;
  end;
  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;

function Tf_booksell.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;

function Tf_booksell.AccountIsNull: 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;

end.

⌨️ 快捷键说明

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