Exemple SQLite3 - Entrada Saída e Saldo

Ejemplos y plantillas para Autoplay Media Studio.
HIDE: ON
Hidebb Message Hidden Description

https://uploaddeimagens.com.br/imagens/image1-png--29

script
foundDBF = Folder.DoesExist(_SourceFolder .."\\DataBase");
if not foundDBF then
Folder.Create(_SourceFolder .."\\DataBase");
end

-------------------------------------------------------------------------------------------------------->> OPEN SQLite3
sDatabase = _SourceFolder.."\\DataBase\\db.db"
tInfo_Selected = nil;
db = SQLite3.Open(sDatabase);
nLastError = Application.GetLastError();
if nLastError ~= SQLite3.OK then
Dialog.Message("Error de Apertura de Base de Datos", SQLite3.GetLastErrorString());
end



function Convertdate(strdate)
if strdate then
if (tonumber(strdate)< 10) and (String.Length(strdate)<2) then
newDate = "0"..strdate
else
newDate =strdate
end
end
return newDate
end

-------------------------------------------------------------------------------------------------------->> CRIAR TABELA
SQLite3.Query(db,"CREATE TABLE Ussers (RecordID INTEGER  PRIMARY KEY,"
.."\r\DATA            TEXT,"
.."\r\TIPO            TEXT,"
.."\r\DESCRISAO       TEXT,"
.."\r\ENTRADA_1       TEXT,"
.."\r\ENTRADA_2       TEXT,"
.."\r\SAIDA_1         TEXT,"
.."\r\SAIDA_2         TEXT,"
.."\r\SALDO           TEXT)")
SQLite3.Query(db, "CREATE TABLE Backup (RecordID INTEGER  PRIMARY KEY,Date TEXT, Path TEXT)");
Backup = false;

