Exemple #1
0
 public void DelLabel(int id, string label)
 {
     var ctx = new ShopContext();
     var temp = ctx.Label.Where(x => x.Id == id).FirstOrDefault();
     temp.Name = label;
     ctx.SaveChanges();
 }
Exemple #2
0
 public void AddLabel(string label)
 {
     var ctx = new ShopContext();
     var temp = new Label();
     temp.Name = label;
     ctx.Label.Add(temp);
     ctx.SaveChanges();
 }
Exemple #3
0
 private void dtGrSale_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     txtHiddenId.Text = dtGrSale.Rows[e.RowIndex].Cells["Id"].Value.ToString();
     var ctx = new ShopContext();
     var temp = dtGrSale.Rows[e.RowIndex].Cells["Name"].Value.ToString();
     txtHiddenIdProduct.Text = ctx.Product.Where(x => x.Name == temp).FirstOrDefault().Id.ToString();
     txtHiddenCount.Text = dtGrSale.Rows[e.RowIndex].Cells["Count"].Value.ToString();
 }
Exemple #4
0
        public List<DataViewLabel> GetAllLabel()
        {
            var ctx = new ShopContext();
            var result = ctx.Label.Select(x => new DataViewLabel()
                                                    {
                                                        Id = x.Id,
                                                        NameLabel = x.Name

                                                    }).ToList();
            return result;
        }
