source: cprs/branches/foia-cprs/CPRS-Chart/fDeviceSelect.pas@ 1154

Last change on this file since 1154 was 460, checked in by Kevin Toppenberg, 16 years ago

Uploading from OR_30_258

File size: 4.6 KB
Line 
1unit fDeviceSelect;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls, fAutoSz, ORCtrls, ORNet, Mask, ExtCtrls;
8
9type
10 TfrmDeviceSelect = class(TfrmAutoSz)
11 grpDevice: TGroupBox;
12 cboDevice: TORComboBox;
13 pnlBottom: TPanel;
14 cmdOK: TButton;
15 cmdCancel: TButton;
16 chkDefault: TCheckBox;
17 pnlGBBottom: TPanel;
18 lblMargin: TLabel;
19 txtRightMargin: TMaskEdit;
20 lblLength: TLabel;
21 txtPageLength: TMaskEdit;
22 procedure cboDeviceChange(Sender: TObject);
23 procedure cmdOKClick(Sender: TObject);
24 procedure cmdCancelClick(Sender: TObject);
25 procedure cboDeviceNeedData(Sender: TObject; const StartFrom: String;
26 Direction, InsertAt: Integer);
27 procedure FormShow(Sender: TObject);
28 procedure FormClose(Sender: TObject; var Action: TCloseAction);
29 private
30 FWinPrint: Boolean;
31 end;
32
33var
34 frmDeviceSelect: TfrmDeviceSelect;
35 ADevice: string;
36
37function SelectDevice(Sender: TObject; ALocation: integer; AllowWindowsPrinter: boolean; ACaption: String): string ;
38
39implementation
40
41{$R *.DFM}
42
43uses ORFn, rCore, uCore, rReports, Printers, fFrame, rMisc;
44
45const
46 TX_NODEVICE = 'A device must be selected to print, or press ''Cancel'' to not print.';
47 TX_NODEVICE_CAP = 'Device Not Selected';
48 TX_ERR_CAP = 'Print Error';
49
50function SelectDevice(Sender: TObject; ALocation: integer; AllowWindowsPrinter: boolean; ACaption: String): string ;
51{ displays a form that prompts for a device}
52var
53 frmDeviceSelect: TfrmDeviceSelect;
54 DefPrt: string;
55begin
56 frmDeviceSelect := TfrmDeviceSelect.Create(Application);
57 try
58 ResizeFormToFont(TForm(frmDeviceSelect));
59 with frmDeviceSelect do
60 begin
61 FWinPrint := AllowWindowsPrinter;
62 with cboDevice do
63 begin
64 if (FWinPrint) and (Printer.Printers.Count > 0) then
65 begin
66 Items.Add('WIN;Windows Printer^Windows Printer');
67 Items.Add('^--------------------VistA Printers----------------------');
68 end;
69 end;
70 if Sender <> frmFrame then
71 begin
72 DefPrt := User.CurrentPrinter;
73 if DefPrt = '' then DefPrt := GetDefaultPrinter(User.Duz, Encounter.Location);
74 if DefPrt <> '' then
75 begin
76 if (not FWinPrint) then
77 begin
78 if (DefPrt <> 'WIN;Windows Printer') then
79 begin
80 cboDevice.InitLongList(Piece(DefPrt, ';', 2));
81 cboDevice.SelectByID(DefPrt);
82 end
83 else
84 cboDevice.InitLongList('');
85 end
86 else if FWinprint then
87 begin
88 cboDevice.InitLongList(Piece(DefPrt, ';', 2));
89 cboDevice.SelectByID(DefPrt);
90 end;
91 end
92 else
93 begin
94 cboDevice.InitLongList('');
95 end;
96 if ACaption<>'' then frmDeviceSelect.Caption:=ACaption;
97 end
98 else
99 begin
100 frmDeviceSelect.Caption := 'Print Device Selection';
101 cboDevice.InitLongList('');
102 end;
103 ShowModal;
104 Result := ADevice;
105 //Result := Piece(ADevice, ';', 1) + U + Piece(ADevice, U, 2);
106 end;
107 finally
108 frmDeviceSelect.Release;
109 end;
110end;
111
112procedure TfrmDeviceSelect.cboDeviceChange(Sender: TObject);
113begin
114inherited;
115 with cboDevice do if ItemIndex > -1 then
116 begin
117 txtRightMargin.Text := Piece(Items[ItemIndex], '^', 4);
118 txtPageLength.Text := Piece(Items[ItemIndex], '^', 5);
119 end;
120end;
121
122procedure TfrmDeviceSelect.cmdOKClick(Sender: TObject);
123begin
124 inherited;
125 if cboDevice.ItemID = '' then
126 begin
127 InfoBox(TX_NODEVICE, TX_NODEVICE_CAP, MB_OK);
128 Exit;
129 end;
130 ADevice := cboDevice.Items[cboDevice.ItemIndex];
131 if chkDefault.Checked then SaveDefaultPrinter(Piece(cboDevice.ItemID, ';', 1));
132 Close;
133end;
134
135procedure TfrmDeviceSelect.cmdCancelClick(Sender: TObject);
136begin
137 inherited;
138 ADevice := '';
139 Close;
140end;
141
142procedure TfrmDeviceSelect.cboDeviceNeedData(Sender: TObject;
143 const StartFrom: String; Direction, InsertAt: Integer);
144begin
145 inherited;
146 cboDevice.ForDataUse(SubsetOfDevices(StartFrom, Direction));
147end;
148
149procedure TfrmDeviceSelect.FormShow(Sender: TObject);
150begin
151 SetFormPosition(Self);
152 inherited;
153end;
154
155procedure TfrmDeviceSelect.FormClose(Sender: TObject;
156 var Action: TCloseAction);
157begin
158 inherited;
159 SaveUserBounds(Self);
160end;
161
162end.
Note: See TracBrowser for help on using the repository browser.