retailfrm.pas

来自「群星医药系统源码」· PAS 代码 · 共 1,103 行 · 第 1/3 页

PAS
1,103
字号
    edInput.Clear;
    PreBillNo := NewBillNo;
    Result := True;
    iFirstPrint := 0;
    ActNewBill.Execute;
  end else
    Application.MessageBox('数据更新失败!', '消息', MB_ICONINFORMATION);
end;

procedure TFmRetail.ActNewBillExecute(Sender: TObject);
begin
  NewBill;
end;

procedure TFmRetail.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case Key of
    VK_HOME: edInput.SetFocus;
  end;
end;

procedure TFmRetail.edInputKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var sInput: string;
    StrLen: integer;
    dValue: Double;
    b1: Boolean;
begin
  sInput := Trim(edInput.Text);
  StrLen := Length(sInput);
  case Key of
    VK_UP: begin
      Key := 0;
      if cdsRetailDtl.State in dsEditModes then
        Exit;
      cdsRetailDtl.Prior;
    end;
    VK_DOWN: begin
      Key := 0;
      if cdsRetailDtl.State in dsEditModes then
        Exit;
      cdsRetailDtl.Next;
    end;
    VK_F2: Begin
      If PreBillNo='' Then Begin
        Application.MessageBox('找不到指定要打印的单据!', '错误', MB_OK+MB_ICONERROR);
        Exit;
      End;
      ActPrintPreBill.Execute;
    End;
    VK_F3: Begin
      ActOpenMoneyBox.Execute;
    End;
    VK_F4: begin //删除行
      Key := 0;
      if cdsRetailDtl.IsEmpty then Exit;
      cdsRetailDtl.Delete;
      dBornSum := dBornSum-cdsRetailDtlBornSum.Value;
    end;
    VK_F5: begin//单品打折
      Key :=0;
      if StrLen=0 then Exit;
      if cdsRetailDtl.IsEmpty then Exit;
      try
        dValue := StrToFloat(sInput);
      Except
        SetOptHint('请输入正确的折扣率!');
        Exit;
      end;
      b1 := cdsRetailDtl.State in dsEditModes;
      if not b1 then
        cdsRetailDtl.Edit;
      cdsRetailDtlRebate.Value := dValue;
      if not b1 then
        cdsRetailDtl.Post;
      edInput.Clear;
    end;
    VK_F6: begin //挂单/提单
      DoHangBill;
    end;
    VK_F7: begin //整单打折
      if StrLen=0 then Exit;
      Key := 0;
      try
        dValue := StrToFloat(sInput);
      Except
        SetOptHint('请输入正确的折扣率!');
        Exit;
      end;
      edInput.Clear;
      DoWholeRebate(dValue);
    end;
    VK_F8: begin //整单作废
      Key := 0;
      if Application.MessageBox('确认将此单作废吗?', '消息', MB_YESNO+MB_ICONQUESTION)=IDNO then
        Exit;
      DeleteCurrBill;
      ActNewBill.Execute;
    end;
    VK_F9 : Begin
      If SelectGoodsID(sInput,False) Then
      If sInput <>'' Then Begin
        edInput.Text := sInput;
        edInput.SetFocus;
      End;
    End;
    VK_F10: begin//VIP客户
      Key := 0;
      if ssShift in Shift then
        cdsRetailVipNo.AsVariant := null
      else begin
        if StrLen=0 then begin
          if not InputQuery('请输入', '请在下面的输入框中输入VIP客户编号:', sInput) then
            Exit;
        end;
        if SetVipNo(sInput) then
          edInput.Clear;
      end;
    end;
    VK_F11: begin//业务促销员
      Key := 0;
      if ssShift in Shift then
        cdsRetailEmpNo.AsVariant := null
      else begin
        if StrLen=0 then Exit;
        if SetEmpNo(sInput) then
          edInput.Clear;
      end;
    end;
    VK_DIVIDE: begin//'/'单价
      //ShowMessage(IntTostr(Key));
      if StrLen=0 then Exit;
      //Key := 8;//这里的Key改变后也没有用,只好在后面PostMessage
      PostMessage(edInput.Handle, WM_KEYDOWN, 8, 0);
      try
        dValue := StrToFloat(sInput);
      Except
        //raise Exception.Create('请输入正确的数字!');
        SetOptHint('请输入正确的数字!');
        Exit;
      end;
      if not(cdsRetailDtl.State in dsEditModes) then
        cdsRetailDtl.Append;
      cdsRetailDtlOPrice.Value := dValue;
      edInput.Clear;
      //ShowMessage(IntTostr(Key));
      //edInput.Perform(WM_KEYDOWN, 8, 0);
