Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- btnSaveChanges.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- try {
- costPrice = Double.parseDouble(etItemCostPrice.getText().toString());
- sellingPrice = Double.parseDouble((etItemSellingPrice.getText().toString()));
- quantitySold = Integer.parseInt(spQuantity.getSelectedItem().toString());
- itemName = etItemName.getText().toString();
- datesold = new Date();
- datesold2 = etDateOfSale.getText().toString();
- //staffRate = true;
- if (rbtnStaffRateNo.isChecked())
- {
- rbtnvalue = "No";
- }
- if (rbtnStaffRateYes.isChecked())
- {
- rbtnvalue = "Yes";
- }
- s = new Sale(itemName, costPrice, sellingPrice, quantitySold, staffRate, datesold);
- displayString(s.toString());
- //DATABASE
- mc.addToDatabase(itemName, costPrice, sellingPrice, quantitySold, datesold2, rbtnvalue, getApplicationContext());
- } catch (NumberFormatException e) {
- costPrice = 0;
- sellingPrice = 0;
- quantitySold = 0;
- }
- }
- });
- public long addToDatabase(String entryName, double entryTel, double sellingprice, int quantitysold, String datesold, String staffdiscount, Context c)
- {
- MyDbAdapter db = new MyDbAdapter(c);
- db.open();
- long rowIDofInsertedEntry = db.insertEntry(entryName, entryTel, sellingprice, quantitysold, datesold, staffdiscount);
- db.close();
- return rowIDofInsertedEntry;
- }
- private static final String DATABASE_NAMEA = "test.db";
- private static final String DATABASE_TABLE = "myTestDb";
- private static final int DATABASE_VERSION = 1;
- private SQLiteDatabase _db;
- private final Context context;
- public static final String KEY_ID = "_id";
- public static final int COLUMN_KEY_ID = 0;
- public static final String ENTRY_NAME = "entry_name";
- public static final int COLUMN_NAME_ID = 1;
- public static final String ENTRY_TEL = "entry_telephone";
- public static final int COLUMN_TEL_ID = 2;
- public static final String ENTRY_SELLINGPRICE = "entry_sellingprice";
- public static final int COLUMN_SELLINGPRICE_ID = 3;
- public static final String ENTRY_QTYSOLD = "entry_qtysold";
- public static final int COLUMN_QTYSOLD_ID = 4;
- public static final String ENTRY_DATESOLD = "entry_datesold";
- public static final int COLUMN_DATESOLD_ID = 5;
- public static final String ENTRY_STAFFDISCOUNT = "entry_staffdiscount";
- public static final int COLUMN_STAFFDISCOUNT_ID = 6;
- private String MYDBADAPTER_LOG_CAT = "MY_LOG";
- public long insertEntry(String entryName, double entryTel, double sellingprice, int quantitysold, String datesold, String staffdiscount)
- {
- try {
- //step 19 - insert record into table
- ContentValues newEntryValues = new ContentValues();
- newEntryValues.put(ENTRY_NAME, entryName);
- newEntryValues.put(ENTRY_TEL, entryTel);
- newEntryValues.put(ENTRY_SELLINGPRICE, sellingprice);
- newEntryValues.put(ENTRY_QTYSOLD, quantitysold);
- newEntryValues.put(ENTRY_DATESOLD, datesold);
- newEntryValues.put(ENTRY_STAFFDISCOUNT, staffdiscount);
- Log.w(MYDBADAPTER_LOG_CAT, "Inserted EntryName = " + entryName +
- "EntryTel = " + entryTel + "EntrySP = " + sellingprice + "EntryQt = " + quantitysold + "Entryds = " + datesold +
- "Entrysd = " + staffdiscount + DATABASE_TABLE);
- check = _db.insert(DATABASE_TABLE, null, newEntryValues);
- }
- catch (Exception ex)
- {
- Log.e("ERROR", ex.toString());
- }
- return check;
- }
- public Cursor retrieveAllEntriesCursor() {
- //step 21 - retrieve all records from table
- Cursor c = null;
- try {
- c = _db.query(DATABASE_TABLE, new String[] {KEY_ID, ENTRY_NAME, ENTRY_TEL, ENTRY_SELLINGPRICE, ENTRY_QTYSOLD, ENTRY_DATESOLD, ENTRY_STAFFDISCOUNT}, null, null, null, null, null);
- }
- catch (SQLiteException e)
- {
- Log.w(MYDBADAPTER_LOG_CAT, "Retrieve fail!");
- }
- return c;
- }
- public ArrayList<SalesItemInformationLV> retrieveAllForlist2(Context c)
- {
- ArrayList<SalesItemInformationLV> items = new ArrayList<SalesItemInformationLV>();
- Cursor myCursor;
- String mystring = "";
- MyDbAdapter db = new MyDbAdapter(c);
- db.open();
- //contactIdList.clear();
- //contactList.clear();
- myCursor = db.retrieveAllEntriesCursor();
- if (myCursor != null && myCursor.getCount() > 0)
- {
- myCursor.moveToFirst();
- do {
- //contactIdList.add(myCursor.getInt(db.COLUMN_KEY_ID)); contactIdList is only for delete purposes
- items.add(new SalesItemInformationLV(myCursor.getString(db.COLUMN_NAME_ID), myCursor.getDouble(db.COLUMN_TEL_ID), myCursor.getDouble(db.COLUMN_SELLINGPRICE_ID), myCursor.getInt(db.COLUMN_QTYSOLD_ID), myCursor.getString(db.COLUMN_DATESOLD_ID), myCursor.getString(db.COLUMN_STAFFDISCOUNT_ID)));
- } while (myCursor.moveToNext());
- }
- db.close();
- return items;
- }
- MyItems mi;
- //For Items display - ArrayList
- private ArrayList<SalesItemInformationLV> displayiteminfo;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_list_sale_item);
- mi = MyItems.getInstance();
- displayiteminfo = mi.retrieveAllForlist(getApplicationContext());
- //New array adapter for customised ArrayAdapter
- final ArrayAdapter<SalesItemInformationLV> adapter = new itemArrayAdapter(this, 0, displayiteminfo);
- //Find the list view, bind it with custom adapter
- final ListView listView = (ListView)findViewById(R.id.customListview);
- listView.setAdapter(adapter);
- //Selecting the listview item!
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- SalesItemInformationLV saleitem = displayiteminfo2.get(position);
- String namevalue = saleitem.getItemname();
- Double costpvalue = saleitem.getCostprice();
- Double sellpvalue = saleitem.getSellingprice();
- int qtyvalue = saleitem.getItemquantity();
- String datevalue = saleitem.getDatesold();
- String staffvalue = saleitem.getStaffdiscount();
- Intent myintent = new Intent(ListSaleItemActivity.this, ViewSaleDetails.class);
- myintent.putExtra("itemname", namevalue);
- myintent.putExtra("itemcp", costpvalue);
- myintent.putExtra("itemsp", sellpvalue);
- myintent.putExtra("itemqty", qtyvalue);
- myintent.putExtra("itemds", datevalue);
- myintent.putExtra("itemsstaffdis", staffvalue);
- startActivity(myintent);
- }
- });
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_view_sale_details);
- //Change action bar name to AddSales
- setTitle("SaleDetailActivity");
- nameTV = (TextView)findViewById(R.id.viewname);
- costTV = (TextView)findViewById(R.id.viewcostprice);
- sellTV = (TextView)findViewById(R.id.viewsellingprice);
- qtyTV = (TextView)findViewById(R.id.viewqtysold);
- datesoldTV = (TextView)findViewById(R.id.viewdatesold);
- staffdisTV = (TextView)findViewById(R.id.viewstaffdiscount);
- androidIm =(ImageView) findViewById(R.id.androidimageview);
- androidIm.setImageResource(R.drawable.android);
- //retrieve data
- Bundle extras = this.getIntent().getExtras();
- String itemName = extras.getString("itemname");
- float itemcost = extras.getFloat("itemcp", 0f);
- float itemselling = extras.getFloat("itemsp", 0f);
- int itemquantity = extras.getInt("itemqty", 0);
- String itemdatesold = extras.getString("itemds");
- String itemstaffdiscount= extras.getString("itemsstaffdis");
- //display data
- nameTV.setText(itemName);
- costTV.setText(String.valueOf(itemcost)); //take note of float
- sellTV.setText(String.valueOf(itemselling));
- qtyTV.setText(String.valueOf(itemquantity));
- datesoldTV.setText(itemdatesold);
- staffdisTV.setText(itemstaffdiscount);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement