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

📄 uquerygoodsbizdm.pas

📁 物流供应链管理系统
💻 PAS
字号:
unit uQueryGoodsBizDM;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComServ, ComObj, VCLCom, StdVcl, bdemts, DataBkr, DBClient,
  MtsRdm, Mtx, QueryGoodsBiz_TLB, DB, MConnect,Variants;

type
  TmtsQueryGoodsObj = class(TMtsDataModule, ImtsQueryGoodsObj)
    DCOMConQuery: TDCOMConnection;
    cdsQuery: TClientDataSet;
    procedure MtsDataModuleActivate(Sender: TObject);
    procedure MtsDataModuleDeactivate(Sender: TObject);
    procedure MtsDataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  protected
    class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
    function QueryGoodsInfoByBarCode(const ABarCode: WideString): OleVariant;
      safecall;
    function QueryGoodsBarCodeListByVendor(
      const AVendorId: WideString): WideString; safecall;
    function QueryGoodsCountByBarCode(const ABarCode: WideString): Integer;
      safecall;
    function QueryStockOutByBarCode(const ABarCode: WideString; AFromDate,
      AToDate: TDateTime): OleVariant; safecall;
    function QueryStockInByVendorId(const AVendorId: WideString; AFromDate,
      AToDate: TDateTime): OleVariant; safecall;
    function QueryGoodsBelowSafetyStock: OleVariant; safecall;
    function QueryStockOutByDateSpan(AFromDate,
      AToDate: TDateTime): OleVariant; safecall;
    function QueryVendorIdByBarCode(const ABarCode: WideString): WideString;
      safecall;
  public
    { Public declarations }
  end;

var
  mtsQueryGoodsObj: TmtsQueryGoodsObj;

implementation
uses BizDBConfig;
{$R *.DFM}

class procedure TmtsQueryGoodsObj.UpdateRegistry(Register: Boolean; const ClassID, ProgID: string);
begin
  if Register then
  begin
    inherited UpdateRegistry(Register, ClassID, ProgID);
    EnableSocketTransport(ClassID);
    EnableWebTransport(ClassID);
  end else
  begin
    DisableSocketTransport(ClassID);
    DisableWebTransport(ClassID);
    inherited UpdateRegistry(Register, ClassID, ProgID);
  end;
end;

function TmtsQueryGoodsObj.QueryGoodsInfoByBarCode(
  const ABarCode: WideString): OleVariant;
var
  LSql: TStringList;
begin
  result := null;
  LSql := TStringList.Create;
  LSql.Clear;
  LSql.Add('select Name,VendorId,Amount,SafetyStock,MinOrder,MaxOrder,EOQ ');
  LSql.Add('from t_GoodsMaster where BarCode=:BarCode');
  cdsQuery.Close;
  cdsQuery.CommandText := LSql.Text;
  LSql.Free;
  cdsQuery.Open;
  cdsQuery.Params.ParamByName('BarCode').AsString := ABarCode;
  if cdsQuery.RecordCount > 0 then
    result := cdsQuery.Data;
end;

function TmtsQueryGoodsObj.QueryGoodsBarCodeListByVendor(
  const AVendorId: WideString): WideString;
var
  sl: TStringList;
begin
  result := '';
  sl := TStringList.Create;
  sl.Clear;
  cdsQuery.Close;
  cdsQuery.CommandText := 'select Barcode from t_GoodsMaster '+
    'where VendorId=:VendorId';
  cdsQuery.Open;
  while not cdsQuery.Eof do
  begin
    sl.Add(cdsQuery.FieldByName('BarCode').AsString);
    cdsQuery.Next;
  end;
  result := sl.Text;
  sl.Free;
end;

function TmtsQueryGoodsObj.QueryGoodsCountByBarCode(
  const ABarCode: WideString): Integer;
begin
  result := 0;
  cdsQuery.Close;
  cdsQuery.CommandText := 'select Amount from t_GoodsMaster '+
    'Where BarCode=:BarCode';
  cdsQuery.Params.ParamByName('BarCode').AsString := ABarCode;
  cdsQuery.Open;
  if cdsQuery.RecordCount > 0 then
    result := cdsQuery.FieldByName('Amount').AsInteger;
end;

procedure TmtsQueryGoodsObj.MtsDataModuleActivate(Sender: TObject);
begin
  DCOMConQuery.Connected := true;
end;

procedure TmtsQueryGoodsObj.MtsDataModuleDeactivate(Sender: TObject);
begin
  DCOMConQuery.Connected := false;
end;

procedure TmtsQueryGoodsObj.MtsDataModuleCreate(Sender: TObject);
var
  cn: string;
begin
  cn := GetComputerName;
  DCOMConQuery.ComputerName := cn;
end;

