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

📄 tcommfunc_unit.pas

📁 这是一个非常实用的实时串口通讯程序
💻 PAS
📖 第 1 页 / 共 3 页
字号:
                      Break;
                   end
                else
                   begin
                      CommNetDriver.ClientComm.SendData(@bSendDataBuf,11);
                   end;
              end;
            ERROR_CALL:
              begin
                CommNetDriver.ClientComm.SendData(@bSendDataBuf,11);
             end;
            End;
          end;
        end;
      end;
      if iCount<3 then
         begin
           result :=true;
         end
      else
         begin
           result :=false;
         end;
    end;
except
end;
end;

procedure TCommFuncClass.InitPosSeting;
{ 从数据库中提取总控器以及每一路总控器所带的控水器的状态}
var
  sSqlStr : String;
  LINKNUM,TCTNUM : Integer;
  i : Integer;
  CTStatus1     : array [1..16]   of Byte;
  CTStatusBit  : Byte;
  iCTValid     : Integer;
  iPosition    : Integer;
  iBit         : Integer;
  jpath        :integer;
begin
    LINKNUM := 1;           // DownloadPosPathSql :=' SELECT Distinct CT_TCPathNUM FROM CTMachineTAB WHERE (CT_CommandNum = 1) ';
    i:=1;
    for jpath :=1 to 4 do
    begin
      if DownloadPath[jpath] =1  then
      begin
         TCTNUM :=jpath;
         TCTLINK[LINKNUM]:=TCTNUM;
         Inc(LINKNUM);
         if GLBDataModule.CTSearADOQuery.Active then GLBDataModule.CTSearADOQuery.Close;
           GLBDataModule.CTSearADOQuery.SQL.Text :='SELECT CT_MachineNUM, CT_VALID  FROM CTMachineTAB '+
                        ' WHERE (CT_CommandNum = 1) AND (CT_TCPathNUM ='+IntToStr(TCTNUM)+') ORDER BY CT_MachineNUM';
         try
           try
              ZeroMemory(@CTStatus1,16);
              GLBDataModule.CTSearADOQuery.Open;
              while Not GLBDataModule.CTSearADOQuery.Eof do
              begin
                 CTStatusBit := GLBDataModule.CTSearADOQuery.FieldByName('CT_MachineNUM').AsInteger;
                 iCTValid    := GLBDataModule.CTSearADOQuery.FieldByName('CT_VALID').AsInteger;
                 CTStatus[i] := iCTValid;
                 Inc(i);
                 if (CTStatusBit mod 8=0) then
                     begin
                        iPosition   := CTStatusBit div 8;
                     end
                 else
                     begin
                        iPosition   := CTStatusBit div 8 + 1;
                     end;
                 iBit        := CTStatusBit mod 8;
                 Case iBit Of
                       1:begin
                         if (iCTValid=1) then
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] Or $80;
                            end
                         else
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] And $7F;
                            end;
                      end;
                    2:begin
                         if (iCTValid=1) then
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] Or $40;
                            end
                         else
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] And $BF;
                            end;
                      end;
                    3:begin
                         if (iCTValid=1) then
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] Or $20;
                            end
                         else
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] And $DF;
                            end;
                      end;
                    4:begin
                         if (iCTValid=1) then
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] Or $10;
                            end
                         else
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] And $EF;
                            end;
                      end;
                    5:begin
                         if (iCTValid=1) then
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] Or $08;
                            end
                         else
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] And $F7;
                            end;
                      end;
                    6:begin
                         if (iCTValid=1) then
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] Or $04;
                            end
                         else
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] And $FB;
                            end;
                      end;
                    7:begin
                         if (iCTValid=1) then
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] Or $02;
                            end
                         else
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] And $FD;
                            end;
                      end;
                    0:begin
                         if (iCTValid=1) then
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] Or $01;
                            end
                         else
                            begin
                               CTStatus1[iPosition] := CTStatus1[iPosition] And $FE;
                            end;
                      end;
                 End;
                 GLBDataModule.CTSearADOQuery.Next;
              end;
              CopyMemory(@TCTLINK[LINKNUM],@CTStatus1[1],16);
              Inc(LINKNUM,16);
           except

           end;
         finally
           if GLBDataModule.CTSearADOQuery.Active then GLBDataModule.CTSearADOQuery.Close;
         end;
      end;
    end;
end;

procedure TCommFuncClass.ReadCardPro(CardNo :Cardinal);
var
  op_money, lea_money : Real;
  oldCardNo : Cardinal;
  CardMoney :integer;
  pDataBuf : array [1..1024] of Byte;
  i,j  : integer;
  Ret : Integer;
  pMoney, plMoney, pStatus, Now1Rate,Now2Rate,Now3Rate :Integer;
  BlockData, NewKeyData:String;
  Key_type ,password: Integer;
