private void ButtonUpdate_Click(object sender, RoutedEventArgs e) { if (dataContext == null) { dataContext = new DataClassesProjectClassifyDataContext(); } Prizes prizes = dataContext.Prizes.FirstOrDefault(p => p.ID.Equals(_currentPrizeID)); if (prizes != null) { var prizeses = dataContext.Prizes.Where( p => p.Name.Equals(prizes.Name) && p.AccountName.Equals(prizes.AccountName) && p.PayYear.Equals(prizes.PayYear) && p.Department.Equals(prizes.Department) && p.PrizeClassify.Equals(prizes.PrizeClassify) && p.Project.Equals(prizes.Project) && p.AwardName.Equals(prizes.AwardName)); try { foreach (var pr in prizeses) { pr.Prize = Convert.ToDecimal(TextBoxPrize.Text); } dataContext.SubmitChanges(); FreshData(); } catch (Exception error) { MessageBox.Show(error.Message); } } }
//------------------------------------------------------------------------------- public Prizes GetPrizeById(int id) { try { DbCommand command = _factory.CreateCommand(); command.CommandText = "SELECT * FROM Prizes WHERE Id = @id"; command.Parameters.Add(instance.GetParameter("id", id, _factory)); DbDataReader reader = command.ExecuteReader(); if (reader.Read()) { Prizes prize = new Prizes(); prize.Id = Convert.ToInt32(reader["Id"]); prize.PictureSrc = Convert.ToString(reader["PictureSrc"]); prize.PrizeName = Convert.ToString(reader["PrizeName"]); return(prize); } return(null); } catch (DbException) { return(null); } }
public void AddPrize(LuckyDipPrize prize) { if (!Prizes.Contains(prize) && OnAddPrize(prize)) { Prizes.Add(prize); } }
//------------------------------------------------------------------------------- public List <Prizes> GetPrizes() { try { DbCommand command = _factory.CreateCommand(); command.CommandText = "SELECT * FROM Prizes"; DbDataReader reader = command.ExecuteReader(); while (reader.Read()) { Prizes prize = new Prizes(); prize.Id = Convert.ToInt32(reader["Id"]); prize.PictureSrc = Convert.ToString(reader["PictureSrc"]); prize.PrizeName = Convert.ToString(reader["PrizeName"]); prizes.Add(prize); } return(prizes); } catch (DbException) { return(null); } }
private void DataGridPrizes_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (DataGridPrizes.SelectedItem == null) { _currentPrizeID = 0; GridPrizeDetail.DataContext = null; } else { Prize prize = (Prize)DataGridPrizes.SelectedItem; _currentPrize = new Prize(); _currentPrize = prize; Prizes prizes = dataContext.Prizes.FirstOrDefault( p => p.Name.Equals(prize.Name) && p.AccountName.Equals(prize.AccountName) && p.Department.Equals(prize.Department) && p.PrizeClassify.Equals(prize.PrizeClassify) && p.Project.Equals(prize.Project) & p.AwardName.Equals(prize.AwardName) && p.PayYear.Equals(prize.PayYear) && p.Prize.Equals(prize.PrizeValue)); _currentPrizeID = prizes?.ID ?? 0; GridPrizeDetail.DataContext = prize; } CheckEmpty(); }
public void RemovePrize(IPrize prize) { if (Prizes.Contains(prize)) { Prizes.Remove(prize); _drawer.Remove(prize); } }
public void RemovePrizes() { foreach (IPrize prize in Prizes) { _drawer.Remove(prize); } Prizes.Clear(); }
private string GetData() { this._id = ID; this._name = NAME; this._address = Address; this._prizes = PRIZES; return(string.Format("ID: {0}\nName: {1}\nAddress: {2}\nPrizes: {3}\n" , _id, _name, _address, _prizes)); }
public override Boolean Check(CompetitionPoster @object) { return((Discipline?.Check(@object.Discipline) ?? true) && (Prizes?.Check(@object.Prizes) ?? true) && (StarterPackItems?.Check(@object.StarterPacks) ?? true) && (Description?.Check(@object.Description) ?? true) && ((SlotCost?.Check(@object.SlotCost.Minimum.Amount) ?? true) || ((Boolean)SlotCost?.Check(@object.SlotCost.Maximum.Amount)))); }
public void InitPrizes() { if (Prizes == null) { Prizes = new List <LuckyDipPrize>(); } Prizes.Clear(); InitBankChecks(); InitItems(); }
public virtual IEnumerable <LuckyDipPrize> GetPrizes(double chance) { if (Prizes == null || Prizes.Count == 0) { yield break; } Normalize(ref chance); foreach (var p in Prizes.Where(e => !e.Disabled && e.Chance >= chance).OrderByDescending(e => e.Chance)) { yield return(p); } }
/// <summary> /// 初始化抽奖容器 /// </summary> /// <returns></returns> private void InitLotteryDrawContainer() { if (!Prizes.IsNull() && Prizes.Count > 0) { int lastMax = 0; Container = new Dictionary <string, ArrayList>(); foreach (KeyValuePair <string, byte> ld in Prizes) { ArrayList typeRange = CreateTypeRange(ld.Value, lastMax); Container.Add(ld.Key, typeRange); lastMax = (int)typeRange[1]; } } }
public virtual LuckyDipPrize[] GetPrizes(double chance) { if (Prizes == null || Prizes.Count == 0) { return(new LuckyDipPrize[0]); } Normalize(ref chance); var p = Prizes.Where(e => !e.Disabled && e.Chance <= chance).OrderByDescending(e => e.Chance).ToArray(); //p.ForEach(o => Console.WriteLine("Prize: T: {0} C: {1}", o.Type, o.Chance)); return(p); }
public PartialViewResult DrawResult(int num) { var drawList = (from mp in _db.Member_Prize join m in _db.Members on mp.MemberID equals m.Id into Members from members in Members.DefaultIfEmpty() join p in _db.Prizes on mp.PrizeID equals p.Id into Prizes from prize in Prizes.DefaultIfEmpty() orderby mp.AddTime descending select new DrawResultModel() { Member = members, Prize = prize }).Where(x => x.Member != null && x.Prize != null).Take(14); return(PartialView(drawList.ToArray())); }
private void DataGridPrizes_SelectionChanged(object sender, SelectionChangedEventArgs e) { Prizes prizes = (Prizes)DataGridPrizes.SelectedItem; if (prizes == null) { GridDetail.DataContext = null; PrizeId = 0; ButtonRemove.IsEnabled = false; return; } GridDetail.DataContext = prizes; Department department = _listDepartment.FirstOrDefault(d => d.Name.Equals(prizes.Department)); //ListBoxItem listItemDepartment = new ListBoxItem(); //listItemDepartment.Content = new TextBlock() { Text = prizes.Department }; //foreach (var item in ListBoxDepartment.Items) //{ // if (item == department) // { // ((ListBoxItem)item).IsSelected = true; // } ListBoxDepartment.SelectedItem = department; if (department != null) { ListBoxDepartment.ScrollIntoView(department); } Employee employee = _listEmployee.FirstOrDefault(em => em.AccountName.Equals(prizes.AccountName)); if (employee != null) { ListBoxEmployee.SelectedItem = employee; ListBoxEmployee.ScrollIntoView(employee); } PrizeClassify prizeClassify = _listPrizeClassify.FirstOrDefault(pc => pc.PrizeClassifyName.Equals(prizes.PrizeClassify)); if (prizeClassify != null) { ListBoxPrizeClassify.SelectedItem = prizeClassify; ListBoxPrizeClassify.ScrollIntoView(prizeClassify); } ButtonPay.IsEnabled = false; ButtonRemove.IsEnabled = true; }
protected void EndGamble(Mobile from) { if (from == null || from.Deleted) { return; } from.EndAction(GetType()); double a = Utility.RandomDouble(); double b = Math.Min(LuckCap, from.Luck) / (double)LuckCap; double c = a + b; Normalize(ref c); //Console.WriteLine("LDT: A = {0} B = {1} C = {2}", a, b, c); LuckyDipPrize prizeEntry = GetPrize(c); if (prizeEntry == null || prizeEntry.Disabled || prizeEntry.Equals(LuckyDipPrize.Empty)) { from.SendMessage(34, "Sorry {0}, you didn't win anything, better luck next time!", from.RawName); Delete(); return; } Item prize = prizeEntry.CreateInstance <Item>(); if (prize == null) { Prizes.Remove(prizeEntry); VitaNexCore.ToConsole( "WARNING: An instance of {0} could not be constructed in {1} at {2}", prizeEntry.Type.FullName, GetType().FullName, prizeEntry.GetType().FullName); from.SendMessage(34, "We couldn't process your ticket, please try again."); return; } from.SendMessage(85, "Congratulations, you won a prize! ({0})", prize.ResolveName(from)); ReplaceWith(prize); }
/// <summary> /// Updates the total player picks and total value based on the selected prize levels /// </summary> public void updateInfo() { if (Prizes.getNumPrizeLevels() > 0) { DivModel.clearPrizeLevelList(); for (int i = 0; i < Prizes.getNumPrizeLevels(); i++) { if (DivModel.levelBoxes[i].IsSelected) { DivModel.addPrizeLevel(Prizes.getPrizeLevel(i)); } } DivModel.TotalPlayerPicks = DivModel.calculateTotalCollections(); DivModel.TotalPrizeValue = DivModel.calculateDivisionValue(); } SectionContainer.validateDivision(); }
/// <summary> /// Updates all of the info and prize level box data in the division /// </summary> public void updateDivision() { if (Prizes.getNumPrizeLevels() > 0) { for (int i = 0; i < DivisionModel.MAX_PRIZE_BOXES; i++) { if (DivModel.levelBoxes[i].IsAvailable && DivModel.levelBoxes[i].IsSelected) { DivModel.addPrizeLevel(Prizes.getPrizeLevel(i)); } else { DivModel.levelBoxes[i].IsSelected = false; } } DivModel.TotalPlayerPicks = DivModel.calculateTotalCollections(); DivModel.TotalPrizeValue = DivModel.calculateDivisionValue(); } }
/// <summary> /// Listens for "shouts" made by other classes, if it is subscribed to that class /// </summary> /// <param name="pass"></param> public void onListen(object pass) { if (pass is PrizeLevels.PrizeLevels) { Prizes = (PrizeLevels.PrizeLevels)pass; for (int i = 0; i < DivisionModel.MAX_PRIZE_BOXES; i++) { DivModel.levelBoxes[i].IsAvailable = false; } for (int i = 0; i < Prizes.getNumPrizeLevels(); i++) { DivModel.levelBoxes[i].IsAvailable = true; } DivModel.clearPrizeLevelList(); updateDivision(); } }
protected IQueryable <DrawResultModel> Filter(RewardFilter filter, LuckyDrawEntities _db) { var fResult = (from mp in _db.Member_Prize join member in _db.Members on mp.MemberID equals member.Id into Members from m in Members.DefaultIfEmpty() join prize in _db.Prizes on mp.PrizeID equals prize.Id into Prizes from p in Prizes.DefaultIfEmpty() where mp.HasReceived && (!string.IsNullOrEmpty(filter.MemberMobile) ? m.Mobile.Contains(filter.MemberMobile) : true) && (!string.IsNullOrEmpty(filter.MemberName) ? m.Name.Contains(filter.MemberName) : true) && (!string.IsNullOrEmpty(filter.PrizeName) ? p.Name.Contains(filter.PrizeName) : true) select new DrawResultModel() { Member = m, Prize = p, Id = mp.Id, AddTime = mp.AddTime }); return(fResult); }
//------------------------------------------------------------------------------- public Prizes UpdatePrize(int i, Prizes prize) { try { DbCommand command = _factory.CreateCommand(); command.CommandText = "UPDATE Prizes SET PictureSrc = @PictureSrc, PrizeName = @PrizeName"; command.Parameters.Add(instance.GetParameter("PictureSrc", prize.PictureSrc, _factory)); command.Parameters.Add(instance.GetParameter("PrizeName", prize.PrizeName, _factory)); command.ExecuteNonQuery(); prizes[i].PictureSrc = prize.PictureSrc; prizes[i].PrizeName = prize.PrizeName; return(prize); } catch (DbException) { return(null); } }
//------------------------------------------------------------------------------- public Prizes AddPrize(Prizes prize) { try { DbCommand command = _factory.CreateCommand(); command.CommandText = "INSERT INTO Prizes (PrizeName, PictureSrc) VALUES (@PrizeName, @PictureSrc)"; command.Parameters.Add(instance.GetParameter("PrizeName", prize.PrizeName, _factory)); command.Parameters.Add(instance.GetParameter("PictureSrc", prize.PictureSrc, _factory)); command.ExecuteNonQuery(); prize.Id = instance.GetNewId("Prizes", _connection); prizes.Add(prize); return(prize); } catch (DbException) { return(null); } }
public double GetMaxChance() { return(Prizes.Max(e => e.Chance)); }
public void AddPrize(IPrize prize) { Prizes.Add(prize); _drawer.Add(prize, _resourceRepository.GetTextureByType(prize.GetType())); }
public SpinOutcome Spin(int stake, int betLines) { //Set prizes this.Prizes = new List <Prize> { new Prize { CardId = 0, Streak = 5, Multiplier = 5000 }, new Prize { CardId = 1, Streak = 3, Multiplier = 3 }, new Prize { CardId = 1, Streak = 4, Multiplier = 10 }, new Prize { CardId = 1, Streak = 5, Multiplier = 100 }, new Prize { CardId = 2, Streak = 3, Multiplier = 5 }, new Prize { CardId = 2, Streak = 4, Multiplier = 20 }, new Prize { CardId = 2, Streak = 5, Multiplier = 100 }, new Prize { CardId = 3, Streak = 3, Multiplier = 5 }, new Prize { CardId = 3, Streak = 4, Multiplier = 20 }, new Prize { CardId = 3, Streak = 5, Multiplier = 100 }, new Prize { CardId = 4, Streak = 3, Multiplier = 7 }, new Prize { CardId = 4, Streak = 4, Multiplier = 25 }, new Prize { CardId = 4, Streak = 5, Multiplier = 150 }, new Prize { CardId = 5, Streak = 3, Multiplier = 7 }, new Prize { CardId = 5, Streak = 4, Multiplier = 25 }, new Prize { CardId = 5, Streak = 5, Multiplier = 150 }, new Prize { CardId = 6, Streak = 3, Multiplier = 10 }, new Prize { CardId = 6, Streak = 4, Multiplier = 30 }, new Prize { CardId = 6, Streak = 5, Multiplier = 200 }, new Prize { CardId = 7, Streak = 3, Multiplier = 10 }, new Prize { CardId = 7, Streak = 4, Multiplier = 30 }, new Prize { CardId = 7, Streak = 5, Multiplier = 200 }, new Prize { CardId = 8, Streak = 3, Multiplier = 15 }, new Prize { CardId = 8, Streak = 4, Multiplier = 75 }, new Prize { CardId = 8, Streak = 5, Multiplier = 500 }, new Prize { CardId = 9, Streak = 3, Multiplier = 15 }, new Prize { CardId = 9, Streak = 4, Multiplier = 75 }, new Prize { CardId = 9, Streak = 5, Multiplier = 500 }, new Prize { CardId = 10, Streak = 3, Multiplier = 15 }, new Prize { CardId = 10, Streak = 4, Multiplier = 75 }, new Prize { CardId = 10, Streak = 5, Multiplier = 1000 }, new Prize { CardId = 11, Streak = 2, Multiplier = 5 }, new Prize { CardId = 11, Streak = 3, Multiplier = 100 }, new Prize { CardId = 11, Streak = 4, Multiplier = 250 }, new Prize { CardId = 11, Streak = 5, Multiplier = 2500 }, new Prize { CardId = 12, Streak = 2, Multiplier = 10 }, new Prize { CardId = 12, Streak = 3, Multiplier = 150 }, new Prize { CardId = 12, Streak = 4, Multiplier = 500 }, new Prize { CardId = 12, Streak = 5, Multiplier = 5000 } }; //Draws Random rng = new Random(); this.Reels = new int[3, 5]; Reels[0, 0] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[0, 1] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[0, 2] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[0, 3] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[0, 4] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[1, 0] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[1, 1] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[1, 2] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[1, 3] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[1, 4] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[2, 0] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[2, 1] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[2, 2] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[2, 3] = CheckNumberDrawn(rng.Next(1, Card_End_13)); Reels[2, 4] = CheckNumberDrawn(rng.Next(1, Card_End_13)); //Map the draws to game reels, just for output simplicity and readability this.GameReels = new List <GameReel> { new GameReel { Id = 1, Positions = new List <GameReelPosition> { new GameReelPosition { Id = 0, CardId = Reels[2, 0] }, new GameReelPosition { Id = 1, CardId = Reels[1, 0] }, new GameReelPosition { Id = 2, CardId = Reels[0, 0] }, } }, new GameReel { Id = 2, Positions = new List <GameReelPosition> { new GameReelPosition { Id = 0, CardId = Reels[2, 1] }, new GameReelPosition { Id = 1, CardId = Reels[1, 1] }, new GameReelPosition { Id = 2, CardId = Reels[0, 1] }, } }, new GameReel { Id = 3, Positions = new List <GameReelPosition> { new GameReelPosition { Id = 0, CardId = Reels[2, 2] }, new GameReelPosition { Id = 1, CardId = Reels[1, 2] }, new GameReelPosition { Id = 2, CardId = Reels[0, 2] }, } }, new GameReel { Id = 4, Positions = new List <GameReelPosition> { new GameReelPosition { Id = 0, CardId = Reels[2, 3] }, new GameReelPosition { Id = 1, CardId = Reels[1, 3] }, new GameReelPosition { Id = 2, CardId = Reels[0, 3] }, } }, new GameReel { Id = 5, Positions = new List <GameReelPosition> { new GameReelPosition { Id = 0, CardId = Reels[2, 4] }, new GameReelPosition { Id = 1, CardId = Reels[1, 4] }, new GameReelPosition { Id = 2, CardId = Reels[0, 4] }, } } }; //Form the lines int[] line1 = { Reels[1, 0], Reels[1, 1], Reels[1, 2], Reels[1, 3], Reels[1, 4] }; int[] line2 = { Reels[0, 0], Reels[0, 1], Reels[0, 2], Reels[0, 3], Reels[0, 4] }; int[] line3 = { Reels[2, 0], Reels[2, 1], Reels[2, 2], Reels[2, 3], Reels[2, 4] }; int[] line4 = { Reels[0, 0], Reels[1, 1], Reels[2, 2], Reels[1, 3], Reels[0, 4] }; int[] line5 = { Reels[2, 0], Reels[1, 1], Reels[0, 2], Reels[1, 3], Reels[2, 4] }; int[] line6 = { Reels[1, 0], Reels[0, 1], Reels[1, 2], Reels[0, 3], Reels[1, 4] }; int[] line7 = { Reels[1, 0], Reels[2, 1], Reels[1, 2], Reels[2, 3], Reels[1, 4] }; int[] line8 = { Reels[0, 0], Reels[0, 1], Reels[1, 2], Reels[2, 3], Reels[2, 4] }; int[] line9 = { Reels[2, 0], Reels[2, 1], Reels[1, 2], Reels[0, 3], Reels[0, 4] }; int[] line10 = { Reels[1, 0], Reels[2, 1], Reels[1, 2], Reels[0, 3], Reels[1, 4] }; int[] line11 = { Reels[1, 0], Reels[0, 1], Reels[1, 2], Reels[2, 3], Reels[1, 4] }; int[] line12 = { Reels[0, 0], Reels[1, 1], Reels[1, 2], Reels[1, 3], Reels[0, 4] }; int[] line13 = { Reels[2, 0], Reels[1, 1], Reels[1, 2], Reels[1, 3], Reels[2, 4] }; int[] line14 = { Reels[0, 0], Reels[1, 1], Reels[0, 2], Reels[1, 3], Reels[0, 4] }; int[] line15 = { Reels[2, 0], Reels[1, 1], Reels[2, 2], Reels[1, 3], Reels[2, 4] }; int[] line16 = { Reels[1, 0], Reels[1, 1], Reels[0, 2], Reels[1, 3], Reels[1, 4] }; int[] line17 = { Reels[1, 0], Reels[1, 1], Reels[2, 2], Reels[1, 3], Reels[1, 4] }; int[] line18 = { Reels[0, 0], Reels[0, 1], Reels[2, 2], Reels[0, 3], Reels[0, 4] }; int[] line19 = { Reels[2, 0], Reels[2, 1], Reels[0, 2], Reels[2, 3], Reels[2, 4] }; int[] line20 = { Reels[1, 0], Reels[2, 1], Reels[2, 2], Reels[2, 3], Reels[1, 4] }; this.Lines = new List <Line> { new Line { Id = 1, Outcome = line1, YPositions = new int[] { 1, 1, 1, 1, 1 }, UICoordinates = "0111213141" }, new Line { Id = 2, Outcome = line2, YPositions = new int[] { 0, 0, 0, 0, 0 }, UICoordinates = "0010203040" }, new Line { Id = 3, Outcome = line3, YPositions = new int[] { 2, 2, 2, 2, 2 }, UICoordinates = "0212223242" }, new Line { Id = 4, Outcome = line4, YPositions = new int[] { 0, 1, 2, 1, 0 }, UICoordinates = "0011223140" }, new Line { Id = 5, Outcome = line5, YPositions = new int[] { 2, 1, 0, 1, 2 }, UICoordinates = "0211203142" }, new Line { Id = 6, Outcome = line6, YPositions = new int[] { 1, 0, 1, 0, 1 }, UICoordinates = "0110213041" }, new Line { Id = 7, Outcome = line7, YPositions = new int[] { 1, 2, 1, 2, 1 }, UICoordinates = "0112213241" }, new Line { Id = 8, Outcome = line8, YPositions = new int[] { 0, 0, 1, 2, 2 }, UICoordinates = "0010213242" }, new Line { Id = 9, Outcome = line9, YPositions = new int[] { 2, 2, 1, 0, 0 }, UICoordinates = "0212213040" }, new Line { Id = 10, Outcome = line10, YPositions = new int[] { 1, 2, 1, 0, 1 }, UICoordinates = "0112213041" }, new Line { Id = 11, Outcome = line11, YPositions = new int[] { 1, 0, 1, 2, 1 }, UICoordinates = "0110213241" }, new Line { Id = 12, Outcome = line12, YPositions = new int[] { 0, 1, 1, 1, 0 }, UICoordinates = "0011213140" }, new Line { Id = 13, Outcome = line13, YPositions = new int[] { 2, 1, 1, 1, 2 }, UICoordinates = "0211213142" }, new Line { Id = 14, Outcome = line14, YPositions = new int[] { 0, 1, 0, 1, 0 }, UICoordinates = "0011203140" }, new Line { Id = 15, Outcome = line15, YPositions = new int[] { 2, 1, 2, 1, 2 }, UICoordinates = "0211223142" }, new Line { Id = 16, Outcome = line16, YPositions = new int[] { 1, 1, 0, 1, 1 }, UICoordinates = "0111203141" }, new Line { Id = 17, Outcome = line17, YPositions = new int[] { 1, 1, 2, 1, 1 }, UICoordinates = "0111223141" }, new Line { Id = 18, Outcome = line18, YPositions = new int[] { 0, 0, 2, 0, 0 }, UICoordinates = "0010223040" }, new Line { Id = 19, Outcome = line19, YPositions = new int[] { 2, 2, 0, 2, 2 }, UICoordinates = "0212203242" }, new Line { Id = 20, Outcome = line20, YPositions = new int[] { 1, 2, 2, 2, 1 }, UICoordinates = "0112223241" } }; //Populate the winning streaks list according to current winnings this.LineStreaks = new List <LineStreak>(); this.StakedLines = Lines.Where(x => x.Id <= betLines).ToList(); foreach (var l in StakedLines) { var s = checkWinnings(l); if (s.Streak > 0) { LineStreaks.Add(s); } } //Calculate the prizes for the lines this.LinePrizes = new List <LinePrize>(); foreach (var s in LineStreaks) { var winning = Prizes.Where(x => x.CardId == s.CardId && x.Streak == s.Streak).ToList(); if (winning.Count() > 0) { var w = winning.First(); this.LinePrizes.Add(new LinePrize { CardId = s.CardId, LineId = s.LineId, Streak = s.Streak, Multiplier = w.Multiplier }); } } //Calculate total winnings int totalWinnings = 0; int linebet = stake / betLines; foreach (var p in this.LinePrizes) { totalWinnings += linebet * p.Multiplier; } var winningsLines = this.Lines.Where(x => this.LinePrizes.Select(y => y.LineId).Contains(x.Id)).ToList(); //Create and return the outcome of the spin return(new SpinOutcome { LineWinnings = this.LinePrizes, Reels = this.GameReels, TotalWinnings = totalWinnings, WinningLines = winningsLines }); }
private void CreateDepartmentSheet(XLWorkbook document, string department) { try { var ws = document.Worksheets.Add(department); ws.Cell(1, 1).Value = "HNCDI(" + _year + "年度)项目奖励明细"; //奖项列别列表 List <string> departmentClassifies = _prizeses.Where(p => p.Department.Equals(department)) .Select(p => p.PrizeClassify) .Distinct() .ToList(); //奖项列表 var awards = _prizeses.Where(p => p.Department.Equals(department)) .Select( p => new { Classify = p.PrizeClassify, Project = p.Project, AwardName = p.AwardName }) .Distinct() .ToList(); var title = ws.Range(1, 1, 1, 2 + awards.Count() + departmentClassifies.Count()); int lastestCol = 2 + awards.Count() + departmentClassifies.Count(); for (int i = 1; i <= lastestCol; i++) { ws.Column(i).Width = 9; } title.Merge(); title.Style.Font.FontSize = 14; title.Style.Font.FontName = "宋体"; title.Style.Font.Bold = true; title.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; title.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; Dictionary <int, string> dictionaryClassify = new Dictionary <int, string>(); Dictionary <int, string> dictionaryProject = new Dictionary <int, string>(); Dictionary <int, string> dictionaryAward = new Dictionary <int, string>(); //员工列表 var employees = _prizeses.Where(p => p.Department.Equals(department)) .Select( p => new { Name = p.Name, AccountName = p.AccountName, Department = p.Department }) .Distinct() .ToList(); //空一行 //奖项类别行 ws.Cell(3, 1).Value = "姓名"; ws.Range(3, 1, 4, 1).Merge(); int currentCol = 3; foreach (string classify in departmentClassifies) { ws.Cell(3, currentCol).Value = classify; int currentClassifyCols = awards.Count(p => p.Classify.Equals(classify)); int lastCol = currentCol + currentClassifyCols; ws.Range(3, currentCol, 3, currentCol + currentClassifyCols).Merge(); for (; currentCol <= lastCol; currentCol++) { dictionaryClassify.Add(currentCol, classify); } } //项目行 ws.Cell(4, 2).Value = "总计"; ws.Range(4, 2, 5, 2).Merge(); ws.Range(4, 2, 5, 2).Style.Fill.BackgroundColor = XLColor.ForestGreen; for (currentCol = 3; currentCol <= lastestCol; currentCol++) { if (currentCol == 3) { ws.Cell(4, currentCol).Value = "小计"; ws.Range(4, currentCol, 5, currentCol).Merge(); ws.Range(4, currentCol, 5, currentCol).Style.Fill.BackgroundColor = XLColor.Yellow; continue; } else { if (dictionaryClassify[currentCol] != dictionaryClassify[currentCol - 1]) { ws.Cell(4, currentCol).Value = "小计"; ws.Range(4, currentCol, 5, currentCol).Merge(); ws.Range(4, currentCol, 5, currentCol).Style.Fill.BackgroundColor = XLColor.Yellow; continue; } } if (dictionaryClassify[currentCol] == "国家、省部级优秀勘察、设计、咨询奖") { string test = ""; } List <string> projects = awards.Where(p => p.Classify.Equals(dictionaryClassify[currentCol])) .Select(p => p.Project) .Distinct() .ToList(); foreach (string project in projects) { ws.Cell(4, currentCol).Value = project; ws.Cell(4, currentCol).Style.Alignment.WrapText = true; if (awards.Count(p => p.Classify.Equals(dictionaryClassify[currentCol]) && p.Project.Equals(project)) > 1) { int projectCols = awards.Count(p => p.Classify.Equals(dictionaryClassify[currentCol]) && p.Project.Equals(project)); ws.Range(4, currentCol, 4, currentCol + projectCols - 1).Merge(); for (int i = 1; i <= projectCols; i++) { dictionaryProject.Add(currentCol, project); currentCol++; } } else { dictionaryProject.Add(currentCol, project); currentCol++; } } currentCol--; } //奖项行 for (currentCol = 4; currentCol <= lastestCol; currentCol++) { if (currentCol > 4 && dictionaryClassify[currentCol] != dictionaryClassify[currentCol - 1]) { continue; } var col = currentCol; var projectAwards = awards.Where( p => p.Classify.Equals(dictionaryClassify[col]) && p.Project.Equals(dictionaryProject[col])); foreach (var award in projectAwards) { ws.Cell(5, currentCol).Value = award.AwardName; ws.Cell(5, currentCol).Style.Alignment.WrapText = true; dictionaryAward.Add(currentCol, award.AwardName); currentCol++; } currentCol--; } //填写个人数据 int currentRow = 6; foreach (var employee in employees) { ws.Cell(currentRow, 1).Value = employee.Name; //总计 List <Prizes> employeePrizeses = _prizeses.Where(p => p.AccountName.Equals(employee.AccountName) && p.Name.Equals(employee.Name)).ToList(); decimal employeeMoney = employeePrizeses.Sum(p => p.Prize) ?? 0; ws.Cell(currentRow, 2).Value = employeeMoney.ToString("N0"); for (currentCol = 3; currentCol <= lastestCol; currentCol++) { if (currentCol == 3) { employeeMoney = employeePrizeses.Where(p => p.PrizeClassify.Equals(dictionaryClassify[currentCol])) .Sum(p => p.Prize) ?? 0; ws.Cell(currentRow, currentCol).Value = employeeMoney == 0 ? "0" : employeeMoney.ToString("N0"); ws.Cell(currentRow, currentCol).Style.Fill.BackgroundColor = XLColor.Yellow; continue; } else { if (dictionaryClassify[currentCol] != dictionaryClassify[currentCol - 1]) { employeeMoney = employeePrizeses.Where(p => p.PrizeClassify.Equals(dictionaryClassify[currentCol])) .Sum(p => p.Prize) ?? 0; ws.Cell(currentRow, currentCol).Value = employeeMoney == 0 ? "0" : employeeMoney.ToString("N0"); ws.Cell(currentRow, currentCol).Style.Fill.BackgroundColor = XLColor.Yellow; continue; } } Prizes prize = employeePrizeses.FirstOrDefault( p => p.PrizeClassify.Equals(dictionaryClassify[currentCol]) && p.Project.Equals(dictionaryProject[currentCol]) && p.AwardName.Equals(dictionaryAward[currentCol])); if (prize?.Prize == null) { continue; } ws.Cell(currentRow, currentCol).Value = (Convert.ToDecimal(prize.Prize)).ToString("N0"); } currentRow++; } //合计行 ws.Cell(currentRow, 1).Value = "合计"; decimal departmentMoney = _prizeses.Where(p => p.Department.Equals(department)).Sum(p => p.Prize) ?? 0; ws.Cell(currentRow, 2).Value = departmentMoney == 0 ? "0" : departmentMoney.ToString("N0"); for (currentCol = 3; currentCol <= lastestCol; currentCol++) { if (currentCol == 3) { departmentMoney = _prizeses.Where( p => p.Department.Equals(department) && p.PrizeClassify.Equals(dictionaryClassify[currentCol])).Sum(p => p.Prize) ?? 0; ws.Cell(currentRow, currentCol).Value = departmentMoney == 0 ? "0" : departmentMoney.ToString("N0"); continue; } else { if (dictionaryClassify[currentCol] != dictionaryClassify[currentCol - 1]) { departmentMoney = _prizeses.Where( p => p.Department.Equals(department) && p.PrizeClassify.Equals(dictionaryClassify[currentCol])).Sum(p => p.Prize) ?? 0; ws.Cell(currentRow, currentCol).Value = departmentMoney == 0 ? "0" : departmentMoney.ToString("N0"); continue; } } departmentMoney = _prizeses.Where( p => p.Department.Equals(department) && p.PrizeClassify.Equals(dictionaryClassify[currentCol]) && p.Project.Equals(dictionaryProject[currentCol]) && p.AwardName.Equals(dictionaryAward[currentCol])).Sum(p => p.Prize) ?? 0; ws.Cell(currentRow, currentCol).Value = departmentMoney == 0 ? "0" : departmentMoney.ToString("N0"); } var lastestRow = ws.Range(currentRow, 2, currentRow, lastestCol); lastestRow.Style.Fill.BackgroundColor = XLColor.ForestGreen; ws.Range(4, 2, currentRow, 2).Style.Fill.BackgroundColor = XLColor.ForestGreen; ws.Range(currentRow, 3, currentRow, lastestCol).Style.Fill.BackgroundColor = XLColor.ForestGreen; var mainbody = ws.Range(3, 1, currentRow, lastestCol); mainbody.Style.Font.FontSize = 10; mainbody.Style.Font.FontName = "宋体"; mainbody.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; mainbody.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; mainbody.Style.Border.OutsideBorder = XLBorderStyleValues.Thick; mainbody.Style.Border.OutsideBorderColor = XLColor.Black; mainbody.Style.Border.InsideBorder = XLBorderStyleValues.Thin; mainbody.Style.Border.InsideBorderColor = XLColor.Black; ws.Columns().Width = 10; ws.Rows().AdjustToContents(); ws.Rows().Height = 15; ws.Row(1).Height = 20; ws.Row(4).Height = 80; ws.Row(5).Height = 80; //MessageBox.Show("导出部门 " + department + " 数据成功!"); } catch (Exception error) { MessageBox.Show(error.Message); } }
public virtual double GetAveragePrizeWorth() { return(Prizes.OfType <LuckyDipBankCheckPrize>().Average(e => e.Worth)); }
public double GetMinChance() { return(Prizes.Min(e => e.Chance)); }
public virtual int GetMaxPrizeWorth() { return(Prizes.OfType <LuckyDipBankCheckPrize>().Max(e => e.Worth)); }
public double GetAverageChance() { return(Prizes.Average(e => e.Chance)); }