stockbillcheckfrm.~pas

来自「群星医药系统源码」· ~PAS 代码 · 共 577 行 · 第 1/2 页

~PAS
577
字号

procedure TFmStockBillCheck.cbBillNoClick(Sender: TObject);
begin
  FCurBillNoID := cbBillNo.ItemIndex;
  ShowCurrentBill;
end;

procedure TFmStockBillCheck.btnPriorClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit;
  Dec(FCurBillNoID);
  if (FCurBillNoID <0)and(cbBillNo.Count >0) then FCurBillNoID := 0;
  cbBillNo.ItemIndex := FCurBillNoID;
  cbBillNoClick(nil);
end;

procedure TFmStockBillCheck.btnNextClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit;
  Inc(FCurBillNoID);
  if FCurBillNoID > (cbBillNo.Count-1) then FCurBillNoID := cbBillNo.Count -1 ;
  cbBillNo.ItemIndex := FCurBillNoID;
  cbBillNoClick(nil);
end;

procedure TFmStockBillCheck.btnAddNewItemClick(Sender: TObject);
var
  bk, OldIFN: string;
  iMaxItemNo: integer;
begin
  //新增盘点项
  if (not cdsStockBillCheck.Active)or(cdsStockBillCheckBillNo.AsString = '') then exit;
  if cdsStockBillCheckFinish.Value then
  begin
    MessageBox(Handle,'不能再操作已进行盈亏结算的盘点单!','警告',MB_ICONEXCLAMATION);
    exit;
  end;
  with TFmAddStockBillCheckItem.Create(self) do
  try
    FCanInsert := true; //允许新增
    with cdsStockBillCheckDtl do
    begin
      if State in dsEditModes then Post;
      bk := Bookmark;
      OldIFN := IndexFieldNames;
      DisableControls;
      IndexFieldNames := 'ItemNo';
      Last;
      iMaxItemNo := FieldByName('ItemNo').AsInteger + 1;
      IndexFieldNames := OldIFN;
      Bookmark := bk;
      EnableControls;
      Insert;    
    end;
    edItemNo.Field.AsInteger := iMaxItemNo;
    cdsStockBillCheckDtlOughtQty.Value :=0;
    cdsStockBillCheckDtlValidDate.Value := Now;
    cdsStockBillCheckDtlBillNo.Value := cdsStockBillCheckBillNo.Value;
    cdsStockBillCheckDtlGroupNo.Value := 0;
    ShowModal;
  finally
    FCanInsert := false;
    Free;
  end;
end;

procedure TFmStockBillCheck.BtnPopMenuClick(Sender: TObject);
Var tp:TPoint;
begin
  tp.X:=BtnPopMenu.Left;
	tp.y:=BtnPopMenu.Top+BtnPopMenu.Height+1;
	tp:=ClientToScreen(tp);
	TopPopmenu.Popup(tp.x,tp.Y);
end;

procedure TFmStockBillCheck.cdsStockBillCheckDtlStockQtyChange(
  Sender: TField);
var
  StockQty,OughtQty,OverQty,Price: Double;
begin
  StockQty := cdsStockBillCheckDtlStockQty.Value;
  OughtQty := cdsStockBillCheckDtlOughtQty.Value;
  Price    := cdsStockBillCheckDtlPrice.Value;
  OverQty  := StockQty - OughtQty;
  cdsStockBillCheckDtlOverQty.Value := OverQty;
  cdsStockBillCheckDtlAmount.Value := OverQty * Price;
end;

procedure TFmStockBillCheck.cdsStockBillCheckBeforeClose(
  DataSet: TDataSet);
begin
  BtnSave.Click;
end;

procedure TFmStockBillCheck.BtnSaveClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit; 
  if cdsStockBillCheck.ApplyUpdates(0)>0 then
  begin
    Application.MessageBox('数据提交失败!', '错误', MB_ICONERROR);
    Abort;
  end;
