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

📄 open.pas

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

interface

{$define DefTestCard}

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, Mask, DBClient, MConnect, MskEdit,
  Db, DBTables, ConstDef, ExtCtrls, Grids;

type

  TFrmOpen = class(TForm)
    DCOMOpen: TDCOMConnection;
    PanelCust: TPanel;
    GrpBoxCustInfo: TGroupBox;
    LabCustNo: TLabel;
    LabIDNo: TLabel;
    LabCustName: TLabel;
    LabMark: TLabel;
    EdtMark: TEdit;
    MskEdtCustName: TMskEdit;
    MskEdtIDNo: TMskEdit;
    MskEdtCustNo: TMskEdit;
    BtnOK: TButton;
    BtnCancel: TButton;
    PanelInfo: TPanel;
    PageCtrlInfo: TPageControl;
    TabSheetMeter: TTabSheet;
    LabENo: TLabel;
    LabEData: TLabel;
    LabEDegree: TLabel;
    LabEConst: TLabel;
    LabERemind: TLabel;
    LabEWarn: TLabel;
    LabESum: TLabel;
    ComboBoxEConst: TComboBox;
    MskEdtENo: TMskEdit;
    MskEdtEDegree: TMskEdit;
    MskEdtESum: TMskEdit;
    MskEdtERemind: TMskEdit;
    MskEdtEWarn: TMskEdit;
    MskEdtEDate: TMskEdit;
    TabSheetFind: TTabSheet;
    LabBuyNum: TLabel;
    MskEdtBuyNum: TMskEdit;
    GrpBoxBuyInfo: TGroupBox;
    LabEBuy: TLabel;
    LabEPriceType: TLabel;
    LabBuyLmt: TLabel;
    MskEdtEBuy: TMskEdit;
    ComboBoxEPriceType: TComboBox;
    MskEdtEBuyLmt: TMskEdit;
    StrGrid: TStringGrid;
    LabMsg: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BtnCancelClick(Sender: TObject);
    procedure BtnOKClick(Sender: TObject);
    procedure ComboBoxEConstChange(Sender: TObject);
    procedure ComboBoxEPriceTypeChange(Sender: TObject);
    procedure PrdFrmOpenIni(Sender: TObject);
    procedure PrdComboBoxIni(Sender: TObject);
    procedure PrdCustRWIni(Sender: TObject);
    procedure StrGridSelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure PrdCreatChkCard(Sender: TObject);
    procedure PrdClearChkCard(Sender: TObject);
    Function  bFunGetInputRec(Sender: TObject):Boolean;
    function  bFunGetCustDBData(var GetRW: RecRWCustDataType): Boolean;
    function  bFunClearDefCustDBData(GetRW: RecRWCustDataType): Boolean;
    function  bFunCmpCustDB_CardData(CustData: RecRWCustDataType;
                  CardData: RecRWCustDataType; CardKind: RecWriteCardKindType): Boolean;
  private
    { Private declarations }
    bCanWrite: Boolean;
  public
    { Public declarations }
    EnterMode: EnterModeType;
  end;

