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

📄 srvrmt.pas

📁 计量功能 事件记录 购电提醒 欠费报警 负荷控制 自检功能 显示功能 用户插卡错误信息显示
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit SrvRmt;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComServ, ComObj, VCLCom, StdVcl, BdeProv, DataBkr, DBClient, NetImsServer_TLB,
  Provider, Db, DBTables, ConstDef, FieldDef;

type
  TNImsSrv = class(TRemoteDataModule, INImsSrv)
    ProviderInfo: TProvider;
    ProviderLog: TProvider;
    TabLog: TTable;
    TabCust: TTable;
    ProviderCust: TProvider;
    TabEMeterInfo: TTable;
    TabBuy: TTable;
    TabSoftInfo: TTable;
    procedure NImsSrvCreate(Sender: TObject);
    procedure NImsSrvDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  protected
    //===============================================================================//
    function Get_ProviderInfo: IProvider; safecall;
    //===============================================================================//
    function btFunRmtCnt(const wsHostName: WideString; btSum1: Byte; btSum2: Byte; btSum3: Byte;
                         btSum4: Byte; btSum5: Byte): Byte; safecall;
    function btFunAnswer(btAsk: Byte): Byte; safecall;
    function btFunGetEMeter(iEKind: Integer; var iEConst: Integer; var wsEMemDT: WideString;
                            var wsEMark: WideString): Byte; safecall;
    function btFunGetEPrice(iEPriceKind: Integer; var wsEPriceName: WideString;
                            var fEPrice: Double; var wsEPriceMark: WideString): Byte; safecall;
    //===============================================================================//
    function Get_ProviderLog: IProvider; safecall;
    //===============================================================================//
    function btFunRmtLogIn(const wsAccount: WideString; const wsPsw: WideString; var btClass: Byte;
                           var wsName: WideString; var wsMark: WideString): Byte; safecall;
    function btFunRmtLogOff(const wsAccount: WideString; btClass: Byte): Byte; safecall;
    function btFunRmtAllLogOff: Byte; safecall;
    function btFunRmtChgPsw(const wsAccount: WideString; const wsPsw: WideString;
                            const wsNewPsw: WideString): Byte; safecall;
    //===============================================================================//
    function Get_ProviderCust: IProvider; safecall;
    //===============================================================================//
    function btFunAddNewCust(var iCustNo: Integer; const wsCustName: WideString;
                             const wsIDNo: WideString; const wsICSC: WideString;
                             const wsMark: WideString): Byte; safecall;
    function btFunGetDefCust(iCustNo: Integer; var wsCustName: WideString; var wsIDNo: WideString;
                             var wsICSC: WideString; var wsMark: WideString): Byte; safecall;
    function btFunSetDefCust(iCustNo: Integer; const wsMark: WideString): Byte; safecall;
    function btFunClearDefCust(iCustNo: Integer): Byte; safecall;
    function btFunFindLikeCust(var iCustNo: Integer; var wsName: WideString;
                               var wsIDNo: WideString; var iRecNo: Integer): Byte; safecall;
    function btFunAddNewEMeterInfo(iCustNo: Integer; const wsENo: WideString;
                                   var dtEDate: TDateTime; iEDegree: Integer; iEConstKind: Integer;
                                   iEConst: Integer; iEBuyLmt: Integer; iERemind: Integer;
                                   iEWarn: Integer; iESum: Integer; iTotalNum: Integer): Byte; safecall;
    function btFunGetDefEMeterInfo(iCustNo: Integer; var wsENo: WideString; var dtEDate: TDateTime;
                                   var iEDegree: Integer; var iEConstKind: Integer;
                                   var iEConst: Integer; var iEBuyLmt: Integer;
                                   var iERemind: Integer; var iEWarn: Integer; var iESum: Integer;
                                   var iTotalNum: Integer): Byte; safecall;
    function btFunSetDefEMeterInfo(iCustNo: Integer; iEBuyLmt: Integer; iERemind: Integer;
                                   iEWarn: Integer; iESum: Integer; iTotalNum: Integer): Byte; safecall;
    function btFunClearDefEMeterInfo(iCustNo: Integer): Byte; safecall;
    function btFunAddBuyRecord(iCustNo: Integer; iBuyNum: Integer; var dtBuyDate: TDateTime;
                               iECurBuy: Integer; iEPriceKind: Integer; fEPrice: Double;
                               const wsOpName: WideString; const wsHostName: WideString): Byte; safecall;
    function btFunGetDefBuyRecord(iCustNo: Integer; iBuyNum: Integer; var dtBuyDate: TDateTime;
                                  var iECurBuy: Integer; var iEPriceKind: Integer;
                                  var fEPrice: Double; var wsOpName: WideString;
                                  var wsHostName: WideString): Byte; safecall;
    function btFunClearDefBuyRecord(iCustNo: Integer; iBuyNum: Integer): Byte; safecall;
    //===============================================================================//
  end;

