Skip to content

Commit e9a8096

Browse files
authored
Add site summary
1 parent 1400efc commit e9a8096

1 file changed

Lines changed: 48 additions & 9 deletions

File tree

RayDairy/app/src/main/java/com/raydairy/SiteDisplay.java

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void buttonClickHandler(View view) {
4545
Log.v(TAG, "buttonClickHandler ");
4646
int id = -1;
4747
String name = "INVALID";
48+
Cursor crsr = null;
4849

4950
switch(view.getId()){
5051
case R.id.add_cust:
@@ -81,7 +82,7 @@ public void buttonClickHandler(View view) {
8182

8283
case R.id.report:
8384
id = Integer.parseInt(((EditText) findViewById(R.id.cust_id)).getText().toString());
84-
Cursor crsr = dbHelper.getDataById(id);
85+
crsr = dbHelper.getDataById(id);
8586
int colName = crsr.getColumnIndex("NAME");
8687
Log.v(TAG, String.valueOf(crsr.getCount()));
8788

@@ -132,16 +133,54 @@ public void buttonClickHandler(View view) {
132133
break;
133134

134135
case R.id.summary:
135-
(findViewById(R.id.cust_id)).setVisibility(View.VISIBLE);
136-
(findViewById(R.id.report)).setVisibility(View.VISIBLE);
137-
(findViewById(R.id.detailed_report)).setVisibility(View.VISIBLE);
138-
139-
(findViewById(R.id.new_cust_id)).setVisibility(View.INVISIBLE);
140-
(findViewById(R.id.new_cust_name)).setVisibility(View.INVISIBLE);
136+
int site_id = 0,
137+
switch(siteName) {
138+
case R.string.site_42:
139+
site_id = 1;
140+
break;
141+
case R.string.site_SSN :
142+
site_id = 2;
143+
break;
144+
case R.string.site_SS :
145+
site_id = 3;
146+
break;
147+
case R.string.site_SP :
148+
site_id = 4;
149+
break;
150+
}
151+
152+
String button_text = ((Button) findViewById(R.id.summary)).getText().toString();
153+
if (button_text == "EXIT") {
154+
(findViewById(R.id.cust_id)).setVisibility(View.VISIBLE);
155+
(findViewById(R.id.report)).setVisibility(View.VISIBLE);
156+
(findViewById(R.id.detailed_report)).setVisibility(View.VISIBLE);
157+
158+
(findViewById(R.id.new_cust_id)).setVisibility(View.INVISIBLE);
159+
(findViewById(R.id.new_cust_name)).setVisibility(View.INVISIBLE);
160+
161+
((Button) findViewById(R.id.summary)).setText("SUMMARY");
162+
((Button) findViewById(R.id.add_cust)).setText("NEW CUSTOMER");
163+
} else if (button_text == "SUMMARY") {
164+
((Button) findViewById(R.id.summary)).setText("HIDE SUMMARY");
165+
166+
crsr = dbHelper.getGrandTotalBySite(site_id);
167+
if( crsr != null && crsr.moveToFirst() ) {
168+
do {
169+
Log.v(TAG, Arrays.toString(crsr.getColumnNames()));
170+
String sum_tot = crsr.getString(crsr.getColumnIndex("SUM(TOTAL)"));
171+
String sum_quant = crsr.getString(crsr.getColumnIndex("SUM(QUANTITY)"));
172+
details += "\n TOTAL AMOUNT to BE PAID:\t" + sum_tot + "\n";
173+
details += "\n TOTAL MILK Collected:\t" + sum_quant + "\n";
174+
} while (crsr.moveToNext());
141175

142-
((Button) findViewById(R.id.summary)).setText("SUMMARY");
143-
((Button) findViewById(R.id.add_cust)).setText("NEW CUSTOMER");
176+
crsr.close();
177+
((TextView)findViewById(R.id.detailed_report)).setText(details);
178+
} else {
179+
((Button) findViewById(R.id.summary)).setText("SUMMARY");
180+
((TextView)findViewById(R.id.detailed_report)).setText("");
181+
}
144182

183+
145184
// Summary
146185
break;
147186
}

0 commit comments

Comments
 (0)