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

📄 unit_public.pas

📁 影院售票系统完整源码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Unit_public;

interface
uses Classes,Forms,Windows,IniFiles,SysUtils,Dialogs,Messages,StdCtrls,Controls,
     Winsock,Mask,NB30,CyberEdit,CyberCmboBx,Graphics,ComCtrls,ExtCtrls,
     encddecd,zlib,ComObj,Variants;
const
    panelheigh=50;
    panelheigh1=25;
    C1=2343;
    C2=5352;
    userkey=12345;
    user_manager        =1000;
    cinema_manager      =1001;
    
type
  PPlanNode     =^TPlanNode;
  TPlanNode     =record
    id          :integer;
    fieldnum    :string;
    starttime   :string;
    endtime     :string;
    filmname    :string;
    hallid      :integer;
  end;
  PTicketNode   =^TTicketNode;
  TTicketNode   =Record
     fieldnum:string;
     rownum:integer;
     colnum:integer;
     seattype:integer;
     seattypename:string;
     tickettype:integer;
     tickettypename:string;
     price:single;
  end;
  PPriceNode=^TPriceNode ;
  TPriceNode=record
    tickettype  :integer;
    seattype    :integer;
    price       :single;
  end;
  TPriceList = class(TList)       //所有座位列表
  private
  protected
     procedure   Notify(Ptr: Pointer; Action: TListNotification); override;
  public
     constructor Create;
     function    IndexOf_price(_tickettype,_seattype: Integer): single;
     function    Add(_tickettype,_seattype:integer;_price:single): Integer; overload;
  end;
  PSeatNode =^TSeatNode;
  TSeatNode = record
     gridrow      : integer;
     gridcol      : integer;
     rownum       : integer;
     colnum       : Integer;
     seattype     : Integer;
     seattypename : String;
     color        : integer;
     status       : string;
  end; //定义座位结点
  TSeatList = class(TList)       //所有座位列表
  private
  protected
     procedure   Notify(Ptr: Pointer; Action: TListNotification); override;
  public
     constructor Create;
     function    IndexOf_Seat(_gridrow,_gridcol: Integer): Integer;
     function    IndexOf_row_col(_row,_col: Integer): Integer;
     function    Add(gridrow,gridcol,rownum,colnum,color,seattype:Integer;seattypename,status: string): Integer; overload;
  end;
  TPublicInfo = Class(TObject)             //公用信息的结构
  private
     procedure initparams;
     function  GetLocalComputerName :string;
     function  GetLocalIP: String;
     function  GetPYIndexChar( hzchar:string):char;
  public
     OperID         : Integer;                    //操作员ID
     OperCode       : String;                     //操作员登陆号
     OperName       : String;                     //操作员姓名
     Password       : String;                     //操作员密码
     OperGroupID    : Integer;                    //操作员组别ID
     Deptid         : Integer;                    //所属部门
     ComputerName   : String;                     //计算机名
     IPAddress      : String;                     //本机IP地址
     SigleLineColor : TColor;                     //单行网格颜色
     DoubleLineColor: TColor;                     //双行网格颜色
     showtime       : smallint;
     constructor  Create;overload;
     destructor   Destroy;override;
     function     QueryPy(hzstr:String):String;     //取拼音码!
     procedure    CreateAForm(InstanceClass: TComponentClass; var Reference);
     procedure    MenuRequest(Menuid:integer);
     function     Encrypt(s:string;Key:word):String;//加密
     function     Decrypt(s:string;key:word):String;//解密
     function     Execsql(sqlstr: string;Execmode:Boolean):Boolean;
     procedure    showmsg(msg:string);
     procedure    DatasetToCombbox(comboxName:TComboBox;mode:Integer);
     procedure    Combboxindexof(comboxName:TComboBox;id:integer);
     procedure    ListViewDraw(Item: TListItem;var DefaultDraw: Boolean);
     procedure    frmview(frm:TForm);
     procedure    Clear(frm:TForm);
     function     formatstr(i,bitcount:integer):string;
     procedure    refreshhallcomb(comb:TCombobox;cinemaid:integer);
     function     CommpressString(stream:TStringStream): string;
     function     Decompression(SourceStr:string):string;
     procedure    ExportToExcel(frm:TForm;LstV:TListView;caption:string;progressbar:TProgressbar);
   end;
var
  PublicInfo:TPublicInfo;
implementation
uses unit_adodm,unit_frmmain,Unit_frmtemplate,Unit_frmusermain,unit_frmflash,
     unit_frmcinema,unit_frmdict,unit_frmplantemplate,unit_frmpricetemplate,
     unit_frmseattype,unit_frmfilm,unit_frmplan,unit_frmsaleticket,
     unit_frmsellrecord,unit_frmcleardata,unit_frmsellBookTicket,
     unit_FrmColdefine,unit_frmsysparam;
procedure TPublicInfo.CreateAForm(InstanceClass: TComponentClass; var Reference);
var
   i : Integer ;