//      PostMessage(edInput.Handle, WM_KEYDOWN, 8, 0);
    end;
    VK_MULTIPLY: begin//'*'数量
      if StrLen=0 then Exit;
      PostMessage(edInput.Handle, WM_KEYDOWN, 8, 0);
      try
        dValue := StrToFloat(sInput);
      Except
        //raise Exception.Create('请输入正确的数字!');
        SetOptHint('请输入正确的数字!');
        Exit;
      end;
      if not(cdsRetailDtl.State in dsEditModes) then
        cdsRetailDtl.Append;
      cdsRetailDtlQty.Value := dValue;
      edInput.Clear;
    end;
    VK_SUBTRACT: begin//'-'暂用作生产批号输入
      if StrLen=0 then Exit;
      PostMessage(edInput.Handle, WM_KEYDOWN, 8, 0);
      b1 := not(cdsRetailDtl.State in dsEditModes);
      if b1 then begin
        b1 := ssShift in Shift;
        if b1 then//当同时按下Shift+"-"号键时
          cdsRetailDtl.Edit
        else
          cdsRetailDtl.Append;
      end;
      cdsRetailDtlBatchNo.Value := sInput;
      if b1 then//注意:这里b1必须满足两个条件,1.数据集原处于非编辑状态,2.同时按下了Shift键
        cdsRetailDtl.Post;
      edInput.Clear;
    end;
    VK_ADD, 187: begin//'+'收款(187是大键盘上的有+和=号那个键)
      if StrLen=0 then Exit;
      if cdsRetailDtl.IsEmpty then Exit;
      PostMessage(edInput.Handle, WM_KEYDOWN, 8, 0);
      If StrToFloat(sInput)-StrtoFloat(lbTotal.Caption)>BaseSetting.MaxChange Then Begin
        Messagebox(Handle,Pchar('付给客户找零的金额不应大于系统设置的最大找零金额['+IntToStr(BaseSetting.MaxChange)+']元'),'提示',64);
        Exit;
      End;
      if SaveBill Then
  	    edInput.Text := '';
    end;
    13: begin
      If BaseSetting.RtlPriceMode<=0 Then Begin
        MessageBox(Handle,Pchar('药品零售方案尚未设好,请先设置好售价方案...'),'提示',64);
        edInPut.ReadOnly := True;
        Exit;
      End;
      if sInput='' then begin
        SetOptHint('请输入商品编号/商品条码/助记码来查询商品!');
        Exit;
      end;
      DoInputGoods(sInput);
    end;
  end;
end;

procedure TFmRetail.edInputKeyPress(Sender: TObject; var Key: Char);
begin
{  case Key of
    '/': begin//'/'单价
      if not(cdsRetailDtl.State in dsEditModes) then
        cdsRetailDtl.Append;
      cdsRetailDtlOPrice.Value := StrToFloat(sInput);
      //edInput.Text := '';
      edInput.Clear;
    end;
    '*': begin//'*'数量
      if not(cdsRetailDtl.State in dsEditModes) then
        cdsRetailDtl.Append;
      cdsRetailDtlQty.Value := StrToFloat(sInput);
    end;
    '-': begin//'-'暂留
      if Length(sInput)=0 then Exit;
    end;
    '+': begin//'+'收款
    end;
    13: begin
      if not(cdsRetailDtl.State in dsEditModes) then
        cdsRetailDtl.Append;
      cdsRetailDtlGoodsID.Value := sInput;
      cdsRetailDtl.Post;
    end;
  end;}
end;

procedure TFmRetail.plTitleResize(Sender: TObject);
begin
  BtnHideRPanel.Left := plTitle.Width-BtnHideRPanel.Width-1;
  BtnViewRPanel.Left := BtnHideRPanel.Left;
end;

procedure TFmRetail.plInputBkResize(Sender: TObject);
begin
	lbOptHint.Width := plInputBk.Width-plInput.Width-lbOptHint.Left*2;
end;

procedure TFmRetail.BtnHideRPanelClick(Sender: TObject);
begin
  plRight.Visible := false;
  BtnHideRPanel.Visible := false;
  BtnViewRPanel.Visible := true;
