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

📄 unit_public.pas

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

procedure TPublicInfo.frmview(frm: TForm);
var
  i     :integer;
begin
  for i:=0 to frm.ComponentCount -1 do
  begin
    if (frm.components[i] is TCyberEdit) then
       (frm.components[i] as TCyberEdit ).Enabled  :=false
    else if (frm.components[i] is TCyberMemo) then
       (frm.components[i] as TCyberMemo ).ReadOnly  :=True
    else if (frm.components[i] is TCyberComboBox) then
       (frm.components[i] as TCyberComboBox ).Enabled  :=false
    else if (frm.components[i] is TCyberDateTimePicker) then
       (frm.components[i] as TCyberDateTimePicker ).Enabled  :=false
    else if (frm.components[i] is TEdit) or (frm.components[i] is TmaskEdit) then
       TEdit(frm.components[i]).Enabled :=false
    else if (frm.components[i] is TComboBox) then
       (frm.components[i] as TComboBox ).Enabled  :=false
    else if (frm.components[i] is TDateTimePicker) then
       (frm.components[i] as TDateTimePicker ).Enabled  :=false
    else if (frm.components[i] is TMemo) then
       (frm.components[i] as TMemo ).ReadOnly  :=True
    else if (frm.components[i] is TRichEdit) then
       (frm.components[i] as TRichEdit ).ReadOnly   :=True;
  end;
end;

procedure TPublicInfo.Clear(frm: TForm);
var
  i     :integer;
begin
  for i:=0 to frm.ComponentCount -1 do
  begin
    if (frm.components[i] is TCyberEdit) then
       (frm.components[i] as TCyberEdit ).Text   :=''
    else if (frm.components[i] is TCyberMemo) then
       (frm.components[i] as TCyberMemo ).Text   :=''
    else if (frm.components[i] is TCyberComboBox) then
       (frm.components[i] as TCyberComboBox ).ItemIndex   :=0
    else if (frm.components[i] is TCyberDateTimePicker) then
       (frm.components[i] as TCyberDateTimePicker ).Date   :=date
    else if (frm.components[i] is TEdit) or (frm.components[i] is TmaskEdit) then
       TEdit(frm.components[i]).Text  :=''
    else if (frm.components[i] is TComboBox) then
       (frm.components[i] as TComboBox ).ItemIndex   :=0
    else if (frm.components[i] is TDateTimePicker) then
       (frm.components[i] as TDateTimePicker ).Date   :=Date
    else if (frm.components[i] is TMemo) then
       (frm.components[i] as TMemo ).Text   :=''
    else if (frm.components[i] is TRichEdit) then
       (frm.components[i] as TRichEdit ).Text   :=''
    else if (frm.components[i] is TLabeledEdit) then
       (frm.components[i] as TLabeledEdit ).Text   :='';
  end;
end;

procedure TPublicInfo.Combboxindexof(comboxName:TComboBox;id: integer);
var
  i     :integer;
begin
  comboxname.ItemIndex :=-1;
  if comboxname.Items.Count >0 then
  begin
    for i:=0 to comboxname.Items.Count-1 do
    begin
      if integer(comboxname.Items.Objects[i])=id then
      begin
        comboxname.ItemIndex :=i;
        break;
      end;
    end;
  end;
end;

function TPublicInfo.formatstr(i, bitcount: integer): string;
var
  j:integer;
begin
  result:=inttostr(i);
  case bitcount of
  1:
    if i<10 then  result:=inttostr(i);
  2:
    begin
      if i<10 then result:='0'+inttostr(i);
    end;
  3:
    begin
       if i>=1000 then exit;
       if (i<10) then
          result:='00'+inttostr(i)
       else if (i<100) then
          result:='0'+inttostr(i) ;
    end;
  4:
    begin
       if i>=1000 then exit;
       if i<10 then
          result:='000'+inttostr(i)
       else if i<100 then
          result:='00'+inttostr(i)
       else if i<1000 then
          result:='0'+inttostr(i);
    end;
  5:
    begin
       if i>=10000 then exit;
       if i<10 then
          result:='000'+inttostr(i)
       else if i<100 then
          result:='00'+inttostr(i)
       else if i<10000 then
          result:='00'+inttostr(i)
       else
          result:='0'+inttostr(i);
    end;
  end;
end;

procedure TPublicInfo.refreshhallcomb(comb: TCombobox;
  cinemaid: integer);
var
  _name:string;
  _id,reccount,i:integer;
  sqlstr:string;
begin
  comb.Items.Clear ;
  sqlstr:='select * from tblhallinfo where cinemaid='+inttostr(cinemaid);
  if publicinfo.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;
        comb.Items.AddObject(_name,Tobject(_id));
        Adodm.ADOQRY.Next ;
      end;
      comb.ItemIndex := 0;
    end;
  end;
end;