Begin
   For i := 0 To Frmmain.MDIChildCount-1 do
   begin
      if Frmmain.MDIChildren[i] is InstanceClass then
      begin
          Frmmain.MDIChildren[i].BringToFront;
          Exit;
      End;
   end;
   Application.CreateForm(InstanceClass,Reference);
end;

procedure TPublicInfo.MenuRequest(Menuid:integer);
var
  i:integer;
begin
  case menuid of
  1000:
     CreateAForm(Tfrmusermain,frmusermain);
  1001:
     CreateAForm(Tfrmcinema,frmcinema);
  1002:
     begin
       frmpricetemplate:=Tfrmpricetemplate.MyCreate(application,false);
       try
         //frmpricetemplate.kind :=1;
         frmpricetemplate.ShowModal ;
       finally
         frmpricetemplate.Free ;
       end;
     end;
  1003:
     begin
       frmplantemplate:=Tfrmplantemplate.Create(application);
       try
         frmplantemplate.kind :=2;
         frmplantemplate.ShowModal ;
       finally
         frmplantemplate.Free ;
       end;
     end;
  1004:
     CreateAForm(Tfrmseattype,frmseattype);
  1005:
     CreateAForm(Tfrmdict,frmdict);
  1006:
     begin
       frmsysparam:=Tfrmsysparam.Create(application);
       try
         frmsysparam.ShowModal ;
       finally
         frmsysparam.Free ;
       end;
     end;
  1007:
     CreateAForm(Tfrmfilm,frmfilm);
  1008:
     begin
       frmcleardata:=Tfrmcleardata.Create(application);
       try
         frmcleardata.ShowModal ;
       finally
         frmcleardata.Free ;
       end;
     end;
  2001:
     begin
       For i := 0 To Frmmain.MDIChildCount-1 do
       begin
         if Frmmain.MDIChildren[i] is Tfrmplan then
         begin
            Frmmain.MDIChildren[i].BringToFront;
            Exit;
         End;
       end;
       frmplan:=Tfrmplan.MyCreate(Application,false);
     end;
  2002:
     begin
       For i := 0 To Frmmain.MDIChildCount-1 do
       begin
         if Frmmain.MDIChildren[i] is Tfrmplan then
         begin
            Frmmain.MDIChildren[i].BringToFront;
            Exit;
         End;
       end;
       frmplan:=Tfrmplan.MyCreate(Application,true);
     end;
  3001:
     CreateAForm(Tfrmsaleticket,frmsaleticket);
  4001:
     begin
       frmsellrecord:=Tfrmsellrecord.MyCreate(Application,false);
       try
         frmsellrecord.sqlstr:='select id,cinemaname,hallname,fieldnum,filmname,seatname,ticketname,price,'+
           'username,selldate,Quitperson,poundage,deldate,status,statuscn from tblticketsale_view where plandate='+#39+datetostr(date)+#39;
         frmsellrecord.ShowModal ;
       finally
         frmsellrecord.Free ;
       end;
     end;
   4002:
     begin
       frmsellBookTicket:=TfrmsellBookTicket.Create(Application);
       try
         frmsellBookTicket.ShowModal ;
       finally
         frmsellBookTicket.Free ;
       end;
     end;
  end;                               
end;
{ TPublicInfo }

constructor TPublicInfo.Create;
begin
  inherited;
  initparams;
end;

destructor TPublicInfo.Destroy;
begin
  inherited;
end;

function TPublicInfo.GetLocalComputerName: string;
var
  ComputerName: array[0..MAX_COMPUTERNAME_LENGTH+1] of char;  // holds the name
  Size: DWORD;                                              // holds the size
begin
  Size := MAX_COMPUTERNAME_LENGTH+1;
  if GetComputerName(ComputerName, Size) then
  result := StrPas(Computername)
end;

function TPublicInfo.GetPYIndexChar(hzchar: string): char;
begin
  case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of
      $B0A1..$B0C4 : result := 'A';
      $B0C5..$B2C0 : result := 'B';
      $B2C1..$B4ED : result := 'C';
      $B4EE..$B6E9 : result := 'D';
      $B6EA..$B7A1 : result := 'E';
      $B7A2..$B8C0 : result := 'F';
      $B8C1..$B9FD : result := 'G';
      $B9FE..$BBF6 : result := 'H';
      $BBF7..$BFA5 : result := 'J';
      $BFA6..$C0AB : result := 'K';
      $C0AC..$C2E7 : result := 'L';
      $C2E8..$C4C2 : result := 'M';
      $C4C3..$C5B5 : result := 'N';
      $C5B6..$C5BD : result := 'O';
      $C5BE..$C6D9 : result := 'P';
      $C6DA..$C8BA : result := 'Q';
      $C8BB..$C8F5 : result := 'R';
      $C8F6..$CBF9 : result := 'S';
      $CBFA..$CDD9 : result := 'T';
      $CDDA..$CEF3 : result := 'W';
      $CEF4..$D1B8 : result := 'X';
      $D1B9..$D4D0 : result := 'Y';
      $D4D1..$D7F9 : result := 'Z';
  else
      result := char(32);
  end;