end;

procedure TFmStockBillCheck.btnCancelClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit;
  if cdsStockBillCheck.ChangeCount >0 then
    if MessageBox(Handle,'你确定要取消所有更改吗?','提示',MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON2)=IDNO then exit;
  cdsStockBillCheck.CancelUpdates;
end;

procedure TFmStockBillCheck.btnRefreshClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit;
  if cdsStockBillCheck.ApplyUpdates(0)>0 then
  begin
    MessageBox(Handle,'试图保存更改后的数据时出错!最近的改变被取消。','警告',MB_ICONEXCLAMATION);
    cdsStockBillCheck.CancelUpdates;
  end;
  LoadBillNoList;
end;

procedure TFmStockBillCheck.btnDeleteItemClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit;
  if cdsStockBillCheckFinish.Value then
  begin
    MessageBox(Handle,'不能再操作已进行盈亏结算的盘点单!','警告',MB_ICONEXCLAMATION);
    exit;
  end;
  cdsStockBillCheckDtl.Delete;
end;

procedure TFmStockBillCheck.btnItemsFirstClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit;
  cdsStockBillCheckDtl.First;
end;

procedure TFmStockBillCheck.btnItemsPriorClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit;
  cdsStockBillCheckDtl.Prior;
end;

procedure TFmStockBillCheck.btnItemsNextClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit;
  cdsStockBillCheckDtl.Next;
end;

procedure TFmStockBillCheck.btnItemsLastClick(Sender: TObject);
begin
  if not cdsStockBillCheck.Active then exit;
  cdsStockBillCheckDtl.Last;
end;

procedure TFmStockBillCheck.cdsStockBillCheckDtlBeforeInsert(
  DataSet: TDataSet);
begin
  if not ActBillDetail.Enabled then exit;
  if not FCanInsert then Abort;
end;

procedure TFmStockBillCheck.cdsStockBillCheckDtlBeforeDelete(
  DataSet: TDataSet);
begin
  if not ActBillDetail.Enabled then exit;
  if cdsStockBillCheckDtlOughtQty.Value <> 0 then
  begin
    MessageBox(Handle,'你不能删除由系统自动创建的盘点项!','警告',MB_ICONWARNING);
    Abort;
  end;
  if MessageBox(Handle,'真的要删除当前盘点项吗?','提示',MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON2)=IDNO then
    Abort;
end;

procedure TFmStockBillCheck.ActAuditExecute(Sender: TObject);
var
  iBranchID, iMachineId: integer;
  sBillNo,sSrcBillNo, sFlagStr, sUserID: string;
