示例#1
0
        private static Combo extractData(SQLiteDataReader reader)
        {
            Combo combo = new Combo();

            combo.Id       = reader.GetInt32(0);
            combo.Name     = reader.GetString(1);
            combo.Discount = reader.GetInt32(2);

            string        detailsQuery   = $"SELECT * FROM {subTable} WHERE comboId = @comboId";
            SQLiteCommand detailsCommand = new SQLiteCommand(detailsQuery, DAL.Conn);

            detailsCommand.Parameters.AddWithValue("@comboId", combo.Id);

            SQLiteDataReader detailsReader = detailsCommand.ExecuteReader();

            while (detailsReader.HasRows)
            {
                while (detailsReader.Read())
                {
                    ComboDetails details = new ComboDetails();
                    details.Combo   = combo;
                    details.Product = ProductDAL.GetById(detailsReader.GetInt32(1));
                    details.Amount  = detailsReader.GetInt32(2);

                    combo.Details.Add(details);
                }

                detailsReader.NextResult();
            }

            return(combo);
        }
示例#2
0
        protected ComboDetails CalculateCombo(Score score)
        {
            var combo = new ComboDetails();

            combo.Tap  = score.Notes.Taps.Count / 2;
            combo.DTap = score.Notes.DTaps.Count;
            combo.HTap = score.Notes.HTaps.Count;
            combo.LTap = score.Notes.LTaps.Count;

            combo.Trace  = score.Notes.Traces.Count;
            combo.DTrace = score.Notes.DTraces.Count;
            combo.HTrace = score.Notes.HTraces.Count;
            combo.LTrace = score.Notes.LTraces.Count;

            combo.Hold  = score.Notes.Holds.Count;
            combo.DHold = score.Notes.DHolds.Count;
            combo.HHold = score.Notes.HHolds.Count;
            combo.LHold = score.Notes.LHolds.Count;

            return(combo);
        }
示例#3
0
        private async void btnUpdate_Click(object sender, EventArgs e)
        {
            List <Product> rows_product = new List <Product>();
            var            x            = dataGridViewProduct.Rows.Count;

            for (int rows = 0; rows < dataGridViewProduct.Rows.Count - 1; rows++)
            {
                Product product = new Product()
                {
                    Id   = Int32.Parse(dataGridViewProduct.Rows[rows].Cells[0].Value.ToString()),
                    Name = dataGridViewProduct.Rows[rows].Cells[1].Value.ToString()
                };
                rows_product.Add(product);
            }
            List <ComboDetails> listComboDetails = new List <ComboDetails>();

            foreach (var item in rows_product)
            {
                ComboDetails comboDetails = new ComboDetails()
                {
                    Product = new Product()
                    {
                        Id = item.Id
                    }
                };

                listComboDetails.Add(comboDetails);
            }
            Combo combo = new Combo()
            {
                Id       = Int32.Parse(textComboId.Text),
                Name     = textComboName.Text,
                Discount = Int32.Parse(textDiscount.Text),
                Details  = listComboDetails
            };
            await ApiHandler.client.PutAsJsonAsync("combo", combo);

            LoadDataCombo();
        }
示例#4
0
        protected ComboDetails CalculateCombo(Score score)
        {
            var combo = new ComboDetails();

            combo.Tap += new int[]
            {
                score.Notes.Taps.Count,
                score.Notes.ExTaps.Count,
                score.Notes.Damages.Count,
                score.Notes.Holds.Count,
                score.Notes.Slides.Count
            }.Sum();

            combo.Flick += score.Notes.Flicks.Count;
            combo.Air   += score.Notes.Airs.Count;

            int barTick   = 4 * score.TicksPerBeat;
            var bpmEvents = score.Events.BPMChangeEvents.OrderBy(p => p.Tick).ToList();
            var airList   = new HashSet <IAirable>(score.Notes.Airs.Select(p => p.ParentNote));
            Func <int, decimal> getHeadBpmAt = tick => (bpmEvents.LastOrDefault(p => p.Tick <= tick) ?? bpmEvents[0]).BPM;
            Func <int, decimal> getTailBpmAt = tick => (bpmEvents.LastOrDefault(p => p.Tick < tick) ?? bpmEvents[0]).BPM;
            Func <decimal, int> comboDivider = bpm => bpm < 120 ? 16 : (bpm < 240 ? 8 : 4);

            // コンボとしてカウントされるstartTickからのオフセットを求める
            Func <int, IEnumerable <int>, List <int> > calcComboTicks = (startTick, stepTicks) =>
            {
                var tickList        = new List <int>();
                var sortedStepTicks = stepTicks.OrderBy(p => p).ToList();
                int duration        = sortedStepTicks[sortedStepTicks.Count - 1];
                int head            = 0;
                int bpmIndex        = 0;
                int stepIndex       = 0;

                while (head < duration)
                {
                    while (bpmIndex + 1 < bpmEvents.Count && startTick + head >= bpmEvents[bpmIndex + 1].Tick)
                    {
                        bpmIndex++;
                    }
                    int interval = barTick / comboDivider(bpmEvents[bpmIndex].BPM);
                    int diff     = Math.Min(interval, sortedStepTicks[stepIndex] - head);
                    head += diff;
                    tickList.Add(head);
                    if (head == sortedStepTicks[stepIndex])
                    {
                        stepIndex++;
                    }
                }

                return(tickList);
            };
            Func <IEnumerable <int>, int, int, IEnumerable <int> > removeLostTicks = (ticks, startTick, duration) =>
            {
                int interval = barTick / comboDivider(getTailBpmAt(startTick + duration));
                return(ticks.Where(p => p <= duration - interval).ToList());
            };

            foreach (var hold in score.Notes.Holds)
            {
                var tickList = new HashSet <int>(calcComboTicks(hold.StartTick, new int[] { hold.Duration }));

                if (airList.Contains(hold.EndNote))
                {
                    combo.Hold += removeLostTicks(tickList, hold.StartTick, hold.Duration).Count();
                }
                else
                {
                    combo.Hold += tickList.Count;
                }
            }

            foreach (var slide in score.Notes.Slides)
            {
                var tickList = new HashSet <int>(calcComboTicks(slide.StartTick, slide.StepNotes.Where(p => p.IsVisible).Select(p => p.TickOffset)));

                if (airList.Contains(slide.StepNotes.OrderByDescending(p => p.TickOffset).First()))
                {
                    combo.Slide += removeLostTicks(tickList, slide.StartTick, slide.GetDuration()).Count();
                }
                else
                {
                    combo.Slide += tickList.Count;
                }
            }

            foreach (var airAction in score.Notes.AirActions)
            {
                var lostSections = airAction.ActionNotes.Select(p => p.Offset).Concat(new[] { 0 }).Select(p =>
                {
                    int interval = barTick / comboDivider(getHeadBpmAt(airAction.StartTick + p));
                    return(Tuple.Create(p, interval));
                }).ToList();

                var validTicks = calcComboTicks(airAction.StartTick, airAction.ActionNotes.Select(p => p.Offset))
                                 .Where(p => lostSections.All(q => p <= q.Item1 || p > q.Item1 + q.Item2));

                combo.Air += new HashSet <int>(validTicks).Count;
            }

            return(combo);
        }