Guest User

Untitled

a guest
Feb 20th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.61 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. public class MyOrderedBill extends AppCompatActivity {
  134.  
  135. ListView myListview;
  136. GetandSet getandSet ;
  137. BillOrderCustomAdapter customAdapter;
  138. CustomArrayAdapter customArrayAdapter;
  139. MySQLiteDatabase mysqlitedatabase;
  140. ArrayList<Integer> postionId;
  141. ArrayList<GetandSet> productOrders = new ArrayList<>();
  142. ArrayList<GetandSet> getProductOrders = new ArrayList<>();
  143. ImageView imgBack;
  144. TextView txtToatalamt,txtgrandTotal;
  145. Button btnPayPrint;
  146.  
  147. ArrayList<GetandSet> selectedList = new ArrayList<GetandSet>(); // to store list of selected views
  148.  
  149. @Override
  150. protected void onCreate(Bundle savedInstanceState) {
  151. super.onCreate(savedInstanceState);
  152. setContentView(R.layout.activity_my_ordered_bill);
  153.  
  154. txtToatalamt = (TextView)findViewById(R.id.txt_Total_Amount);
  155. btnPayPrint = (Button) findViewById(R.id.btn_Pay_Print);
  156. txtgrandTotal = (TextView)findViewById(R.id.txt_Grand_Total);
  157. myListview = (ListView)findViewById(R.id.list_item);
  158. imgBack = (ImageView)findViewById(R.id.imgBack);
  159.  
  160. imgBack.setOnClickListener(new View.OnClickListener() {
  161. @Override
  162. public void onClick(View v) {
  163. startActivity(new Intent(MyOrderedBill.this,PlaceOrder.class));
  164. onBackPressed();
  165. }
  166. });
  167.  
  168. btnPayPrint.setOnClickListener(new View.OnClickListener() {
  169. @Override
  170. public void onClick(View v) {
  171. placeOrder();
  172. }
  173. });
  174.  
  175. Bundle b = this.getIntent().getExtras();
  176. postionId = b.getIntegerArrayList("selected_list");
  177. productOrders = (ArrayList<GetandSet>)getIntent().getSerializableExtra("selected_order");
  178.  
  179. for(int i = 1; i < postionId.size();++i)
  180. {
  181.  
  182. if(postionId.get(i) == i)
  183. {
  184.  
  185. GetandSet d = new GetandSet();
  186.  
  187. d.setMenu_name(productOrders.get(i).getMenu_name());
  188. d.setMenu_rate(productOrders.get(i).getMenu_rate());
  189. d.setMenu_Remark(productOrders.get(i).getMenu_Remark());
  190. d.setMenu_Qty(productOrders.get(i).getMenu_Qty());
  191.  
  192. productOrders.add(d);
  193. }
  194. }
  195. customArrayAdapter = new CustomArrayAdapter(this,productOrders);
  196. myListview.setAdapter(customArrayAdapter);
  197. }
  198.  
  199. Context CONTEXT ;
  200. List<GetandSet> DETAILS ;
  201. ImageView itemImage;
  202. LayoutInflater layoutInflater;
  203. Activity activity;
  204. ViewHolder viewHolder;
  205.  
  206. public ItemCustomAdapter(Activity activity, List<GetandSet> details) {
  207. this.activity = activity;
  208. this.DETAILS = details;
  209. this.layoutInflater = (LayoutInflater) activity.getSystemService(activity.LAYOUT_INFLATER_SERVICE);
  210.  
  211. }
  212.  
  213. @Override
  214. public int getCount() {
  215. return DETAILS.size() ;
  216. }
  217.  
  218. @Override
  219. public Object getItem(int position) {
  220. return DETAILS.get(position);
  221. }
  222.  
  223. @Override
  224. public long getItemId(int position) {
  225. return position;
  226. }
  227.  
  228. @Override
  229. public View getView(int position, View convertView, ViewGroup parent) {
  230. GetandSet details = new GetandSet();
  231. if (convertView == null) {
  232. convertView = layoutInflater.inflate(R.layout.custom_adapter_template, parent, false);
  233. viewHolder = new ViewHolder(convertView);
  234. convertView.setTag(viewHolder);
  235. } else {
  236. viewHolder = (ViewHolder) convertView.getTag();
  237. }
  238.  
  239. viewHolder.txtitemname.setText(DETAILS.get(position).getMenu_name());
  240. viewHolder.txtitemprice.setText(DETAILS.get(position).getMenu_rate()+"/-");
  241. viewHolder.txtremark.setText(DETAILS.get(position).getMenu_Remark());
  242. viewHolder.txtQuantity.setText(DETAILS.get(position).getMenu_Qty()+"");
  243.  
  244. return convertView;
  245. }
  246. public class ViewHolder{
  247. TextView txtitemname,txtitemprice,txtremark;
  248. EditText txtQuantity;
  249.  
  250. public ViewHolder(View view) {
  251. txtitemname = (TextView)view.findViewById(R.id.txt_Item_Name);
  252. txtitemprice = (TextView)view.findViewById(R.id.txt_Item_Price);
  253. txtremark = (TextView)view.findViewById(R.id.txt_Item_remark);
  254. txtQuantity = (EditText)view.findViewById(R.id.txt_Quantity);
  255. }
  256. }//View holder
  257.  
  258. public class CustomArrayAdapter extends ArrayAdapter<GetandSet> {
  259.  
  260. private Context Context;
  261. public ArrayList<GetandSet> selectedarraylist = new ArrayList<>();
  262.  
  263. TextView itemName,itemRemark,itemrate,txtqty;
  264. Button btnadd,btnsub;
  265. GetandSet products;
  266.  
  267.  
  268. public CustomArrayAdapter(@NonNull Context context, ArrayList<GetandSet> list) {
  269. super(context, 0 , list);
  270. Context = context;
  271. selectedarraylist = list;
  272. }
  273.  
  274. @NonNull
  275. @Override
  276. public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  277. View listItem = convertView;
  278. if(listItem == null)
  279. listItem = LayoutInflater.from(Context).inflate(R.layout.custom_menu_item_bill,parent,false);
  280.  
  281. itemName = (TextView)listItem.findViewById(R.id.txt_Item_Name);
  282. itemRemark = (TextView)listItem.findViewById(R.id.txt_Remark);
  283. itemrate = (TextView)listItem.findViewById(R.id.txt_Item_Net_Price);
  284.  
  285. txtqty = (TextView)listItem.findViewById(R.id.txt_dis_qty);
  286. btnadd = (Button)listItem.findViewById(R.id.btn_add_qty);
  287. btnsub = (Button)listItem.findViewById(R.id.btn_remove_qty);
  288.  
  289. itemName.setText(selectedarraylist.get(position).getMenu_name());
  290. itemrate.setText(selectedarraylist.get(position).getMenu_rate());
  291. itemRemark.setText(selectedarraylist.get(position).getMenu_Remark());
  292. txtqty.setText(selectedarraylist.get(position).getMenu_Qty()+"");
  293.  
  294. btnadd.setOnClickListener(new View.OnClickListener() {
  295. @Override
  296. public void onClick(View v) {
  297.  
  298. updateQuantity(position, txtqty, 1);
  299. }
  300. });
  301.  
  302. btnsub.setOnClickListener(new View.OnClickListener() {
  303. @Override
  304. public void onClick(View v) {
  305. updateQuantity(position, txtqty, -1);
  306. }
  307. });
  308.  
  309. return listItem;
  310.  
  311. }
  312. private void updateQuantity(int position, TextView edTextQuantity, int value) {
  313.  
  314. // GetandSet products = (GetandSet) getItem(position);
  315. products = selectedarraylist.get(position);
  316.  
  317. if(value > 0)
  318. {
  319. products.menu_Qty = products.menu_Qty + 1;
  320. edTextQuantity.setText(products.menu_Qty+"");
  321. notifyDataSetChanged();
  322. }
  323. else
  324. {
  325. if(products.menu_Qty > 0)
  326. {
  327. products.menu_Qty = products.menu_Qty - 1;
  328. edTextQuantity.setText(products.menu_Qty+"");
  329. notifyDataSetChanged();
  330. }
  331. }
  332. }
  333.  
  334. public class GetandSet implements Serializable {
  335. int id;
  336. String _name, _passwrod, _status ;
  337. String cat_id,cat_name,cat_desc,cat_kot;
  338. String menu_ID;
  339. String menu_name;
  340. String menu_int;
  341. String menu_rate;
  342. String menu_Remark;
  343. String menu_cat;
  344.  
  345.  
  346. public int getMenu_Qty() {
  347. return menu_Qty;
  348. }
  349.  
  350. public void setMenu_Qty(int menu_Qty) {
  351. this.menu_Qty = menu_Qty;
  352. }
  353.  
  354. int menu_Qty;
  355.  
  356.  
  357. public String getCat_id() {
  358. return cat_id;
  359. }
  360.  
  361. public void setCat_id(String cat_id) {
  362. this.cat_id = cat_id;
  363. }
  364.  
  365. public String getCat_name() {
  366. return cat_name;
  367. }
  368.  
  369. public void setCat_name(String cat_name) {
  370. this.cat_name = cat_name;
  371. }
  372.  
  373. public String getCat_desc() {
  374. return cat_desc;
  375. }
  376.  
  377. public void setCat_desc(String cat_desc) {
  378. this.cat_desc = cat_desc;
  379. }
  380.  
  381. public String getCat_kot() {
  382. return cat_kot;
  383. }
  384.  
  385. public void setCat_kot(String cat_kot) {
  386. this.cat_kot = cat_kot;
  387. }
  388.  
  389. public int getId() {
  390. return id;
  391. }
  392.  
  393. public String get_name() {
  394. return _name;
  395. }
  396.  
  397. public String get_passwrod() {
  398. return _passwrod;
  399. }
  400.  
  401. public String get_status() {
  402. return _status;
  403. }
  404.  
  405. public void setId(int id) {
  406. this.id = id;
  407. }
  408.  
  409. public void set_name(String _name) {
  410. this._name = _name;
  411. }
  412.  
  413. public void set_passwrod(String _passwrod) {
  414. this._passwrod = _passwrod;
  415. }
  416.  
  417. public void set_status(String _status) {
  418. this._status = _status;
  419. }
  420.  
  421. public String getMenu_ID() {
  422. return menu_ID;
  423. }
  424.  
  425. public void setMenu_ID(String menu_ID) {
  426. this.menu_ID = menu_ID;
  427. }
  428.  
  429. public String getMenu_name() {
  430. return menu_name;
  431. }
  432.  
  433. public String setMenu_name(String menu_name) {
  434. this.menu_name = menu_name;
  435. return menu_name;
  436. }
  437.  
  438. public String getMenu_int() {
  439. return menu_int;
  440. }
  441.  
  442. public void setMenu_int(String menu_int) {
  443. this.menu_int = menu_int;
  444. }
  445.  
  446. public String getMenu_rate() {
  447. return menu_rate;
  448. }
  449.  
  450. public void setMenu_rate(String menu_rate) {
  451. this.menu_rate = menu_rate;
  452. }
  453.  
  454. public String getMenu_Remark() {
  455. return menu_Remark;
  456. }
  457.  
  458. public void setMenu_Remark(String menu_Remark) {
  459. this.menu_Remark = menu_Remark;
  460. }
  461.  
  462. public String getMenu_cat() {
  463. return menu_cat;
  464. }
  465.  
  466. public void setMenu_cat(String menu_cat) {
  467. this.menu_cat = menu_cat;
  468. }
  469.  
  470. public class MySQLiteDatabase extends SQLiteOpenHelper {
  471.  
  472. private static final int DATABASE_VERSION = 1 ;
  473. private static final String DATABASE_NAME = "restroquickpos";
  474. public static final String TABLE_NAME ="Login";
  475. public static final String COL_ID ="ID";
  476. public static final String COL_NAME ="username";
  477. public static final String COL_PASSWORD ="password";
  478. public static final String COL_STATUS = "status";
  479.  
  480.  
  481.  
  482. public static final String TABLE_NAME1 ="CategoryMaster";
  483. public static final String COL_CATID ="Cat_ID";
  484. public static final String COL_CATNAME ="cat_name";
  485. public static final String COL_CATDESC ="cat_desc";
  486. public static final String COL_CATKOT = "cat_kot";
  487.  
  488.  
  489. public SQLiteDatabase DB;
  490.  
  491. public static final String TABLE_MENU ="MenuMaster";
  492. public static final String COL_MENUID ="menu_ID";
  493. public static final String COL_MENUNAME ="menu_name";
  494. public static final String COL_MENUINT ="menu_int";
  495. public static final String COL_MENURATE = "menu_rate";
  496. public static final String COL_MENUREMARK ="menu_Remark";
  497. public static final String COL_MENUCAT ="menu_cat";
  498. public static final String COL_MENUQTY ="menu_qty";
  499.  
  500.  
  501.  
  502.  
  503. public MySQLiteDatabase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
  504. super(context, DATABASE_NAME, factory, DATABASE_VERSION);
  505. Log.d("DatabaseOperation","Database Created");
  506. }
  507.  
  508. @Override
  509. public void onCreate(SQLiteDatabase db) {
  510.  
  511. this.DB = db ;
  512. String loginquery = "CREATE TABLE " + TABLE_NAME + " ("
  513. + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
  514. + COL_NAME + " TEXT NOT NULL, "
  515. + COL_PASSWORD + " TEXT NOT NULL, "
  516. + COL_STATUS + " TEXT "
  517. + ");";
  518. db.execSQL(loginquery);
  519. Log.d("DatabaseOperation","Table Created");
  520.  
  521. String catquery = "CREATE TABLE " + TABLE_NAME1 + " ("
  522. + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
  523. + COL_CATID + " TEXT NOT NULL, "
  524. + COL_CATNAME + " TEXT NOT NULL, "
  525. + COL_CATDESC + " TEXT NOT NULL, "
  526. + COL_CATKOT + " TEXT NOT NULL "
  527. + ");";
  528. db.execSQL(catquery);
  529. Log.d("DatabaseOperation","Table Created");
  530.  
  531. String Menuquery = "CREATE TABLE " + TABLE_MENU + " ("
  532. + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
  533. + COL_MENUID + " TEXT NOT NULL, "
  534. + COL_MENUNAME + " TEXT NOT NULL, "
  535. + COL_MENUINT + " TEXT NOT NULL, "
  536. + COL_MENURATE + " TEXT NOT NULL, "
  537. + COL_MENUREMARK + " TEXT NOT NULL, "
  538. + COL_MENUCAT + " TEXT NOT NULL, "
  539. + COL_MENUQTY + " INTEGER NOT NULL "
  540. + ");";
  541. db.execSQL(Menuquery);
  542. Log.d("DatabaseOperation","Table Created");
  543. }
  544.  
  545. @Override
  546. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  547.  
  548. this.DB = db ;
  549. db.execSQL(" DROP TABLE IF EXISTS " + TABLE_NAME);//drop tabel command
  550. onCreate(db);//execute query
  551. }
  552. public void addDetails(GetandSet details)//Adding into Login
  553. {
  554. ContentValues values = new ContentValues();
  555. values.put(COL_NAME,details.get_name());
  556. values.put(COL_PASSWORD,details.get_passwrod());
  557. values.put(COL_STATUS,details.get_status());
  558.  
  559. SQLiteDatabase db = getWritableDatabase();
  560. db.insert(TABLE_NAME,null,values);
  561. Log.d("DatabaseOperation","Values Inserted");
  562. db.close();
  563. }
  564.  
  565. public void addCategory(GetandSet details)//Adding into Category
  566. {
  567. ContentValues values = new ContentValues();
  568. values.put(COL_CATID,details.getCat_id());
  569. values.put(COL_CATNAME,details.getCat_name());
  570. values.put(COL_CATDESC,details.getCat_desc());
  571. values.put(COL_CATKOT,details.getCat_kot());
  572.  
  573. SQLiteDatabase db = getWritableDatabase();
  574. db.insert(TABLE_NAME1,null,values);
  575. Log.d("DatabaseOperation","Values Inserted");
  576. db.close();
  577. }
  578.  
  579. public void addMenuItems(GetandSet details)//Adding into Menu Items
  580. {
  581. ContentValues values = new ContentValues();
  582. values.put(COL_MENUID,details.getMenu_ID());
  583. values.put(COL_MENUNAME,details.getMenu_name());
  584. values.put(COL_MENUINT,details.getMenu_int());
  585. values.put(COL_MENURATE,details.getMenu_rate());
  586. values.put(COL_MENUREMARK,details.getMenu_Remark());
  587. values.put(COL_MENUCAT,details.getMenu_cat());
  588. values.put(COL_MENUQTY,1);
  589.  
  590. SQLiteDatabase db = getWritableDatabase();
  591. db.insert(TABLE_MENU,null,values);
  592. Log.d("DatabaseOperation","Values Inserted");
  593. db.close();
  594. }
  595.  
  596.  
  597. public String searchPass(String userid) {
  598.  
  599. DB = this.getReadableDatabase();
  600. String query = "SELECT * FROM " + TABLE_NAME ;
  601. Cursor cursor = DB.rawQuery(query,null);
  602.  
  603. String Username, password,fullname;
  604. password = "Not Found";
  605.  
  606. if(cursor.moveToNext())
  607. {
  608. do {
  609. // Username = cursor.getString(2);
  610. fullname = cursor.getString(1);
  611. /*if(Username.equals(userid))
  612. {
  613. password = cursor.getString(4);
  614. break;
  615. }*/
  616. if(fullname.equals(userid))
  617. {
  618. password = cursor.getString(2);
  619. break;
  620. }
  621. }while (cursor.moveToNext());
  622. }
  623. return password;
  624. }
  625.  
  626. public List<String> getAllLabels(){
  627. List<String> labels = new ArrayList<String>();
  628.  
  629. // Select All Query
  630. String selectQuery = "SELECT * FROM " + TABLE_NAME1;
  631.  
  632. SQLiteDatabase db = this.getReadableDatabase();
  633. Cursor cursor = db.rawQuery(selectQuery, null);
  634.  
  635. // looping through all rows and adding to list
  636. if (cursor.moveToFirst()) {
  637. do {
  638. labels.add(cursor.getString(2));
  639. } while (cursor.moveToNext());
  640. }
  641.  
  642. // closing connection
  643. cursor.close();
  644. db.close();
  645. // returning lables
  646. return labels;
  647. }
  648. public Cursor selectQuery(String query) {
  649. Cursor c1 ;
  650. DB = getWritableDatabase();
  651. c1 = DB.rawQuery(query, null);
  652. return c1;
  653. }
Add Comment
Please, Sign In to add comment