begin
try
  ///刷卡操作///与界面结合 **********************************
   Case iChangeCardNo Of
    1:
      begin
         AccInfoSet_Form.Edit2.Text := IntToHex(CardNo,8);
         Bleep(bOK);
      end;
    2:
      begin
         if (SetCardNo_Form.ListView1.Selected<>Nil) then
            begin
            if SetCardNo_Form.ListView1.Selected.SubItems.Strings[2]='' then
              begin
                /////////同一张卡///////////////
                if oldCardNo = CardNo then
                begin
                  SetCardNo_Form.Label5.Caption:= '卡片无效请换卡!';
                  SetCardNo_Form.Label5.Color :=$00FEA89E;
                  PcSlide;
                  Exit;
                end
                else
                begin
                  oldCardNo := CardNo;
                end;
                  
                With GlbDataModule.ADOQuery_Read do
                begin
                  if CardVerify=0 then//进行授权
                  begin
                    Close;
                    Sql.Text := 'Select Count(*) From JzksCard Where CardNo ='+IntToStr(CardNo);
                    try
                     Open;
                    except
                    end;
                    if Fields[0].AsInteger =0 then
                    begin
                      SetCardNo_Form.Label5.Caption:= '卡片未授权!';
                      SetCardNo_Form.Label5.Color :=$00FEA89E;
                      PcSlide;
                      exit;
                    end;
                  end;

                  //////////050331////////////////////////
                  if VerifyCard(CardNo) <>0 then  ///使用卡片注册码校验卡片是否授权
                  begin
                    SetCardNo_Form.Label5.Caption:= '卡片未授权!';
                    SetCardNo_Form.Label5.Color :=$00FEA89E;
                    PcSlide;
                  end
                  else
                  /////////////////////////////////////////
                  begin
                    try
                      begin
                        if Active then Close;
                        SQL.Text := 'SELECT COUNT(*) FROM PERSON_ACCOUNT WHERE PA_CARDNO=' + IntToStr(CardNo);
                        try
                           try
                              Open;
                              if (Fields.Fields[0].AsInteger>0) then
                                 begin
                                    SetCardNo_Form.Label5.Caption:= '该卡片已经注册!';
                                    SetCardNo_Form.Label5.Color :=$00FEA89E;
                                    PcSlide;
                                 end
                              else
                                //////???????????????
                                begin
                                  if Active then Close;
                                  SQL.Text := 'SELECT COUNT(*) FROM Sys_USERS WHERE Oper_Card=' + IntToStr(CardNo);
                                  try
                                     Open;
                                     if (Fields.Fields[0].AsInteger>0) then
                                        begin
                                           SetCardNo_Form.Label5.Caption:= '该卡片已经注册!';
                                           SetCardNo_Form.Label5.Color :=$00FEA89E;
                                           PcSlide;
                                        end;
                                  except
                                  end;

                                  //////???????????????
                                  if (StrToFloat(AccPre) >= StrToFloat(SetCardNo_Form.Edit3.Text)) then
                                  begin
                                  ///先写卡片
                                    CardMoney:= Round(StrToFloat(AccPre)*100 -StrToFloat(SetCardNo_Form.Edit3.Text)*100);
                                   if  WriteOpenAccCard(CardNo,0,CardMoney,cardpLMoney,dpassWord,Cardp1Rate,Cardp2Rate,Cardp3Rate,0)<>true then
                                   begin
                                     SetCardNo_Form.Label5.Caption:= '卡片写卡失败!';
                                     SetCardNo_Form.Label5.Color :=$00FEA89E;
                                     Exit;
                                   end;
                                  ///
                                    GlbDataModule.ADOConn_ReadCard.BeginTrans;
                                    begin
                                      if Active then Close;
                                      SQL.Text := 'UPDATE PERSON_ACCOUNT SET PA_CARDNO='+IntToStr(CardNo)+',Card_DateTime ='''+FormatDateTime('yyyy-mm-dd hh:nn:ss',now)+''', '+
                                        '  PA_MONEY='+FloatToStr(StrToFloat(AccPre)*100 -StrToFloat(SetCardNo_Form.Edit3.Text)*100)+', '+
                                        '  CardFee=CardFee + '+FloatToStr(StrToFloat(SetCardNo_Form.Edit3.Text)*100)+' '+
                                        '  WHERE PA_ACCOUNT=' + Trim(SetCardNo_Form.ListView1.Selected.Caption);
                                      try
                                          ExecSql;
                                          Close;
                                          Sql.Text := 'SELECT Trade_Time FROM PERSON_ACCOUNT Where PA_ACCOUNT=' + Trim(SetCardNo_Form.ListView1.Selected.Caption) ;
                                          Open;
                                          if VarIsNull(FieldbyName('Trade_Time').Value) then
                                          begin
                                            Close;
                                            Sql.Text :=' Update AccountGlideTAB set ORCardFee ='+FloatToStr(StrToFloat(SetCardNo_Form.Edit3.Text)*100)+' '+
                                                       ' Where  Account_No='+CardAcc+' and Consume_type =1 '+
                                                       ' INSERT INTO AccountGlideTAB '+
                                                       '        (Account_No, Account_Name, Account_DeptName, Account_Degree, PreView_Money,Consume_Money,'+
                                                       '         Now_Money, Record_Time, Operator_Name,Operator_ID,Consume_type,CardFee_type) '+
                                                       '  VALUES ('+CardAcc+','''+CardName+''','''+CardDept+''','''+CardDeg+''','+
                                                       ' '+FloatToStr(StrToFloat(AccPre)*100)+','+FloatToStr(StrToFloat(SetCardNo_Form.Edit3.Text)*-100)+','+
                                                       ' '+FloatToStr((StrToFloat(AccPre)-StrToFloat(SetCardNo_Form.Edit3.Text))*100)+','+
                                                       ' '''+FormatDateTime('yyyy-mm-dd hh:nn:ss',now)+''','''+UserName+''','+
                                                       ' '+IntToStr(UserID)+',8,1)';
                                            try
                                              ExecSql;

⌨️ 快捷键说明

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