local VCL=require "qvcl"
local path = getScriptPath().."\\config.cfg"
local stopped
function OnStop()
if mainForm then mainForm:Release(); mainForm = nil; VCL = nil end
message("Робот отключен пользователем")
stopped = true
end
ACCOUNT = "";
CLIENT_CODE = "";
SEC_CODE = "";
CLASS_CODE = "";
function Log (ad,...)
local str="";
for i=1,arg.n do
if arg[i] ~= nil then str=str..tostring(arg[i]) end
end
end
function Handler(Sender,...)
local SN=Sender.Name
if SN == "Button_exit" then OnFormClose() end
if SN == "Button_save" then SaveToFile("config.cfg") Log(0,"Значения из таблицы сохранены в файл ", path) end
if SN == "Button_load" then LoadFromFile("config.cfg") Log(0,"Значения загружены в таблицу из файла ", path) end
if SN == "EditButton_account" then
ACCOUNT = EditButton_account.Text
elseif SN == "EditButton_client_code" then
CLIENT_CODE = EditButton_client_code.Text
elseif SN == "EditButton_sec_code" then
SEC_CODE = EditButton_sec_code.Text
elseif SN == "ComboBox_class_code" then
CLASS_CODE = ComboBox_class_code.Text
end
end
mainForm = VCL.Form({Name = "mainForm", Height = 150, Width = 600, Caption = "Робот",
Position = "", OnClose = OnStop})
Button_save = VCL.Button(mainForm, {Name = "Button_save", top=100, left=130, Caption="Сохранить", Width=80, Enabled = true, OnClick = Handler, ShowHint=true, Hint="Запись значений таблицы в файл"})
Button_load = VCL.Button(mainForm, {Name = "Button_load", top=100, left=350, Caption="Загрузить", Width=80, Enabled = true, OnClick = Handler, ShowHint=true, Hint="Загрузка значений в таблицу из файла"})
Label_account = VCL.Label(mainForm, {Name = "Label_account", top=10, left=10, Caption="Торговый счет", ShowHint=true, Hint=" Элемент Label"})
EditButton_account = VCL.EditButton(mainForm, {Name = "EditButton_account", top=10, left=110, Width=90, ShowHint=true, OnButtonClick = Handler, Hint="Элемент EditButton"})
Label_client_code = VCL.Label(mainForm, {Name = "Label_client_code", top=10, left=240, Caption="Код клиента", ShowHint=true, Hint=" Элемент Label"})
EditButton_client_code = VCL.EditButton(mainForm, {Name = "EditButton_client_code", top=10, left=330, Width=90, ShowHint=true, OnButtonClick = Handler, Hint="Элемент EditButton"})
Label_sec_code = VCL.Label(mainForm, {Name = "Label_sec_code", top=40, left=10, Caption="Код бумаги", ShowHint=true, Hint=" Элемент Label"})
EditButton_sec_code = VCL.EditButton(mainForm, {Name = "EditButton_sec_code", top=40, left=110, Width=90, ShowHint=true, OnButtonClick = Handler, Hint="Элемент EditButton"})
Label_class_code = VCL.Label(mainForm, {Name = "Label_class_code", top=40, left=240, Caption="Код класса", ShowHint=true, Hint=" Элемент Label"})
ComboBox_class_code = VCL.ComboBox(mainForm, {Name = "ComboBox_class_code", top=40, left=330, Width=110, Text="Выбрать...", OnChange = Handler, ShowHint=true, Hint="Элемент ComboBox"})
for _,i in ipairs({"SPBFUT","SPBOPT","TQBR"}) do ComboBox_class_code.Items:Add(i) end
mainForm:Show()
function LoadFromFile ( directory )
return os.rename ( directory, directory )
end
local st, err = LoadFromFile ( path )
if st then
local func, err = loadfile ( path )
if func then
func ()
ACCOUNT = config.ACCOUNT
CLIENT_CODE = config.CLIENT_CODE
SEC_CODE = config.SEC_CODE
CLASS_CODE = config.CLASS_CODE
else
message ( err, 3 )
end
else
message ( err, 3 )
end
function SaveToFile (table_name, path)
os.remove ( "config.cfg" )
local t = {ACCOUNT = ACCOUNT, CLIENT_CODE = CLIENT_CODE, SEC_CODE = SEC_CODE, CLASS_CODE = CLASS_CODE}
local f, err = io.open ("config.cfg", "w")
if not f then
return nil, err
end
local res = {}
f:write ( table_name.." =\n{\n" )
for k, v in pairs ( t ) do
res[#res + 1] = "\t"..k.."="..v
end
f:write ( table.concat ( res, "," ) )
f:write ("}"); f:flush (); f:close ()
return true
end
SaveToFile ( "config", path )
function main()
while not stopped do
sleep (1)
end
sleep(300)
end