begin
  sBillNo := cbBillNo.Text ;
  if sBillNo = '' then exit;
  if cdsStockBillCheckFinish.Value then
  begin
    MessageBox(Handle,'当前盘点单已进行盈亏结算,不能再次结算!','警告',MB_ICONEXCLAMATION);
    exit;
  end;
  sSrcBillNo := sBillNo;
  iBranchID  := IFmMain.IFmMainEx.GetLocSetting^.BranchNo;
  iMachineId := IFmMain.IFmMainEx.GetLocSetting^.MachineNo;
  sUserID := IFmMain.IFmMainEx.LogonInfo^.UserID;
  sFlagStr := FormatFloat('000',iBranchID)+FormatFloat('00',iMachineID);
  sBillNo := SvrStockBillCheck.AppServer.CompleteStockBillCheck(iClientID,sBillNo,sUserID,sFlagStr,0);
  if sBillNo <> '' then
  begin
    if MessageBox(Handle,PChar('结算完成!系统已自动生成['+sBillNo+']号盘点盈亏单。'#13'要查看吗?'),'提示',MB_ICONINFORMATION or MB_YESNO)=IDYES then
      IFmMain.DoSome(ActViewBill.ModuleFile, 'ViewBill', sBillNo);
    cbBillNo.ItemIndex := cbBillNo.Items.IndexOf(sSrcBillNo);
    cbBillNoClick(nil);
  end;
end;

procedure TFmStockBillCheck.ActInsertExecute(Sender: TObject);
var
  iDepotID, iBranchID, iMachineId: integer;
  sBillNo, sFlagStr, sBerthNo, sUserID: string;
begin
  with TFmGetDepotAndBerth.Create(self) do
  try
    edDepotID.Text := cdsStockBillCheckDepotNo.Value;
    edDepotID.Tag := cdsStockBillCheckDepotID.Value;
    if ShowModal=mrOK then
    begin
      iDepotID := edDepotID.Tag;
      sBerthNo := edBerthNo.Text;
    end
    else
      exit;
  finally
    Free;
  end;
  iBranchID  := IFmMain.IFmMainEx.GetLocSetting^.BranchNo;
  iMachineId := IFmMain.IFmMainEx.GetLocSetting^.MachineNo;
  sUserID := IFmMain.IFmMainEx.LogonInfo^.UserID;
  sFlagStr := FormatFloat('000',iBranchID)+FormatFloat('00',iMachineID);
  sBillNo := SvrStockBillCheck.AppServer.StartStockBillCheck(iClientID,sFlagStr,iDepotID,sBerthNo,sUserID);
  if sBillNo = '' then exit;
  MessageBox(Handle,PChar('已成功新建按库整批盘点单!'#13'单号:'+sBillNo),'提示',MB_ICONINFORMATION);
  cbBillNo.ItemIndex := cbBillNo.Items.Add(sBillNo);
  cbBillNoClick(nil);
end;

procedure TFmStockBillCheck.ActDeleteExecute(Sender: TObject);
var
  sBillNo : string;
begin
  sBillNo := cbBillNo.Text ;
  if sBillNo = '' then exit;
  if cdsStockBillCheckFinish.Value then
  begin
    MessageBox(Handle,'当前盘点单已进行盈亏结算,不能中止!','警告',MB_ICONEXCLAMATION);
    exit;
  end;
  if MessageBox(Handle,'你确定要中止当前的盘点单吗?'#13'注意:盘点单一旦中止,在该单上的盘点数据将被删除且不能恢复!'#13'要继续吗?','警告',MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON2)=IDNO then exit;
  if SvrStockBillCheck.AppServer.AbortStockBillCheck(iClientID, sBillNo) then
    MessageBox(Handle,PChar('盘点单:'#13+sBillNo+' 已中止!'),'提示',MB_ICONINFORMATION);
  cbBillNo.ItemIndex := -1;
  LoadBillNoList;
end;

procedure TFmStockBillCheck.ActFieldLayoutExecute(Sender: TObject);
begin
  SetFieldsLayOut(LocSetting^.FieldLayoutCfgFile, Name,
                  [dbgCheckBillDtl],'按库整批盘点明细');
end;

procedure TFmStockBillCheck.ActDataExportExecute(Sender: TObject);
begin
  if not(cdsStockBillCheck.Active and cdsStockBillCheckDtl.Active) then exit;
  if cdsStockBillCheck.IsEmpty then
  begin
    MessageBox(Handle,'没有可导出的数据!','警告',MB_ICONEXCLAMATION);
    exit;
  end;
	ExportData([cdsStockBillCheck,cdsStockBillCheckDtl],'按库整批盘点;按库整批盘点明细', '');
end;

procedure TFmStockBillCheck.cdsStockBillCheckDtlBeforeEdit(
  DataSet: TDataSet);
begin
  if cdsStockBillCheckFinish.Value then
  begin
    MessageBox(Handle,'不能再操作已进行盈亏结算的盘点单!','警告',MB_ICONEXCLAMATION);
    Abort;
  end;
end;

initialization
  RegisterClass(TFmStockBillCheck);

finalization
  UnRegisterClass(TFmStockBillCheck);

end.

⌨️ 快捷键说明

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