christo garces
unread,Nov 18, 2015, 4:44:35 AM11/18/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DroidScript
function OnStart()
{
db =app.OpenDatabase("/sdcard/school");
db.ExecuteSql("CREATE TABLE IF NOT EXISTS studrec"+
"(id integer primary key, "+
"firstname text, "+
"surname text, "+
"idnumber text, "+
"class text, "+
"teacher text)");
layit = app.CreateLayout( "Absolute" );
app.ShowPopup("Student Personal Details");
btn = app.CreateButton( "Next",0.1,0.1 ,"Alum");
btn.SetOnTouch(fwdstud);
btn.SetPosition(0.5,0.9);
btn1 = app.CreateButton( "Back",0.1,0.1 ,"Alum");
btn1.SetOnTouch(fwdstud);
btn1.SetPosition(0.4,0.9);
btn2 = app.CreateButton( "Save",0.1,0.1 ,"Alum");
btn2.SetOnTouch(fwdstud);
btn2.SetPosition(0.6,0.9);
btn3 = app.CreateButton( "Remove",0.1,0.1 ,"Alum");
btn3.SetOnTouch(fwdstud);
btn3.SetPosition(0.3,0.9);
text = app.CreateText(" First Name",0.1,0.05);
text.SetPosition(0.1,0.2);
txt1 = app.CreateTextEdit("",0.2,0.07);
txt1.SetPosition(0.2,0.2);
txt2 = app.CreateText("Surname",0.1,0.1);
txt2.SetPosition(0.1,0.3);
txt3 = app.CreateTextEdit("",0.2,0.07);
txt3.SetPosition(0.2,0.3);
txt4 = app.CreateText("ID Number",0.1,0.1);
txt4.SetPosition(0.1,0.4);
txt5 = app.CreateTextEdit("",0.2,0.07);
txt5.SetPosition(0.2,0.4);
txt6 = app.CreateText("Grade",0.1,0.1);
txt6.SetPosition(0.1,0.5);
txt7 = app.CreateSpinner("1,2,3,4,5,6,7,8,9,10,11,12" ,0.2,0.07);
txt7.SetPosition(0.2,0.5);
//spn1.SetOnChange(nil);
txt8 = app.CreateText("Teacher",0.1,0.1);
txt8.SetPosition(0.1,0.6);
txt9 = app.CreateTextEdit("",0.2,0.07);
txt9.SetPosition(0.2,0.6);
txt10 = app.CreateText("Ethnicity",0.1,0.1);
txt10.SetPosition(0.1,0.7);
txt11 = app.CreateSpinner("Black,White,Indian,Coloured",0.2,0.07);
txt11.SetPosition(0.2,0.7);
txt12 = app.CreateText("Religion",0.1,0.1);
txt12.SetPosition(0.1,0.8);
txt13 = app.CreateSpinner("Christian,Hindu,Tamil,Mormon,Catholic,Atheist,Other,None",0.2,0.07);
txt13.SetPosition(0.2,0.8);
txt14 = app.CreateText("Address",0.1,0.1);
txt14.SetPosition(0.5,0.2);
txt15 = app.CreateTextEdit("",0.2,0.07);
txt15.SetPosition(0.6,0.2);
txt16 = app.CreateTextEdit("",0.2,0.07);
txt16.SetPosition(0.6,0.3);
txt17 = app.CreateTextEdit("",0.2,0.07);
txt17.SetPosition(0.6,0.4);
txt18 = app.CreateText("Disabilities",0.1,0.1);
txt18.SetPosition(0.5,0.5);
txt19 = app.CreateSpinner("Yes,No",0.2,0.07);
txt19.SetPosition(0.6,0.5);
txt20 = app.CreateText("Parent Name",0.1,0.1);
txt20.SetPosition(0.5,0.6);
txt21 = app.CreateTextEdit("",0.2,0.07);
txt21.SetPosition(0.6,0.6);
txt22 = app.CreateText("Contact No",0.1,0.1);
txt22.SetPosition(0.5,0.7);
txt23 = app.CreateTextEdit("",0.2,0.07);
txt23.SetPosition(0.6,0.7);
txt24 = app.CreateText("Alternate No",0.1,0.1);
txt24.SetPosition(0.5,0.8);
txt25 = app.CreateTextEdit("",0.2,0.07);
txt25.SetPosition(0.6,0.8);
layit.AddChild(text);
layit.AddChild(txt2);
layit.AddChild(txt1);
layit.AddChild(txt3);
layit.AddChild(txt4);
layit.AddChild(txt5);
layit.AddChild(txt6);
layit.AddChild(txt7);
layit.AddChild(txt8);
layit.AddChild(txt9);
layit.AddChild(txt10);
layit.AddChild(txt11);
layit.AddChild(txt12);
layit.AddChild(txt13);
layit.AddChild(txt14);
layit.AddChild(txt15);
layit.AddChild(txt16);
layit.AddChild(txt17);
layit.AddChild(txt18);
layit.AddChild(txt19);
layit.AddChild(txt20);
layit.AddChild(txt21);
layit.AddChild(txt22);
layit.AddChild(txt23);
layit.AddChild(txt24);
layit.AddChild(txt25);
layit.AddChild( btn );
layit.AddChild ( btn1 );
layit.AddChild ( btn2 );
layit.AddChild ( btn3 );
app.AddLayout( layit );
}
function fwdstud()
{
item1=txt1.GetText();
item2=txt3.GetText();
item3=txt5.GetText();
item4=txt7.GetText();
item5=txt9.GetText();
db.ExecuteSql("INSERT INTO studrec"+
"(firstname, "+
"surname, "+
"idnumber, "+
"class, "+
"teacher)"+
"VALUES (?,?,?,?,?)",
[item1,
item2,
item3,
item4,
item5],null,OnError );
retr()
}
function OnError()
{
app.Alert( "Error: " + msg );
console.log( "Error: " + msg );
}
function retr()
{
db.ExecuteSql( "SELECT * from studrec WHERE surname = 'garcez' ",[],OnR)
}
function OnR(results)
{
var s = "";
var len = results.rows.length;
for(var i = 0;i < len;i++)
{
var item = results.rows.item(i)
s = getPropertyString(item) + "\n";
txt1.SetText(s);
txt3.SetText(s);
}
}
function getPropertyString( object )
{
return Object.keys(object).map( function(key) { return object [key]; } ).join(",");
}