1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215:
| unit vigilimpmain;
interface
uses Windows, SysUtils, Printers, Winspool, Typinfo, Classes, Graphics, Forms, Controls, Menus, StdCtrls, Dialogs, Buttons, Messages, ExtCtrls, ComCtrls, StdActns, ActnList, ToolWin, ImgList, PBPrintersmonitorU, CoolTrayIcon;
type TSDIAppForm = class(TForm) ToolBar1: TToolBar; StatusBar: TStatusBar; MainMenu1: TMainMenu; File1: TMenuItem; FileExitItem: TMenuItem; Help1: TMenuItem; HelpAboutItem: TMenuItem; CoolTrayIcon1: TCoolTrayIcon; CheckBox1: TCheckBox; PopupMenu1: TPopupMenu; Fensterzeigen1: TMenuItem; Label1: TLabel; Label2: TLabel; Hilfe1: TMenuItem; Bericht1: TMenuItem; erstellen1: TMenuItem; drucken1: TMenuItem; Memo1: TMemo; ListView1: TListView; RichEdit1: TRichEdit; Admin1: TMenuItem; procedure HelpAboutItemClick(Sender: TObject); procedure Admin1Click(Sender: TObject); procedure drucken1Click(Sender: TObject); procedure erstellen1Click(Sender: TObject); procedure Fensterzeigen1Click(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure FormCreate(Sender: TObject); procedure WMQueryEndSession(var Message: TMessage); procedure positionieren(datensatz: integer); private FMonitor: TPBPrintersMonitor; formShowed: boolean; SessionEnding: boolean; FMonitorAlreadyRunning: Boolean; procedure JobNotification( const jobinfo: TPBJobInformation); public end; Type Druckauftrag = record user: string[25]; pn: integer; end;
var SDIAppForm: TSDIAppForm; erstellen: boolean; jobident: integer; Counter: integer; Datei: file of Druckauftrag; aktdatensatz,sortdata: array[0..300] of Druckauftrag; const WM_TASKBAREVENT = WM_USER + 1; implementation
uses about, vigilimpadmin;
{$R *.dfm}
procedure TSDIAppForm.WMQueryEndSession(var Message: TMessage); begin SessionEnding := True; Message.Result := 1; end;
procedure TSDIAppForm.JobNotification(const jobinfo: TPBJobInformation); var Kopien,Seiten: integer; Datei: file of Druckauftrag; Satz: Druckauftrag;
begin jobident:=0; Try if GetEnumName( Typeinfo( TPBJobStatus), Ord( jobinfo.Status))='jsCompleted' then begin ShowMessage(jobinfo.user+' '+InttoStr(jobinfo.TotalPages)); if jobident<>jobinfo.JobID then begin jobident:=jobinfo.JobID; if jobinfo.Copies = 0 then Kopien:=1 else Kopien:=jobinfo.Copies; Seiten:=Kopien*jobinfo.TotalPages; Label1.caption:='Letzter druckender User: '+jobinfo.user; Label2.caption:='Seiten: '+InttoStr(Seiten); Satz.user:=jobinfo.user; Satz.pn:=Seiten; AssignFile(Datei,'C:\report.dat'); if not fileexists('C:\report.dat') then Rewrite(Datei) else Reset(Datei); Seek(Datei,Filesize(Datei)); Write(Datei,Satz); Closefile(Datei); end; end; Finally End;
end;
procedure TSDIAppForm.FormCreate(Sender: TObject); begin FMonitor:= TPBPrintersMonitor.Create( self ); FMonitor.OnNewJob := JobNotification; FMonitor.OnJobChange := JobNotification; FMonitor.OnJobComplete := JobNotification; FMonitor.Active := true; FMonitorAlreadyRunning := true; end;
procedure TSDIAppForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose := ((not CheckBox1.Checked) or SessionEnding); if not CanClose then begin CoolTrayIcon1.HideMainForm; CoolTrayIcon1.IconVisible := True; end; end;
procedure TSDIAppForm.Fensterzeigen1Click(Sender: TObject); begin CoolTrayIcon1.ShowMainForm; formshowed:=true; end;
procedure TSDIAppForm.erstellen1Click(Sender: TObject); var i,n: integer; item: TListItem; begin for i:=0 to 300 do begin sortdata[i].user:=''; sortdata[i].pn:=0; end; Listview1.Items.Clear; AssignFile(Datei,'C:\report.dat'); Reset(Datei); Listview1.items.BeginUpdate; for i:=0 to FileSize(Datei) do begin positionieren(i); item:= listview1.Items.Add; if aktdatensatz[i].user<>'' then begin item.Caption:=aktdatensatz[i].user; item.SubItems.Add(InttoStr(aktdatensatz[i].pn)); end; end; ListView1.SortType:=stText; ListView1.Items.EndUpdate; n:=1; sortdata[n].user:=ListView1.Items[n].Caption; sortdata[n].pn:=StrToInt(ListView1.Items[n].SubItems.Strings[0]); if ListView1.Items.Count>2 then for i:=2 to ListView1.Items.Count do begin if Listview1.Items[i].Caption=sortdata[n].user then sortdata[n].pn:=sortdata[n].pn+StrToInt(ListView1.Items[i].SubItems.Strings[0]) else begin inc(n); sortdata[n].user:=ListView1.Items[i].Caption; sortdata[n].pn:=StrToInt(ListView1.Items[i].SubItems.Strings[0]); end; end; Memo1.lines.beginupdate; Memo1.lines.clear; for i:=0 to n do if sortdata[i].user<>'' then Memo1.lines.add('User: '+sortdata[i].user+', Seiten: '+InttoStr(sortdata[i].pn)+ ', Kosten: '+Floattostr(0.03*sortdata[i].pn)+' €.'); Memo1.lines.endupdate; Richedit1.lines.beginupdate; Richedit1.lines.clear; Richedit1.Lines.Add('Druckerkostenabrechnung vom '+DatetoStr(date)); Richedit1.Lines.Add(''); for i:=0 to n do if sortdata[i].user<>'' then Richedit1.lines.add('User: '+sortdata[i].user+', Seiten: '+InttoStr(sortdata[i].pn)+ ', Kosten: '+Floattostr(0.03*sortdata[i].pn)+' €.'); Richedit1.lines.endupdate; Closefile(Datei); erstellen:=true; end; procedure TSDIAppForm.positionieren(datensatz: integer); begin if (datensatz<0) or (datensatz>=FileSize(Datei)) then exit else begin seek(Datei, datensatz); read(Datei, aktdatensatz[datensatz]); end; end; procedure TSDIAppForm.drucken1Click(Sender: TObject); begin if erstellen=true then Richedit1.Print('VigilImp 0.2'); end;
procedure TSDIAppForm.Admin1Click(Sender: TObject); begin PasswordDlg.ShowModal; if PasswordDlg.Password.Text='catholica' then Bericht1.enabled:=true else ShowMessage('Passwort falsch!'); end; procedure TSDIAppForm.HelpAboutItemClick(Sender: TObject); begin Aboutbox.ShowModal; end;
end. |