How to Retrieve Last Entered Result and Perform Subtraction after that store into SQLite Android -
I am making a stock in system - I know how to start a new record in the table
But now, I have to do an additional job by recovering the previous value and connecting with the current value.
E.G:
ROWID | | Stock ID | Stock amount | Total Stock # 01 A0001 | 20 | 20 || 02 | B0002 | 50 | 50 | 03 | A0001 | 40 | 60 & lt; & Lt; & Lt; (Assuming this new ant value is "40", when I get "60" when STOCKIN is pressed in the database) - Pisces 20 + 40 = 60
The following is code:
DBAdapter class
public long stock in (string indent, string provident, string unit, string total, string rack) {ContentValues InitialValues = new content value (); initial value. Input (KEY_STOCK_IN_DATE, Indent); InitialValues.put (KEY_PRO_CODE, Prudent); InitialValues.put (KEY_STOCK_IN_AMT, unit); InitialValues.put (KEY_STOCK_TOTAL, total); InitialValues.put (KEY_STOCK_RACK, rack); Return DBInstant (DATABASE_TRANS_TABLE, blank, initial value); } Stocks in the class
Public Zero STOCKIN {stockinBttn.setOnClickListener (New OnClickListener) {@ Click Override Public Zero (see V) {string end input, idinput, unit input, total input, rack input; Date input = date Lbl.getText (). ToString () Trim (); IDInput = PRODText.Get Text () ToString () Trim (); UnitInput = prounitTxt.getText (). ToString () Trim (); TotalInput = prounitTxt.getText (). ToString () Trim (); RackInput = prorackTxt.getText () ToString () Trim (); DB.Open (); Long id = db.stock in (user input, dead input, idinput, unit input, rack input); DB Close ();}}); }
Your gesture suggestions and help is greatly appreciated. Regards
Read all previous transactions from the table, and add it to the current amount:
< Public long stock in public (string indent, string provident, long unit, string rack) {long time ago = database user.file (db, "select total (" KEY_STOCK_TOTAL + ")" + "FROM" + DATABASE_TRANS_TABLE + "WHERE" + KEY_PRO_CODE + "=?", New string [] {proid}); Content value cv = new content value (); Cv.put (KEY_STOCK_IN_DATE, Indent); Cv.put (KEY_PRO_CODE, Prudent); Cv.put (KEY_STOCK_IN_AMT, unit); Cv.put (KEY_STOCK_TOTAL, previous total + unit); Cv.put (KEY_STOCK_RACK, rack); Return DBInstant (DATABASE_TRANS_TABLE, blank, CV); }
Comments
Post a Comment