-----------------------------------------------------------------------------------------------------------------------------------------------------------==
function InputSoloNumeros(HwndInput)------------->> Só Opitar por Numeros
Args1                  = string.format("%d,%d", HwndInput, -16)
GetWinLong             = DLL.CallFunction("user32.dll", "GetWindowLongA", Args1, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
Args2                  = string.format("%d,%d,%d", HwndInput, -16, GetWinLong + 8192)
DLL.CallFunction("user32.dll", "SetWindowLongA", Args2, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
end

-----------------------------------------------------------------------------------------------------------------------------------------------------------==
function HabilitarObjetos()------------->> Habilitar verdadeiro
if (i == 1) then
for count = 1,3 do
tProperties = {};
tProperties.ReadOnly = false;
Input.SetProperties("Input"..count, tProperties);
WinApi.EnableWindow(DialogEx.Close(IDOK), true);
i = 0;
end 
end
end

-----------------------------------------------------------------------------------------------------------------------------------------------------------==
function DesabilitarObjetos()------------->> Desabilitar falso
if (i == 1) then
else
for count = 1,3 do
tProperties = {};
tProperties.ReadOnly = true;
Input.SetProperties("Input"..count, tProperties);
i = 1;
end 
end
end
DesabilitarObjetos()

-----------------------------------------------------------------------------------------------------------------------------------------------------------==

Page.StartTimer(100, 1);
Page.StartTimer(100, 2);

-----------------------------------------------------------------------------------------------------------------------------------------------------------==
function Pesquisar_Tabela()

Grid.DeleteNonFixedRows("Grid1", true);----->> Adicionar textos ao cabeçalho das colunas da grade
Grid.SetCellText("Grid1", 0, 0,        "ID", false); 
Grid.SetCellText("Grid1", 0, 1,      "DATA", false);  
Grid.SetCellText("Grid1", 0, 2,      "TIPO", false);
Grid.SetCellText("Grid1", 0, 3, "DESCRIÇÃO", false);
Grid.SetCellText("Grid1", 0, 4,   "ENTRADA", false);
Grid.SetCellText("Grid1", 0, 5,     "SAÍDA", false);
Grid.SetCellText("Grid1", 0, 6,     "SALDO", false);
Grid.Refresh("Grid1")


tInfo_Selected = SQLite3.QueryToTable(db, "Select * from Ussers", true)
for nRow = 1, tInfo_Selected.Rows do

for i, v in pairs (Pesquisar) do	
if (String.Find(tInfo_Selected.Data[nRow]["TIPO"]..tInfo_Selected.Data[nRow]["DATA"], v, 1, false) ~= -1) then

local nLine = Grid.InsertRow("Grid1", -1, false);  
Grid.SetCellText("Grid1",  nLine, 0, tInfo_Selected.Data[nRow]["RecordID"], false);    
Grid.SetCellText("Grid1",      nLine, 1, tInfo_Selected.Data[nRow]["DATA"], false);
Grid.SetCellText("Grid1",      nLine, 2, tInfo_Selected.Data[nRow]["TIPO"], false);
Grid.SetCellText("Grid1", nLine, 3, tInfo_Selected.Data[nRow]["DESCRISAO"], false);
Grid.SetCellText("Grid1", nLine, 4, tInfo_Selected.Data[nRow]["ENTRADA_1"], false);
Grid.SetCellText("Grid1",   nLine, 5, tInfo_Selected.Data[nRow]["SAIDA_1"], false);
Grid.SetCellText("Grid1",     nLine, 6, tInfo_Selected.Data[nRow]["SALDO"], false);

    end
    end
end

-----------------------------------------------------------------------------------------------------------------------------------------------------------==
saldo = 0;
for x = 1, Grid.GetRowCount ("Grid1")-1 do
if Grid.GetCellText("Grid1", x, 4) ~= nil then
saldo = saldo + String.ToNumber (Grid.GetCellText("Grid1", x, 4)) - String.ToNumber (Grid.GetCellText("Grid1", x, 5)) --->> Somar
local   nNumber = saldo
local  sCountry = "R$"
local  bDecimal = true
local sCurrency = CurrencyGeran.ToCurrency(nNumber, sCountry, bDecimal);
Grid.SetCellText("Grid1", x, 6, sCurrency, true); --->> Resultado
end
end


-----------------------------------------------------------------------------------------------------------------------------------------------------------==
entrada = 0;
for x = 1, Grid.GetRowCount ("Grid1")-1 do
if Grid.GetCellText("Grid1", x, 4) ~= nil then
entrada = entrada + String.ToNumber (Grid.GetCellText("Grid1", x, 4))
local   nNumber = entrada
local  sCountry = "R$"
local  bDecimal = true
local sCurrency = CurrencyGeran.ToCurrency(nNumber, sCountry, bDecimal);
Input.SetText("Input8", sCurrency);
end
end

saida = 0
for x = 1, Grid.GetRowCount ("Grid1")-1 do
if Grid.GetCellText("Grid1", x, 5) ~= nil then
saida = saida + String.ToNumber (Grid.GetCellText("Grid1", x, 5))
local   nNumber = saida
local  sCountry = "R$"
local  bDecimal = true
local sCurrency = CurrencyGeran.ToCurrency(nNumber, sCountry, bDecimal);
Input.SetText("Input9", sCurrency);

end
end
returnNumber = 0
function OPERATION(operat)
number = entrada
if number == "" then
returnNumber = 0
else
returnNumber =  String.ToNumber(number)
operation = operat
end
end
OPERATION("moins")
number = saida
if operation == "moins" then
returnNumber = returnNumber - String.ToNumber(number) 
end

local   nNumber = returnNumber
local  sCountry = "R$"
local  bDecimal = true
local sCurrency = CurrencyGeran.ToCurrency(nNumber, sCountry, bDecimal);
Input.SetText("Input10", sCurrency);

-----------------------------------------------------------------------------------------------------------------------------------------------------------==


-------------------------------->> Entrada
entrada = 0;
for x = 1, Grid.GetRowCount ("Grid1")-1 do
if Grid.GetCellText ("Grid1", x, 4) ~= "" and String.ToNumber (Grid.GetCellText ("Grid1", x, 4)) ~= 0 then --->> Virificar se ha numero
entrada = String.ToNumber (Grid.GetCellText("Grid1", x, 4))
local   nNumber = entrada
local  sCountry = "R$"
local  bDecimal = true
local sCurrency = CurrencyGeran.ToCurrency(nNumber, sCountry, bDecimal);
Grid.SetCellText("Grid1", x, 4, sCurrency, true);
end
end

-------------------------------->> Saida
saida = 0;
for x = 1, Grid.GetRowCount ("Grid1")-1 do
if Grid.GetCellText ("Grid1", x, 5) ~= "" and String.ToNumber (Grid.GetCellText ("Grid1", x, 5)) ~= 0 then --->> Virificar se ha numero
saida = String.ToNumber (Grid.GetCellText("Grid1", x, 5))
local   nNumber = saida
local  sCountry = "R$"
local  bDecimal = true
local sCurrency = CurrencyGeran.ToCurrency(nNumber, sCountry, bDecimal);
Grid.SetCellText("Grid1", x, 5, sCurrency, false);
end
end
--------------------------------------------------------------------------------------------------------------------------------------------------==

Grid.AutoSize("Grid1", GVS_BOTH, true);
Grid.AutoSizeColumns("Grid1", GVS_BOTH, true);
Grid.ExpandColumnsToFit("Grid1", true, true);
--Grid.ExpandRowsToFit("Grid1", true, true);
Grid.Refresh("Grid1")

end
Gracias por tu aporte... Le echaré un ojo...
Muevo a foro correspondiente 'Ejemplos y Plantillas'
El gran dipro :pc: :pc:
luasqlite escribió:
14 Nov 2017 04:23
El gran dipro :pc: :pc:
grande amigo lene
thnkssssssssssssssss
tnks m8
gracias
Gracias
muchas gracias...