Beispiel #1
0
        private void DeleteDayBtn_Click(object sender, EventArgs e)
        {
            DateTime date   = dateTimePicker1.Value;
            SqlDay   sqlDay = new SqlDay();

            sqlDay.DeleteOneByDate(date.ToString("yyyy - MM - dd"));
        }
Beispiel #2
0
        private void StartCalcBtn_Click(object sender, EventArgs e)
        {
            List <string> categoryCommon = new List <string>();
            List <string> nameCommon     = new List <string>();

            SqlDay   sqlDay  = new SqlDay();
            DateTime beginDt = BeginDtp.Value;
            DateTime endDt   = EndDtp.Value;

            decimal totalMade         = 0;
            decimal totalSpent        = 0;
            int     totalProductsSold = 0;


            while (true)
            {
                DayModel day = new DayModel();
                day                = sqlDay.GetOneByDate(beginDt.ToString("yyyy - MM - dd"));
                totalMade         += day.TotalMade;
                totalSpent        += day.TotalSpent;
                totalProductsSold += day.SoldProductsCount;
                categoryCommon.Add(day.MostCommonCategory);
                nameCommon.Add(day.MostCommonProduct);

                if (beginDt.ToString("yyyy - MM - dd") == endDt.ToString("yyyy - MM - dd"))
                {
                    break;
                }

                beginDt = beginDt.AddDays(1);
            }

            var mostCommonCategory = categoryCommon
                                     .GroupBy(i => i)
                                     .OrderByDescending(grp => grp
                                                        .Count())
                                     .Select(grp => grp.Key)
                                     .First();
            var mostCommonName = nameCommon
                                 .GroupBy(i => i)
                                 .OrderByDescending(grp => grp
                                                    .Count())
                                 .Select(grp => grp.Key)
                                 .First();


            TotalMadeView.Text        = totalMade.ToString();
            TotalSpentView.Text       = totalSpent.ToString();
            ProductsSoldView.Text     = totalProductsSold.ToString();
            MostSoldProductView.Text  = mostCommonName;
            MostSoldCategoryView.Text = mostCommonCategory;
        }
Beispiel #3
0
        private async void FinalizeDayBtn_Click(object sender, EventArgs e)
        {
            bool dayExist = false;

            SqlDay sqlDay = new SqlDay();

            DayModel dayChek = sqlDay.GetOneByDate(day.Date.ToString("yyyy - MM - dd"));

            if (dayChek.Id != 0)
            {
                dayExist = true;
            }

            decimal totalEarned  = Convert.ToDecimal(TotalMadeView.Text);
            decimal totalSpend   = Convert.ToDecimal(TotalSpentView.Text);
            int     productsSold = dataGridView1.Rows.Count - 1;


            List <string> categoryCommon = new List <string>();
            List <string> nameCommon     = new List <string>();

            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                string category = dataGridView1.Rows[i].Cells["Category"].Value.ToString();
                categoryCommon.Add(category);
            }
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                string category = dataGridView1.Rows[i].Cells["Name"].Value.ToString();
                nameCommon.Add(category);
            }


            try
            {
                var mostCommonCategory = categoryCommon
                                         .GroupBy(i => i)
                                         .OrderByDescending(grp => grp
                                                            .Count())
                                         .Select(grp => grp.Key)
                                         .First();

                var mostCommonName = nameCommon
                                     .GroupBy(i => i)
                                     .OrderByDescending(grp => grp
                                                        .Count())
                                     .Select(grp => grp.Key)
                                     .First();


                MostSoldCategory.Text = mostCommonCategory;
                MostSoldProduct.Text  = mostCommonName;

                day.MostCommonCategory = mostCommonCategory;
                day.MostCommonProduct  = mostCommonName;
                day.SoldProductsCount  = productsSold;
                day.TotalMade          = totalEarned;
                day.TotalSpent         = totalSpend;


                progressBar1.Maximum = 100;
                progressBar1.Step    = 1;

                var progress = new Progress <int>(v =>
                {
                    progressBar1.Value = v;
                });


                await Task.Run(() => DoWork(progress));

                if (!dayExist)
                {
                    sqlDay.SaveDay(day);
                }
                else
                {
                    DayModel newDay = new DayModel();
                    newDay.Id                 = dayChek.Id;
                    newDay.TotalMade          = dayChek.TotalMade + day.TotalMade;
                    newDay.TotalSpent         = dayChek.TotalSpent + day.TotalSpent;
                    newDay.SoldProductsCount  = dayChek.SoldProductsCount + day.SoldProductsCount;
                    newDay.MostCommonProduct  = dayChek.MostCommonProduct;
                    newDay.MostCommonCategory = dayChek.MostCommonCategory;

                    sqlDay.Update(newDay);
                }
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Add products!");
            }
        }