我们公司的delphi代码(胆不是我写的!),看看,你觉得怎么样

Posted jijm123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我们公司的delphi代码(胆不是我写的!),看看,你觉得怎么样相关的知识,希望对你有一定的参考价值。

unit unt_LotBill_dyc;

interface

uses
  windows, SysUtils, Classes, ComCtrls, Forms, Controls, StrUtils, Math, superobject,
  SyncObjs, unt_ShareVar, unt_LotVar, uDycIFace;

type
  TLotBillDyc = class
  private
  protected
    class function FormatIssueForBill(LotID, AIssue: integer): string;
    class function CreateTicketID(LotID, OptID, ChipID: integer): string;
  public
    class function DoPostWithoutThread(const ALotID: Integer; const BillID, AnteCode,
      BillIssue: string; const ChipMul, TicketMoney, AOneMoney: Integer;
      const sPlayType:string=‘‘): integer;
    class function InitParam(ErrMsgFlag: boolean = true): boolean;
    class function DoPrepare(const AChip: TChipProjInfo): integer;
    //投注相关操作
    class function DoPrint(const AChip: TChipProjInfo; AItem: TListItem;
      ShowErrFlag: boolean = true): integer;
    class function DoQueryAndFinishPrint(const AChip: TChipProjInfo): integer;
    class function PrintQuery(const AValue: ISuperObject): Integer;
  end;

implementation

uses
  DmLottery, unt_ActionDef, unt_ShareFunc, unt_LotShareFunc, uXcReqFun, unt_OptVar,
  unt_Lottery, LcUtils, unt_StrFunc;

{ 参数初始化 }
class function TLotBillDyc.InitParam(ErrMsgFlag: boolean): boolean;
var
  Version, md5key, url, partnerid: string;
begin
  url := GUserIniFile.ReadString(INI_BILL_ROOT, billurl_21, ‘‘);
  Version := GUserIniFile.ReadString(INI_BILL_ROOT, billuid_21, 1.0);
  partnerid := GUserIniFile.ReadString(INI_BILL_ROOT, billkey_21, ‘‘);
  md5key := GUserIniFile.ReadString(INI_BILL_ROOT, billpwd_21, ‘‘); 
  if (url = ‘‘) or (md5key = ‘‘) then
  begin
    if ErrMsgFlag then
      TShareFunc.ShowWarn(对不起,请配置您的出票服务接口地址!);
    Exit;
  end;
  partnerid := TShareFunc.UncrypString(partnerid); //解密
  md5key := TShareFunc.UncrypString(md5key); //解密
  InitDycParam(Version,partnerid,md5key,url);
  //InitDycParam(‘31017736722‘,‘136016974‘,‘d4I9y24I9C3a1i9O‘,‘http://openapi.diyicai.com/enterpriseAPI/lotServiceCtrl!login.ac‘);
  Result := true;
end;

class function TLotBillDyc.FormatIssueForBill(LotID, AIssue: integer): string;
begin
  if LotID=LOT_ID_ELEVEN then
    Result := Copy(IntToStr(AIssue),3, 10)
  else
    Result := IntToStr(AIssue);
end;

class function TLotBillDyc.PrintQuery(const AValue: ISuperObject): Integer;
var
  sSql: string;
  res : ISuperObject;
  nChipMoney, nResult: integer;
begin
  Result := 0;
  res := DycTicketCheckOut(AValue.s[DycID]);
  if Assigned(res) then
  begin
    if res.i[Code] = 9 then
    begin
      //出票成功
      nResult := 9;
      Result := Result + res.i[Value.amount];
    end
    else if res.i[Code] = 8 then
      //出票失败、撤单、流单
      nResult := 8
    else
    begin
      //其他
      nResult := 1;
    end;
    sSql := UPDATE Sale_LotBillRec SET BillReturn=‘‘%s‘‘, BillResult=%d WHERE TicketID=‘‘%s‘‘;
    sSql := Format(sSql, [res.AsJSon, nResult, AValue.s[LocID]]);
    dmLot.conShare.Execute(sSql);
  end;
end;

class function TLotBillDyc.DoPrepare(const AChip: TChipProjInfo): integer;
var
  obj: ISuperObject;
  sSql: string;
begin
  Result := 0;
  sSql := SELECT TicketID, BillOrder FROM Sale_LotBillRec WHERE (BillResult NOT IN (0,9)) AND LotID=
    + IntToStr(AChip.LotID) +  AND OptID in  + ZxhtGetProjID(AChip.OptID);
  dmLot.qryPublic.Close;
  dmLot.qryPublic.SQL.Text := sSql;
  dmLot.qryPublic.Open;
  while not dmLot.qryPublic.Eof do
  begin
    obj := SO;
    obj.S[DycID] := dmLot.qryPublic.FieldByName(BillOrder).AsString;
    obj.S[LocID] := dmLot.qryPublic.FieldByName(TicketID).AsString;
    dmLot.qryPublic.Next;
    Result:= Result + PrintQuery(obj);
  end;
  dmLot.qryPublic.Close;
