Guest User

Untitled

a guest
Feb 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.74 KB | None | 0 0
  1. public class PlaceOrder extends AppCompatActivity{
  2.  
  3. ListView myListview;// Place Order listview
  4. String str ;
  5. Spinner spnCategory; // Catergory filter
  6. ArrayList<GetandSet> details = new ArrayList<GetandSet>();
  7. ItemCustomAdapter customAdapter; // custom adapter template
  8. CustomArrayAdapter customArrayAdapter;
  9. ArrayList<GetandSet> productOrders = new ArrayList<GetandSet>(); // to store list of selected views
  10. ArrayList<Integer> positionArr = new ArrayList<Integer>(); // to store list of selected position
  11. GetandSet getandSet ;
  12.  
  13. private static int counter = 1;
  14.  
  15. TextView title,countTv;
  16. ImageView imgback, imgMenu,imgcart;
  17. MySQLiteDatabase mysqlitedatabase;
  18.  
  19.  
  20.  
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_place_order);
  25.  
  26. title = (TextView) findViewById(R.id.title);
  27. countTv = (TextView) findViewById(R.id.count_tv);
  28. imgback = (ImageView) findViewById(R.id.img_back);
  29. imgMenu = (ImageView) findViewById(R.id.img_menu);
  30. imgcart= (ImageView) findViewById(R.id.img_cart);
  31.  
  32. mysqlitedatabase = new MySQLiteDatabase(getApplicationContext(),null,null,1);
  33. SQLiteDatabase db = mysqlitedatabase.getWritableDatabase();
  34. Cursor cursor = db.rawQuery("SELECT * FROM MenuMaster", null);
  35.  
  36. title.setText("Place Order");
  37.  
  38. imgback.setOnClickListener(new View.OnClickListener() {
  39. @Override
  40. public void onClick(View v) {
  41. startActivity(new Intent(PlaceOrder.this, DashBoard.class));
  42. finish();
  43. counter = 1;
  44. }
  45. });
  46.  
  47. imgMenu.setVisibility(View.INVISIBLE);
  48.  
  49. myListview = (ListView)findViewById(R.id.my_list_view);//defined list_view
  50. spnCategory = (Spinner)findViewById(R.id.spn_place_category);//defined category
  51. loadSpinnerData();
  52. showList();
  53. }
  54.  
  55. //Binding Adapter and list view and Showing Data from database
  56. public void showList() {
  57. final Cursor c1 = mysqlitedatabase.selectQuery("SELECT * FROM MenuMaster ");
  58. if (c1 != null && c1.getCount() != 0) {
  59. if (c1.moveToFirst()) {
  60. do {
  61. getandSet = new GetandSet();
  62.  
  63. getandSet.setMenu_name(c1.getString(c1.getColumnIndex("menu_name")));
  64. getandSet.setMenu_rate(c1.getString(c1.getColumnIndex("menu_rate")));
  65. getandSet.setMenu_Remark(c1.getString(c1.getColumnIndex("menu_Remark")));
  66. getandSet.setMenu_Qty(c1.getInt(c1.getColumnIndex("menu_qty")));
  67.  
  68. details.add(getandSet);
  69.  
  70. } while (c1.moveToNext());
  71. }
  72. }
  73. c1.close();
  74. customAdapter = new ItemCustomAdapter(PlaceOrder.this, details);
  75. myListview.setAdapter(customAdapter);
  76. //display all data
  77. //On Item Click Listener
  78. myListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  79. @Override
  80. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  81.  
  82. str = Integer.toString(counter++);
  83. countTv.setText(str);//shopping cart counter
  84.  
  85. positionArr.add(position);// getting clicked position
  86. HashSet<Integer> hashSet = new HashSet<Integer>();
  87. hashSet.addAll(positionArr);
  88. positionArr.clear();
  89. positionArr.addAll(hashSet);// assigning position serialy
  90.  
  91. int len = myListview.getCount();//list view size
  92.  
  93. for (int i = 0; i < len; i++) {
  94.  
  95. if (position == i) {
  96.  
  97. getandSet = new GetandSet();
  98. getandSet.setMenu_name(customAdapter.DETAILS.get(i).getMenu_name());
  99. getandSet.setMenu_rate(customAdapter.DETAILS.get(i).getMenu_rate());
  100. getandSet.setMenu_Remark(customAdapter.DETAILS.get(i).getMenu_Remark());
  101. getandSet.setMenu_Qty(customAdapter.DETAILS.get(i).getMenu_Qty());
  102.  
  103. productOrders.add(getandSet);
  104.  
  105. }
  106. }
  107.  
  108. customAdapter.viewHolder.txtQuantity.setText(String.valueOf(customAdapter.DETAILS.get(position).getMenu_Qty()));
  109. onimgButtonClick();
  110. }
  111. });
  112. }
  113.  
  114. @Override
  115. public void onBackPressed() {
  116. finish();
  117. }
  118.  
  119. public void onimgButtonClick()
  120. {
  121. imgcart.setOnClickListener(new View.OnClickListener() {
  122. @Override
  123. public void onClick(View v) {
  124. Intent intent = new Intent(PlaceOrder.this,MyOrderedBill.class);
  125. intent.putExtra("selected_list", positionArr);//sending positions
  126. intent.putExtra("selected_order",productOrders);
  127. counter=1;
  128. startActivity(intent);
  129. }
  130. });
  131. }
  132. }
  133.  
  134. public class MyOrderedBill extends AppCompatActivity {
  135.  
  136. ListView myListview;
  137. GetandSet getandSet ;
  138. BillOrderCustomAdapter customAdapter;
  139. CustomArrayAdapter customArrayAdapter;
  140. MySQLiteDatabase mysqlitedatabase;
  141. ArrayList<Integer> postionId;
  142. ArrayList<GetandSet> productOrders = new ArrayList<>();
  143. ArrayList<GetandSet> getProductOrders = new ArrayList<>();
  144. ImageView imgBack;
  145. TextView txtToatalamt,txtgrandTotal;
  146. Button btnPayPrint;
  147.  
  148. ArrayList<GetandSet> selectedList = new ArrayList<GetandSet>(); // to store list of selected views
  149.  
  150. @Override
  151. protected void onCreate(Bundle savedInstanceState) {
  152. super.onCreate(savedInstanceState);
  153. setContentView(R.layout.activity_my_ordered_bill);
  154.  
  155. txtToatalamt = (TextView)findViewById(R.id.txt_Total_Amount);
  156. btnPayPrint = (Button) findViewById(R.id.btn_Pay_Print);
  157. txtgrandTotal = (TextView)findViewById(R.id.txt_Grand_Total);
  158. myListview = (ListView)findViewById(R.id.list_item);
  159. imgBack = (ImageView)findViewById(R.id.imgBack);
  160.  
  161. imgBack.setOnClickListener(new View.OnClickListener() {
  162. @Override
  163. public void onClick(View v) {
  164. startActivity(new Intent(MyOrderedBill.this,PlaceOrder.class));
  165. onBackPressed();
  166. }
  167. });
  168.  
  169. btnPayPrint.setOnClickListener(new View.OnClickListener() {
  170. @Override
  171. public void onClick(View v) {
  172. placeOrder();
  173. }
  174. });
  175.  
  176. Bundle b = this.getIntent().getExtras();
  177. postionId = b.getIntegerArrayList("selected_list");
  178. productOrders = (ArrayList<GetandSet>)getIntent().getSerializableExtra("selected_order");
  179.  
  180. for(int i = 1; i < postionId.size();++i)
  181. {
  182.  
  183. if(postionId.get(i) == i)
  184. {
  185.  
  186. GetandSet d = new GetandSet();
  187.  
  188. d.setMenu_name(productOrders.get(i).getMenu_name());
  189. d.setMenu_rate(productOrders.get(i).getMenu_rate());
  190. d.setMenu_Remark(productOrders.get(i).getMenu_Remark());
  191. d.setMenu_Qty(productOrders.get(i).getMenu_Qty());
  192.  
  193. productOrders.add(d);
  194. }
  195. }
  196. customArrayAdapter = new CustomArrayAdapter(this,productOrders);
  197. myListview.setAdapter(customArrayAdapter);
  198. }
  199. }
  200.  
  201. public class ItemCustomAdapter extends BaseAdapter{
  202.  
  203.  
  204. Context CONTEXT ;
  205. List<GetandSet> DETAILS ;
  206. ImageView itemImage;
  207. LayoutInflater layoutInflater;
  208. Activity activity;
  209. ViewHolder viewHolder;
  210.  
  211. public ItemCustomAdapter(Activity activity, List<GetandSet> details) {
  212. this.activity = activity;
  213. this.DETAILS = details;
  214. this.layoutInflater = (LayoutInflater) activity.getSystemService(activity.LAYOUT_INFLATER_SERVICE);
  215.  
  216. }
  217.  
  218. @Override
  219. public int getCount() {
  220. return DETAILS.size() ;
  221. }
  222.  
  223. @Override
  224. public Object getItem(int position) {
  225. return DETAILS.get(position);
  226. }
  227.  
  228. @Override
  229. public long getItemId(int position) {
  230. return position;
  231. }
  232.  
  233. @Override
  234. public View getView(int position, View convertView, ViewGroup parent) {
  235. GetandSet details = new GetandSet();
  236. if (convertView == null) {
  237. convertView = layoutInflater.inflate(R.layout.custom_adapter_template, parent, false);
  238. viewHolder = new ViewHolder(convertView);
  239. convertView.setTag(viewHolder);
  240. } else {
  241. viewHolder = (ViewHolder) convertView.getTag();
  242. }
  243.  
  244. viewHolder.txtitemname.setText(DETAILS.get(position).getMenu_name());
  245. viewHolder.txtitemprice.setText(DETAILS.get(position).getMenu_rate()+"/-");
  246. viewHolder.txtremark.setText(DETAILS.get(position).getMenu_Remark());
  247. viewHolder.txtQuantity.setText(DETAILS.get(position).getMenu_Qty()+"");
  248.  
  249. return convertView;
  250. }
  251. public class ViewHolder{
  252. TextView txtitemname,txtitemprice,txtremark;
  253. EditText txtQuantity;
  254.  
  255. public ViewHolder(View view) {
  256. txtitemname = (TextView)view.findViewById(R.id.txt_Item_Name);
  257. txtitemprice = (TextView)view.findViewById(R.id.txt_Item_Price);
  258. txtremark = (TextView)view.findViewById(R.id.txt_Item_remark);
  259. txtQuantity = (EditText)view.findViewById(R.id.txt_Quantity);
  260. }
  261. }//View holder
  262.  
  263. }
  264.  
  265. public class CustomArrayAdapter extends ArrayAdapter<GetandSet> {
  266.  
  267. private Context Context;
  268. public ArrayList<GetandSet> selectedarraylist = new ArrayList<>();
  269.  
  270. TextView itemName,itemRemark,itemrate,txtqty;
  271. Button btnadd,btnsub;
  272. GetandSet products;
  273.  
  274.  
  275. public CustomArrayAdapter(@NonNull Context context, ArrayList<GetandSet> list) {
  276. super(context, 0 , list);
  277. Context = context;
  278. selectedarraylist = list;
  279. }
  280.  
  281. @NonNull
  282. @Override
  283. public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  284. View listItem = convertView;
  285. if(listItem == null)
  286. listItem = LayoutInflater.from(Context).inflate(R.layout.custom_menu_item_bill,parent,false);
  287.  
  288. itemName = (TextView)listItem.findViewById(R.id.txt_Item_Name);
  289. itemRemark = (TextView)listItem.findViewById(R.id.txt_Remark);
  290. itemrate = (TextView)listItem.findViewById(R.id.txt_Item_Net_Price);
  291.  
  292. txtqty = (TextView)listItem.findViewById(R.id.txt_dis_qty);
  293. btnadd = (Button)listItem.findViewById(R.id.btn_add_qty);
  294. btnsub = (Button)listItem.findViewById(R.id.btn_remove_qty);
  295.  
  296. itemName.setText(selectedarraylist.get(position).getMenu_name());
  297. itemrate.setText(selectedarraylist.get(position).getMenu_rate());
  298. itemRemark.setText(selectedarraylist.get(position).getMenu_Remark());
  299. txtqty.setText(selectedarraylist.get(position).getMenu_Qty()+"");
  300.  
  301. btnadd.setOnClickListener(new View.OnClickListener() {
  302. @Override
  303. public void onClick(View v) {
  304.  
  305. updateQuantity(position, txtqty, 1);
  306. }
  307. });
  308.  
  309. btnsub.setOnClickListener(new View.OnClickListener() {
  310. @Override
  311. public void onClick(View v) {
  312. updateQuantity(position, txtqty, -1);
  313. }
  314. });
  315.  
  316. return listItem;
  317.  
  318. }
  319. private void updateQuantity(int position, TextView edTextQuantity, int value) {
  320.  
  321. // GetandSet products = (GetandSet) getItem(position);
  322. products = selectedarraylist.get(position);
  323.  
  324. if(value > 0)
  325. {
  326. products.menu_Qty = products.menu_Qty + 1;
  327. edTextQuantity.setText(products.menu_Qty+"");
  328. notifyDataSetChanged();
  329. }
  330. else
  331. {
  332. if(products.menu_Qty > 0)
  333. {
  334. products.menu_Qty = products.menu_Qty - 1;
  335. edTextQuantity.setText(products.menu_Qty+"");
  336. notifyDataSetChanged();
  337. }
  338. }
  339. }
  340. }
  341.  
  342. public class GetandSet implements Serializable {
  343. int id;
  344. String _name, _passwrod, _status ;
  345. String cat_id,cat_name,cat_desc,cat_kot;
  346. String menu_ID;
  347. String menu_name;
  348. String menu_int;
  349. String menu_rate;
  350. String menu_Remark;
  351. String menu_cat;
  352.  
  353.  
  354. public int getMenu_Qty() {
  355. return menu_Qty;
  356. }
  357.  
  358. public void setMenu_Qty(int menu_Qty) {
  359. this.menu_Qty = menu_Qty;
  360. }
  361.  
  362. int menu_Qty;
  363.  
  364.  
  365. public String getCat_id() {
  366. return cat_id;
  367. }
  368.  
  369. public void setCat_id(String cat_id) {
  370. this.cat_id = cat_id;
  371. }
  372.  
  373. public String getCat_name() {
  374. return cat_name;
  375. }
  376.  
  377. public void setCat_name(String cat_name) {
  378. this.cat_name = cat_name;
  379. }
  380.  
  381. public String getCat_desc() {
  382. return cat_desc;
  383. }
  384.  
  385. public void setCat_desc(String cat_desc) {
  386. this.cat_desc = cat_desc;
  387. }
  388.  
  389. public String getCat_kot() {
  390. return cat_kot;
  391. }
  392.  
  393. public void setCat_kot(String cat_kot) {
  394. this.cat_kot = cat_kot;
  395. }
  396.  
  397. public int getId() {
  398. return id;
  399. }
  400.  
  401. public String get_name() {
  402. return _name;
  403. }
  404.  
  405. public String get_passwrod() {
  406. return _passwrod;
  407. }
  408.  
  409. public String get_status() {
  410. return _status;
  411. }
  412.  
  413. public void setId(int id) {
  414. this.id = id;
  415. }
  416.  
  417. public void set_name(String _name) {
  418. this._name = _name;
  419. }
  420.  
  421. public void set_passwrod(String _passwrod) {
  422. this._passwrod = _passwrod;
  423. }
  424.  
  425. public void set_status(String _status) {
  426. this._status = _status;
  427. }
  428.  
  429. public String getMenu_ID() {
  430. return menu_ID;
  431. }
  432.  
  433. public void setMenu_ID(String menu_ID) {
  434. this.menu_ID = menu_ID;
  435. }
  436.  
  437. public String getMenu_name() {
  438. return menu_name;
  439. }
  440.  
  441. public String setMenu_name(String menu_name) {
  442. this.menu_name = menu_name;
  443. return menu_name;
  444. }
  445.  
  446. public String getMenu_int() {
  447. return menu_int;
  448. }
  449.  
  450. public void setMenu_int(String menu_int) {
  451. this.menu_int = menu_int;
  452. }
  453.  
  454. public String getMenu_rate() {
  455. return menu_rate;
  456. }
  457.  
  458. public void setMenu_rate(String menu_rate) {
  459. this.menu_rate = menu_rate;
  460. }
  461.  
  462. public String getMenu_Remark() {
  463. return menu_Remark;
  464. }
  465.  
  466. public void setMenu_Remark(String menu_Remark) {
  467. this.menu_Remark = menu_Remark;
  468. }
  469.  
  470. public String getMenu_cat() {
  471. return menu_cat;
  472. }
  473.  
  474. public void setMenu_cat(String menu_cat) {
  475. this.menu_cat = menu_cat;
  476. }
  477.  
  478. }
  479.  
  480. myDatabaseHandler file (MySQLiteDatabase )
  481.  
  482.  
  483. public class MySQLiteDatabase extends SQLiteOpenHelper {
  484.  
  485. private static final int DATABASE_VERSION = 1 ;
  486. private static final String DATABASE_NAME = "restroquickpos";
  487. public static final String TABLE_NAME ="Login";
  488. public static final String COL_ID ="ID";
  489. public static final String COL_NAME ="username";
  490. public static final String COL_PASSWORD ="password";
  491. public static final String COL_STATUS = "status";
  492.  
  493.  
  494.  
  495. public static final String TABLE_NAME1 ="CategoryMaster";
  496. public static final String COL_CATID ="Cat_ID";
  497. public static final String COL_CATNAME ="cat_name";
  498. public static final String COL_CATDESC ="cat_desc";
  499. public static final String COL_CATKOT = "cat_kot";
  500.  
  501.  
  502. public SQLiteDatabase DB;
  503.  
  504. public static final String TABLE_MENU ="MenuMaster";
  505. public static final String COL_MENUID ="menu_ID";
  506. public static final String COL_MENUNAME ="menu_name";
  507. public static final String COL_MENUINT ="menu_int";
  508. public static final String COL_MENURATE = "menu_rate";
  509. public static final String COL_MENUREMARK ="menu_Remark";
  510. public static final String COL_MENUCAT ="menu_cat";
  511. public static final String COL_MENUQTY ="menu_qty";
  512.  
  513.  
  514.  
  515.  
  516. public MySQLiteDatabase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
  517. super(context, DATABASE_NAME, factory, DATABASE_VERSION);
  518. Log.d("DatabaseOperation","Database Created");
  519. }
  520.  
  521. @Override
  522. public void onCreate(SQLiteDatabase db) {
  523.  
  524. this.DB = db ;
  525. String loginquery = "CREATE TABLE " + TABLE_NAME + " ("
  526. + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
  527. + COL_NAME + " TEXT NOT NULL, "
  528. + COL_PASSWORD + " TEXT NOT NULL, "
  529. + COL_STATUS + " TEXT "
  530. + ");";
  531. db.execSQL(loginquery);
  532. Log.d("DatabaseOperation","Table Created");
  533.  
  534. String catquery = "CREATE TABLE " + TABLE_NAME1 + " ("
  535. + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
  536. + COL_CATID + " TEXT NOT NULL, "
  537. + COL_CATNAME + " TEXT NOT NULL, "
  538. + COL_CATDESC + " TEXT NOT NULL, "
  539. + COL_CATKOT + " TEXT NOT NULL "
  540. + ");";
  541. db.execSQL(catquery);
  542. Log.d("DatabaseOperation","Table Created");
  543.  
  544. String Menuquery = "CREATE TABLE " + TABLE_MENU + " ("
  545. + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
  546. + COL_MENUID + " TEXT NOT NULL, "
  547. + COL_MENUNAME + " TEXT NOT NULL, "
  548. + COL_MENUINT + " TEXT NOT NULL, "
  549. + COL_MENURATE + " TEXT NOT NULL, "
  550. + COL_MENUREMARK + " TEXT NOT NULL, "
  551. + COL_MENUCAT + " TEXT NOT NULL, "
  552. + COL_MENUQTY + " INTEGER NOT NULL "
  553. + ");";
  554. db.execSQL(Menuquery);
  555. Log.d("DatabaseOperation","Table Created");
  556. }
  557.  
  558. @Override
  559. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  560.  
  561. this.DB = db ;
  562. db.execSQL(" DROP TABLE IF EXISTS " + TABLE_NAME);//drop tabel command
  563. onCreate(db);//execute query
  564. }
  565. public void addDetails(GetandSet details)//Adding into Login
  566. {
  567. ContentValues values = new ContentValues();
  568. values.put(COL_NAME,details.get_name());
  569. values.put(COL_PASSWORD,details.get_passwrod());
  570. values.put(COL_STATUS,details.get_status());
  571.  
  572. SQLiteDatabase db = getWritableDatabase();
  573. db.insert(TABLE_NAME,null,values);
  574. Log.d("DatabaseOperation","Values Inserted");
  575. db.close();
  576. }
  577.  
  578. public void addCategory(GetandSet details)//Adding into Category
  579. {
  580. ContentValues values = new ContentValues();
  581. values.put(COL_CATID,details.getCat_id());
  582. values.put(COL_CATNAME,details.getCat_name());
  583. values.put(COL_CATDESC,details.getCat_desc());
  584. values.put(COL_CATKOT,details.getCat_kot());
  585.  
  586. SQLiteDatabase db = getWritableDatabase();
  587. db.insert(TABLE_NAME1,null,values);
  588. Log.d("DatabaseOperation","Values Inserted");
  589. db.close();
  590. }
  591.  
  592. public void addMenuItems(GetandSet details)//Adding into Menu Items
  593. {
  594. ContentValues values = new ContentValues();
  595. values.put(COL_MENUID,details.getMenu_ID());
  596. values.put(COL_MENUNAME,details.getMenu_name());
  597. values.put(COL_MENUINT,details.getMenu_int());
  598. values.put(COL_MENURATE,details.getMenu_rate());
  599. values.put(COL_MENUREMARK,details.getMenu_Remark());
  600. values.put(COL_MENUCAT,details.getMenu_cat());
  601. values.put(COL_MENUQTY,1);
  602.  
  603. SQLiteDatabase db = getWritableDatabase();
  604. db.insert(TABLE_MENU,null,values);
  605. Log.d("DatabaseOperation","Values Inserted");
  606. db.close();
  607. }
  608.  
  609.  
  610. public String searchPass(String userid) {
  611.  
  612. DB = this.getReadableDatabase();
  613. String query = "SELECT * FROM " + TABLE_NAME ;
  614. Cursor cursor = DB.rawQuery(query,null);
  615.  
  616. String Username, password,fullname;
  617. password = "Not Found";
  618.  
  619. if(cursor.moveToNext())
  620. {
  621. do {
  622. // Username = cursor.getString(2);
  623. fullname = cursor.getString(1);
  624. /*if(Username.equals(userid))
  625. {
  626. password = cursor.getString(4);
  627. break;
  628. }*/
  629. if(fullname.equals(userid))
  630. {
  631. password = cursor.getString(2);
  632. break;
  633. }
  634. }while (cursor.moveToNext());
  635. }
  636. return password;
  637. }
  638.  
  639. public List<String> getAllLabels(){
  640. List<String> labels = new ArrayList<String>();
  641.  
  642. // Select All Query
  643. String selectQuery = "SELECT * FROM " + TABLE_NAME1;
  644.  
  645. SQLiteDatabase db = this.getReadableDatabase();
  646. Cursor cursor = db.rawQuery(selectQuery, null);
  647.  
  648. // looping through all rows and adding to list
  649. if (cursor.moveToFirst()) {
  650. do {
  651. labels.add(cursor.getString(2));
  652. } while (cursor.moveToNext());
  653. }
  654.  
  655. // closing connection
  656. cursor.close();
  657. db.close();
  658. // returning lables
  659. return labels;
  660. }
  661. public Cursor selectQuery(String query) {
  662. Cursor c1 ;
  663. DB = getWritableDatabase();
  664. c1 = DB.rawQuery(query, null);
  665. return c1;
  666. }
  667.  
  668. }
Add Comment
Please, Sign In to add comment