var
  FrmOpen:   TFrmOpen;

  CustRW: RecRWCustDataType;   //要进行读写的用户数据
  {CustRW.Cust:   RecCustInfoType;   //用户信息
   CustRW.EM:     RecEMeterInfoType; //电表信息(EMeter:Electrical Meter)
   CustRW.Buy:    RecBuyInfoType;    //申购信息}
  WriteCK: RecWriteCardKindType;//写要的卡类型

  aCntRslt:  Array[1..MaxCntRsltNum] of CntResultType; //存放各次远程连接结果

  iSelctRow: integer;//用户补卡时选择的行

Function  sFunCheckStr(sStrIn: String): widestring;
   export;far;external 'NIMStrans.dll';
Function  sFunGetRandomHexSC: WideString;
   export;far;external 'NIMStrans.dll';
Function  sFunGetStrByDate(dtDate: TDateTime): WideString;
   export;far;external 'NIMStrans.dll';
Function  btFunGetEMeterKind(var RecEKind: RecEMeterKindType):Byte;
   export;far;external 'NImsDB.dll';
Function  btFunGetEPriceKind(var RecEKind: RecEPriceKindType):Byte;
   export;far;external 'NImsDB.dll';

implementation

uses
  ClntMain, RWCard;
{$R *.DFM}

procedure TFrmOpen.FormCreate(Sender: TObject);
begin
  with DCOMOpen do begin
    ComputerName:=RecNImsInfo.SrvHost.sHostName;
    ServerGUID:=DefSrvGUID;
    LoginPrompt:=False;  Connected:=False;
   end;
end;

procedure TFrmOpen.PrdCustRWIni(Sender: TObject);
begin
  CustRW.iCustNo:=0;
  if EnterMode=NewCustMode then begin
     with CustRW.Cust do begin
    {$ifdef Def_Test} //设置用户密码
        sICSC:=OriCardPsw;
    {$else}
        sICSC:=sFunGetRandomHexSC;
    {$endif}
        sCustName:='请输入姓名'; sMark:='';
        sIDNo:='000000000000000';
      end;
   end
  else begin
     bCanWrite:=False;
     with CustRW.Cust do begin
        sCustName:=''; sMark:='';
        sICSC:='';     sIDNo:='';
      end;
   end;//end if
  with CustRW.EM do begin
    sENo:='00000001';  dtEDate:=Date;
    iEDegree:=0;       iEConstKind:=0;
    iEConst:=0;        iEBuyLmt:=200;
    iERemind:=20;      iEWarn:=10;
    iESum:=0;          iTotalNum:=0;
   end;
  with CustRW.Buy do begin
    iBuyNum:=0;        iECurBuy:=0;
    iEPriceKind:=0;    fEPrice:=0.0;
    iWCurBuy:=0;       iGCurBuy:=0;
   end;
end;

function TFrmOpen.bFunGetCustDBData(var GetRW:RecRWCustDataType): Boolean;
label TOGetError,TOGetOK;
var
  wsRetA,wsRetB,wsRetC,wsRetD: widestring;
  iRetA,iRetB,iRetC,iRetD,iRetE,iRetF,iRetG,iRetH: integer;
  fPrice: Double;
  EMK: RecEMeterKindType;
  CntRslt: CntResultType;
begin
   with DCOMOpen do begin
     with GetRW.Cust do begin //读指定用户信息数据库
       Connected:=True;
       CntRslt:=AppServer.btFunGetDefCust(GetRW.iCustNo,
                wsRetA,wsRetB,wsRetC,wsRetD);
       Connected:=False;
       sCustName:=wsRetA; sIDNo:=wsRetB;
       sICSC:=wsRetC;     sMark:=wsRetD;
      end; if CntRslt<>CntRecOK then goto TOGetError;
     with GetRW.EM do begin //读指定电表信息数据库
       Connected:=True;
       CntRslt:=AppServer.btFunGetDefEMeterInfo(GetRW.iCustNo,wsRetA,
                dtEDate,iRetA,iRetB,iRetC,iRetD,iRetE,iRetF,iRetG,iRetH);
       Connected:=False;
       sENo:=wsRetA; iEDegree:=iRetA; iEConstKind:=iRetB;
       iEConst:=iRetC; iEBuyLmt:=iRetD; iERemind:=iRetE;
       iEWarn:=iRetF;  iESum:=iRetG; iTotalNum:=iRetH;
      end; if CntRslt<>CntRecOK then goto TOGetError;
     with GetRW.Buy do begin //读指定申购信息数据库
       iBuyNum:=GetRW.EM.iTotalNum; //取最新一次购电记录
       Connected:=True;
       CntRslt:=AppServer.btFunGetDefBuyRecord(GetRW.iCustNo,
                iBuyNum,dtBuyDate,iRetB,iRetC,fPrice,wsRetA,wsRetB);
       Connected:=False;
       iECurBuy:=iRetB; iEPriceKind:=iRetC; fEPrice:=fPrice;
      end; if CntRslt<>CntRecOK then goto TOGetError;
      //取IC卡内存格式
     EMK.sAilas:=DefClntAlias; EMK.iEKind:=GetRW.EM.iEConstKind;
     if btFunGetEMeterKind(EMK)=Byte(CntSuccess) then
        GetRW.sEMemDT:=EMK.sEMemDT
     else goto TOGetError;
    end;//end DCOMOpen
TOGetOK:
   Result:=True; Exit;
TOGetError:
   Result:=False; Exit;
end;

function  TFrmOpen.bFunClearDefCustDBData(GetRW: RecRWCustDataType): Boolean;
label TOClearError,TOClearOK;
var
  CntRslt: CntResultType;
begin
  with DCOMOpen do begin
    Connected:=True; //清除指定用户信息数据库
    CntRslt:=AppServer.btFunClearDefCust(GetRW.iCustNo);
    Connected:=False;
    if CntRslt<>CntRecOK then goto TOClearError;

    Connected:=True; //清除指定电表信息数据库
    CntRslt:=AppServer.btFunClearDefEMeterInfo(GetRW.iCustNo);
    Connected:=False;
    if CntRslt<>CntRecOK then goto TOClearError;

    Connected:=True; //清除指定申购信息数据库
    CntRslt:=AppServer.btFunClearDefBuyRecord(GetRW.iCustNo,1);
    Connected:=False;
    if CntRslt<>CntRecOK then goto TOClearError;
   end;
TOClearOK:
   Result:=True; Exit;
TOClearError:
   Result:=False; Exit;
end;

function  TFrmOpen.bFunCmpCustDB_CardData(CustData: RecRWCustDataType;
                  CardData: RecRWCustDataType; CardKind: RecWriteCardKindType): Boolean;
Label  TOCmpError,TOCmpOK;
begin //CustData用户数据库内记录,CardData读用户卡内数据
  case CardKind.ECK of
    PatchForBuyCard,PatchBuyCard: begin
      Result:=True; Exit; end;
  else
    if CardData.EM.iTotalNum>CustData.EM.iTotalNum
      then begin Result:=False; Exit; end;
    if CardData.EM.iESum-1>CardData.EM.iEConsume+CardData.EM.iERemain
      then goto TOCmpError;
    if CustData.EM.iESum<CardData.EM.iESum+CardData.Buy.iECurBuy
      then goto TOCmpError;
   end;
TOCmpOK:
    Result:=True; Exit;
TOCmpError:
    Result:=False; Exit;
end;

Function  TFrmOpen.bfunGetInputRec(Sender: TObject):Boolean;
var
  iNum,iSum: integer;
begin
   if EnterMode=NewCustMode then begin
      iNum:=0;  iSum:=0;
    end
   else begin
      iNum:=CustRW.EM.iTotalNum;
      iSum:=CustRW.EM.iESum;
    end;
   CustRW.iCustNo:=strtoint(sFunCheckStr(MskEdtCustNo.EditText));
   with CustRW.Cust do begin
     sCustName:=MskEdtCustName.EditText;
     sIDNo:=MskEdtIDNo.EditText;  sMark:=EdtMark.Text;
    end;
   with CustRW.EM do begin
     sENo:=sFunCheckStr(MskEdtENo.EditText);
     iEDegree:=strtoint(sFunCheckStr(MskEdtEDegree.EditText));
     iEBuyLmt:=strtoint(sFunCheckStr(MskEdtEBuyLmt.EditText));
     iERemind:=strtoint(sFunCheckStr(MskEdtERemind.EditText));
     iEWarn:=strtoint(sFunCheckStr(MskEdtEWarn.EditText));
    end;
   if (EnterMode=NewCustMode) or (EnterMode=CustBuyMode) then begin
     CustRW.EM.iTotalNum:=iNum+1;//计算总申购次数
     with CustRW.Buy do begin //输入合法性检查
       iBuyNum:=CustRW.EM.iTotalNum;
       iECurBuy:=strtoint(sFunCheckStr(MskEdtEBuy.Text));
       if iECurBuy<=0 then begin
          wFunShowError('购电量不能为零!',[mbOK]); Result:=False; Exit;
        end;
       CustRW.EM.iESum:=iSum+iECurBuy;//计算总购电量
       if iECurBuy>CustRW.EM.iEBuyLmt then begin
          wFunShowError('购电超过限额!',[mbOK]); Result:=False; Exit;
        end;
       iWCurBuy:=0;  iGCurBuy:=0;
      end;//end with
     end;//end if
    ComboBoxEConstChange(Sender); {从下拉框中选择sEConst和sEConstKind}
    ComboBoxEPriceTypeChange(Sender);{从下拉框中选择sEPrice,sEPriceType}
    Result:=True;  Exit;
end;

procedure TFrmOpen.StrGridSelectCell(Sender: TObject; ACol, ARow: Integer;

⌨️ 快捷键说明

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