public static ObservableCollection <SalesGrid> ShowAllSales()
        {
            using (AvalonContext context = new AvalonContext())
            {
                var sales = context.Sales.Select(s => new
                {
                    Id               = s.Id,
                    Date             = s.Date,
                    Customer         = s.Customer.Name,
                    BeersCount       = s.Beers.Select(b => b.Quantity).ToList(),
                    TotalSalePrice   = s.Beers.Select(b => new { BeerPrice = b.Beer.SalePrice, Quantity = b.Quantity }).ToList(),
                    TotalBoughtPrice = s.Beers.Select(b => new { BeerPrice = b.Beer.DistributorPrice, Quantity = b.Quantity }).ToList(),
                    Seller           = s.Seller.Username
                });
                ObservableCollection <SalesGrid> result = new ObservableCollection <SalesGrid>();

                foreach (var sale in sales)
                {
                    SalesGrid saleGrid = new SalesGrid
                    {
                        SaleId   = sale.Id,
                        Date     = sale.Date,
                        Customer = sale.Customer,
                        Seller   = sale.Seller
                    };

                    int     beerCount   = 0;
                    decimal salePrice   = 0;
                    decimal boughtPrice = 0;

                    foreach (var q in sale.BeersCount)
                    {
                        beerCount += q;
                    }

                    foreach (var b in sale.TotalSalePrice)
                    {
                        salePrice += (decimal)(b.BeerPrice * b.Quantity);
                    }

                    foreach (var b in sale.TotalBoughtPrice)
                    {
                        boughtPrice += (decimal)(b.BeerPrice * b.Quantity);
                    }
                    var profit = salePrice - boughtPrice;

                    saleGrid.TotalBoughtPrice = boughtPrice;
                    saleGrid.Profit           = profit;
                    saleGrid.TotalSalePrice   = salePrice;
                    saleGrid.BeersCount       = beerCount;
                    result.Add(saleGrid);
                }
                return(result);
            }
        }