end;

procedure TFmRetail.BtnViewRPanelClick(Sender: TObject);
begin
  plRight.Visible := true;
  BtnHideRPanel.Visible := true;
  BtnViewRPanel.Visible := false;
end;

procedure TFmRetail.cdsRetailDtlNewRecord(DataSet: TDataSet);
begin
  Inc(iLastItemNo);
  cdsRetailDtlBillNo.Value := cdsRetailBillNo.Value;
  cdsRetailDtlItemNo.Value := iLastItemNo;
  cdsRetailDtlRebate.Value := WholeRebate;
  cdsRetailDtlQty.Value := 1;
end;

procedure TFmRetail.cdsRetailDtlOPriceChange(Sender: TField);
begin
  if cdsRetailDtlRebate.IsNull then
    cdsRetailDtlPrice.Value := cdsRetailDtlOPrice.Value
  else
    cdsRetailDtlPrice.Value := cdsRetailDtlOPrice.Value*(cdsRetailDtlRebate.Value/100);
end;

procedure TFmRetail.cdsRetailDtlQtyChange(Sender: TField);
begin
  cdsRetailDtlAmount.Value := cdsRetailDtlQty.Value*cdsRetailDtlPrice.Value;
  cdsRetailDtlBornSum.Value := cdsRetailDtlQty.Value*cdsRetailDtlOPrice.Value;
end;

procedure TFmRetail.SetOptHint(sHint: String);
begin
	lbOptHint.Caption := sHint;
//  lbOptHint.ScrollType := stNone;
  lbOptHint.Scrolling := false;
  Timer1.Enabled := false;
  if sHint<>'' then begin
    lbOptHint.Blinking := true;
    Timer1.Interval := 5*(lbOptHint.BlinkIntervalOff+lbOptHint.BlinkIntervalOn);
    Timer1.Enabled := true;
  end;
end;

procedure TFmRetail.Timer1Timer(Sender: TObject);
begin
	Timer1.Enabled := false;
  lbOptHint.Blinking := false;
  lbOptHint.Caption	 := '';
end;

procedure TFmRetail.edInputExit(Sender: TObject);
begin
  SetOptHint('按下[Home]键可以快速回到输入框中!');
end;

procedure TFmRetail.cdsRetailNewRecord(DataSet: TDataSet);
begin
  iLastItemNo := 0;
  WholeRebate := 100;
	dBornSum := 0; 
  NewBillNo := BuildBillNo('Retail');
  cdsRetailBillNo.Value   := NewBillNo;
  cdsRetailFDate.Value    := Now;
  CdsRetailBranchID.Value := iBranchNo;
  cdsRetailMachNo.Value   := iMachineNo;
  cdsRetailDepotID.Value  := BaseSetting.DepotID;
  cdsRetailTeamNo.Value   := iTeamNo;
  cdsRetailPayeeNo.Value  := IFmMain.IFmMainEx.LogonInfo^.UserID;
  iRecord := 1;
end;

procedure TFmRetail.cdsRetailDtlBeforeCancel(DataSet: TDataSet);
begin
  if cdsRetailDtl.State=dsInsert then
    Dec(iLastItemNo);
end;

procedure TFmRetail.cdsRetailBillNoChange(Sender: TField);
var mark: TBookmark;
    sBillNo: String;
begin
{  with cdsRetailDtl do begin
    if IsEmpty then Exit;
    sBillNo := cdsRetailBillNo.Value;
    DisableControls;
    try
      mark := GetBookmark;
      First;
      while not eof do begin
        Edit;
        cdsRetailDtlBillNo.Value := NewBillNo;
        Post;
        Next;
      end;
      GotoBookmark(mark);
    finally
      FreeBookmark(mark);
      EnableControls;
    end;
  end;}
end;

procedure TFmRetail.DoHangBill;
var i, k: integer;
begin
  if BillHang then begin//如果已有挂单
    if not cdsRetailDtl.IsEmpty then begin
      SetOptHint('请先结束当前单据的操作才能执行提单操作!');
      Exit;
    end;
    cdsTemp.Close;
    cdsTemp.LoadFromFile('RtlTemp.XML');
//    cdsRetail.LoadFromFile('RtlTemp.XML');
    k := cdsRetailDtl.FieldCount;

⌨️ 快捷键说明

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