| Subject |
Re: printer paper source |
| From |
Akshat Kapoor <akshat.kapoor@kapoorsons.in> |
| Date |
Sat, 15 Aug 2020 22:46:16 +0530 |
| Newsgroups |
dbase.getting-started |
| Attachment(s) |
set_ini.wfm, get_printer.prg, load_ini.prg, menu_main.wfm |
On 12.08.2020 19:47, Mervyn Bick wrote:
> On 2020-08-12 15:29, Mervyn Bick wrote:
>
>> paperbin.prg is attached. papersize.prg is in the dUFLP.
>
> getBINinfo.cc posted by Rich of autotraker and a little demo program are
> attached.
>
> The .cc may be of more use than the two programs as it is easily
> incorporated into your own programs.
Good Evening Mervyn, Rich, Mustansir,
I expanded on the files received in this thread and tried to design a
form to save the printer settings. The efforts till now are attached as
set_ini.wfm
It gets data from the getbininfo.cc and displays it in comboboxes so
that the same can be selected.
The main intention was to save the info once so that it can used by
reports repeatedly.
But I failed.
In the newsgroup we are always advised not to hardcode paths for tables
or other files. If a reference to paths is required it should be
relative so that if there is change in parent directory for some reason
then all the forms need not be changed.
Mustansir just wanted info about paper size numbers and paper bin
numbers associated with required sizes so that he can use them in reports.
Printers / Printer configuration (i.e. local/network or papersizes in
trays) are one of the most frequently changed parameters.
Will it be wise to spend so much time in hardcoding of paper sizes and
paper bin info?
Some time ago I had faced what Mustansir is facing now. My label printer
was attached to one laptop (th USB) and shared over LAN.
The same .lab file was supposed to print to the printer from both
computers without user intervention.
It was then that I had developed get_printer.prg and load_ini.prg.
The form used to load the data from the ini file (different on both
computers) and render the labels to desired printer without user
intervention.
get_printer uses chooseprinter() to get all the info and save it in ini
files. chooseprinter() can easily be handled by any user and it is a one
time operation till there is no change in printer configuration when it
can be reassigned at will.
The usage seems simple to me. It is for yo all to decide if it is simple
or not.
To save label.ini
do get_printer with 'label.ini'
(Please add paths as and when required)
and usage
set procedure to p_label2.lab
l = new p_LABEL2REPORT()
load_ini("label.ini","l.printer")
l.render()
This will assign the required defaults to the following properties
color
duplex
orientation
papersize
papersource
printername
I do not think there are any more properties of a printer that require
change.
I am also attaching menu_main.wfm which I use to set the ini options.
The controls / events of interest for this thread are
ini_file
ini_name
ini_file_onclick
I rest my case.
Regards
Akshat
| set procedure to getbininfo.cc
set procedure to papersize.prg
** END HEADER -- do not remove this line
//
// Generated on 15-08-2020
//
parameter bModal
local f
f = new set_iniForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class set_iniForm of FORM
with (this)
onOpen = class::FORM_ONOPEN
height = 20.5909
left = 51.5714
top = 0.0
width = 104.4286
text = ""
endwith
this.TEXT1 = new TEXT(this)
with (this.TEXT1)
height = 1.0
left = 1.0
top = 4.5
width = 33.0
text = "Please Select the Printer name"
endwith
this.PRINTER_NAME = new COMBOBOX(this)
with (this.PRINTER_NAME)
onChangeCommitted = class::PRINTER_NAME_ONCHANGECOMMITTED
height = 1.0
left = 43.0
top = 4.5
width = 34.0
style = 2 // DropDownList
endwith
this.TEXT2 = new TEXT(this)
with (this.TEXT2)
height = 1.0
left = 1.0
top = 1.0
width = 33.0
text = "Please Enter the INI File name"
endwith
this.INI_NAME = new ENTRYFIELD(this)
with (this.INI_NAME)
height = 1.0
left = 43.0
top = 1.0
width = 26.0
value = " "
endwith
this.TEXT3 = new TEXT(this)
with (this.TEXT3)
height = 1.0
left = 1.0
top = 6.4545
width = 33.0
text = "Please Select the Paper size"
endwith
this.PAPER_SIZE = new COMBOBOX(this)
with (this.PAPER_SIZE)
height = 1.0
left = 43.0
top = 6.4545
width = 34.0
style = 2 // DropDownList
endwith
this.TEXT4 = new TEXT(this)
with (this.TEXT4)
height = 1.0
left = 1.4286
top = 8.4091
width = 33.0
text = "Please Select the Paper Bin"
endwith
this.PAPER_BIN = new COMBOBOX(this)
with (this.PAPER_BIN)
height = 1.0
left = 43.4286
top = 8.4091
width = 34.0
style = 2 // DropDownList
endwith
this.SAVE_INI = new PUSHBUTTON(this)
with (this.SAVE_INI)
onClick = class::SAVE_INI_ONCLICK
height = 1.0909
left = 15.0
top = 11.5
width = 15.2857
text = "&Save Ini File"
endwith
function PRINTER_NAME_onChangeCommitted()
if not empty(form.printer_name.value)
local x
x = new getBINinfo(form.printer_name.value,'0')
if x.aBinNames.size >0
pap_bins = 'array {'
for i = 1 to x.aBinNames.size
if i >1
pap_bins+=[,]
endif
pap_bins+=["]+x.aBins[i]+ [-]+x.aBinNames[i]+["]
endfor
pap_bins+=[}]
form.paper_bin.enabled = true
form.paper_bin.datasource = pap_bins
form.paper_bin.value = x.aBins[1]+ [-]+x.aBinNames[1]
else
form.paper_bin.datasource =[array {"No bins found"}]
form.paper_bin.value = "No bins found"
form.paper_bin.enabled = false
endif
pap_sizes = 'array {'
for i = 1 to x.aSourceNames.size
if i >1
pap_sizes+=[,]
endif
pap_sizes+=["]+x.aSources[i]+ [-]+x.aSourceNames[i]+["]
endfor
form.paper_size.datasource = pap_sizes + [}]
form.paper_size.value = x.aSources[1]+ [-]+x.aSourceNames[1]
endif
return
function SAVE_INI_onClick()
if not empty(form.ini_name.value)
of = new file()
// of.create(rtrim(ltrim(form.ini_name.value))+".ini")
// of.writeln("color[N]"+r.printer.color)
// of.writeln("duplex[N]"+r.printer.duplex)
// of.writeln("orientation[N]"+r.printer.orientation)
// of.writeln("papersize[N]"+r.printer.papersize)
// of.writeln("papersource[N]"+r.printer.papersource)
// of.writeln("printername[C]"+r.printer.printername)
// of.close()
endif
return
function form_onOpen()
//basic code of getting printer names copied from selprinter.cc of duflp
avprinters = new array()
data_source = 'array {'
x = new OleAutoClient("WScript.Network")
oPrinters = x.EnumPrinterConnections()
for i = 0 to oPrinters.count() -1 step 2
if len(data_source) >8
data_source = data_source+[,]
endif
data_source = data_Source+ ["]+oPrinters.Item(i+1) + ["]
next i
data_source = data_source + [}]
form.printer_name.datasource = data_source
initexterns()
form.printer_name.value = getprinterdefault()
form.printer_name_onchangecommitted()
return
endclass
| /*
-----------------------------------------------------------------
Description:
Altering the printer for every report on different installations
is tedious. chooseprinter() offers full choice but at times speed is of
essence. Get_printer.prg program captures the normally required parameters and
save them to an ini file passed to it as parameter.This will save
color
duplex
orientation
papersize
papersource
printername
Programmers:
Akshat Kapoor
History:
12 Feb 2019 Sharing the ready to deploy code for the first time.
Instantiation/use:
Just place get_printer.prg and load_ini in the required directory.
get_printer("report1.ini") will save the required parameters in report1.ini
(A one time event or as and when required from any form )
When running the report
set procedure to report1.rep
r = new report1report()
load_ini("report1.ini","r.printer")
will restore the required defaults.
thereafter
r.render()
No more changing of code.
with change of printer.
Some Code which I am actually using
set procedure to p_sales.rep
r = new p_salesreport()
r.salesdatamodule1.sales.params["invoice"].value = str(minvoice,10,0)
r.salesdatamodule1.sales.params["location"].value = mlocat
r.salesdatamodule1.sales.requery()
r.title = "Invoice no. "+str(minvoice,10,0)
load_ini("cashmemo.ini","r.printer")
r.render()
Additional requirements :
Both load_ini.prg and get_printer.prg are required.
They compliment each other.
for Any further suggestions please email me akshatkapoor76 at gmail dot com
----------------------------------------------------------------
*/
parameters file_name
r = new report()
if r.printer.chooseprinter()
of = new file()
of.create(file_name)
of.writeln("color[N]"+r.printer.color)
of.writeln("duplex[N]"+r.printer.duplex)
of.writeln("orientation[N]"+r.printer.orientation)
of.writeln("papersize[N]"+r.printer.papersize)
of.writeln("papersource[N]"+r.printer.papersource)
of.writeln("printername[C]"+r.printer.printername)
of.close()
endif
| /*
-----------------------------------------------------------------
Description:
Altering the printer for every report on different installations
is tedious. chooseprinter() offers full choice but at times speed is of
essence. Get_printer.prg program captures the normally required parameters and
save them to an ini file passed to it as parameter.This will save
color
duplex
orientation
papersize
papersource
printername
Programmers:
Akshat Kapoor
History:
12 Feb 2019 Sharing the ready to deploy code for the first time.
Instantiation/use:
Just place get_printer.prg and load_ini in the required directory.
get_printer("report1.ini") will save the required parameters in report1.ini
(A one time event or as and when required from any form )
When running the report
set procedure to report1.rep
r = new report1report()
load_ini("report1.ini","r.printer")
will restore the required defaults.
thereafter
r.render()
No more changing of code.
with change of printer.
Some Code which I am actually using
set procedure to p_sales.rep
r = new p_salesreport()
r.salesdatamodule1.sales.params["invoice"].value = str(minvoice,10,0)
r.salesdatamodule1.sales.params["location"].value = mlocat
r.salesdatamodule1.sales.requery()
r.title = "Invoice no. "+str(minvoice,10,0)
load_ini("cashmemo.ini","r.printer")
r.render()
Additional requirements :
Both load_ini.prg and get_printer.prg are required.
They compliment each other.
for Any further suggestions please email me akshatkapoor76 at gmail dot com
----------------------------------------------------------------
*/
parameters mfile,obj_name
infile = new file()
if file(mfile)
infile.open(mfile)
do while not infile.eof()
mstr = infile.readln()
prop_name = left(mstr,at("[",mstr)-1)
prop_value= right(mstr,len(mstr)-at("]",mstr))
prop_type=substr(mstr,at("[",mstr)+1,1)
if prop_type = "N"
prop_value = val(prop_value)
endif
if prop_type = "D"
prop_value = ctod(prop_value)
endif
if prop_type = "L"
prop_value = iif(upper(prop_value)="TRUE",true,false)
endif
mvar = obj_name+"."+prop_name
&mvar = prop_value
enddo
endif
| xmenu = 0
local f
f = new menu_mainForm()
do while xmenu<>6
f.mdi = false // ensure not MDI
f.readModal()
do case
case xmenu = 1
//do blank.wfm with "do reindex"
do reindex.wfm
case xmenu = 2
do repost.wfm
case xmenu = 3
do cre_user.wfm with .t.
case xmenu = 4
msgbox("alter user")
case xmenu = 5
do reset_pa.wfm
case xmenu = 6
//exit hence no action required
case xmenu = 7
do vatrate.wfm with .t.
case xmenu = 8
do renum.wfm with .t.
endcase
enddo
return
** END HEADER -- do not remove this line
//
// Generated on 03-06-2020
//
parameter bModal
local f
f = new menu_mainForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class menu_mainForm of MUN_FORM from "mun_controls.cc"
set procedure to mun_controls.cc additive
with (this)
onOpen = class::FORM_ONOPEN
height = 31.5
left = -12.2857
top = -0.4545
width = 214.5714
endwith
this.REINDEX = new MUN_PUSH(this)
with (this.REINDEX)
onClick = class::REINDEX_ONCLICK
height = 2.0
left = 62.0
top = 3.5
width = 30.0
text = "Rebuild &Index"
fontSize = 12.0
endwith
this.REPOST = new MUN_PUSH(this)
with (this.REPOST)
onClick = class::REPOST_ONCLICK
height = 2.0
left = 62.0
top = 7.0
width = 30.0
text = "&Repost Current Year Entries"
fontSize = 12.0
endwith
this.CREATE = new MUN_PUSH(this)
with (this.CREATE)
onClick = class::CREATE_ONCLICK
height = 2.0
left = 62.0
top = 10.5
width = 30.0
text = "Create &Users"
fontSize = 12.0
endwith
this.DELETE_USER = new MUN_PUSH(this)
with (this.DELETE_USER)
onClick = class::DELETE_USER_ONCLICK
height = 2.0
left = 62.0
top = 14.0
width = 30.0
text = "&Alter User"
fontSize = 12.0
endwith
this.RESET = new MUN_PUSH(this)
with (this.RESET)
when = {||alltrim(mcompany.user) # "super"}
onClick = class::RESET_ONCLICK
height = 2.0
left = 62.0
top = 17.5
width = 30.0
text = "&Reset Password"
endwith
this.CLOSE_FORM = new MUN_PUSH(this)
with (this.CLOSE_FORM)
onClick = class::CLOSE_FORM_ONCLICK
height = 2.0
left = 62.0
top = 21.0
width = 30.0
text = "&Close"
fontSize = 12.0
endwith
this.MUN_TEXTLABEL1 = new MUN_TEXTLABEL(this)
with (this.MUN_TEXTLABEL1)
height = 1.0
left = 53.5714
top = 1.0
width = 40.0
text = "Settings Menu"
fontSize = 16.0
fontBold = true
alignHorizontal = 1 // Center
endwith
this.VATRATE = new MUN_PUSH(this)
with (this.VATRATE)
onClick = class::VATRATE_ONCLICK
height = 2.0
left = 103.0
top = 3.5
width = 30.0
text = "&Set/Alter Vat/Gst Rates"
endwith
this.EXP_INVEN = new MUN_PUSH(this)
with (this.EXP_INVEN)
when = {||mcompany.inven}
onClick = class::PUSHBUTTON1_ONCLICK
height = 2.0
left = 103.0
top = 7.0
width = 30.0
text = "Export Inventory"
endwith
this.IMPORT_SALES = new MUN_PUSH(this)
with (this.IMPORT_SALES)
when = {||mcompany.inven}
onClick = class::IMPORT_SALES_ONCLICK
height = 2.0
left = 103.0
top = 10.5
width = 30.0
text = "Import Sales"
endwith
this.PACK_TABLES = new MUN_PUSH(this)
with (this.PACK_TABLES)
when = {||mcompany.inven}
onClick = class::PACK_TABLES_ONCLICK
height = 2.0
left = 103.0
top = 14.0
width = 30.0
text = "&Pack Tables"
endwith
this.MUN_TEXT1 = new MUN_TEXT(this)
with (this.MUN_TEXT1)
height = 1.7273
left = 134.0
top = 11.0
width = 46.0
visible = false
text = " Sales Transactions are being imported please wait.............."
endwith
this.INI_FILE = new MUN_PUSH(this)
with (this.INI_FILE)
when = {||mcompany.inven}
onClick = class::INI_FILE_ONCLICK
height = 2.0
left = 103.0
top = 17.5
width = 30.0
text = "Set Default printer options of"
endwith
this.INI_NAME = new MUN_COMBO(this)
with (this.INI_NAME)
height = 1.1818
left = 139.0
top = 18.0
width = 20.0
dataSource = 'array {"cashmemo.ini","cashmemo_h.ini","label.ini","p_big.ini"}'
endwith
function CLOSE_FORM_onClick()
xmenu = 6
form.close()
return
function CREATE_onClick()
xmenu = 3
form.close()
return
function DELETE_USER_onClick()
xmenu = 4
form.close()
return
function IMPORT_SALES_onClick()
form.mun_text1.visible = true
do import_sales
msgbox("Import of sales enteries complete")
form.mun_text1.visible = false
return
function INI_FILE_onClick()
msgbox("To insert code for this option first load the earlier option and then ask for new one and save only when confirmed")
if msgbox("Do you really want to change the printer settings for "+form.ini_name.value,"Confirm ",4 ) = 6
do get_printer with form.ini_name.value
endif
return
function PACK_TABLES_onClick()
xmenu = 8
form.close()
return
function PUSHBUTTON1_onClick()
do export_inve
msgbox("Inventory has been exported")
return
function REINDEX_onClick()
xmenu = 1
form.close()
return
function REPOST_onClick()
xmenu = 2
form.close()
return
function RESET_onClick()
xmenu = 5
form.close()
return
function VATRATE_onClick()
xmenu = 7
form.close()
return
function form_onOpen()
form.height = form_height
form.width = form_width
form.text = [Settings Menu ]+ mcompany.company
if alltrim(mcompany.user)= "super"
form.reset.enabled = false
form.reset.colornormal = push_dis
endif
return
endclass
|
|