Ejemplo n.º 2
0
        private void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            SalesGrid export = this.ListViewSales.SelectedItem as SalesGrid;

            if (export != null)
            {
                FileStream fs = new FileStream("..\\..\\ExportPdf" + "\\" + $"SaleId {export.SaleId} PDF Document.pdf", FileMode.Create);

                Document  document = new Document(PageSize.A6);
                PdfWriter writer   = PdfWriter.GetInstance(document, fs);
                document.Open();
                document.AddHeader("Date of sale", export.Date.ToString());
                document.AddAuthor(export.Seller);

                PdfContentByte        cb  = writer.DirectContent;
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance("..\\..\\Images\\avalon-mark.png");
                img.SetAbsolutePosition(180, 30);
                img.ScalePercent(40);
                cb.AddImage(img);

                Font calibri = new Font(Font.FontFamily.COURIER, 14, Font.ITALIC);

                iTextSharp.text.Paragraph p1 = new iTextSharp.text.Paragraph($"Data of sale: {export.Date.ToString()}", calibri);
                iTextSharp.text.Paragraph p2 = new iTextSharp.text.Paragraph($"Customer: {export.Customer}", calibri);
                iTextSharp.text.Paragraph p3 = new iTextSharp.text.Paragraph($"Number of beers: {export.BeersCount}", calibri);
                iTextSharp.text.Paragraph p4 = new iTextSharp.text.Paragraph($"Total Sale Price: {export.TotalSalePrice}$", calibri);
                iTextSharp.text.Paragraph p5 = new iTextSharp.text.Paragraph($"Total Bought Price: {export.TotalBoughtPrice}$", calibri);
                iTextSharp.text.Paragraph p6 = new iTextSharp.text.Paragraph($"Profit: {export.Profit}$", calibri);
                iTextSharp.text.Paragraph p7 = new iTextSharp.text.Paragraph($"Seller: {export.Seller}", calibri);

                document.Add(p1);
                document.Add(p2);
                document.Add(p3);
                document.Add(p4);
                document.Add(p5);
                document.Add(p6);
                document.Add(p7);

                document.Close();
                writer.Close();
                fs.Close();

                this.WarningLabel.Content    = $"Sale with id {export.SaleId} succesfully exported.";
                this.WarningLabel.Visibility = Visibility.Visible;
                ProcessStartInfo startInfo = new ProcessStartInfo("..\\..\\ExportPdf" + "\\" + $"SaleId {export.SaleId} PDF Document.pdf");
                Process.Start(startInfo);
            }
            else
            {
                this.WarningLabel.Content    = $"You should select sale first!";
                this.WarningLabel.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 3
0
    void FillGridView()
    {
        if (sqlcon.State == ConnectionState.Closed)
        {
            sqlcon.Open();
        }
        string           sales_grid_query = "Select SalesProductName, SalesCompanyName, SalesQuantity from Sales";
        MySqlCommand     cmd2             = new MySqlCommand(sales_grid_query, sqlcon);
        MySqlDataAdapter sda = new MySqlDataAdapter(cmd2);
        DataTable        dt  = new DataTable();

        sda.Fill(dt);
        sqlcon.Close();
        SalesGrid.DataSource = dt;
        SalesGrid.DataBind();
    }
Ejemplo n.º 4
0
    //protected void SaveSell()
    //{
    //    if (sqlcon.State == ConnectionState.Closed)
    //        sqlcon.Open();
    //    string insertquery = "insert into Sales (SalesProductName, SalesCompanyName, SalesQuantity) values ('"+TextBox2.Text+ "','"+TextBox2.Text+ "','"+txtQuantity2.Text+"')";
    //    SqlCommand cmd1 = new SqlCommand(insertquery, sqlcon);
    //    cmd1.ExecuteNonQuery();
    //    sqlcon.Close();
    //    //lblsuccessmassage.Text = "Saved Successfully";
    //   FillGridView();



    //}
    void FillGridView()
    {
        if (sqlcon.State == ConnectionState.Closed)
        {
            sqlcon.Open();
        }
        string         sales_grid_query = "Select * from Qutation";
        SqlCommand     cmd2             = new SqlCommand(sales_grid_query, sqlcon);
        SqlDataAdapter sda = new SqlDataAdapter(cmd2);
        DataTable      dt  = new DataTable();

        sda.Fill(dt);
        sqlcon.Close();
        SalesGrid.DataSource = dt;
        SalesGrid.DataBind();
    }
Ejemplo n.º 5
0
        /// <summary>
        /// контестное меню таблицы
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SalesMouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ContextMenu m = new ContextMenu();
                int         currentMouseOverRow = SalesGrid.HitTest(e.X, e.Y).RowIndex;

                if (currentMouseOverRow >= 0)
                {
                    m.MenuItems.Add(new MenuItem("Просмотр", new EventHandler(delegate(Object o, EventArgs a)
                    {
                        string id = (string)SalesGrid.Rows[currentMouseOverRow].Cells[0].Value;
                        var form  = new BuyerData(id);
                        form.ShowDialog();
                        RefreshGrid();
                    })));
                }

                m.Show(SalesGrid, new Point(e.X, e.Y));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// контестное меню таблицы
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SalesMouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ContextMenu m = new ContextMenu();
                int         currentMouseOverRow = SalesGrid.HitTest(e.X, e.Y).RowIndex;

                if (currentMouseOverRow >= 0)
                {
                    m.MenuItems.Add(new MenuItem("Просмотр", new EventHandler(delegate(Object o, EventArgs a)
                    {
                        int id   = (int)SalesGrid.Rows[currentMouseOverRow].Cells[0].Value;
                        var form = new SaleForm(id, Models.EditMode.View);
                        form.ShowDialog();
                        RefreshGrid();
                    })));
                    m.MenuItems.Add(new MenuItem("Редактировать", new EventHandler(delegate(Object o, EventArgs a)
                    {
                        int id   = (int)SalesGrid.Rows[currentMouseOverRow].Cells[0].Value;
                        var form = new SaleForm(id, Models.EditMode.Edit);
                        form.ShowDialog();
                        RefreshGrid();
                    })));
                    m.MenuItems.Add(new MenuItem("Удалить", new EventHandler(delegate(Object o, EventArgs a)
                    {
                        int id = (int)SalesGrid.Rows[currentMouseOverRow].Cells[0].Value;
                        if (MessageBox.Show("Вы точно хотите удалить этот элемент?", "Удалить?", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            var context = new ApplicationDbContext();
                            //TODO удаление продажи по ключу
                            context.Sales.Remove(context.Sales.FirstOrDefault(x => x.Id == id));
                            context.SaveChanges();
                        }
                        RefreshGrid();
                    })));
                }

                m.Show(SalesGrid, new Point(e.X, e.Y));
            }
        }
        private void initSalesChart()
        {
            string       cacheKey     = "0AD3A3DA-15F1-4f43-82A3-C0AC3262399D";
            CacheWrapper cacheWrapper = Cache[cacheKey] as CacheWrapper;
            Dictionary <string, object> salesData;

            if (cacheWrapper == null)
            {
                //GET SALES
                DateTime localNow   = LocaleHelper.LocalNow;
                DateTime last60Days = (new DateTime(localNow.Year, localNow.Month, localNow.Day, 0, 0, 0)).AddDays(-60);
                IList <ProductSummary> productSales = ReportDataSource.GetSalesByProduct(last60Days, DateTime.MaxValue, 8, 0, "TotalPrice DESC");
                if (productSales.Count > 0)
                {
                    SalesChart1.Series["Sales"].Points.Clear();
                    for (int i = 0; i < productSales.Count; i++)
                    {
                        int       roundedTotal = (int)Math.Round((double)productSales[i].TotalPrice, 0);
                        DataPoint point        = new DataPoint(SalesChart1.Series["Sales"]);
                        point.SetValueXY(productSales[i].Name, new object[] { roundedTotal });
                        SalesChart1.Series["Sales"].Points.Add(point);
                    }
                    SalesChart1.DataBind();

                    //BIND THE DATA GRID
                    SalesGrid.DataSource = productSales;
                    SalesGrid.DataBind();

                    //CACHE THE DATA
                    salesData = new Dictionary <string, object>();
                    salesData["DataSource"] = productSales;
                    cacheWrapper            = new CacheWrapper(salesData);
                    Cache.Remove(cacheKey);
                    Cache.Add(cacheKey, cacheWrapper, null, LocaleHelper.LocalNow.AddMinutes(5).AddSeconds(-1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
                }
                else
                {
                    //NO PRODUCTS HAVE BEEN SOLD YET
                    Control container = SalesChart1.Parent;
                    container.Controls.Clear();
                    Panel noViewsPanel = new Panel();
                    noViewsPanel.CssClass = "emptyData";
                    Label noViewsMessage = new Label();
                    noViewsMessage.Text = "No products have been sold yet.";
                    noViewsPanel.Controls.Add(noViewsMessage);
                    container.Controls.Add(noViewsPanel);

                    // REMOVE SALES DATA TAB
                    Tabs.Tabs[1].Visible = false;
                }
            }
            else
            {
                //USE CACHED VALUES
                salesData = (Dictionary <string, object>)cacheWrapper.CacheValue;
                IList <ProductSummary> productSales = (List <ProductSummary>)salesData["DataSource"];
                SalesChart1.Series["Sales"].Points.Clear();
                for (int i = 0; i < productSales.Count; i++)
                {
                    int       roundedTotal = (int)Math.Round((double)productSales[i].TotalPrice, 0);
                    DataPoint point        = new DataPoint(SalesChart1.Series["Sales"]);
                    point.SetValueXY(productSales[i].Name, new object[] { roundedTotal });
                    SalesChart1.Series["Sales"].Points.Add(point);
                }
                SalesChart1.DataBind();
                SalesGrid.DataSource = productSales;
                SalesGrid.DataBind();
            }
        }
Ejemplo n.º 8
0
 private void GridInEditModeEventHandler()
 {
     SalesGrid.CancelEdit();
     SalesGrid.CancelEdit();
 }