public static void UpdateSystemOrCombiticket(Ticket ticketToCalculate) { lock (locker) { if (ticketToCalculate == null) { ticketToCalculate = ChangeTracker.NewTicket; } List <TipItemVw> localTipItems = new List <TipItemVw>(); localTipItems = ticketToCalculate.TipItems.Where(x => x.IsChecked).ToList(); decimal oddVal = 1; decimal multiWayOddVal = 1; int? minCombMax = 0; int bonusTipsCount = 0; Dictionary <int, List <TipItemVw> > tipItemDict = new Dictionary <int, List <TipItemVw> >(); foreach (TipItemVw t in localTipItems) { int iSvrMatchId = (int)t.Match.MatchId; if (tipItemDict.ContainsKey(iSvrMatchId)) { tipItemDict[iSvrMatchId].Add(t); } else { List <TipItemVw> list = new List <TipItemVw>(); list.Add(t); tipItemDict.Add(iSvrMatchId, list); } } // de: Anzahl der Wege berechnen // en: Number of ways to calculate // de: h?chste Quote der Mehrwege finden // en: highest rate of multipath are // int pathCount = 0; int rowCount = 1; int singlesCount = 0; foreach (List <TipItemVw> list in tipItemDict.Values) { if (list.Count >= 1) { decimal maxOdd = 1; foreach (TipItemVw tip in list) { if (maxOdd < tip.Odd.Value.Value) { maxOdd = tip.Odd.Value.Value; } } TipItemVw t = list[0]; if (t.IsBank || list.Count > 1) { pathCount++; rowCount *= list.Count; multiWayOddVal *= maxOdd; } else { oddVal *= maxOdd; singlesCount++; } int?curCombMax = minCombinationOfAll(t); if (curCombMax > minCombMax) { minCombMax = curCombMax; } if (list.Count == 1 && ticketToCalculate.TicketState == TicketStates.Multy) { if (t.Odd.Value.Value >= BonusFromOdd) { //Bonus gibt es nicht bei Mehrwegen bonusTipsCount++; } } } } TipListInfo.MinCombination = minCombMax; TipListInfo.NumOfTipps = tipItemDict.Count; TipListInfo.PathCount = pathCount; TipListInfo.RowCount = rowCount; TipListInfo.MultiWayOddFactor = multiWayOddVal; TipListInfo.CurrentTicketPossibleWin = 0; TipListInfo.FullOddFactor = 0; TipListInfo.ManipulationFeePercentage = StationRepository.GetManipulationFeePercentage(ticketToCalculate); TipListInfo.BonusFactor = StationRepository.GetBonusValueForBets(ticketToCalculate) / 100 + 1; switch (ticketToCalculate.TicketState) { default: if (localTipItems.Count > 1 && ticketToCalculate.TicketState != TicketStates.MultySingles) { ticketToCalculate.TicketState = TicketStates.Multy; UpdateSystemOrCombiticket(ticketToCalculate); return; } foreach (var tipItem in localTipItems) { tipItem.IsBank = false; } if (localTipItems.Count == 1 && ticketToCalculate.TicketState != TicketStates.MultySingles) { UpdateSingleticketItems(localTipItems, ticketToCalculate); } if (localTipItems.Count == 0) { TipListInfo.MinBet = 0; TipListInfo.OddOfTipps = 0; TipListInfo.MaxBet = 0; TipListInfo.MinWin = 0; TipListInfo.MaxWin = 0; TipListInfo.ManipulationFeePercentage = 0; TipListInfo.ResetNumXY(); } break; case TicketStates.MultySingles: return; case TicketStates.Multy: //rowCount = 1; TipListInfo.ResetNumXY(); if (localTipItems.Count < 2) { ticketToCalculate.TicketState = TicketStates.Single; UpdateSystemOrCombiticket(ticketToCalculate); return; } //TipListInfo.FullOddFactor = oddVal * multiWayOddVal * TipListInfo.BonusFactor; TipListInfo.FullOddFactor = oddVal * multiWayOddVal; if (TipListInfo.FullOddFactor >= MaxOdd) { TipListInfo.IsMaxOddBet = true; if (TipListInfo.FullOddFactor > MaxOdd) { TipListInfo.IllegalOddFactor = TipListInfo.FullOddFactor; ticketToCalculate.MaxOddExceeded = true; } TipListInfo.FullOddFactor = MaxOdd; TipListInfo.OddOfTipps = MaxOdd; } else { TipListInfo.OddOfTipps = oddVal * multiWayOddVal; TipListInfo.IllegalOddFactor = 0; TipListInfo.IsMaxOddBet = false; ticketToCalculate.MaxOddExceeded = false; } foreach (var tipItem in localTipItems) { tipItem.IsBank = false; } TipListInfo.MinBet = MinStakeCombiBet; TipListInfo.MaxBet = StationRepository.GetMaxStakeCombi(ticketToCalculate); TipListInfo.MinWin = TipListInfo.FullOddFactor * TipListInfo.MinBet / rowCount * (100 - TipListInfo.ManipulationFeePercentage) / 100; var manipulationFee = (TipListInfo.MaxBet / rowCount * TipListInfo.ManipulationFeePercentage) / 100; //TipListInfo.MaxWin = ((TipListInfo.MaxBet / rowCount - manipulationFee) * TipListInfo.FullOddFactor * TipListInfo.BonusFactor) - TipListInfo.MaxBet / rowCount; //TipListInfo.MaxWin *= rowCount; TipListInfo.MaxWin = (((TipListInfo.MaxBet - manipulationFee) / rowCount) * TipListInfo.FullOddFactor * TipListInfo.BonusFactor) - TipListInfo.MaxBet; var maxWinMultiBetFromAdmin = StationRepository.GetMaxWinMultiBet(ticketToCalculate); if (maxWinMultiBetFromAdmin > 0 && TipListInfo.MaxWin > maxWinMultiBetFromAdmin) { var a0 = 100 * maxWinMultiBetFromAdmin * rowCount; var a1 = (100 - TipListInfo.ManipulationFeePercentage); var a2 = (a1 * TipListInfo.BonusFactor * TipListInfo.FullOddFactor); var varX = (a0) / (a2 - 100 * rowCount); TipListInfo.MaxBet = Round(varX, 2); //manipulationFee = (TipListInfo.MaxBet / rowCount * TipListInfo.ManipulationFeePercentage) / 100; } //var posWin = TipListInfo.FullOddFactor * TipListInfo.Bet / rowCount; //TipListInfo.CurrentTicketPossibleWin = posWin * ((100 - TipListInfo.ManipulationFeePercentage) / 100) * TipListInfo.BonusFactor; var pw1 = (TipListInfo.Bet - (TipListInfo.Bet * TipListInfo.ManipulationFeePercentage / 100)) * TipListInfo.BonusFactor * TipListInfo.FullOddFactor; TipListInfo.CurrentTicketPossibleWin = pw1 / rowCount; //TipListInfo.MaxWin = (TipListInfo.MaxBet - manipulationFee) * TipListInfo.FullOddFactor * TipListInfo.BonusFactor / rowCount; TipListInfo.MaxWin = ((TipListInfo.MaxBet - (TipListInfo.MaxBet * TipListInfo.ManipulationFeePercentage / 100)) * TipListInfo.BonusFactor * TipListInfo.FullOddFactor) / rowCount; TipListInfo.FullOddFactor = TipListInfo.FullOddFactor; break; case TicketStates.System: TipListInfo.SystemX = ticketToCalculate.SystemX; TipListInfo.IllegalOddFactor = 0; int ind = 0; if (!LimitHandling.SystemBetYAllowed(TipListInfo.SystemY)) { //avoid useless time and memory consuming calculations TipListInfo.MinBet = 0; TipListInfo.OddOfTipps = 0; TipListInfo.MaxBet = 0; TipListInfo.MinWin = 0; TipListInfo.MaxWin = 0; TipListInfo.ManipulationFeePercentage = 0; TipListInfo.ResetNumXY(); //UpdateSystemOrCombiticket(ticketToCalculate); return; } if (TipListInfo.SystemX == 0) { TipListInfo.ResetNumXY(); } decimal[] oddVals = new decimal[TipListInfo.SystemY]; bool disableBankBtn = TipListInfo.PathCount + TipListInfo.MinSystemY >= TipListInfo.NumOfTipps; decimal dBankTipValue = 0; foreach (TipItemVw t in localTipItems) { if (!t.IsBank && t.Odd != null) { if (ind < oddVals.Length) { oddVals[ind++] = t.Odd.Value.Value; } else { } t.IsBankEnabled = !disableBankBtn; } else if (t.IsBank && t.Odd != null) { if (dBankTipValue == 0) { dBankTipValue = 1; // to make multiplication possible; } dBankTipValue *= t.Odd.Value.Value; } } RefreshBanks(); decimal maxOdd = OddUtilities.AllCombinationsSum(oddVals, TipListInfo.SystemX); // TipListInfo.SystemX if (maxOdd == 0) { ticketToCalculate.TicketState = TicketStates.Multy; UpdateSystemOrCombiticket(ticketToCalculate); return; } if (maxOdd * TipListInfo.MultiWayOddFactor > MaxOdd) { maxOdd = MaxOdd; TipListInfo.MultiWayOddFactor = 1; ticketToCalculate.MaxOddExceeded = true; } else { ticketToCalculate.MaxOddExceeded = false; } if (oddVals.Length < TipListInfo.SystemX) { UpdateSystemOrCombiticket(ticketToCalculate); return; } //ViewControl.SetTicketErrorMessage(TicketError.NoError); TipListInfo.MinBet = MinStakeSystemBet; //TipListInfo.MaxBet = StationSettings.Station.MaxStakeSystemBet; TipListInfo.OddOfTipps = maxOdd; decimal manFee = 0; manFee = StationRepository.GetManipulationFeePercentage(ChangeTracker.NewTicket); //TipListInfo.MaxBet = (100 * StationRepository.GetMaxWinSystemBet(ChangeTracker.NewTicket)) / ((100 - manFee) * TipListInfo.BonusFactor * (maxOdd * TipListInfo.MultiWayOddFactor / TipListInfo.RowCount)); TipListInfo.MaxBet = (100 * StationRepository.GetMaxWinSystemBet(ChangeTracker.NewTicket) * TipListInfo.RowCount) / ((100 - manFee) * TipListInfo.BonusFactor * (maxOdd * TipListInfo.MultiWayOddFactor)); TipListInfo.MaxBet = Round(Math.Min(TipListInfo.MaxBet, StationRepository.GetMaxStakeSystemBet(ChangeTracker.NewTicket)), 2); TipListInfo.MinWin = TipListInfo.MinBet * maxOdd * TipListInfo.MultiWayOddFactor / TipListInfo.RowCount; //TipListInfo.MaxWin = TipListInfo.MaxBet * maxOdd * TipListInfo.MultiWayOddFactor / TipListInfo.RowCount * TipListInfo.BonusFactor * (100 - TipListInfo.ManipulationFeePercentage) / 100; TipListInfo.MaxWin = ((TipListInfo.MaxBet * (100 - TipListInfo.ManipulationFeePercentage) / 100) * TipListInfo.BonusFactor * maxOdd * TipListInfo.MultiWayOddFactor) / TipListInfo.RowCount; ///////////////////////////////////////////// var maxWinSystemBetFromAdmin = StationRepository.GetMaxWinSystemBet(ticketToCalculate); if (maxWinSystemBetFromAdmin > 0 && TipListInfo.MaxWin > maxWinSystemBetFromAdmin) { TipListInfo.MaxWin = maxWinSystemBetFromAdmin; //manFee = StationRepository.GetManipulationFeePercentage(ChangeTracker.NewTicket); //TipListInfo.MaxBet = (100 * TipListInfo.MaxWin) / ((100 - manFee) * TipListInfo.BonusFactor * (maxOdd * TipListInfo.MultiWayOddFactor / TipListInfo.RowCount)); TipListInfo.MaxBet = Round((100 * StationRepository.GetMaxWinSystemBet(ChangeTracker.NewTicket) * TipListInfo.RowCount) / ((100 - manFee) * TipListInfo.BonusFactor * (maxOdd * TipListInfo.MultiWayOddFactor)), 2); } ///////////////////////////////////////////// if (dBankTipValue > 0) { if (maxOdd * (multiWayOddVal / rowCount) > MaxOdd) { TipListInfo.FullOddFactor = MaxOdd; ticketToCalculate.MaxOddExceeded = true; } else { TipListInfo.FullOddFactor = maxOdd * multiWayOddVal; ticketToCalculate.MaxOddExceeded = false; } } else { TipListInfo.FullOddFactor = maxOdd; } //TipListInfo.CurrentTicketPossibleWin = TipListInfo.Bet * maxOdd * TipListInfo.MultiWayOddFactor / TipListInfo.RowCount * TipListInfo.BonusFactor * (100 - TipListInfo.ManipulationFeePercentage) / 100; TipListInfo.CurrentTicketPossibleWin = ((TipListInfo.Bet - ((TipListInfo.Bet * TipListInfo.ManipulationFeePercentage) / 100)) * TipListInfo.BonusFactor * maxOdd * TipListInfo.MultiWayOddFactor) / TipListInfo.RowCount; TipListInfo.OddOfTipps = maxOdd; break; } ticketToCalculate.NumberOfBets = localTipItems.Count; ticketToCalculate.TotalOddDisplay = TipListInfo.FullOddFactor; ticketToCalculate.ManipulationFeeValue = TipListInfo.ManipulationFeeValue; ticketToCalculate.MaxBet = TipListInfo.MaxBet; //ticketToCalculate.MaxBet = Math.Min(TipListInfo.MaxBet, StationRepository.GetMaxStake(ticketToCalculate)); //ticketToCalculate.MaxBet = Math.Min(TipListInfo.MaxBet, TipListInfo.Bet); ticketToCalculate.MinBet = TipListInfo.MinBet; ticketToCalculate.BonusPercentage = TipListInfo.BonusFactorPerc; ticketToCalculate.BonusValue = TipListInfo.BonusValue / TipListInfo.RowCount; ticketToCalculate.MaxWin = TipListInfo.MaxWin; ticketToCalculate.RowCount = TipListInfo.RowCount; ticketToCalculate.StakeByRow = ticketToCalculate.Stake / TipListInfo.RowCount; ticketToCalculate.CurrentTicketPossibleWin = TipListInfo.CurrentTicketPossibleWin; ticketToCalculate.SystemX = TipListInfo.SystemX; ticketToCalculate.SystemY = TipListInfo.SystemY; //ticketToCalculate.SystemButtonName = string.Format(TranslationProvider.Translate(MultistringTags.SYSTEM_FORMAT) as string, TipListInfo.SystemX, TipListInfo.SystemY, "+Banker"); } }
public TicketWS CreateNewTicketWS(Ticket newticket) { var rTicketWs = new TicketWS(); List <ITipItemVw> ti = newticket.TipItems.ToSyncList().Where(x => x.IsChecked).ToList(); try { PasswordGenerator PWGen = new PasswordGenerator(); //if (string.IsNullOrEmpty(rTicketWs.TicketNbr)) //try //{ // long number, creditnumber, transactionnumber; // creditnumber = WsdlRepository.GetBusinessProps(StationRepository.StationNumber, out number, out transactionnumber); // BusinessPropsHelper.Initialize(StationRepository.StationNumber, new BusinessProps(number, creditnumber, transactionnumber)); //} //catch (Exception excp) //{ // Log.Error(ExcpHelper.FormatException(excp, "Initialize(sStationNumber = '{0}', {1}) ERROR", StationRepository.StationNumber, "")); //} rTicketWs.ticketNbr = BusinessPropsHelper.GenerateNextTicketNumber(); //rTicketWs.TicketNbr = StationSettings.GetSettings.StationNumber+DateTime.Now.ToString("yy")+StationSettings.GetSettings.NewTicketNumber.ToString("0000000"); //rTicketWs.TicketNbr = PWGen.Generate(14, 14, true); rTicketWs.checkSum = PWGen.Generate(4, 4, true); rTicketWs.paidBy = StationTyp; rTicketWs.paidTime = DateTime.Now; rTicketWs.paid = false; rTicketWs.acceptedBy = StationTyp; rTicketWs.acceptedTime = DateTime.Now; rTicketWs.stake = newticket.Stake; rTicketWs.cancelledTime = DateTimeUtils.DATETIMENULL; rTicketWs.enablePayTime = DateTime.MaxValue; rTicketWs.wonExpireTime = DateTimeUtils.DATETIMENULL; rTicketWs.userId = (int)ChangeTracker.CurrentUser.AccountId; //string bonusX = newticket.BonusValue.ToString(CultureInfo.InvariantCulture); //string manFeeX = newticket.ManipulationFeeValue.ToString(CultureInfo.InvariantCulture); //string a = Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator; //if (bonusX.IndexOf(a) != -1) //{ // bonusX = bonusX.Substring(0, bonusX.IndexOf(a) + 3); // newticket.BonusValue = Decimal.Parse(bonusX, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture); //} //if (manFeeX.IndexOf(a) != -1) //{ // manFeeX = manFeeX.Substring(0, manFeeX.IndexOf(a) + 3); // newticket.ManipulationFeeValue = Decimal.Parse(manFeeX, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture); //} newticket.BonusValue = ChangeTracker.TruncateDecimal(newticket.BonusValue); newticket.ManipulationFeeValue = ChangeTracker.TruncateDecimal(newticket.ManipulationFeeValue); rTicketWs.manipulationFeeValue = ChangeTracker.TruncateDecimal(newticket.ManipulationFeeValue);// newticket.ManipulationFeeValue; rTicketWs.superBonusValue = ChangeTracker.TruncateDecimal(newticket.BonusValue); BetWS bets = new BetWS(); bets.systemX = bets.systemY = newticket.NumberOfBets; switch (newticket.TicketState) { case TicketStates.Multy: var dup = newticket.TipItems.ToSyncList().GroupBy(x => new { x.Match.MatchId }).Select(group => new { Name = group.Key, Count = group.Count() }).OrderByDescending(x => x.Count); int duplicatesCount = 0; foreach (var x in dup) { if (x.Count > 1) { duplicatesCount += x.Count; } } int baseSize = newticket.NumberOfBets - duplicatesCount; if (duplicatesCount > 0 && baseSize > 0) //means there are ways { bets.systemX = bets.systemY = baseSize; } bets.betType = Bet.BET_TYPE_COMBI; break; case TicketStates.System: bets.betType = Bet.BET_TYPE_SYSTEM; bets.systemX = newticket.SystemX; bets.systemY = newticket.SystemY; break; default: bets.betType = Bet.BET_TYPE_SINGLE; break; } bets.maxOdd = newticket.TotalOddDisplay; //bets.MaxWin = rTicketWs.Stake * bets.MaxOdd; bets.maxWin = newticket.CurrentTicketPossibleWin; bets.stake = rTicketWs.stake; bets.isMaxOddBet = newticket.IsMaxOddBet; rTicketWs.bets = new BetWS[] { bets }; rTicketWs.superBonus = StationRepository.GetBonusValueForBets(newticket) / 100 + 1; rTicketWs.manipulationFee = StationRepository.GetManipulationFeePercentage(newticket); Dictionary <long, int> matchIDCountDictionary = new Dictionary <long, int>(); foreach (TipItemVw t in ti) { long iMatchCode = t.Match.MatchId; if (matchIDCountDictionary.ContainsKey(iMatchCode)) { matchIDCountDictionary[iMatchCode]++; } else { matchIDCountDictionary.Add(iMatchCode, 1); } } int liveBetTipCount = 0; int sportBetTipCount = 0; var tips2BetMulti = new ObservableCollection <TipWS>(); var bankTips = new ObservableCollection <TipWS>(); foreach (TipItemVw t in ti) { if (t.Odd != null) { if (t.Odd.IsLiveBet.Value) { liveBetTipCount++; } else { sportBetTipCount++; } } TipWS tip = new TipWS(); tip.bank = t.IsBank; if (t.Odd != null) { tip.odd = t.Value; tip.svrOddID = t.Odd.OutcomeId; //TODO: Wurde auf ServerOddID umgewandelt *g* 05.03.2008 by GMU SportRadar.DAL.OldLineObjects.eServerSourceType sType = t.Odd.BetDomain.Match.SourceType; if (sType == SportRadar.DAL.OldLineObjects.eServerSourceType.BtrLive || sType == SportRadar.DAL.OldLineObjects.eServerSourceType.BtrVfl || sType == SportRadar.DAL.OldLineObjects.eServerSourceType.BtrVhc) { tip.svrOddID = tip.svrOddID * -1; } tip.betDomainNumber = t.Odd.BetDomain.BetDomainNumber.Value; tip.matchCode = t.Odd.BetDomain.Match.Code.Value; tip.oddTag = t.Odd.OddTag.Value; } if (tip.bank || matchIDCountDictionary[t.Match.MatchId] != 1) { tip.bankGroupID = t.Match.MatchId; tip.bank = matchIDCountDictionary[t.Match.MatchId] == 1; //Mehrwege haben kein Bank-Flag if (newticket.TicketState == TicketStates.Multy && matchIDCountDictionary[t.Match.MatchId] != 1) { bets.betType = Bet.BET_TYPE_COMBIPATH; } else if (newticket.TicketState == TicketStates.System && matchIDCountDictionary[t.Match.MatchId] != 1) { bets.betType = Bet.BET_TYPE_SYSTEMPATH; } tips2BetMulti.Add(tip); //banken von system mit banken } else { bankTips.Add(tip); //system, kombi, einzeln } } bets.tips2BetMulti = tips2BetMulti.ToArray(); bets.bankTips = bankTips.ToArray(); if (newticket.TipItems[0].Match.MatchView.LineObject.SourceType == SportRadar.DAL.OldLineObjects.eServerSourceType.BtrVfl) { rTicketWs.ticketTyp = Ticket.TICKET_TYP_VFL; } else if (newticket.TipItems[0].Match.MatchView.LineObject.SourceType == SportRadar.DAL.OldLineObjects.eServerSourceType.BtrVhc) { rTicketWs.ticketTyp = Ticket.TICKET_TYP_VHC; } else if (liveBetTipCount > 0 && sportBetTipCount == 0) { rTicketWs.ticketTyp = Ticket.TICKET_TYP_LIVEBET; } else if (liveBetTipCount == 0 && sportBetTipCount > 0) { rTicketWs.ticketTyp = Ticket.TICKET_TYP_SPORTBET; } else { rTicketWs.ticketTyp = Ticket.TICKET_TYP_BOTH; } int rowCount = 1; int[,] temp; if (newticket.TicketState == TicketStates.System) { OddUtilities.SetPermutations(out temp, bets.systemY, bets.systemX); rowCount = temp.GetLength(0); } Dictionary <int, int> tempMatchCodeCountDict = new Dictionary <int, int>(); foreach (TipWS t in bets.tips2BetMulti) { if (tempMatchCodeCountDict.ContainsKey(t.matchCode)) { tempMatchCodeCountDict[t.matchCode]++; } else { tempMatchCodeCountDict.Add(t.matchCode, 1); } } foreach (int curCount in tempMatchCodeCountDict.Values) { rowCount *= curCount; } bets.rows = rowCount; return(rTicketWs); } catch (Exception ex) { WriteRemoteError2Log(ex.Message, 1, ex.GetType().ToString(), NbtLogSr.MSG_TERMINAL); return(null); } }