Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        private void ViewDayBtn_Click(object sender, EventArgs e)
        {
            DateTime date = dateTimePicker1.Value;

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

            TotalSpentView.Text       = day.TotalSpent.ToString();
            TotalMadeView.Text        = day.TotalMade.ToString();
            ProductsSoldView.Text     = day.SoldProductsCount.ToString();
            MostSoldProductView.Text  = day.MostCommonProduct;
            MostSoldCategoryView.Text = day.MostCommonCategory;
            DateView.Text             = day.Date.ToString("yyyy - MM - dd");
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            DayModel day = sqlDay.GetOneByDate(DateTime.Now.ToString("yyyy - MM - dd"));

            if (day.Id == 0)
            {
                day.SoldProductsCount += order.ProductCount;
                day.TotalMade         += order.Cost;
                day.TotalSpent        += order.Spent;
                day.MostCommonProduct  = "could not determine";
                day.MostCommonCategory = "could not determine";
                sqlDay.SaveDay(day);
            }
            else
            {
                day.SoldProductsCount += order.ProductCount;
                day.TotalMade         += order.Cost;
                day.TotalSpent        += order.Spent;
                day.MostCommonProduct  = "could not determine";
                day.MostCommonCategory = "could not determine";
                sqlDay.Update(day);
            }
        }
Exemplo n.º 4
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!");
            }
        }