var
  NImsSrv: TNImsSrv;

Procedure PrdGetSumFromGUID(sGUID:string;var RecSum:RecCheckSumType);
   export;far;external 'NIMSsys.dll';
Function  btFunGetEMeterKind(var RecEKind: RecEMeterKindType):Byte;
   export;far;external 'NImsDB.dll';
Function  btFunGetEPriceKind(var RecEKind: RecEPriceKindType):Byte;
   export;far;external 'NImsDB.dll';

implementation

{$R *.DFM}

//============================================//
function TNImsSrv.Get_ProviderInfo: IProvider;
begin
  Result := ProviderInfo.Provider;
end;

function TNImsSrv.Get_ProviderLog: IProvider;
begin
  Result := ProviderLog.Provider;
end;

function TNImsSrv.Get_ProviderCust: IProvider;
begin
  Result := ProviderCust.Provider;
end;
//============================================//

//==================================================================================//
function TNImsSrv.btFunRmtCnt(const wsHostName: WideString; btSum1: Byte;
            btSum2: Byte; btSum3: Byte; btSum4: Byte; btSum5: Byte): Byte; safecall;
var
  sHostName,sSoftID: string;
  RecSum:RecCheckSumType;
begin
  sHostName:=wsHostName;
  try
   with tabSoftInfo do begin
     DatabaseName:=DefSrvAlias; Open;
     SetKey;
     FieldByName(FLDSHostName).AsString:=sHostName;
     if not GotoKey then begin //查找计算机名
       Result:=Byte(InValidNetIms);
       tabSoftInfo.close; Exit;
      end;
     sSoftID:=FieldByName(FLDSSoftID).AsString; //检查SoftID
     PrdGetSumFromGUID(sSoftID,RecSum);
     if (RecSum.btSum1=btSum1) and (RecSum.btSum2=btSum2)
       and (RecSum.btSum3=btSum3) and (RecSum.btSum4=btSum4)
       and (btSum5=btSum5) then Result:=Byte(CntSuccess)
     else  Result:=Byte(InValidNetIms);
    end;
   tabSoftInfo.close;
  except
    Result:=Byte(CntFail);
   end;
end;

function TNImsSrv.btFunAnswer(btAsk: Byte): Byte; safecall;
begin //网络应答
   Result:=btAsk;
end;

function TNImsSrv.btFunGetEMeter(iEKind: Integer; var iEConst: Integer; var wsEMemDT: WideString;
                  var wsEMark: WideString): Byte; safecall;
var
  RecEMKind: RecEMeterKindType;
  btRet: Byte;
begin
  RecEMKind.sAilas:=DefSrvAlias;
  RecEMKind.iEKind:=iEKind;
  btRet := btFunGetEMeterKind(RecEMKind);
  if btRet=Byte(CntSuccess) then begin
     iEConst:=RecEMKind.iEConst;
     wsEMemDT:=RecEMKind.sEMemDT;
     wsEMark:=RecEMKind.sEMark;
   end;
  Result := btRet;
end;

function TNImsSrv.btFunGetEPrice(iEPriceKind: Integer; var wsEPriceName: WideString;
                  var fEPrice: Double; var wsEPriceMark: WideString): Byte; safecall;
var
  RecEPKind: RecEPriceKindType;
  btRet: Byte;
begin
  RecEPKind.sAilas:=DefSrvAlias;
  RecEPKind.iEPriceKind:=iEPriceKind;
  btRet := btFunGetEPriceKind(RecEPKind);
  if btRet=Byte(CntSuccess) then begin
     wsEPriceName:=RecEPKind.sEPriceName;
     fEPrice:=RecEPKind.fEPrice;
     wsEPriceMark:=RecEPKind.sEPriceMark;
   end;
  Result := btRet;
end;

function TNImsSrv.btFunRmtLogIn(const wsAccount, wsPsw: WideString;
                  var btClass: Byte; var wsName, wsMark: WideString): Byte; safecall;
var
  sTOpClass:  String;
  btTOpClass: Byte;