end;

class function TLotBillDyc.DoQueryAndFinishPrint(const AChip: TChipProjInfo): integer;
var
  sSql, TIDs: string;
begin
  //先查询出票结果
  Self.DoPrepare(AChip);
  Result := 0;
  sSql := SELECT SUM(ChipMoney*ChipMul) FROM Sale_LotBillRec WHERE BillResult=9 AND LotID=
    + IntToStr(AChip.LotID) +  AND OptID IN  + ZxhtGetProjID(AChip.OptID);
  Result := dmLot.GetFirstValInt(sSql, 0);
  //如果出票成功则自动更新状态
  if (Result > 0) and (Result = AChip.ChipMoney) then
  begin
    sSql := SELECT BillOrder FROM Sale_LotBillRec WHERE LotID=%d AND OptId IN %s;
    sSql := Format(sSql, [AChip.LotID, ZxhtGetProjID(AChip.OptID)]);
    try
      TIDs := DmLot.GetSomeValStr(sSql, ,, True);
    except
      TIDs := ‘‘;
    end;
    if TIDs<>‘‘ then
      XcFinishPrint(CurrUserInfo.UserID, AChip.LotID, AChip.OptID, TIDs)
    else
      Result:= 0;
  end
  else Result:=0;
end;

{ 生成唯一的出票票号 }
class function TLotBillDyc.CreateTicketID(LotID, OptID, ChipID: integer):string;
begin
  Result := IntToStr(OptID) + A + IntToStr(ChipID);
end;

{ 不通过线程出票 }
class function TLotBillDyc.DoPostWithoutThread(const ALotID: Integer; const BillID, AnteCode, BillIssue: string;
  const ChipMul, TicketMoney, AOneMoney: Integer; const sPlayType:string=‘‘): Integer;
var
  nResult: integer;
  DycID, sSql: string;
  res: ISuperObject;
begin
  Result := 0;
  DycID  := ‘‘;
  res := DycTicketPrint(ALotID, BillID, BillIssue, AnteCode, sPlayType, trunc(TicketMoney / AOneMoney), ChipMul, AOneMoney);
  if Assigned(res) then
  begin
    if res.I[Code] = 1 then
    begin
      nResult:= 1;
      DycID  := res.S[Value.aOrderID];
      Result := Result + TicketMoney * ChipMul;
    end
    else
      nResult := 3; //收单失败
    //更新出票记录
    sSql := UPDATE Sale_LotBillRec SET BillReturn=‘‘%s‘‘, BillResult=%d, BillMoney=%d, BillTime=‘‘%s‘‘, BillOrder=‘‘%s‘‘ WHERE TicketID=‘‘%s‘‘;
    sSql := Format(sSql, [res.AsJSon, nResult, Result, FormatDateTime(yyyy-mm-dd hh:nn:ss, now()), DycID, BillID]);
    dmLot.ExecuteUpdate(sSql);
  end;
end;

function objlstSort(List: TStringList; Index1, Index2: Integer): Integer;
begin
  Result:= StrToInt(List[Index1]) - StrToInt(List[Index2]);