function TmtsQueryGoodsObj.QueryStockOutByBarCode(
  const ABarCode: WideString; AFromDate, AToDate: TDateTime): OleVariant;
var
  LSql: TStringList;
  s: string;
begin
  result := null;
  LSql := TStringList.Create;
  LSql.Clear;
  LSql.Add('select distinct master.RealStockOutDate as MasterRealStockOutDate, ');
  LSql.Add(' slave.SendedAmount as SalveAmount ');
  LSql.Add('from t_StockOutRecordMaster master,t_StockOutRecordSlave slave ');
  s := Format('where master.RealStockOutDate>=%f and master.RealStockOutDate<=%f ',[AFromDate,AToDate]);
  LSql.Add(s);
  LSql.Add('and slave.Barcode=:BarCode');
  cdsQuery.Close;
  cdsQuery.CommandText := LSql.Text;
  cdsQuery.Params.ParamByName('BarCode').AsString := ABarCode;
  LSql.Free;
  cdsQuery.Open;
  if cdsQuery.RecordCount > 0 then
    result := cdsQuery.Data;
end;

function TmtsQueryGoodsObj.QueryStockInByVendorId(
  const AVendorId: WideString; AFromDate, AToDate: TDateTime): OleVariant;
var
  LSql: TStringList;
  s: string;
begin
  result := null;
  LSql := TStringList.Create;
  LSql.Clear;
  LSql.Add('select distinct master.SendableDate as MasterRealStockInDate, ');
  LSql.Add('slave.Barcode as SlaveBarCode, slave.ReceivedAmount as SalveAmount ');
  LSql.Add('from t_StockInRecordMaster master,t_StockInRecordSlave slave, ');
  LSql.Add('t_StockInListMaster inList');
  s := Format('where master.SendableDate>=%f and master.SendableDate<=%f ',[AFromDate,AToDate]);
  LSql.Add(s);
  LSql.Add('and inList.VendorId=:VendorId');
  cdsQuery.Close;
  cdsQuery.CommandText := LSql.Text;
  cdsQuery.Params.ParamByName('VendorId').AsString := AVendorId;
  LSql.Free;
  cdsQuery.Open;
  if cdsQuery.RecordCount > 0 then
    result := cdsQuery.Data;
end;

function TmtsQueryGoodsObj.QueryGoodsBelowSafetyStock: OleVariant;
var
  LSql: TStringList;
begin
  result := null;
  LSql := TStringList.Create;
  LSql.Clear;
  LSql.Add('select distinct BarCode, Name, VendorId,Amount, SafetyStock, MinOrder,');
  LSql.Add('MaxOrder,EOQ from t_GoodsMaster');
  LSql.Add('where Amount<=SafetyStock');
  cdsQuery.Close;
  cdsQuery.CommandText := LSql.Text;
  LSql.Free;
  cdsQuery.Open;
  if cdsQuery.RecordCount > 0 then
    result := cdsQuery.Data;
end;

function TmtsQueryGoodsObj.QueryStockOutByDateSpan(AFromDate,
  AToDate: TDateTime): OleVariant;
var
  LSql: TStringList;
  s: string;
begin
  result := null;
  LSql := TStringList.Create;
  LSql.Clear;
  LSql.Add('select distinct master.RealStockOutDate as MasterRealStockOutDate, ');
  LSql.Add(' slave.SendedAmount as SalveAmount ');
  LSql.Add('from t_StockOutRecordMaster master,t_StockOutRecordSlave slave ');
  s := Format('where master.RealStockOutDate>=%f and master.RealStockOutDate<=%f ',[AFromDate,AToDate]);
  LSql.Add(s);
  cdsQuery.Close;
  cdsQuery.CommandText := LSql.Text;
  LSql.Free;
  cdsQuery.Open;
  if cdsQuery.RecordCount > 0 then
    result := cdsQuery.Data;
end;

function TmtsQueryGoodsObj.QueryVendorIdByBarCode(
  const ABarCode: WideString): WideString;
var
  LSql: TStringList;
begin
  result := '';
  LSql := TStringList.Create;
  LSql.Clear;
  LSql.Add('select VendorId ');
  LSql.Add('from t_GoodsMaster where BarCode=:BarCode');
  cdsQuery.Close;
  cdsQuery.CommandText := LSql.Text;
  LSql.Free;

  cdsQuery.Params.ParamByName('BarCode').AsString := ABarCode;
  cdsQuery.Open;
  if cdsQuery.RecordCount > 0 then
    result := cdsQuery.FieldByName('VendorId').AsString;
end;

initialization
  TComponentFactory.Create(ComServer, TmtsQueryGoodsObj,
    Class_mtsQueryGoodsObj, ciMultiInstance, tmApartment);
end.

⌨️ 快捷键说明

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