孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
unit uCard; interface uses Classes, SysUtils, DB, ADODB, DateUtils, StrUtils, uCellPrintInterface, Sys_ADOQ_Interface, uInterface, uReadCard_Interface, uReadCardDllLoader, Graphics,uPubData,uSecIDCARDinterface,uIDCardLoader,Dialogs,Contnrs; type TCategory = (SP, ID, YB, TL, ZG, NH); //卡类别 TRecCardType = record //字段取自 Name: Integer; //0手工,1身份证,2医保卡 Sex: Integer; Birth: Integer; Age: Integer; end; TCardInfo=record CardNo:Int64; IDNo:string; YbNo:string; iSex:Integer; Birthday:string; iAge:Integer; Area:string; end; TData = class(TObject) private FAge: Integer; FBirthDay: string; FSex: string; FArea: string; FS1, FS2, FS3, FS4: string; //冗余字段 FI1, FI2, FI3, FI4: Integer; //冗余字段 procedure SetAge(const Value: Integer); procedure SetBirthDay(const Value: string); public property Age: Integer read FAge write SetAge; property BirthDay: string read FBirthDay write SetBirthDay; property Sex: string read FSex write FSex; property Area: string read FArea write FArea; property S1: string read FS1 write FS1; property S2: string read FS2 write FS2; property S3: string read FS3 write FS3; property S4: string read FS4 write FS4; property I1: Integer read FI1 write FI1; property I2: Integer read FI2 write FI2; property I3: Integer read FI3 write FI3; property I4: Integer read FI4 write FI4; end; TCard = class(TObject) private FCardNo: string; //FCardData: TData; FPriority, FOldPriority: Integer; FCardInfo:TCardInfo; //1:射频卡 2:身份证 3:医保卡(4:铁路医保卡,5:职工医保卡,6:农合卡) FCardType, FOldCardType: TRecCardType; function GetCardInfo(var RecCardInfo:TCardInfo): Integer; virtual; abstract; protected procedure SetToCardType(Card: TRecCardType; i: Integer); public procedure SetCardType(iName, iSex, iBirth, iAge: Integer); function ReadCard: Integer; virtual; property CardNo: string read FCardNo write FCardNo; //property CardData: TData read FCardData write FCardData; property CardType: TRecCardType read FCardType write FCardType; property OldCardType: TRecCardType read FOldCardType write FOldCardType; property Priority: Integer read FPriority write FPriority; property OldPriority: Integer read FOldPriority write FOldPriority; property CardInfo:TCardInfo read FCardInfo write FCardInfo; constructor Create; virtual; destructor Destroy; override; end; TSPCard = class(TCard) private FReadCardClass: IReadCard; FCount: Integer; public function GetCardInfo(var RecCardInfo:TCardInfo): Integer; override; property Count: Integer read FCount write FCount; property ReadCardClass: IReadCard read FReadCardClass write FReadCardClass; constructor Create; override; destructor Destroy;override; end; TIDCard = class(TCard) private FSEIDCard:TIDCardLoader; FIDCardInfo:TIDCARDALLINFO; FBitmap:TBitmap; FErrMessage:String; procedure IDCardErr(ErrMsg: Integer); public function GetIDInfoGetDInfo(const CardNo: string; var Sex, BirthDay: string; var Age: Integer; var Area: string): Integer; property SEIDCard:TIDCardLoader read FSEIDCard write FSEIDCard; property IDCardInfo:TIDCARDALLINFO read FIDCardInfo write FIDCardInfo; property Bitmap:TBitmap read FBitmap write FBitmap; property ErrMessage:string read FErrMessage write FErrMessage; constructor Create; override; destructor Destroy;override; end; TYbCard = class(TCard) private constructor Create; override; end; TTlCard = class(TYbCard) private constructor Create; override; end; TZgCard = class(TYbCard) private constructor Create; override; end; TNhCard = class(TYbCard) private constructor Create; override; end; TCardFactory = class(TObject) private AList: TList; FPriority, FOldPriority: Integer; FCardType, FOldCardType: TRecCardType; function SetCreate(sClassName: string): TCard; procedure SetCardType(CardType: TRecCardType; iName, iSex, iBirth, iAge: Integer); public constructor Create; destructor Destroy; override; property Priority: Integer read FPriority write FPriority; property OldPriority: Integer read FOldPriority write FOldPriority; property CardType: TRecCardType read FCardType write FCardType; property OldCardType: TRecCardType read FOldCardType write FOldCardType; function CreateCard(Category: TCategory): TCard; end; implementation { TData } procedure TData.SetAge(const Value: Integer); begin if Value > 120 then FAge := -1 //表示年龄错误 else FAge := Value; end; procedure TData.SetBirthDay(const Value: string); begin FBirthDay := Value; end; { TCard } constructor TCard.Create; begin //FCardData := TData.Create; {if not Assigned(ReadCardLoader) then ReadCardLoader := TReadCardLoader.Create; FReadCardClass := ReadCardLoader.GetIReadCard;} end; destructor TCard.Destroy; begin //FreeAndNil(FCardData); inherited; end; procedure TCard.SetCardType(iName, iSex, iBirth, iAge: Integer); begin with FCardType do begin Name := iName; Sex := iSex; Birth := iBirth; Age := iAge; end; end; function TCard.ReadCard: Integer; begin // end; procedure TCard.SetToCardType(Card: TRecCardType; i: Integer); begin with Card do begin Name := i; Sex := i; Birth := i; Age := i; end; end; { TIDCard } constructor TIDCard.Create; begin inherited; FSEIDCard := TIDCardLoader.Create; FSEIDCard.GetIReadCard.initDriver; SetToCardType(FCardType, 2); FPriority := 2; end; /// /// 获得身份证信息 /// /// 身份证号 /// 性别 /// 生日 /// 年龄 /// 省份 /// 返回值,0表示成功 1:位长不对 2:为非数字 3:生日格式不对 4:年龄错误 destructor TIDCard.Destroy; begin if Assigned(FSEIDCard) then FSEIDCard.Free; inherited; end; function TIDCard.GetIDInfoGetDInfo(const CardNo: string; var Sex, BirthDay: string; var Age: Integer; var Area: string): Integer; var iCardNo: Int64; iYear, iSex: Integer; sBirth, fBirth: string; dBirth: TDateTime; begin Result := 0; //表示身份证输入正确 if (Length(CardNo) <> 15) and (Length(CardNo) <> 18) then begin Result := 1; //位长不对 Exit; end; if Length(CardNo) = 15 then begin if not TryStrToInt64(CardNo, iCardNo) then begin Result := 2; //必须为数字 Exit; end; sBirth := '19' + Copy(CardNo, 7, 6); iSex := StrToInt(Copy(CardNo, 15, 1)); if Odd(iSex) then Sex := '男' else Sex := '女'; end else begin if not TryStrToInt64(Copy(CardNo, 1, 17), iCardNo) then begin Result := 2; //前17位必须为数字 Exit; end; sBirth := Copy(CardNo, 7, 8); iSex := StrToInt(Copy(CardNo, 17, 1)); case iSex of 0: Sex := '未知'; 1: Sex := '男'; 2: Sex := '女'; 9: Sex := '未说明'; end; end; fBirth := Format('%s-%s-%s', [Copy(sBirth, 1, 4), Copy(sBirth, 5, 2), Copy(sBirth, 7, 2)]); if not TryStrToDate(fBirth, dBirth) then begin Result := 3; //生日格式不对 Exit; end; iYear := YearsBetween(Date, dBirth); if (iYear < 0) or (iYear >= 120) then begin Result := 4; //年龄错误 Exit; end; BirthDay := sBirth; Age := iYear; Area := GetArea(StrToInt(Copy(CardNo, 1, 2))); end; /// /// 获取身份证读取错误信心 /// /// procedure TIDCard.IDCardErr(ErrMsg: Integer); begin case Errmsg of 0: FErrMessage :='读卡错误'; -1: FErrMessage :='相片解码错误'; -2: FErrMessage :='wlt文件后缀错误'; -3: FErrMessage :='wlt文件打开错误'; -4: FErrMessage :='wlt文件格式错误'; -5: FErrMessage :='软件未授权'; -11: FErrMessage :='无效参数'; end; end; { TSPCard } /// /// 就医卡的初始化 /// constructor TSPCard.Create; begin inherited; if not Assigned(ReadCardLoader) then ReadCardLoader := TReadCardLoader.Create; FReadCardClass := ReadCardLoader.GetIReadCard; FReadCardClass.UsePosition :=0; FReadCardClass.Active :=True; SetToCardType(FCardType, 1); FPriority := 1; end; destructor TSPCard.Destroy; begin //if Assigned(ReadCardLoader) then // ReadCardLoader.Free; inherited; end; /// /// 获得卡信息 /// /// /// function TSPCard.GetCardInfo(var RecCardInfo:TCardInfo): Integer; begin RecCardInfo.CardNo := ReadCardClass.CardNo; with ReadCardClass.IDCardInfo do begin RecCardInfo.iSex := Sex; RecCardInfo.iAge := Age; RecCardInfo.BirthDay := BirthDate; RecCardInfo.Area := Address; RecCardInfo.IDNo := IdentityCard; SetCardType(NameSource, SexSource, BirthSource, AgeSource); end; end; { TYbCard } constructor TYbCard.Create; begin inherited; SetToCardType(FCardType, 3); FPriority := 3; end; { TNhCard } constructor TNhCard.Create; begin inherited; SetToCardType(FCardType, 6); FPriority := 6; end; { TZgCard } constructor TZgCard.Create; begin inherited; SetToCardType(FCardType, 5); FPriority := 5; end; { TTlCard } constructor TTlCard.Create; begin inherited; SetToCardType(FCardType, 4); FPriority := 4 end; { TCardFactory } constructor TCardFactory.Create; begin AList := TList.Create; end; function TCardFactory.CreateCard(Category: TCategory): TCard; var i: Integer; FNo: Boolean; begin FNo := False; case Category of SP: Result := SetCreate('TSPCard'); ID: Result := SetCreate('TIDCard'); YB: Result := SetCreate('TYbCard'); TL: Result := SetCreate('TTlCard'); ZG: Result := SetCreate('TZgCard'); NH: Result := SetCreate('TNhCard'); end; end; destructor TCardFactory.Destroy; var i: Integer; begin for i := 0 to AList.Count-1 do begin //if TObject(AList.Items[i]).ClassName='TSPCard' then // TSPCard(Alist.Items[i]).Free; if Assigned(AList[i]) then TObject(AList[i]).Free; end; { for i:=Alist.count-1 downto 0 do begin Alist.Delete(i); end; } AList.clear; AList.Free; inherited; end; procedure TCardFactory.SetCardType(CardType: TRecCardType; iName, iSex, iBirth, iAge: Integer); begin CardType.Name := iName; CardType.Sex := iSex; CardType.Birth := iBirth; CardType.Age := iAge; end; function TCardFactory.SetCreate(sClassName: string): TCard; var i: Integer; FNo: Boolean; begin FNo := False; for i := 0 to Alist.Count - 1 do begin if TObject(AList.Items[i]).ClassName = sClassName then begin FNo := True; Result := Alist[i]; Break; end; end; if not FNo then begin //还没有生成该类的实例 if AList.Count = 0 then begin FOldPriority := 0; SetCardType(FOldCardType, 0, 0, 0, 0); end else begin FOldPriority := FPriority; SetCardType(FOldCardType, FCardType.Name, FCardType.Sex, FCardType.Birth, FCardType.Age); end; if sClassName = 'TSPCard' then begin FPriority := 1; Result := TSPCard.Create; AList.Add(Result as TSPCard); end else if sClassName = 'TIDCard' then begin FPriority := 2; Result := TIDCard.Create; AList.Add(Result as TIDCard); end else if sClassName = 'TYbCard' then begin FPriority := 3; Result := TYbCard.Create; AList.Add(Result as TYbCard); end else if sClassName = 'TTlCard' then begin FPriority := 4; Result := TTlCard.Create; AList.Add(Result as TTlCard); end else if sClassName = 'TZgCard' then begin FPriority := 5; Result := TZgCard.Create; AList.Add(Result as TZgCard); end else if sClassName = 'TNhCard' then begin FPriority := 6; Result := TNhCard.Create; AList.Add(Result as TNhCard); end; end else begin //已生成该类实例 if sClassName = 'TSPCard' then begin FOldPriority := 1; FPriority := 1; end else if sClassName = 'TIDCard' then begin FOldPriority := 2; FPriority := 2; end else if sClassName = 'TYbCard' then begin FOldPriority := 3; FPriority := 3; end else if sClassName = 'TTlCard' then begin FOldPriority := 4; FPriority := 4; end else if sClassName = 'TZgCard' then begin FOldPriority := 5; FPriority := 5; end else if sClassName = 'TNhCard' then begin FOldPriority := 6; FPriority := 6; end; end; end; end.
posted on 2010-07-15 11:00  孤独的猫  阅读(521)  评论(0编辑  收藏  举报