FIRSTPAGE.JAVAここには編集テキストがほとんどなく、一時的に保存する必要があります
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.first_page);
applno = (EditText) findViewById(R.id.rpfno);
financerups = (EditText) findViewById(R.id.finance_rupees);
tenure = (EditText) findViewById(R.id.tenure);
assetname = (EditText) findViewById(R.id.asset);
rowId = (EditText) findViewById(R.id.etRowInfo);
page1 = (Button) findViewById(R.id.pf1);
page2 = (Button) findViewById(R.id.pf2);
page3 = (Button) findViewById(R.id.pf3);
page4 = (Button) findViewById(R.id.pf4);
save = (Button) findViewById(R.id.btn_saveandcontinue);
exit = (Button) findViewById(R.id.btn_exit);
info = (Button) findViewById(R.id.info);
submitserver = (Button) findViewById(R.id.submitserver);
edit = (Button) findViewById(R.id.bEdit);
update = (Button) findViewById(R.id.bUpdate);
delete = (Button) findViewById(R.id.bDelete);
delete.setOnClickListener(this);
save.setOnClickListener(this);
exit.setOnClickListener(this);
info.setOnClickListener(this);
submitserver.setOnClickListener(this);
edit.setOnClickListener(this);
update.setOnClickListener(this);
page2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(FirstPage.this, Reference.class));
}
});
page1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(FirstPage.this, ProfilePage1.class));
}
});
page3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(FirstPage.this, Asset.class));
}
});
page4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(FirstPage.this, OfficeUse.class));
}
});
}
public void onClick(View arg0)
{
switch (arg0.getId())
{
case R.id.btn_saveandcontinue:
boolean didItWork = true;
try{
String Applno = applno.getText().toString();
String Financerups = financerups.getText().toString();
String Tenure = tenure.getText().toString();
String Assetname = assetname.getText().toString();
WayDataBase entry = new WayDataBase(FirstPage.this);
entry.open();
entry.createEntry(Applno, Financerups, Tenure, Assetname);
entry.close();
} catch (Exception e){
didItWork = false;
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("Dang");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}finally
{
if(didItWork)
{
/*Dialog d = new Dialog(this);
d.setTitle("Heck Yea!");
TextView tv = new TextView(this);
tv.setText("SUCCESS");
d.setContentView(tv);
d.show();*/
startActivity(new Intent(FirstPage.this, OfficeUse.class));
}
}
break;
case R.id.info:
startActivity(new Intent (FirstPage.this, TableView.class));
finish();
break;
case R.id.bEdit:
String s = rowId.getText().toString();
long l = Long.parseLong(s);
WayDataBase wdb = new WayDataBase(this);
wdb.open();
String returnedappno = wdb.getAppno(l);
String returnedfinancerups= wdb.getfinancerups(l);
String returnedtenure = wdb.getTenure(l);
String returnedasset = wdb.getAsset(l);
wdb.close();
applno.setText(returnedappno);
financerups.setText(returnedfinancerups);
tenure.setText(returnedtenure);
assetname.setText(returnedasset);
break;
case R.id.bUpdate:
break;
case R.id.bDelete:
break;
}}}
OFFICEUSE.JAVAここでは、更新メソッドを使用して上記のフィールドに関連して保存する編集テキストがほとんどなく、対応する一意のフィールドを使用して取得する必要があります
page2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(OfficeUse.this, Reference.class));
}});
page1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(OfficeUse.this,ProfilePage1.class));
}});
page4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(OfficeUse.this, OfficeUse.class));
}});
page3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(OfficeUse.this, Asset.class));
}});
exit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),FirstPage.class);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}});}
public void onClick(View arg0){
switch (arg0.getId()){
case R.id.btn_saveandcontinue:
boolean isItWork = true;
try{
String Applcname = applcname.getText().toString();
String Employee = employee.getText().toString();
String Psnem = psnem.getText().toString();
String Branch = branch.getText().toString();
String Clientid = clientid.getText().toString();
String Schmcode = schmcode.getText().toString();
String Agreeno = agreeno.getText().toString();
String Promoschm = promoschm.getText().toString();
WayDataBase entry1 = new WayDataBase(OfficeUse.this);
entry1.open();
entry1.createEntry1(Applcname, Employee, Psnem, Branch, Clientid, Schmcode, Agreeno, Promoschm);
entry1.close();
} catch (Exception e){
isItWork = false;
String error = e.toString();
Dialog d1 = new Dialog(this);
d1.setTitle("Office Dang");
TextView tv1 = new TextView(this);
tv1.setText(error);
d1.setContentView(tv1);
d1.show();
}finally{
if(isItWork){
Dialog d1 = new Dialog(this);
d1.setTitle("Office too work");
TextView tv1 = new TextView(this);
d1.setContentView(tv1);
d1.show();
}}
break;
case R.id.info:
startActivity(new Intent (OfficeUse.this, TableView.class));
finish();
break;
}}}
WAYDATABASE.JAVA
private static class DBHelper extends SQLiteOpenHelper{
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL( "CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_APPNO + " TEXT NOT NULL, " +
KEY_AMT + " TEXT NOT NULL, " +
KEY_TENURE + " TEXT NOT NULL, " +
KEY_ASSETS + " TEXT NOT NULL, " +
KEY_APPLCNAME + " TEXT NOT NULL, " +
KEY_EMPLOYEE + " TEXT NOT NULL, " +
KEY_PSNEM + " TEXT NOT NULL, " +
KEY_BRANCH + " TEXT NOT NULL, " +
KEY_CLIENTID + " TEXT NOT NULL, " +
KEY_SCHMCODE + " TEXT NOT NULL, " +
KEY_AGREENO + " TEXT NOT NULL, " +
KEY_PROMOSCHM + " TEXT NOT NULL);" );}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(" DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
} }
public WayDataBase(Context c){
ourContext=c;
}
public WayDataBase open() throws SQLException{
ourHelper = new DBHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public long createEntry(String applno, String financerups, String tenure,String assetname){
ContentValues cv = new ContentValues();
cv.put(KEY_APPNO, applno);
cv.put(KEY_AMT, financerups);
cv.put(KEY_TENURE, tenure);
cv.put(KEY_ASSETS, assetname);
return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
public long createEntry1(String applcname, String employee, String psnem,
String branch, String clientid, String schmcode, String agreeno,
String promoschm) {
ContentValues cv1 = new ContentValues();
cv1.put(KEY_APPLCNAME,applcname);
cv1.put(KEY_EMPLOYEE,employee);
cv1.put(KEY_PSNEM,psnem);
cv1.put(KEY_BRANCH,branch);
cv1.put(KEY_CLIENTID,clientid);
cv1.put(KEY_SCHMCODE,schmcode);
cv1.put(KEY_AGREENO,agreeno);
cv1.put(KEY_PROMOSCHM,promoschm);
return ourDatabase.insert(DATABASE_TABLE, null, cv1);
}
public void close(){
ourHelper.close();
}
public String getData() {
String[] columns = new String[]{ KEY_ROWID, KEY_APPNO, KEY_AMT,KEY_TENURE, KEY_ASSETS,KEY_APPLCNAME,KEY_EMPLOYEE,KEY_PSNEM,KEY_BRANCH,KEY_CLIENTID,KEY_SCHMCODE,KEY_AGREENO,KEY_PROMOSCHM };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result=" ";
int iRow = c.getColumnIndex(KEY_ROWID);
int iAppno = c.getColumnIndex(KEY_APPNO);
int iAmt = c.getColumnIndex(KEY_AMT);
int iTenure = c.getColumnIndex(KEY_TENURE);
int iAssets = c.getColumnIndex(KEY_ASSETS);
int iApplcname = c.getColumnIndex(KEY_APPLCNAME);
int iEmployee = c.getColumnIndex(KEY_EMPLOYEE);
int iPsnem = c.getColumnIndex(KEY_PSNEM);
int iBranch = c.getColumnIndex(KEY_BRANCH);
int iClientId = c.getColumnIndex(KEY_CLIENTID);
int iSchmode = c.getColumnIndex(KEY_SCHMCODE);
int iAgreeno = c.getColumnIndex(KEY_AGREENO);
int iPromoschm = c.getColumnIndex(KEY_PROMOSCHM);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{
result = result + c.getString(iRow) + " " + c.getString(iAppno) + " " + c.getString(iAmt) + " " + c.getString(iTenure) + c.getString(iAssets) +
c.getString(iApplcname) + " " + c.getString(iEmployee) + " " + c.getString(iPsnem) + " " + c.getString(iBranch) + c.getString(iClientId) +
c.getString(iSchmode) + " " + c.getString(iAgreeno) + " " + c.getString(iPromoschm) + "\n";
}
return result; }
public String getAppno(long l) {
String[] columns = new String[]{ KEY_ROWID, KEY_APPNO, KEY_AMT, KEY_TENURE, KEY_ASSETS};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + l, null, null, null, null, null);
if(c != null) {
c.moveToFirst();
String appno = c.getString(1);
return appno;
}
return null;}
public String getfinancerups(long l) {
String[] columns = new String[]{ KEY_ROWID, KEY_APPNO, KEY_AMT, KEY_TENURE, KEY_ASSETS};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + l, null, null, null, null, null);
if(c != null) {
c.moveToFirst();
String rups = c.getString(2);
return rups;
}
return null; }
public String getTenure(long l) {
String[] columns = new String[]{ KEY_ROWID, KEY_APPNO, KEY_AMT, KEY_TENURE, KEY_ASSETS};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + l, null, null, null, null, null);
if(c != null){
c.moveToFirst();
String tenur = c.getString(3);
return tenur;
}
return null;
}
public String getAsset(long l) {
String[] columns = new String[]{ KEY_ROWID, KEY_APPNO, KEY_AMT, KEY_TENURE, KEY_ASSETS};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + l, null, null, null, null, null);
if(c != null){
c.moveToFirst();
String aset = c.getString(4);
return aset;
}
return null;
}}