function TPublicInfo.CommpressString(stream: TStringStream): string;
var
    ass1:tstringstream;
    amm1:tmemorystream;
    strtemp:string;
    mscompressedstream:tcompressionstream;
begin
    ass1:=tstringstream.Create('');
    amm1:=tmemorystream.Create ;
    try
        strtemp:=stream.DataString;
        mscompressedstream:=TCompressionstream.Create(cldefault,amm1);
        try
           mscompressedstream.Write(strtemp[1],length(strtemp));
        finally
            mscompressedstream.Free ;
        end;
        amm1.Position :=0;
        amm1.SaveToStream(ass1);
        result:=encodestring(ass1.DataString);
    finally
        amm1.Free;
        ass1.Free ;
    end;
end;

function TPublicInfo.Decompression(SourceStr: string): string;
var
    ass:tstringstream;
    amm,amm1:tmemoryStream;
    uncompressed:tdecompressionstream;
    fbuflen:integer;
    fbuffer:array[0..16383] of byte;
begin
    amm:=tmemoryStream.create;
    amm1:=tmemoryStream.create;
    ass:=tstringstream.Create(decodestring(SourceStr));
    amm1.LoadFromStream(ass);
    try
        amm.Size :=0;
        amm1.Position :=0;
        uncompressed:=tdecompressionstream.Create(amm1);
        try
                fbuflen:= uncompressed.Read(fbuffer,sizeof(fbuffer));
                while fbuflen>0 do
                begin
                        amm.Write(fbuffer,fbuflen);

                        fbuflen:=uncompressed.Read(fbuffer,sizeof(fbuffer));
                end;
        finally
              uncompressed.Free ;
        end;

        amm.Position :=0;
        setlength(result,amm.size);
        move(amm.memory^,result[1],amm.Size );

    finally
        ass.Free ;
        amm.Free ;
        amm1.Free ;
    end;

end;

procedure TPublicInfo.ExportToExcel(frm:TForm;LstV:TListView;caption:string;progressbar:TProgressbar);
var
  i,j           :integer;
  colcount,colnum:integer;
  item0         :TListItem;
  Excel,Sheet,rang:Variant;
  tmpstr        :string;
  collab        :string;
  recordcount1  :integer;
  ColList       :TStringList;
begin
  collist:=TStringList.Create ;
  recordcount1:=LstV.Items.Count ;
  if  recordcount1<=0 then exit;
  screen.Cursor :=crhourglass;
  try
    //定义打印列
    FrmColdefine:=TFrmColdefine.MyCreate(Application,LstV);
    try
      if  FrmColdefine.ShowModal=mrok then
      begin
        for i:=0 to LstV.Columns.Count-1 do
        begin
          ColList.Add(LstV.Columns.Items[i].Caption) ;
        end;
      end;  
    finally
      FrmColdefine.Free ;
    end;
    if collist.Count <=0 then exit;
    Try
      Excel:=UnAssigned;
      Excel:=CreateOleObject('Excel.Application');
      Excel.Visible:=False;
      Excel.WorkBooks.Add;
    Except
      Excel.quit;
      Excel:=UnAssigned;
      application.MessageBox('本机未安装EXCEL,本功能必须在安装有EXCEL的电脑上才能运行!','必须安装EXCEL',mb_ok);
    End;
    if VarIsEmpty(Excel) then
    begin
      application.MessageBox('建立Excel对象不成功,请重试!','建立Excel对象',mb_ok);
      Excel.quit;
      Excel:=UnAssigned;
    end;
    try
      if trim(caption)='' then caption:='汇总表';
      sheet:=Excel.worksheets[1];
      Sheet.Name:=caption;
      Excel.WorkSheets[1].Activate;
      Excel.ActiveSheet.PageSetup.Orientation := 2;
      Excel.ActiveSheet.PageSetup.CenterHeader :=caption;
      Excel.ActiveSheet.PageSetup.CenterFooter := '第&P页  共&N页';
      Excel.ActiveSheet.PageSetup.HeaderMargin := 1/0.035;
      Excel.ActiveSheet.PageSetup.FooterMargin := 1/0.035;
      Excel.ActiveSheet.PageSetup.TopMargin := 2/0.035;
      Excel.ActiveSheet.PageSetup.LeftMargin := 1.5/0.035;
      Excel.ActiveSheet.PageSetup.RightMargin := 1.5/0.035;
      Excel.ActiveSheet.PageSetup.BottomMargin :=2/0.035;
      colcount:=ColList.Count;
      For I:=0 To colcount-1  Do
      begin
        colnum:=strtoint(ColList.Strings[i]);
        if (pos('▲',LstV.Columns[colnum].Caption)>0)
           or (pos('▼',LstV.Columns[colnum].Caption)>0) then
           Sheet.Cells[1,i+1]:=copy(LstV.Columns[colnum].Caption,1,length(LstV.Columns[colnum].Caption)-1)  //设置列标题
        else
           Sheet.Cells[1,i+1]:=LstV.Columns[colnum].Caption;  //设置列标题
        //Excel.ActiveSheet.Columns[i].ColumnWidth:=LstV.Columns[colnum].Width/100 ;
      end;
      if progressbar<>nil then
      begin
         progressbar.Visible :=true;
         progressbar.Max :=recordcount1;
      end;
      for i:=1 to recordcount1 do
      begin
        item0:=LstV.Items[i-1];
        for j:=0 to colcount-1  do
        begin
          colnum:=strtoint(ColList.Strings[j]);
          if colnum=0 then
             sheet.cells[(1+i),j+1]:=item0.Caption
          else
             sheet.cells[(1+i),j+1]:=item0.SubItems[colnum-1];
        end;
        if progressbar<>nil then progressbar.Position:=i;
      end;
      sheet.cells[recordcount1+3,1]:='制表日期:'+FormatDateTime('yyyy"年"mm"月"dd"日"',Now);
      if colcount>2 then
         Sheet.Cells[recordcount1+3,colcount-1]:='制表人:'+publicinfo.OperName    //以上为表头输出
      else
         Sheet.Cells[recordcount1+3,2]:='制表人:'+publicinfo.OperName ;
      //所有行
      collab:=char(65+colcount-1);
      tmpstr:='A1:'+collab+inttostr(recordcount1+1);
      rang:=sheet.range[tmpstr] ;
      rang.font.size:=9;
      rang.VerticalAlignment:=2;
      rang.Borders.LineStyle:=1;
      //第一行
      tmpstr:='A1:'+collab+'1';
      sheet.Range[tmpstr].select;
      Excel.selection.columnwidth:=15;
      Excel.Selection.HorizontalAlignment:=3;
      Excel.Selection.VerticalAlignment:=2;
      Excel.Selection.font.size    :=12;
    finally
      Excel.Visible:=True;
      Excel.ActiveSheet.PrintPreview;
      Excel:=UnAssigned;
    end;
  finally
    screen.Cursor :=crdefault;
    collist.Free ;
  end;