end;
{ 出票 }
class function TLotBillDyc.DoPrint(const AChip: TChipProjInfo; AItem: TListItem; ShowErrFlag: boolean): integer;
var
  i: Integer;
  nOneMoney, nOneCount: integer;
  LastPt, sBillIssue, sBillChip: string;
  ssChip: TStringList;
  LotInfo: TSaleLotRec;
  { 执行出票打印, 返回出票成功金额 }
  function DoPostChip(ChipID: integer): integer;
  var
    chipobj: ISuperObject;
    nState, nBillMoney, nBillResult: integer;
    sSql, sBillID, sTicket, sValue: string;
  begin
    Result := 0;
    //系统流水号
    sBillID := Self.CreateTicketID(AChip.LotID, AChip.OptID, ChipID + 1);
    sTicket := sBillChip;
    //检查定单是否已经出票
    sSql := SELECT BillMoney*10+BillResult FROM Sale_LotBillRec WHERE LotID=%d AND OptID=%d AND ChipID=%d;
    sSql := Format(sSql, [AChip.LotID, AChip.OptID, ChipID + 1]);
    nState := dmLot.GetFirstValInt(sSql, -1);
    if nState >= 0 then
    begin
      nBillMoney := nState div 10;
      nState := nState mod 10;
    end;
    if (nState = 9) or (nState = 1) then
    begin
      if nState = 9 then
        Result := Result + nBillMoney;
      Exit;
    end;
    //插入出票记录
    if nState = -1 then
    begin
      try
        chipobj:=so;
        chipobj.S[pt]  := LastPt;
        chipobj.S[code]:= sBillChip;
        chipobj.I[onemoney] := AChip.OneMoney;
        chipobj.i[chipmoney]:= nOneMoney;
        //插入出票记录
        sSql := INSERT INTO Sale_LotBillRec(TicketID, OptId, ChipID, LotID, LotIssue, UserChip,
          +  ChipMoney, ChipMul, PostTime, PostStr, BillSP)
          +  VALUES(‘‘%s‘‘, %d, %d, %d, %d, ‘‘%s‘‘, %d,%d, %s, ‘‘%s‘‘, 1010);
        sSql := Format(sSql, [sBillID, AChip.OptID, ChipID + 1, AChip.LotID,
          AChip.LotIssue, chipobj.AsJSon , nOneMoney, AChip.ChipMul, dmLot.DbFunc_Now, sTicket]);
        dmLot.ExecuteUpdate(sSql);
      except
      end;
    end;
    //出票
    Result := Result + Self.DoPostWithoutThread(AChip.LotID, sBillID, sTicket, sBillIssue, achip.ChipMul,
      nOneMoney, AChip.OneMoney, LastPt);
  end;
  function TodyjCode(Acode: string): string;
  var
    k: Integer;
    lst, lst2: TStrings;
    ncount: Integer;
    tcode: string;
  begin
    lst := TStringList.Create;
    lst2 := TStringList.Create;
    lst.Text := Acode;
    for k := 0 to lst.Count - 1 do
    begin
      tcode := lst[k];
      ncount := TLottery.GetSomeChipCount(tcode, LotInfo.LotID, LotInfo.LotType, LotInfo.DsCodeNum, LotInfo.DsCodeNum2);
      nOneCount := nOneCount + ncount;
      if ncount = 1 then
        lst2.Add(ds| + tcode)
      else
      begin
        if Pos($, tcode) > 0 then
          lst2.Add(dt| + tcode)
        else
          lst2.add(fs| + tcode);
      end;
    end;
    result := lst2.text;
    lst.free;
    lst2.free;
  end;
begin
  Result := 0;
  if AChip.LotId<>LOT_ID_ELEVEN then
  begin
    if ShowErrFlag then
      TShareFunc.ShowWarn(对不起,该接口暂时只支持十一运夺金投注!);
    Exit;
  end;
  LastPt := ‘‘;
  sBillIssue:= Self.FormatIssueForBill(AChip.LotId, AChip.LotIssue);
  LotInfo := TLottery.GetOneSaleLottery(AChip.LotId);
  ssChip := TStringList.Create;
  try
    ssChip.Text := AChip.UserChip;
    ssChip.Sort;
    for i := 0 to ssChip.Count - 1 do
    begin
      if LastPt=‘‘ then
      begin
        LastPt:= TStrFunc.CopyLeft(ssChip.Strings[i], |);
        sBillChip:= UpperCase(ssChip.Strings[i]);
      end else if UpperCase(LastPt)=UpperCase(TStrFunc.CopyLeft(ssChip.Strings[i], |)) then
        sBillChip:= sBillChip + #13 + UpperCase(ssChip.Strings[i])
      else begin
        nOneCount := 0;
        sBillChip := TodyjCode(sBillChip);
        nOneMoney := nOneCount * 2;
        Result := Result + DoPostChip(i);
        //状态显示
        if Assigned(AItem) then
          AItem.SubItems.Strings[4] := IntToStr(((i + 1) * 100 div ssChip.Count)) + %;
        Application.ProcessMessages;
        //重新装载
        LastPt:=‘‘;
        sBillChip:= ‘‘;
        LastPt:= TStrFunc.CopyLeft(ssChip.Strings[i], |);
        sBillChip:= UpperCase(ssChip.Strings[i]);
      end;
    end;
    if (sBillChip<>‘‘) and (LastPt<>‘‘) then
    begin
      nOneCount := 0;
      sBillChip := TodyjCode(sBillChip);
      nOneMoney := nOneCount * 2;
      Result := Result + DoPostChip(I+1);
      //状态显示
      if Assigned(AItem) then
        AItem.SubItems.Strings[4] := IntToStr(((i + 1) * 100 div ssChip.Count)) + %;
      Application.ProcessMessages;
    end;
    if Result <= 0 then
      XcCancelPrint(CurrUserInfo.UserID, AChip.LotID, 0, RecIDs= + IntToStr(AChip.OptID));
  finally
    FreeAndNil(ssChip);
  end
end;

initialization

finalization

end.

 

以上是关于我们公司的delphi代码(胆不是我写的!),看看,你觉得怎么样的主要内容,如果未能解决你的问题,请参考以下文章

我写了个下载程序,用Java写的,但是写完以后发现下载大文件的时候报错,内存溢出,能看看是哪的问题么?

delphi StringGrid的问题

delphi写多行文本文件操作

Delphi - XP扫雷外挂制作

我写的python代码中的\t为啥变红而不是变紫色?

VS2017写的exe调用Delphi 7写的DLL