WorkDetailsTable.java
I have two tables, one is Info and another is WorkDetails.
Table Info: ID(PK), Name, Weather, Date, Status, TimeIn_Info, TimeOut_Info
Table WorkDetails: ID(PK),Project,WorkDescription,Per,TimeIn,TimeOut // 4 row
As you can see, I have 4 row in my WorkDetails. When I click button to insert them into SQLite, the 4 row and information in Table Info will be inserted. But what I want is, the row which contains value only will be inserted. If not, it will not be inserted.
Button btn1=(Button)findViewById(R.id.button2);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
AlertDialog.Builder builder=new AlertDialog.Builder(WorkDetailsTable.this);
builder.setTitle("Data Saved");
builder.setMessage("Are you sure you want to save?");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int ii) {
W1 = txtWork1.getText().toString();
W2 = txtWork2.getText().toString();
W3 = txtWork3.getText().toString();
W4 = txtWork4.getText().toString();
a1 = spinnerTra.getSelectedItem().toString();
a2 = spinnerTra2.getSelectedItem().toString();
a3 = spinnerTra3.getSelectedItem().toString();
a4 = spinnerTra4.getSelectedItem().toString();
P1 = per1.getText().toString();
P2 = per2.getText().toString();
P3 = per3.getText().toString();
P4 = per4.getText().toString();
if((W4.equals("null"))&&(P4.equals("null"))&&(h.equals(null))&&(i.equals("null"))) // check whether row 4 is null
{
checkRow3(W3, P3, f, g);// check row 3;
}
Toast.makeText(context, "Row 4 and 3 are empty", Toast.LENGTH_SHORT).show();
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int ii) {
dialog.dismiss();
}
});
builder.show();
}
});
}
public void checkRow3(String a, String b, String c, String d)
{
if((a.equals("null"))&&(b.equals("null"))&&(c.equals(null))&&(d.equals("null")))
{
return ;
}
else if(!d.equals("null"))
{
WD.insertWorkDetails(a3, a, b, c, d); // since row 3 not null, it will inserted into Table WorkDetails
db.execSQL("INSERT into" + MyDatabaseHelper.TABLE_INFO + "(TimeOut_Info) values(?);", new String[]{d}); //insert d to Table Info column TableOut_Info
Toast.makeText(this, "Done", Toast.LENGTH_SHORT).show();
return;
}
}
But the problem now is, it keeps on telling me that row 3 and row 4 are empty which suppose has value in row3. When I check data in SQLite, of course I get zero value in my SQLite. What's wrong with my code?
Aucun commentaire:
Enregistrer un commentaire