end;

procedure TPublicInfo.initparams;
begin
  ComputerName  := GetLocalComputerName;
  IPAddress     :=GetLocalIP;
end;

function TPublicInfo.QueryPy(hzstr: String): String;
var
  i: Integer;
  PY: string;
  s: string;
begin
  s := '' ;
  i := 1;
  while i <= Length(hzstr) do
  begin
    PY := Copy(hzstr, i , 1);
    if PY >= Chr(128) then
    begin
      Inc(i);
      PY := PY + Copy(hzstr, i , 1);
      s := s + GetPYIndexChar(PY);
    end
    else
      s := s + PY;
    Inc(i);
  end;
  result := LowerCase(s);
end;

function TPublicInfo.GetLocalIP: String;
type
  TaPInAddr = array [0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
var
  phe  : PHostEnt;
  pptr : PaPInAddr;
  Buffer : array [0..63] of char;
  I    : Integer;
  GInitData      : TWSADATA;
begin
  WSAStartup($101, GInitData);
  try
    Result:='';
    GetHostName(Buffer, SizeOf(Buffer));
    phe :=GetHostByName(buffer);
    if phe = nil then Exit;
    pptr := PaPInAddr(Phe^.h_addr_list);
    I := 0;
    while pptr^[I] <> nil do
    begin
        result:=StrPas(inet_ntoa(pptr^[I]^));
        Inc(I);
    end;
  finally
    WSACleanup;
  end;
end;

function TPublicInfo.Decrypt(s: string; key: word): String;
var
   I: Integer;
begin
  Result := S;
  for I := 1 to Length(S) do
  begin
       Result[I] := char(byte(S[I]) xor (Key shr 8));
       Key := (byte(Result[I]) + Key) * C1 + C2;
  end;
end;

function TPublicInfo.Encrypt(s: string; Key: word): String;
var
   I: Integer;
begin
  Result := S;
  for I := 1 to Length(S) do
  begin
       Result[I] := char(byte(S[I]) xor (Key shr 8));
       Key := (byte(S[I]) + Key) * C1 + C2;
  end;
end;

function TPublicInfo.Execsql(sqlstr: string;Execmode:Boolean):Boolean;
begin
  result:=false;
  try
    With  adodm.ADOQRY  do
    begin
      Close ;
      sql.clear;
      sql.Add(sqlstr);
    end;
    if Execmode then
    begin
      if adodm.ADOQRY.ExecSQL>0  then result:=True ;
    end
    else
    begin
      adodm.ADOQRY.Open ;
      adodm.ADOQRY.first;
      result:=true;
    end;
  except
    on e:exception do result:=false;
  end;
end;

procedure TPublicInfo.showmsg(msg: string);
begin
  frmflash              :=Tfrmflash.Create(application);
  frmflash.msg          :=msg;
  frmflash.ShowModal ;
  frmflash.Free ;
end;

procedure TPublicInfo.DatasetToCombbox(comboxName:TComboBox;mode:integer);
var
  _name:string;
  _id,reccount,i:integer;
  sqlstr:string;
begin
  ComBoxName.Items.Clear ;
  case mode of
  1:
    sqlstr:='select * from tblgroup';           //角色
  2:
    sqlstr:='select * from tblcinemainfo';     //影院
  3:
    sqlstr:='select * from tblhallinfo';       //影厅
  4:
    sqlstr:='select * from tbldict where kind=2';  //片类
  5:
    sqlstr:='select * from tblseattype';           //座类
  6:
    sqlstr:='select * from tbldict where kind=1';  //票类
  end;
 
  if self.Execsql(sqlstr,false) then
  begin
    reccount:=Adodm.ADOQRY.RecordCount;
    if reccount>0 then
    begin
      Adodm.ADOQRY.First ;
      for i:=1 to reccount do
      begin
        _id         := Adodm.ADOQRY.fieldByName('id').AsInteger;
        _name       := Adodm.ADOQRY.fieldByName('name').AsString;
        ComBoxName.Items.AddObject(_name,Tobject(_id));
        Adodm.ADOQRY.Next ;
      end;
      ComBoxName.ItemIndex := 0;
    end;
  end;
end;

procedure TPublicInfo.ListViewDraw(Item: TListItem;var DefaultDraw: Boolean);
begin
  DefaultDraw:=false;
  if  odd(item.Index)   then
     item.ListView.Canvas.Brush.Color:=publicinfo.DoubleLineColor//$00CAF3BE
  else
     item.ListView.Canvas.Brush.Color:=publicinfo.SigleLineColor ;//$00EBFBE6;
  DefaultDraw:=true;

⌨️ 快捷键说明

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