end;

{ TSeatList }

function TSeatList.Add(gridrow, gridcol, rownum, colnum, color,
  seattype: Integer; seattypename,status: string): Integer;
var
  Ptr: PSeatNode;
begin
  New(Ptr);
  Ptr^.gridrow       := gridrow;
  Ptr^.gridcol       := gridcol;
  Ptr^.rownum        := rownum;
  Ptr^.colnum        := colnum;
  ptr^.color         := color;
  Ptr^.seattype      := seattype;
  Ptr^.seattypename  := seattypename;
  ptr^.status        := status;
  Result             := Add(Ptr);
end;

constructor TSeatList.Create;
begin
  inherited;
end;

function TSeatList.IndexOf_row_col(_row, _col: Integer): Integer;
var
  prt:PSeatNode;
  t:string;
  i:integer;
begin
  Result := -1;
  for i:=0 to count-1 do
  begin
    prt:=PSeatNode(Items[i]);
    if ((prt^.rownum =_row) and (prt^.colnum =_col)) then
    begin
      result:=i;
      break;
    end;
  end;
end;

function TSeatList.IndexOf_Seat(_gridrow, _gridcol: Integer): Integer;
var
  prt:PSeatNode;
  t:string;
  i:integer;
begin
  Result := -1;
  for i:=0 to count-1 do
  begin
    prt:=PSeatNode(Items[i]);
    if ((prt^.gridrow=_gridrow) and (prt^.gridcol=_gridcol)) then
    begin
      result:=i;
      break;
    end;
  end;
end;

procedure TSeatList.Notify(Ptr: Pointer; Action: TListNotification);
begin
  if Action = lnDeleted then
  begin
    Dispose(Ptr);
  end;
  inherited;
end;

{ TPriceList }

function TPriceList.Add(_tickettype, _seattype: integer;
  _price: single): Integer;
var
  Ptr: PpriceNode;
begin
  New(Ptr);
  Ptr^.tickettype    := _tickettype;
  Ptr^.seattype      := _seattype;
  Ptr^.price         := _price;
  Result             := Add(Ptr);
end;

constructor TPriceList.Create;
begin
  inherited;
end;

function TPriceList.IndexOf_price(_tickettype, _seattype: Integer): single;
var
  prt:PPriceNode;
  t:string;
  i:integer;
begin
  result:=-1;
  for i:=0 to count-1 do
  begin
    prt:=PPriceNode(Items[i]);
    if ((prt^.tickettype =_tickettype) and (prt^.seattype =_seattype)) then
    begin
      result:=prt^.price;
      break;
    end;
  end;
end;

procedure TPriceList.Notify(Ptr: Pointer; Action: TListNotification);
begin
  if Action = lnDeleted then
  begin
    Dispose(Ptr);
  end;
  inherited;
end;

end.

⌨️ 快捷键说明

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