begin
  try
   with tabLog do begin
     DatabaseName:=DefSrvAlias; Open;
     SetKey;
     FieldByName(FLDSAccount).AsString:=wsAccount;
     if not GotoKey then begin //查找登录帐号
       Result:=Byte(CntNotExist);
       tabLog.close; Exit;
      end;
     if wsPsw<>FieldByName(FLDSPsw).AsString then begin
       Result:=Byte(CntPswError); //检测登录密码
       tabLog.close; Exit;
      end;
     if FieldByName(FLDBLog).AsBoolean then begin
       Result:=Byte(CntLogged);   //检测是否已经登录
       tabLog.close; Exit;
      end;
     sTOpClass:=FieldByName(FLDCOpClass).AsString;
     btTOpClass:=Byte(sTOpClass[1]); //核对系统操作员级别
     if ((btClass<>Byte(DefSysNullChar)) and (btTOpClass<>btClass)) or
        ((btClass=Byte(DefSysNullChar)) and (btTOpClass=Byte(DefSysOpChar)))
       then begin
         Result:=Byte(CntNotExist);
         tabLog.close; Exit;
      end;               //若登录前系统操作级别为DefSysNullChar
     btClass:=btTOpClass;//则登录后返回登录帐号的系统操作级别
     wsName:=FieldByName(FLDSOpName).AsString;
     wsMark:=FieldByName(FLDSMark).AsString;
     Edit;
     FieldByName(FLDBLog).AsBoolean:=True;//设置系统操作员登录
     Post; SetKey;
     Result:=Byte(CntLogOK);
    end;
   tabLog.close;
  except
    Result:=Byte(CntLogFail);
   end;
end;

function TNImsSrv.btFunRmtLogOff(const wsAccount: WideString;
                  btClass: Byte): Byte;  safecall;
var
  sTOpClass: String;
begin
  try
   with tabLog do begin
     DatabaseName:=DefSrvAlias; Open;
     SetKey;
     FieldByName(FLDSAccount).AsString:=wsAccount;
     if not GotoKey then begin //查找登录帐号
       Result:=Byte(CntNotExist);
       tabLog.close; Exit;
      end;
     sTOpClass:=FieldByName(FLDCOpClass).AsString;
     if btClass<>Byte(sTOpClass[1]) then begin
       Result:=Byte(CntNotExist); //核对系统操作员级别
       tabLog.close; Exit;
      end;
     if not FieldByName(FLDBLog).AsBoolean then begin
       Result:=Byte(CntLogged);  //检测是否已经登录
       tabLog.close; Exit;
      end;
     Edit;
     FieldByName(FLDBLog).AsBoolean:=False;//设置系统操作员退出
     Post;
     Result:=Byte(CntLogOK);
    end;
   tabLog.close;
  except
    Result:=Byte(CntLogFail);
   end;
end;

function TNImsSrv.btFunRmtAllLogOff: Byte; safecall;
var
  iCount: integer;
begin
  try
   with tabLog do begin
     DatabaseName:=DefSrvAlias; Open;
     for iCount:=1 to RecordCount do
       begin //关闭所有帐号
         SetKey; RecNo:=iCount; Edit;
         if FieldByName(FLDBLog).AsBoolean then begin
            FieldByName(FLDBLog).AsBoolean:=False;
            Post;
          end;
       end;
     Result:=Byte(CntLogOK);
    end;
   tabLog.close;
  except
    Result:=Byte(CntLogFail);
   end;
end;

function TNImsSrv.btFunRmtChgPsw(const wsAccount, wsPsw,
                  wsNewPsw: WideString): Byte; safecall;
var
  sT1,sT2: String;
begin
  try
   with tabLog do begin
     DatabaseName:=DefSrvAlias; Open;
     SetKey;
     FieldByName(FLDSAccount).AsString:=wsAccount;
     if not GotoKey then begin  //查找登录帐号
       Result:=Byte(CntNotExist);
       tabLog.close; Exit;
      end;
     sT1:=wsPsw;  sT2:=FieldByName(FLDSPsw).AsString;
     if sT1<>sT2 then begin   //核对旧登录密码
       Result:=Byte(CntPswError);
       tabLog.close; Exit;
      end;
     sT1:=wsNewPsw;
     Edit;
     FieldByName(FLDSPsw).AsString:=sT1;//设置新口令
     Post; SetKey;
     Result:=Byte(CntChgPswOK);
    end;
   tabLog.close;
  except
    Result:=Byte(CntLogFail);
   end;
end;
//==================================================================================//

//==================================================================================//
function TNImsSrv.btFunAddNewCust(var iCustNo: Integer; const wsCustName: WideString;
                  const wsIDNo: WideString; const wsICSC: WideString;
                  const wsMark: WideString): Byte; safecall;
var
  iGetNo: integer;
begin
  try
    with tabCust do begin
      DatabaseName:=DefSrvAlias; Open;
      Last;
      iGetNo:=FieldByName(FLDiCustNo).AsInteger;
      iCustNo:=iGetNo+1;
      Insert; //添加新记录
      FieldByName(FLDiCustNo).AsInteger:=iCustNo;
      FieldByName(FLDSIDNo).AsString:=wsIDNo;
      FieldByName(FLDSCustName).AsString:=wsCustName;
      FieldByName(FLDSICSC).AsString:=wsICSC;
      FieldByName(FLDSMark).AsString:=wsMark;
      Post; Result := Byte(CntRecOK);
     end;
    tabCust.close;
  except
    Result := Byte(CntRecFail);
   end;

⌨️ 快捷键说明

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