예제 #1
0
        public static BettingPerding Calculate(string history, double quota
                                               , double nextBet, int offset)
        {
            //string historyTxt = history.Text;

            if (offset == 0)
            {
                offset += 5;
            }

            BettingPerding result = new BettingPerding();

            string[] quote = history.Split(',');
            double   sum   = 0;

            foreach (var q in quote)
            {
                sum += Int32.Parse(q);
            }
            //int lastBet = Int32.Parse(quote[quote.Length - 1]);
            int lastBet = (int)(sum / quote.Length);

            while (lastBet % 5 != 0)
            {
                lastBet++;
            }


            bool isPositive = false;
            //double nextBet = 0;
            double profit = 0;

            if (nextBet == 0)
            {
                do
                {
                    nextBet = lastBet + offset;
                    sum    += nextBet;
                    //Double.Parse(quota.Text)
                    double temp = nextBet * quota;
                    profit     = temp - sum;
                    isPositive = profit > 0;
                    if (!isPositive)
                    {
                        lastBet = (int)nextBet;
                        sum    -= lastBet;
                    }
                } while (!isPositive);

                //nextBetTxt.Text = nextBet.ToString();
                result.NextBet = (int)nextBet;
            }
            else
            {
                sum += nextBet;
                double temp = nextBet * quota;
                profit = temp - sum;
            }


            //profit = Math.Round(profit);
            result.Profit = Math.Round(profit);
            return(result);
        }
예제 #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            // return inflater.Inflate(Resource.Layout.YourFragment, container, false);

            View view = inflater.Inflate(Resource.Layout.CalculateBet, null);

            List <BetDetails> betDetails = AWSDataAccess.GetBetDetailsByTeamId(TeamId);
            string            history    = string.Empty;

            foreach (var item in betDetails)
            {
                int temp = (int)item.Quantity;
                history += temp + ",";
            }

            history = history.Substring(0, history.LastIndexOf(','));

            view.FindViewById <EditText>(Resource.Id.History).Text = history;

            view.FindViewById <EditText>(Resource.Id.Quote).FixDigits();
            Button   calculateBtn = view.FindViewById <Button>(Resource.Id.Calculate);
            EditText historyTxt   = view.FindViewById <EditText>(Resource.Id.History);
            EditText quote        = view.FindViewById <EditText>(Resource.Id.Quote);
            EditText nextbet      = view.FindViewById <EditText>(Resource.Id.NextBet);
            EditText profit       = view.FindViewById <EditText>(Resource.Id.Profit);
            EditText offset       = view.FindViewById <EditText>(Resource.Id.Offset);
            Button   saveBetBtn   = view.FindViewById <Button>(Resource.Id.SaveBet);


            saveBetBtn.Click += delegate
            {
                if (nextbet.Text != String.Empty)
                {
                    BetDetails newBet = new BetDetails()
                    {
                        Id       = Guid.NewGuid(),
                        Quantity = Decimal.Parse(nextbet.Text),
                        Team_Id  = TeamId
                    };

                    if (AWSDataAccess.InsertBetDetails(newBet) != Guid.Empty)
                    {
                        Toast.MakeText(Activity, "Bet saved", ToastLength.Long).Show();
                        FragmentTransaction ft = FragmentManager.BeginTransaction();
                        ft.Replace(Resource.Id.frameLayout1, new ActiveBetFragment());
                        ft.Commit();
                    }
                    else
                    {
                        Toast.MakeText(Activity, "Error in bet saving", ToastLength.Long).Show();
                    }
                }
                else
                {
                    return;
                }
            };

            calculateBtn.Click += delegate
            {
                InputMethodManager inputManager = (InputMethodManager)Activity.GetSystemService(Context.InputMethodService);

                //inputManager.HideSoftInputFromWindow(Activity.CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways);
                if (Activity.CurrentFocus != null)
                {
                    inputManager.HideSoftInputFromWindow(Activity.CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways);
                }

                //&& offset.Text != string.Empty
                if (historyTxt.Text != string.Empty && quote.Text != string.Empty)
                {
                    BettingPerding result = new BettingPerding();

                    int offsetVal = 0;
                    if (offset.Text != string.Empty)
                    {
                        Int32.Parse(offset.Text);
                    }

                    result = BetCalculator.Calculate(historyTxt.Text,
                                                     Double.Parse(quote.Text), 0, offsetVal);

                    //nextbet.SetText(ciccio.ToString(),TextView.BufferType.Normal);
                    profit.Text  = "" + result.Profit;
                    nextbet.Text = "" + result.NextBet;
                }
                else
                {
                    quote.Error = "Requested";
                    //offset.Error = "Requested";
                }
            };

            nextbet.TextChanged += delegate
            {
                //&& offset.Text != string.Empty

                if (historyTxt.Text != string.Empty && quote.Text != string.Empty)
                {
                    BettingPerding result      = new BettingPerding();
                    int            offsetValue = 0;
                    if (offset.Text != string.Empty)
                    {
                        offsetValue = Int32.Parse(offset.Text);
                    }

                    double next = 0;
                    if (!String.IsNullOrEmpty(nextbet.Text))
                    {
                        next = Double.Parse(nextbet.Text);
                    }
                    result = BetCalculator.Calculate(historyTxt.Text,
                                                     Double.Parse(quote.Text), next, offsetValue);


                    profit.Text = "" + result.Profit;
                }
            };

            return(view);
        }