Автор: blaze96
Дата сообщения: 26.02.2013 22:05
[more] Zloy_Gelud
вот весь код, полностью
Код: --Get combobox text of the selected item
local sCBText = ComboBox.GetItemText(this, e_Selection);
--check to see if there is an error
if sCBText ~= "" then
--define local and global variables
local bEnable = false;
local sQuery = "";
local sText = "";
sData = "";
--Delete all items in the listbox
ListBox.DeleteItem("ListBox1", -1);
--check for combobox selection.
if sCBText == "All Orders" then
--If All Orders was selected then define our query as follows
sQuery = "Select Orders.OrderID, Customers.CompanyName from Orders, Customers where Orders.CustomerID = Customers.CustomerID";
else
bEnable = true;
if sCBText == "Country" then
--If Country is selected, then set bEnable to true define the query and a couple of other parameters
sQuery = "Select Distinct ShipCountry from Orders order by ShipCountry";
sText = "ShipCountry";
sData = "ShipCountry";
elseif sCBText == "Customer" then
--If Customer is selected, then set bEnable to true define the query and a couple of other parameters
sQuery = "Select CustomerID, CompanyName from Customers order by CompanyName";
sText = "CompanyName";
sData = "CustomerID";
elseif sCBText == "Employee" then
--If Employee is selected, then set bEnable to true define the query and a couple of other parameters
sQuery = "Select EmployeeID, LastName from Employees order by LastName";
sText = "LastName";
sData = "EmployeeID";
elseif sCBText == "Shipper" then
--If Shipper is selected, then set bEnable to true define the query and a couple of other parameters
sQuery = "Select ShipperID, CompanyName from Shippers order by CompanyName";
sText = "CompanyName";
sData = "ShipperID";
end
end
--Reset the content of ComboBox2
ComboBox.ResetContent("ComboBox2");
--if bEnabled then perform the following function
if bEnable then
--Enable ComboBox2 for further filter criteria and give it the page focus
ComboBox.SetEnabled("ComboBox2", true);
Page.SetFocus("ComboBox2");
--Reset the Row Count Label
Label.SetText("Label3", "0 of 0 Rows");
--Perform the query as defined above to populate ComboBox2
tbReturn = SQLite.QueryToTable(db, sQuery);
if tbReturn and tbReturn.Rows > 0 then
--for each item returned by the query add it to the combobox
for i,v in tbReturn.Data do
ComboBox.AddItem("ComboBox2", tbReturn.Data[i][sText], tbReturn.Data[i][sData]);
end
end
else
--If "All Orders" was selected then do the following
--Disable ComboBox2 and set focus the Combobox1
ComboBox.SetEnabled("ComboBox2", false);
Page.SetFocus("ComboBox1");
--Perform the query as defined above
tbReturn = SQLite.QueryToTable(db, sQuery);
if tbReturn and tbReturn.Rows > 0 then
--Reseet the listbox
ListBox.DeleteItem("ListBox1", -1);
--Disable update on the listbox so the update occurs quicker
ListBox.SetUpdate("ListBox1", false);
--For each item returned add it to the Listbox
for i,v in tbReturn.Data do
ListBox.AddItem("ListBox1", tbReturn.Data[i]["Orders.OrderID"] .." - "..tbReturn.Data[i]["Customers.CompanyName"], tbReturn.Data[i]["Orders.OrderID"]);
end
--Reenable the update on the listbox
ListBox.SetUpdate("ListBox1", true);
--Calculate the total number of rows in the Orders table
tbCount = SQLite.QueryToTable(db, "Select count(*) from Orders");
--Set the number of rows returned in the query to the Label3 object
Label.SetText("Label3", tbReturn.Rows .. " of " .. tbCount.Data[1]["count(*)"] .. " Rows");
end
end
else
--There was an error - sCBText was blank
--Disable ComboBox2, delete all items in teh list box and reset our global variable
ComboBox.SetEnabled("ComboBox2", false);
ListBox.DeleteItem("ListBox1", -1);
sData = "";
local sPath = ComboBox.GetItemData(this, e_Selection);
File.Open(sPath, "AutoPlay\\Videos", SW_SHOWNORMAL);
end