-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiscountFragment.cs
75 lines (61 loc) · 2.05 KB
/
DiscountFragment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Views.InputMethods;
using Android.Graphics;
namespace CalculatePercent
{
public class DiscountFragment : Fragment
{
public override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
// Create your fragment here
}
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate (Resource.Layout.Discount, container, false);
var discount = view.FindViewById<EditText> (Resource.Id.discountEditText);
var price = view.FindViewById<EditText> (Resource.Id.priceEditText);
var finalPrice = view.FindViewById<TextView> (Resource.Id.discountResultValue);
var calculateButton = view.FindViewById<Button> (Resource.Id.discountCalculateButton);
discount.SetBackgroundColor (Color.Black);
price.SetBackgroundColor (Color.Black);
//Get fragment's associated Activity context
Activity context = this.Activity;
finalPrice.Text = "---";
calculateButton.Click+= (object sender, EventArgs e) =>
{
//Dismiss keyboard
InputMethodManager imm = (InputMethodManager)context.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow (context.CurrentFocus.WindowToken, 0);
try{
if ((!String.IsNullOrEmpty(discount.Text)&&(!String.IsNullOrEmpty(price.Text)))){
int dscnt = Convert.ToInt16 (discount.Text);
int prc = Convert.ToInt16 (price.Text);
double rslt = (double)(prc * dscnt) / 100;
finalPrice.Text = (prc - rslt).ToString();
}
else
{
Toast.MakeText(context,"Empty field!",ToastLength.Short).Show();
}
}
catch(Exception exc)
{
Console.WriteLine("EXCEPTION!!! = "+exc.ToString());
}
};
return view;
}
}
}