initstockfrm.pas

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

PAS
651
字号

procedure TFmInitStock.ActAddExecute(Sender: TObject);
begin
  if StockInited(CurrDepotID) then begin
    Application.MessageBox('该仓库已经初始化!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
  cdsInitStock.Append;
  if not SelectGoods(cdsInitStock, cdsInitStockGoodsID, cdsInitStockUnit, true, true, false) then
    cdsInitStock.Cancel;
end;

procedure TFmInitStock.ActCopyExecute(Sender: TObject);
begin
  if (not cdsInitStock.Active)or(cdsInitStock.IsEmpty) then
    Exit;
  if StockInited(CurrDepotID) then begin
    Application.MessageBox('该仓库已经初始化!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
  CopyRecSelf(cdsInitStock, 'Qty', false);
  dbgInitStock.SetFocus;
end;

procedure TFmInitStock.ActDelExecute(Sender: TObject);
begin
  if StockInited(CurrDepotID) then begin
    Application.MessageBox('该仓库已经初始化!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
  if Application.MessageBox('确定删除当前记录吗?', '警告', MB_YESNO+MB_ICONWARNING)=IDYES then
    cdsInitStock.Delete;
end;

procedure TFmInitStock.ActChangeUnitExecute(Sender: TObject);
begin
  if StockInited(CurrDepotID) then begin
    Application.MessageBox('该仓库已经初始化!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
end;

procedure TFmInitStock.ActFieldLayoutExecute(Sender: TObject);
begin
  SetFieldsLayOut(LocSetting^.FieldLayoutCfgFile, Name, [dbgInitStock], '期初库存');
end;

procedure TFmInitStock.ActDataExportExecute(Sender: TObject);
begin
	ExportData([cdsInitStock], '期初库存', '');
end;

procedure TFmInitStock.cdsInitStockBeforeClose(DataSet: TDataSet);
begin
  if not cdsInitStock.Active then Exit;
  if cdsInitStock.State in dsEditModes then
    cdsInitStock.Post;
  if cdsInitStock.ApplyUpdates(0)>0 then
    raise Exception.Create('数据已修改,但提交到服务器失败!');
end;

procedure TFmInitStock.cdsInitStockQtyChange(Sender: TField);
begin
  cdsInitStockAmount.Value := cdsInitStockQty.Value*cdsInitStockPrice.Value;
end;

procedure TFmInitStock.dbgInitStockEditButtonClick(Sender: TObject);
var iDepotID: Integer;
    sBerthNo, sField, sProvNo, sProvName: String;
begin
  if not ActEdit.Enabled then Exit;
  sField := LowerCase(dbgInitStock.SelectedField.FieldName);
  if sField='berthno' then begin
    iDepotID := cdsInitStockDepotID.Value;
    if SelectBerth(iDepotID,sBerthNo) then begin
      cdsInitStock.Edit;
      cdsInitStockBerthNo.Value := sBerthNo;
    end;
  end else if (sField='provno')or(sField='provname') then begin
    if SelectProv(sProvNo,sProvName) then begin
      cdsInitStockProvNo.AsString := sProvNo;
      cdsInitStockProvName.AsString := sProvName;
    end;
  end;
end;

procedure TFmInitStock.cdsInitStockNewRecord(DataSet: TDataSet);
begin
  cdsInitStockDepotID.Value := CurrDepotID;
  cdsInitStockDepotNo.Value := CurrDepotNo;
  if ckAddByProvNo.Checked and (edProvNo.Text<>'') then
    cdsInitStockProvNo.Value := edProvNo.Text;
end;

procedure TFmInitStock.RzBitBtn6Click(Sender: TObject);
begin
  if not cdsInitSTock.Active then Exit;
  if Application.MessageBox('请谨慎使用此功能,你确定要放弃所有修改吗?', '警告', MB_OKCANCEL+MB_ICONWARNING)=IDOK then
  begin
    if Application.MessageBox('你真的考虑清楚了吗?丢失的数据将无法挽回!', '再次警告', MB_YESNO+MB_ICONQUESTION)=IDYES then
      cdsInitStock.CancelUpdates;
  end;
end;

procedure TFmInitStock.RzBitBtn7Click(Sender: TObject);
begin
  Close;
end;

procedure TFmInitStock.edGoodsIDKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key=13 then
    BtnDataFilter.Click;
end;

procedure TFmInitStock.edProvNoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key=13 then
    BtnDataFilter.Click
  else if Key=vk_Delete then begin
    edProvNo.Text := '';
    edProvNO.Hint := '';
  end;
end;

procedure TFmInitStock.edProvNoButtonClick(Sender: TObject);
var ProvNo,ProvName :String;
begin
  ProvNo := '';
  ProvName := '';
  if SelectProv(ProvNo,ProvName) then begin
    edProvNo.Text := ProvNo;
    edProvNo.Hint := ProvName;
  end;
end;

procedure TFmInitStock.cdsInitStockBeforeOpen(DataSet: TDataSet);
begin
  cdsInitStock.Filtered := false;
end;

procedure TFmInitStock.BtnDataFilterClick(Sender: TObject);
var str, sf: String;
begin
  str := edProvNo.Text;
  if str<>'' then
    sf := ' and ProvNo='''+str+'''';
  str := edBerthNo.Text;
  if str<>'' then
    sf := sf+' and BerthNo='''+str+'''';
  str := edGoodsID.Text;
  if str<>'' then
    sf := sf+' and GoodsID='''+str+'''';
  if sf<>'' then delete(sf, 1, 5);
  cdsInitStock.Filter := sf;
  cdsInitStock.Filtered := sf<>''; 
end;

procedure TFmInitStock.BtnUnFilteredClick(Sender: TObject);
begin
  cdsInitStock.Filtered := false;
end;

procedure TFmInitStock.ActDoInitializeExecute(Sender: TObject);
var aNode: TTreeNode;
    iDepotID: Integer;
    vDate: TDateTime;
    str: String;
begin
  aNode := tvDepots.Selected;
  if (aNode=nil)or(aNode.Level=0) then Exit;
  iDepotID := integer(aNode.Data);
  if not cdsDepots.Locate('DepotID', iDepotID, []) then
    raise Exception.Create('找不到仓库记录');
  if cdsDepots.FieldByName('RankDepot').AsBoolean then begin
    Application.MessageBox('只能对未初始化库存的实物仓进行库存初始化,而你选择的是虚拟仓!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
  if cdsDepots.FieldByName('initialized').AsBoolean then begin
    Application.MessageBox('此仓库已完成初始化!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
  if iDepotID<>CurrDepotID then begin
    str := '你所选择的仓库与当前正在查看库存的仓库不同,建议先查看库存记录是否正确,以避免误操作!'#13'按[是]返回,按[否]继续!';
    if Application.MessageBox(PChar(str), '警告', MB_YESNO+MB_ICONWARNING)=IDYES then
      Exit;
  end;
  str := InputBox('请输入', '请输入库存初始化日期,系统以该日期入库:', '');
  if str='' then Exit;
  try
    vDate := StrToDate(str);
  Except
    Application.MessageBox('请输入有效的日期值!', '消息', MB_ICONERROR);
    Exit;
  end;
  if Application.MessageBox('完成初始化以后的仓库将不允许再修改期初库存,继续吗?', '警告', MB_YESNO+MB_ICONWARNING)=IDNO then
    Exit;
  if SvrStock.AppServer.DoInitStock(IFmMain.IFmMainEx.ClientID, iDepotID, vDate) then begin
    plBottom.Enabled := false;
    with cdsDepots do begin
      Edit;
      FieldByName('initialized').AsBoolean := true;
      Post;
      aNode.Text := FieldByName('DepotNo').AsString+'['+FieldByName('DepotName').AsString+'](已初始化库存)';
    end;
  end;
end;

procedure TFmInitStock.ActUndoInitializeExecute(Sender: TObject);
var aNode: TTreeNode;
    iDepotID: Integer;
    str: String;
begin
  aNode := tvDepots.Selected;
  if (aNode=nil)or(aNode.Level=0) then Exit;
  iDepotID := integer(aNode.Data);
  if not cdsDepots.Locate('DepotID', iDepotID, []) then
    raise Exception.Create('找不到仓库记录');
  if cdsDepots.FieldByName('RankDepot').AsBoolean then
    Exit;
  if not cdsDepots.FieldByName('initialized').AsBoolean then begin
    Application.MessageBox('此仓库尚未进行库存初始化!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
  if iDepotID<>CurrDepotID then begin
    str := '你所选择的仓库与当前正在查看库存的仓库不同,建议先查看库存记录是否正确,以避免误操作!'#13'按[是]返回,按[否]继续!';
    if Application.MessageBox(PChar(str), '警告', MB_YESNO+MB_ICONWARNING)=IDYES then
      Exit;
  end;
  if Application.MessageBox('确定取消库存初始化吗?', '警告', MB_YESNO+MB_ICONWARNING)=IDNO then
    Exit;
  if SvrStock.AppServer.UndoInitStock(IFmMain.IFmMainEx.ClientID, iDepotID) then begin
    plBottom.Enabled := true;
    with cdsDepots do begin
      Edit;
      FieldByName('initialized').AsBoolean := false;
      Post; //这里Post以后并没有applyupdates是因为,在服务器的UndoInitStock方法已修改该的值,这里只是为了客户层面上的同步
      aNode.Text := FieldByName('DepotNo').AsString+'['+FieldByName('DepotName').AsString+'](未初始化库存)';
    end;
  end;
end;

procedure TFmInitStock.ActPrintExecute(Sender: TObject);
begin
  SelRepPrint(Name, [cdsInitStock], '期初库存记录', ActDesignReport.Enabled);
end;

procedure TFmInitStock.tvDepotsCollapsing(Sender: TObject; Node: TTreeNode;
  var AllowCollapse: Boolean);
begin
  AllowCollapse := Node.Level>0;
end;

procedure TFmInitStock.ActBuildInitStockExecute(Sender: TObject);
var sProvNo: String;
    mark1: TBookmark;
begin
  sProvNo := edProvNo.Text;
  if (sProvNo='')or not ckAddByProvNo.Checked then
  begin
    Application.MessageBox('请先选择供应商,并在"供应商"标签前的方框中打√。以用该供应商初始化库存!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
  if (not cdsInitStock.Active)or(AnsiPos('%', CurrDepotNo)>0) then begin
    Application.MessageBox('请先选择一个实物仓库,然后再执行此操作!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
  if SvrStock.AppServer.BuildInitStock(iClientID, CurrDepotID, edBerthNo.Text, sProvNo, edGoodsID.Text) then
  begin
    mark1 := cdsInitStock.GetBookmark;
    try
      cdsInitStock.Refresh;
      cdsInitStock.GotoBookmark(mark1);
    finally
      cdsInitStock.FreeBookmark(mark1);
    end;
  end;
end;

procedure TFmInitStock.ActClearZeroExecute(Sender: TObject);
var sProvNo, str: String;
begin
  sProvNo := edProvNo.Text;
  if (not cdsInitStock.Active)or(AnsiPos('%', CurrDepotNo)>0) then begin
    Application.MessageBox('为了避免操作失误,请先选择一个实物仓库,然后再执行此操作!', '消息', MB_ICONINFORMATION);
    Exit;
  end;
  if (sProvNo<>'')and ckAddByProvNo.Checked then
    str := '将清除'+sProvNo+'供应商在'+CurrDepotNo+'仓库中的期初库存为0的记录,确定吗?'
  else
    str := '将清除所有供应商在'+CurrDepotNo+'仓库中的期初库存为0的记录,确定吗?';
  if Application.MessageBox(PChar(str), '警告', MB_ICONINFORMATION+MB_OKCANCEL)=IDCANCEL then
    Exit;
  if SvrStock.AppServer.BuildInitStock(iClientID, CurrDepotID, sProvNo) then
    cdsInitStock.Refresh;
end;

procedure TFmInitStock.edGoodsIDButtonClick(Sender: TObject);
var sGoodsID: string;
begin
  if SelectGoodsID(sGoodsID, true) then
  begin
    edGoodsID.Text := sGoodsID;
  end;
end;

function TFmInitStock.StockInited(iDepotID: Integer): Boolean;
begin
  if not cdsDepots.Locate('DepotID', iDepotID, []) then
    raise Exception.Create('找不到仓库记录');
  if cdsDepots.FieldByName('RankDepot').AsBoolean then
    raise Exception.Create('你选择的是虚拟仓,请选择一个实物仓!');
  Result := cdsDepots.FieldByName('initialized').AsBoolean;
end;

initialization
  RegisterClass(TFmInitStock);

finalization
  UnRegisterClass(TFmInitStock);

end.

⌨️ 快捷键说明

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