private TransactionDTO PlaceSingleIBET(string BetStrategy, string oddPrice, MatchDTO ibetMatch, string oddID, string oddValue, eOddType oddType, string ibetOddType, string stake, string homeScore, string awayScore, IBetEngine ibetEngine, bool followtype, string followref, string accountName)
        {
            this._betting = true;
            TransactionDTO transactionDTO = new TransactionDTO();
            string acctoScan = "";
            List<Bet> bl;
            string RefID = "";
            if (BetStrategy.Contains("Over15_XA"))
            {
                bl = this._ibetEngine.ibetAgent2.betList;
                acctoScan = this._ibetEngine.ibetAgent2.Config.Account;
                string[] array = BetStrategy.Split(new string[] { "Ref ID:" }, System.StringSplitOptions.None);
                RefID = array[1];
                if (!AllowOddBet(RefID + ibetOddType, ibetOddType))
                {
                    transactionDTO.HomeTeamName = ibetMatch.HomeTeamName;
                    transactionDTO.AwayTeamName = ibetMatch.AwayTeamName;
                    transactionDTO.Note = "Under account: " + acctoScan + " just bet on this odd";
                    transactionDTO.DateTime = DateTime.Now;
                    this._betting = false;
                    return transactionDTO;
                }
            }            
            else
            {
                bl = this._ibetEngine.ibetAgent.betList;
                acctoScan = this._ibetEngine.ibetAgent.Config.Account;
            }
            if (BetStrategy.Contains("Warning"))
            {
                transactionDTO.HomeTeamName = ibetMatch.HomeTeamName;
                transactionDTO.AwayTeamName = ibetMatch.AwayTeamName;
                transactionDTO.Note = BetStrategy;
                transactionDTO.DateTime = DateTime.Now;
                this._betting = false;
                return transactionDTO;
            }
            foreach (Bet bet in bl)
            {
                if (bet.Home == ibetMatch.HomeTeamName)
                {                    
                    if (bet.Handicap == decimal.Parse(oddValue))
                    {
                        if (bet.Choice.ToString().ToLower() == ibetOddType)
                        {
                            transactionDTO.HomeTeamName = ibetMatch.HomeTeamName;
                            transactionDTO.AwayTeamName = ibetMatch.AwayTeamName;
                            transactionDTO.Note = acctoScan + " : Bet list contains this odd already";
                            transactionDTO.DateTime = DateTime.Now;
                            this._betting = false;
                            return transactionDTO;
                        }
                    }                    
                }
            }
            if (!AllowOddBet(oddID + ibetOddType,ibetOddType))
            {
                transactionDTO.HomeTeamName = ibetMatch.HomeTeamName;
                transactionDTO.AwayTeamName = ibetMatch.AwayTeamName;
                transactionDTO.Note = acctoScan + " just bet on this odd";
                transactionDTO.DateTime = DateTime.Now;
                this._betting = false;
                return transactionDTO;
            }
            if (this._ibetEngine.ibetAgent.Config.Balance < int.Parse(stake))
            {
                transactionDTO.HomeTeamName = ibetMatch.HomeTeamName;
                transactionDTO.AwayTeamName = ibetMatch.AwayTeamName;
                transactionDTO.Note = "Not enough money";
                transactionDTO.DateTime = DateTime.Now;
                this._betting = false;
                return transactionDTO;
            }

            
            string following = string.Empty;
            if (followtype)
                following = "following";
            else
                following = "unfollowing";

            string betKindValue = string.Empty;
            string homeTeamName = string.Empty;
            string awayTeamName = string.Empty;
            string newOddValue = string.Empty;
            string newHomeScore = string.Empty;
            string newAwayScore = string.Empty;

            bool flag = false;
            bool flag2 = false;
            string text = string.Empty;

            //System.Collections.Generic.List<MatchDTO> listIbetMatch = this._listIBETMatch;
            Dictionary<string, IbetMatch> listIbetMatch = this._ibetMatchs;
            //MatchDTO matchDTO = MatchDTO.SearchMatchFull(ibetMatch, listIbetMatch);
            if (ibetMatch != null && ibetMatch.HomeTeamName != string.Empty)
            {
                //OddDTO oddDTO = OddDTO.SearchOdd(oddType, odd, true, ibetMatch.Odds);
                //if (oddDTO != null)
                //{
                    string ibetOddNow = string.Empty;
                    //if (ibetOddType == "a")
                    //    ibetOddNow = oddDTO.Away.ToString();
                    //else
                    //    ibetOddNow = oddDTO.Home.ToString();
                    if (followtype || (!followtype && ((float.Parse(ibetOddNow) >= (float)txtLowestOddValue.Value && float.Parse(ibetOddNow) > 0)) || float.Parse(ibetOddNow) < 0))
                    {
                        int maxBet = 0;
                        int minBet = 0;
                        string ibetOddID = oddID;
                        try
                        {
                            string valueAway = "";
                            if (BetStrategy == "Under" || BetStrategy == "Over")
                            {
                                #region UNDER_OVER
                                if (BetStrategy == "Under")
                                {
                                    ibetEngine.PrepareBet2(ibetOddID, "h", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                    valueAway = newOddValue;
                                    Thread.Sleep(2000);
                                    ibetEngine.PrepareBet2(ibetOddID, "a", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                }
                                else if (BetStrategy == "Over")
                                {
                                    ibetEngine.PrepareBet2(ibetOddID, "a", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                    valueAway = newOddValue;
                                    Thread.Sleep(2000);
                                    ibetEngine.PrepareBet2(ibetOddID, "h", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                }
                                if (homeTeamName == ibetMatch.HomeTeamName)
                                {
                                    if (valueAway == newOddValue)
                                    {
                                        ibetEngine.ConfirmBet(oddType, newOddValue, stake, minBet.ToString(), maxBet.ToString(), out flag2);
                                        if (!flag2)
                                        {
                                            if (BetStrategy == "Under")
                                                text = "Under:: Confirm bet failed";
                                            else
                                                text = "Over:: Confirm bet failed";
                                        }
                                        else
                                        {
                                            this._lastTransactionTime = DateTime.Now;
                                            if (BetStrategy == "Under")
                                            {
                                                text = "Under:: - Success ";
                                                UpdateOddBetHistory(oddID + "a", "a");
                                            }
                                            else
                                            {
                                                text = "Over:: - Success ";
                                                UpdateOddBetHistory(oddID + "h", "h");
                                            }
                                            this._ibetEngine.ibetAgent.RefreshBetList();
                                        }
                                    }
                                    else
                                    {
                                        if (BetStrategy == "Under")
                                            text = "Under:: Odd requested: " + oddPrice.ToString();
                                        else
                                            text = "Over:: Odd requested: " + oddPrice.ToString();
                                    }
                                }
                                else
                                {
                                    if (BetStrategy == "Under")
                                        text = "Under:: Not same match. Comparing: " + ibetMatch.HomeTeamName + " - " + ibetMatch.AwayTeamName;
                                    else
                                        text = "Over:: Not same match. Comparing: " + ibetMatch.HomeTeamName + " - " + ibetMatch.AwayTeamName;
                                }
                                #endregion
                            }
                            else if (BetStrategy == "Over9290")
                            {
                                #region Over9290
                                ibetEngine.PrepareBet2(ibetOddID, "h", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                if (flag && homeTeamName == ibetMatch.HomeTeamName)
                                {
                                    ibetEngine.ConfirmBet(oddType, newOddValue, stake, minBet.ToString(), maxBet.ToString(), out flag2);
                                    if (!flag2)
                                    {
                                        text = "Over 92/90:: Confirm bet failed";
                                    }
                                    else
                                    {
                                        this._lastTransactionTime = DateTime.Now;
                                        text = "Over 92/90:: - Success ";
                                        //this._ibetEngine.ibetAgent.RefreshBetList();
                                        UpdateOddBetHistory(oddID + "h", "h");
                                    }
                                }
                                else
                                {
                                    text = "Over1.75:: Not same match. Comparing: " + ibetMatch.HomeTeamName + " - " + ibetMatch.AwayTeamName;
                                }
                                #endregion 
                            }
                            else if (BetStrategy == "SapKeo")
                            {
                                #region SAP_KEO
                                stake = ((int)(int.Parse(stake) * 1.5)).ToString();
                                ibetEngine.PrepareBet2(ibetOddID, "h", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                if (newOddValue == oddPrice.ToString())
                                {
                                    if (homeTeamName == ibetMatch.HomeTeamName)
                                    {
                                        ibetEngine.ConfirmBet(oddType, newOddValue, stake, minBet.ToString(), maxBet.ToString(), out flag2);
                                        if (!flag2)
                                        {
                                            text = "Sap Keo:: Confirm bet failed";
                                        }
                                        else
                                        {
                                            this._lastTransactionTime = DateTime.Now;
                                            text = "Odd Down:: - Success ";
                                            //this._ibetEngine.ibetAgent.RefreshBetList();
                                            UpdateOddBetHistory(oddID + "h", "h");
                                        }
                                    }
                                    else
                                    {
                                        text = "Sap Keo:: Not same match. Comparing: " + ibetMatch.HomeTeamName + " - " + ibetMatch.AwayTeamName;
                                    }
                                }
                                else
                                {
                                    text = "Sap Keo:: Odd change. Requested: " + oddPrice.ToString();
                                }
                                #endregion
                            }
                            else if (BetStrategy == "Over1.75")
                            {
                                #region Over1.75
                                ibetEngine.PrepareBet2(ibetOddID, "h", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                if (homeTeamName == ibetMatch.HomeTeamName)
                                {
                                    ibetEngine.ConfirmBet(oddType, newOddValue, stake, minBet.ToString(), maxBet.ToString(), out flag2);
                                    if (!flag2)
                                    {
                                        text = "Over1.75:: Confirm bet failed";
                                    }
                                    else
                                    {
                                        this._lastTransactionTime = DateTime.Now;
                                        text = "Over1.75:: - Success ";
                                        //this._ibetEngine.ibetAgent.RefreshBetList();
                                        UpdateOddBetHistory(oddID + "h", "h");
                                    }
                                }
                                else
                                {
                                    text = "Over1.75:: Not same match. Comparing: " + ibetMatch.HomeTeamName + " - " + ibetMatch.AwayTeamName;
                                }
                                #endregion
                            }
                            else if (BetStrategy == "nguoc" || BetStrategy == "xuoi")
                            {
                                #region BEST_STRATEGIES
                                if (BetStrategy == "nguoc")
                                {
                                    ibetEngine.PrepareBet2(ibetOddID, "a", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                    valueAway = newOddValue;
                                    Thread.Sleep(2000);
                                    ibetEngine.PrepareBet2(ibetOddID, "h", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                }
                                else if (BetStrategy == "xuoi")
                                {
                                    ibetEngine.PrepareBet2(ibetOddID, "h", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                    valueAway = newOddValue;
                                    Thread.Sleep(2000);
                                    ibetEngine.PrepareBet2(ibetOddID, "a", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                }

                                if (homeTeamName == ibetMatch.HomeTeamName)
                                {
                                    if (valueAway == newOddValue)
                                    {
                                        ibetEngine.ConfirmBet(oddType, newOddValue, stake, minBet.ToString(), maxBet.ToString(), out flag2);
                                        if (!flag2)
                                        {
                                            text = "Best Strategy:: Confirm bet failed";
                                        }
                                        else
                                        {
                                            this._lastTransactionTime = DateTime.Now;
                                            text = "Best Strategy:" + this.txtAddValue.Value.ToString() + " : - Success. " + BetStrategy.Replace("nguoc", "Over").Replace("xuoi", "Under");
                                            this._ibetEngine.ibetAgent.RefreshBetList();
                                            if (BetStrategy == "nguoc")
                                            {
                                                UpdateOddBetHistory(oddID + "h", "h");
                                            }
                                            else if (BetStrategy == "xuoi")
                                            {
                                                UpdateOddBetHistory(oddID + "a", "a");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        text = "Best Strategy:: Odd requested: " + oddPrice.ToString();
                                    }
                                }
                                else
                                {
                                    text = "Best Strategy:: Not same match. Comparing: " + ibetMatch.HomeTeamName + " - " + ibetMatch.AwayTeamName;
                                }
                                #endregion
                            }
                            #region IBET_vs_IBET_Over
                            else if (BetStrategy.Contains("Over15_Fang"))
                            {

                                ibetEngine.PrepareBet2(ibetOddID, "h", oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                if (homeTeamName == ibetMatch.HomeTeamName
                                    && (homeTeamName.Contains("30:01-45:00") || homeTeamName.Contains("75:01-90:00"))
                                    )
                                {
                                    ibetEngine.ConfirmBet(oddType, newOddValue, stake, minBet.ToString(), maxBet.ToString(), out flag2);
                                    if (!flag2)
                                    {
                                        text = "Over_15:: Confirm bet failed";
                                    }
                                    else
                                    {
                                        this._lastTransactionTime = DateTime.Now;
                                        text = "Over_15:: - Success ";
                                        UpdateOddBetHistory(oddID + "h", "h");

                                        //this._ibetEngine.ibetAgent.RefreshBetList();
                                    }
                                }
                            }

                            #endregion
                            else if (BetStrategy.Contains("Over15_XA"))
                            {
                                #region IBET_vs_IBET_Over30-45_XA

                                ibetEngine.PrepareBetFor2ndIBET(ibetOddID, ibetOddType, oddPrice.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                                if (homeTeamName.TrimEnd() == ibetMatch.HomeTeamName && awayTeamName.TrimEnd() == ibetMatch.AwayTeamName)
                                {
                                    
                                    if (float.Parse(newOddValue) >= 0.35f || float.Parse(newOddValue) < 0f)//tranh suu ban
                                    {
                                        if (!betKindValue.EndsWith("75"))
                                        {
                                            ibetEngine.ConfirmBetFor2ndIBET(oddType, newOddValue, stake, minBet.ToString(), maxBet.ToString(), out flag2);
                                            if (!flag2)
                                            {
                                                text = BetStrategy + ":: Confirm bet failed";
                                            }
                                            else
                                            {
                                                this._lastTransactionTime = DateTime.Now;
                                                text = BetStrategy + ":: - Success ";
                                                UpdateOddBetHistory(oddID + ibetOddType, ibetOddType);
                                                UpdateOddBetHistory(RefID + ibetOddType, ibetOddType);
                                                this._ibetEngine.ibetAgent2.RefreshBetList();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        text = BetStrategy + ":: Keo nho hon 0.35 >> Hien tai: " + newOddValue + ". Xem xet xa tay >>>>>>>>>>";
                                    }
                                }
                                else
                                {
                                    iBet.Utilities.WriteLog.Write("Not same match: Tim: " + ibetMatch.HomeTeamName + "-" 
                                    + ibetMatch.AwayTeamName + "Tra ve: " + homeTeamName + "-" + awayTeamName);
                                }

                                #endregion


                            }                            
                        }
                        catch (Exception ex)
                        {
                            text = ex.Message;
                        }
                    }
                    else
                    {
                        text = "Odd value is smaller than lowest accepted:" + ibetOddNow;
                    }
                //}
                //else
                //{
                //    string text2 = string.Empty;                    
                //    text = "Odd not found.";
                //}
            }
            else
                text = "Match not found ";


            transactionDTO.HomeTeamName = homeTeamName + ":" + homeScore;
            transactionDTO.AwayTeamName = awayTeamName + ":" + awayScore;
            transactionDTO.HomeScore = homeScore;
            transactionDTO.AwayScore = awayScore;
            transactionDTO.Score = homeScore + "-" + awayScore;
            transactionDTO.AccountPair = this._ibetAccount;// +" - " + this._ibetSubAccount;
            transactionDTO.OddType = oddType.ToString();
            transactionDTO.Odd = betKindValue;
            transactionDTO.OddKindValue = betKindValue;
            transactionDTO.OddValue = newOddValue;
            transactionDTO.Stake = stake;            
            transactionDTO.Note = text + " >>> " + acctoScan;
            transactionDTO.IBETTrade = flag2;
            transactionDTO.IBETAllow = flag;
            transactionDTO.IsFollowTypeTrans = true;
            transactionDTO.DateTime = DateTime.Now;
            transactionDTO.FollowRef = followref;

            this._betting = false;
            return transactionDTO;
        }
        private TransactionDTO PlaceSingleIBET(MatchDTO ibetMatch, string odd, string oddValue, eOddType oddType, string ibetOddType, string stake, string homeScore, string awayScore, IBetEngine ibetEngine, bool followtype, string followref, string accountName)
        {
            this._betting = true;
            TransactionDTO transactionDTO = new TransactionDTO();
            string following = string.Empty;
            if (followtype)
                following = "following";
            else
                following = "unfollowing";

            string betKindValue = string.Empty;
            string homeTeamName = string.Empty;
            string awayTeamName = string.Empty;
            string newOddValue = string.Empty;
            string newHomeScore = string.Empty;
            string newAwayScore = string.Empty;

            bool flag = false;
            bool flag2 = false;
            string text = string.Empty;

            System.Collections.Generic.List<MatchDTO> listIbetMatch = this._listIBETMatch;
            //MatchDTO matchDTO = MatchDTO.SearchMatchFull(ibetMatch, listIbetMatch);
            if (ibetMatch != null && ibetMatch.HomeTeamName != string.Empty)
            {
                OddDTO oddDTO = OddDTO.SearchOdd(oddType, odd, true, ibetMatch.Odds);
                if (oddDTO != null)
                {
                    string ibetOddNow = string.Empty;
                    if (ibetOddType == "a")
                        ibetOddNow = oddDTO.Away.ToString();
                    else
                        ibetOddNow = oddDTO.Home.ToString();
                    if (followtype || (!followtype && ((float.Parse(ibetOddNow) >= (float)txtLowestOddValue.Value && float.Parse(ibetOddNow) > 0)) || float.Parse(ibetOddNow) < 0))
                    {
                        int maxBet = 0;
                        int minBet = 0;
                        string ibetOddID = oddDTO.ID;
                        try
                        {
                            ibetEngine.PrepareBet2(ibetOddID, ibetOddType, ibetOddNow.ToString(), stake, out flag, out minBet, out maxBet, out betKindValue, out homeTeamName, out awayTeamName, out newOddValue, out newHomeScore, out newAwayScore);
                            if (homeTeamName == ibetMatch.HomeTeamName)
                            {
                                if (newHomeScore == homeScore && newAwayScore == awayScore)
                                {
                                    float num1 = float.Parse(odd);
                                    float num2 = float.Parse(betKindValue);
                                    if (num1 + num2 == 0f || num1 == num2)
                                    {
                                        if (int.Parse(stake) > maxBet)
                                            stake = maxBet.ToString();

                                        float newIbetOddValue = float.Parse(newOddValue);
                                        float oldIbetOddValue = float.Parse(oddValue);

                                        //if (OddDTO.IsValidOddPair(newIbetOddValue, oldIbetOddValue, (float)txtAllowTradeMinValue.Value, true))
                                        //{
                                        ibetEngine.ConfirmBet(oddType, newOddValue, stake, minBet.ToString(), maxBet.ToString(), out flag2);
                                        if (!flag2)
                                        {
                                            //this._lastTransactionTime = System.DateTime.Now;
                                            //SendReportToMainForm("- Follow Bet: " + this._ibetAccount + " >> " + matchDTO.HomeTeamName + " - " + matchDTO.AwayTeamName + ": Bet confirmed failed. ");
                                            text = "Confirm bet failed";
                                        }
                                        else
                                        {
                                            this._lastTransactionTime = DateTime.Now;
                                            text = " - Success " + following + " " + this._ibetSubAccount + ". Follow: " + ibetOddType + " > " + accountName;
                                        }
                                        //}
                                        //else
                                        //{
                                        //    SendReportToMainForm("Follow Bet: " + this._ibetAccount + " >> " + matchDTO.HomeTeamName + " - " + matchDTO.AwayTeamName + ": New odd value: " + newOddValue + " is lower than allowed number ");
                                        //}
                                    }
                                    else
                                        text = "Invalid Odd while Preparing Ticket. IBET Odd: " + betKindValue;
                                }
                                else
                                {
                                    text = "Score changed.";
                                }
                            }
                            else
                            {
                                text = "Not same match. Comparing: " + ibetMatch.HomeTeamName + " - " + ibetMatch.AwayTeamName;
                            }
                        }
                        catch (Exception ex)
                        {
                            text = ex.Message;
                        }
                    }
                    else
                    {
                        text = "Odd value is smaller than lowest accepted:" + ibetOddNow;
                    }
                }
                else
                {
                    string text2 = string.Empty;
                    //foreach (OddDTO o in ibetMatch.Odds)
                    //{
                    //    text2 += o.Odd + ","; 
                    //}
                    text = "Odd not found.";
                }
            }
            else
                text = "Match not found ";


            transactionDTO.HomeTeamName = homeTeamName;
            transactionDTO.AwayTeamName = awayTeamName;
            transactionDTO.HomeScore = homeScore;
            transactionDTO.AwayScore = awayScore;
            transactionDTO.Score = homeScore + "-" + awayScore;
            transactionDTO.AccountPair = this._ibetAccount + " - " + this._ibetSubAccount;
            transactionDTO.OddType = oddType.ToString();
            transactionDTO.Odd = betKindValue;
            transactionDTO.OddKindValue = betKindValue;
            transactionDTO.OddValue = newOddValue;
            transactionDTO.Stake = stake;
            transactionDTO.Note = text;
            transactionDTO.IBETTrade = flag2;
            transactionDTO.IBETAllow = flag;
            transactionDTO.IsFollowTypeTrans = true;
            transactionDTO.DateTime = DateTime.Now;
            transactionDTO.FollowRef = followref;

            this._betting = false;
            return transactionDTO;
        }