Exemple #5
0
        public bool DeleteProduct(int id)
        {
            try
            {
                var ctx = new ShopContext();
                ctx.Product.Remove(ctx.Product.Where(x => x.Id == id).FirstOrDefault());
                ctx.SaveChanges();
                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
 public List<DataViewSaleProduct> GetAllSale()
 {
     var ctx = new ShopContext();
     var result = ctx.SaleProduct.Select(x => new DataViewSaleProduct()
                                                     {
                                                         Id = x.Id,
                                                         LabelName = x.Label.Name,
                                                         Name = x.Name,
                                                         Count = x.Count,
                                                         Price = x.Price,
                                                         Discount = x.Discount,
                                                         DateTimeSale = x.DateTimeSale
                                                     }).ToList();
     return result;
 }
Exemple #7
0
        public bool DelSale(int id, int count)
        {
            try
            {
                var ctx = new ShopContext();
                var temp = ctx.Product.Where(x => x.Id == id).FirstOrDefault();
                temp.Count += count;
                ctx.SaveChanges();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
Exemple #8
0
        public bool AddProduct(Product product, string label)
        {
            try
            {
                var ctx = new ShopContext();
                var temp = ctx.Label.Where(x => x.Name == label).SingleOrDefault();
                product.Label = temp;
                ctx.Product.Add(product);
                ctx.SaveChanges();
                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
        public bool AddSale(SaleProduct sale, string label)
        {
            try
            {
                var ctx = new ShopContext();
                var temp = ctx.Label.Where(x => x.Name == label).FirstOrDefault();
                sale.Label = temp;
                sale.Price = (sale.Price * sale.Count) - sale.Discount;
                ctx.SaleProduct.Add(sale);
                ctx.SaveChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }
Exemple #10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Добавить этот товар?", "Добавить",
                               MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {

                    return;
                }
                else
                {
                    var ctx = new ShopContext();
                    var helper = new Product()
                    {
                        Name = txtNameProduct.Text.ToString(),
                        Volume = Convert.ToInt32(txtVolumeProduct.Text),
                        Price = Convert.ToInt32(txtPriceProduct.Text),
                        Count = Convert.ToInt32(txtСountProduct.Text)
                    };
                    var temp = new ProductManager();
                    if (temp.AddProduct(helper, cmbLabel.Text.ToString()))
                    {
                        dtGridProducts.DataSource = temp.GetAllProduct();
                        txtCountProductGrid.Text = temp.GetAllProductCount(temp.GetAllProduct()).ToString();
                        txtAllPriceGrid.Text = temp.GetAllProductPrice(temp.GetAllProduct()).ToString();
                        MessageBox.Show("Товар добавлен!");
                    }
                    else
                    {
                        MessageBox.Show("Упс! Что-то пошло не так!");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Упс! Что-то пошло не так!");

            }
        }
Exemple #11
0
        private void cmbLabel_Click(object sender, EventArgs e)
        {
            try
            {
                var ctx = new ShopContext();
                txtHiddenIdLabel.Text = ctx.Label.Where(x => x.Name == cmbLabel.Text).FirstOrDefault().Id.ToString();

            }
            catch (Exception)
            {

                //throw;
            }
        }
Exemple #12
0
        public bool SaveProduct(Product product, string label)
        {
            try
            {
                var ctx = new ShopContext();
                var temp = ctx.Label.Where(x => x.Name == label).FirstOrDefault();
                var tempProduct = ctx.Product.Where(x => x.Id == product.Id).FirstOrDefault();
                tempProduct.Label = temp;
                tempProduct.Name = product.Name;
                tempProduct.Volume = product.Volume;
                tempProduct.Price = product.Price;
                tempProduct.Count = product.Count;
                ctx.SaveChanges();
                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
 public List<DataViewSaleProduct> GetSaleBetween(DateTime dateBegin, DateTime dateEnd)
 {
     var ctx = new ShopContext();
     var tempSale = ctx.SaleProduct.Where(x => (x.DateTimeSale >= dateBegin.Date)).ToList();
     var tempResult = tempSale.Where(x => x.DateTimeSale < dateEnd.Date.AddDays(1).Date).ToList();
     var result = tempResult.Select(x => new DataViewSaleProduct()
                                                 {
                                                     Id = x.Id,
                                                     LabelName = x.Label.Name,
                                                     Name = x.Name,
                                                     Price = x.Price,
                                                     Discount = x.Discount,
                                                     Count = x.Count,
                                                     DateTimeSale = x.DateTimeSale
                                                 }).ToList();
     return result;
 }
        public List<DataViewSaleProduct> GetSaleToday(DateTime date)
        {
            var ctx = new ShopContext();
            var temp = ctx.SaleProduct.Where(x => x.DateTimeSale > date.Date).ToList();
            var result = temp.Select(x => new DataViewSaleProduct()
                                                    {
                                                        Id = x.Id,
                                                        LabelName = x.Label.Name,
                                                        Name = x.Name,
                                                        Price = x.Price,
                                                        Discount = x.Discount,
                                                        Count = x.Count,
                                                        DateTimeSale = x.DateTimeSale
                                                    }).ToList();

            return result;
        }
Exemple #15
0
        private void dtGridProducts_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                txtHiddenId.Text = dtGridProducts.Rows[e.RowIndex].Cells["Id"].Value.ToString();
                txtNameProduct.Text = dtGridProducts.Rows[e.RowIndex].Cells["Name"].Value.ToString();
                txtVolumeProduct.Text = dtGridProducts.Rows[e.RowIndex].Cells["Volume"].Value.ToString();
                txtPriceProduct.Text = dtGridProducts.Rows[e.RowIndex].Cells["Price"].Value.ToString();
                txtСountProduct.Text = dtGridProducts.Rows[e.RowIndex].Cells["Count"].Value.ToString();
                var tempNameLabel = dtGridProducts.Rows[e.RowIndex].Cells["LabelName"].Value.ToString();
                var ctx = new ShopContext();
                cmbLabel.SelectedValue = ctx.Label.Where(x => x.Name == tempNameLabel).FirstOrDefault().Id;
                txtDiscount.Text = "0";
                txtHiddenIndex.Text = dtGridProducts.CurrentRow.Index.ToString();
            }
            catch (Exception)
            {

                MessageBox.Show("Но-но-но!!");
            }
        }
Exemple #16
0
        public List<DataViewProducts> GetProductLabel(string label)
        {
            var ctx = new ShopContext();
            var helper = ctx.Label.Where(x => x.Name == label).FirstOrDefault();
            var temp = ctx.Product.Where(m => m.Label.Name == helper.Name).ToList();

            var result = temp.Select(x => new DataViewProducts()
            {
                Id = x.Id,
                LabelName = x.Label.Name,
                Name = x.Name,
                Volume = x.Volume,
                Price = x.Price,
                Count = x.Count
            }).ToList();
            return result;
        }
Exemple #17
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Изменить этот товар?", "Изменить",
                               MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {

                    return;
                }
                else
                {
                    var ctx = new ShopContext();
                    var helper = new Product()
                    {
                        Id = Convert.ToInt32(txtHiddenId.Text),
                        Name = txtNameProduct.Text.ToString(),
                        Volume = Convert.ToInt32(txtVolumeProduct.Text),
                        Price = Convert.ToInt32(txtPriceProduct.Text),
                        Count = Convert.ToInt32(txtСountProduct.Text)
                    };
                    var temp = new ProductManager();
                    if (temp.SaveProduct(helper, cmbLabel.Text.ToString()))
                    {
                        dtGridProducts.DataSource = temp.GetAllProduct();
                        if (Convert.ToInt32(txtHiddenIndex.Text) < dtGridProducts.RowCount)
                        {
                            dtGridProducts.ClearSelection();
                            dtGridProducts.Rows[Convert.ToInt32(txtHiddenIndex.Text)].Selected = true;
                            dtGridProducts.FirstDisplayedScrollingRowIndex = Convert.ToInt32(txtHiddenIndex.Text);
                            dtGridProducts.Update();
                        }
                        txtCountProductGrid.Text = temp.GetAllProductCount(temp.GetAllProduct()).ToString();
                        txtAllPriceGrid.Text = temp.GetAllProductPrice(temp.GetAllProduct()).ToString();
                        MessageBox.Show("Товар изменен");
                    }
                    else
                    {
                        MessageBox.Show("Упс! Что-то пошло не так!");
                    }
                }
            }
            catch (Exception)
            {

                MessageBox.Show("Упс! Что-то пошло не так!");
            }
        }
Exemple #18
0
 public List<DataViewProducts> GetAllProduct()
 {
     var ctx = new ShopContext();
     var result = ctx.Product.Select(x => new DataViewProducts()
                                                 {
                                                     Id = x.Id,
                                                     LabelName = x.Label.Name,
                                                     Name = x.Name,
                                                     Volume = x.Volume,
                                                     Price = x.Price,
                                                     Count = x.Count
                                                 }).ToList();
     return result;
 }
Exemple #19
0
        public void ZeroCountProduct()
        {
            var ctx = new ShopContext();
            foreach (var item in ctx.Product)
            {
                item.Count = 0;

            }
            ctx.SaveChanges();
        }