Пример #1
0
        private void ReloadProduct()
        {
            showProducts = ProductManagement.SelectAllProducts();
            ProductDataGridView.DataSource  = showProducts;
            ProductDataGridView.MultiSelect = false;

            ProductDataGridView.Columns["Id_Product"].HeaderText     = "Id";
            ProductDataGridView.Columns["Code"].HeaderText           = "Código";
            ProductDataGridView.Columns["Brand"].HeaderText          = "Marca";
            ProductDataGridView.Columns["Category"].HeaderText       = "Categoría";
            ProductDataGridView.Columns["SubCategory"].HeaderText    = "Sub-Categoría";
            ProductDataGridView.Columns["Description"].HeaderText    = "Descripción";
            ProductDataGridView.Columns["Quantity_Stock"].HeaderText = "Stock";
            ProductDataGridView.Columns["Price"].HeaderText          = "Precio Detalle";
            ProductDataGridView.Columns["Lower_Price"].HeaderText    = "Precio Mayor";
            ProductDataGridView.Columns["Ivi"].HeaderText            = "Ivi";

            ProductDataGridView.Columns["Id_Product"].AutoSizeMode     = DataGridViewAutoSizeColumnMode.AllCells;
            ProductDataGridView.Columns["Code"].AutoSizeMode           = DataGridViewAutoSizeColumnMode.AllCells;
            ProductDataGridView.Columns["Brand"].AutoSizeMode          = DataGridViewAutoSizeColumnMode.AllCells;
            ProductDataGridView.Columns["Category"].AutoSizeMode       = DataGridViewAutoSizeColumnMode.AllCells;
            ProductDataGridView.Columns["SubCategory"].AutoSizeMode    = DataGridViewAutoSizeColumnMode.AllCells;
            ProductDataGridView.Columns["Description"].AutoSizeMode    = DataGridViewAutoSizeColumnMode.AllCells;
            ProductDataGridView.Columns["Quantity_Stock"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            ProductDataGridView.Columns["Price"].AutoSizeMode          = DataGridViewAutoSizeColumnMode.AllCells;
            ProductDataGridView.Columns["Lower_Price"].AutoSizeMode    = DataGridViewAutoSizeColumnMode.AllCells;
            ProductDataGridView.Columns["Ivi"].AutoSizeMode            = DataGridViewAutoSizeColumnMode.AllCells;

            ProductDataGridView.Columns["Id_Product"].Visible     = false;
            ProductDataGridView.Columns["Quantity_Stock"].Visible = false;
            ProductDataGridView.Columns["Price"].Visible          = false;
            ProductDataGridView.Columns["Lower_Price"].Visible    = false;
            ProductDataGridView.Columns["Image"].Visible          = false;
            ProductDataGridView.Columns["Ivi"].Visible            = false;
        }
Пример #2
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                string id = ProductDataGridView.CurrentRow.Cells[0].Value.ToString();

                if (!string.IsNullOrEmpty(codeTextBox.Text) && !string.IsNullOrEmpty(unityPriceTextBox.Text))
                {
                    if (MetroMessageBox.Show(this, $"¿Seguro que desea eliminar el Producto?", "Eliminar Prodcuto", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        if (ProductManagement.DeleteProductById(id))
                        {
                            FrmMain.Instance.ToolStripLabel.Text = "Producto eliminado de manera exitosa.";
                            CleanProduct();
                        }
                        else
                        {
                            MetroMessageBox.Show(this, $"Ha ocurrido un error al eliminar el Producto.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MetroMessageBox.Show(this, "Debe seleccionar un Producto para poder eliminarlo.", "Campo vacío", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                FrmMain.Instance.ToolStripLabel.Text = "Error: " + ex.Message;
            }
        }
        public IActionResult CreateProduct(IFormCollection valueCollection)
        {
            string code        = valueCollection["i_code"];
            string name        = valueCollection["i_name"];
            string description = valueCollection["i_description"];
            string priceStr    = valueCollection["i_price"];

            try
            {
                decimal price          = 0;
                bool    priceToDecimal = Decimal.TryParse(priceStr, out price);

                ProductManagement  pm    = new ProductManagement();
                CreateProductModel model = new CreateProductModel()
                {
                    Code        = code,
                    Name        = name,
                    Description = description,
                    Price       = price
                };
                CreateProductResultModel result = pm.Create(model);
            }
            catch (Exception ex)
            {
                return(new ContentResult()
                {
                    Content = "An error has occurred: " + Environment.NewLine + ex.Message
                });
            }

            return(RedirectToAction("Search"));
        }
Пример #4
0
        // GET: Product/Edit/5
        public ActionResult Edit(int id)
        {
            ProductManagement productManagement = new ProductManagement();
            ProductDO         modelData         = productManagement.GetProductByID(id);

            ProductEditViewModel model = new ProductEditViewModel();

            model.Product_ID   = modelData.Product_ID;
            model.Product_Name = modelData.Product_Name;
            model.Price        = modelData.Price;

            // model.Category_ID = modelData.Category_ID;
            model.Categories = GetCategoryDropdownData();

            model.SubCategory_ID = modelData.SubCategory_ID;
            model.SubCategories  = getSubCategoryDropDownData();

            model.Brand_ID = modelData.Brand_ID;
            model.Brands   = getBrandDropDownData();

            model.Size          = modelData.Size;
            model.Color         = modelData.Color;
            model.Product_Image = modelData.Product_Image;
            model.Description   = modelData.Description;
            model.Quantity      = modelData.Quantity;

            TempData["ImagesPath"] = model.Product_Image;

            return(View(model));
        }
Пример #5
0
        public Product PostProduct(ProductOption prodOpt)
        {
            using CrmDbContext db = new CrmDbContext();
            ProductManagement prodMangr = new ProductManagement(db);

            return(prodMangr.CreateProduct(prodOpt));
        }
Пример #6
0
 public ShopListPresentationModel(CategoryManagement productTypeManagement, ProductManagement productManagement)
 {
     this._productTypeManagement = productTypeManagement;
     _productManagement          = productManagement;
     _cart    = new AddToCart();
     RowCount = 0;
 }
Пример #7
0
        public List <Product> GetAllProducts(int id)
        {
            using CrmDbContext db = new CrmDbContext();
            ProductManagement prodMangr = new ProductManagement(db);

            return(prodMangr.GetAllProducts());
        }
Пример #8
0
        public bool HardDeleteProduct(int id)
        {
            using CrmDbContext db = new CrmDbContext();
            ProductManagement prodMangr = new ProductManagement(db);

            return(prodMangr.DeleteProductById(id));
        }
Пример #9
0
        public List <Product> GetAllProduct()
        {
            using CrmDbContext db = new CrmDbContext();
            ProductManagement prodMangr = new ProductManagement(db);

            return(db.Products.ToList());
        }
Пример #10
0
        static void Main()
        {
            ProductOption productOption = new ProductOption
            {
                Name     = "iPhone",
                Price    = 500,
                Quantity = 4
            };

            using CrmDbContext db = new CrmDbContext();
            ProductManagement productManager = new ProductManagement(db);

            Product product = productManager.CreateProduct(productOption);

            Console.WriteLine($"Id= {product.Id} Price= {product.Price} Quantityy= {product.Quantity}");

            //CustomerOption custOpt = new CustomerOption
            //{
            //    FirstName = "Maria",
            //    LastName = "Pentagiotissa",
            //    Address = "Athens",
            //    Email = "*****@*****.**",
            //};

            //using CrmDbContext db = new CrmDbContext();
            //CustomerManagement custManager = new CustomerManagement(db);

            ////testing the creation of a customer
            //Customer customer = custManager.CreateCustomer(custOpt);
            //Console.WriteLine($"Id= {customer.Id} Address= {customer.Address}");

            ////testing reading a customer
            //Customer cx = custManager.FindCustomerById(2);
            //Console.WriteLine($"Id= {cx.Id} Address= {cx.Address}");

            ////testing updating
            //CustomerOption custChangeAdress = new CustomerOption
            //{
            //    Address = "Lamia"
            //};

            //Customer c2 = custManager.Update(custChangeAdress, 2);
            //Console.WriteLine($"Id= {cx.Id} Address= {cx.Address}");

            ////testing deletion

            //bool result = custManager.DeleteCustomerById(2);
            //Console.WriteLine($"Result = {result}");
            //Customer cx2 = custManager.FindCustomerById(2);
            //if (cx2 != null)
            //{
            //    Console.WriteLine(
            //    $"Id= {cx2.Id} Name= {cx2.FirstName} Address= {cx2.Address}");

            //}
            //else
            //{
            //    Console.WriteLine("not found");
            //}
        }
        public IActionResult Detail(string code)
        {
            ProductManagement pm      = new ProductManagement();
            ProductModel      product = pm.Get(code);

            return(View(product));
        }
Пример #12
0
        private void codeTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    string       productCode  = codeTextBox.Text;
                    ProductModel productModel = ProductManagement.SelectProductByCode(productCode);

                    if (!SearchDuplicates(productCode))
                    {
                        SubCategoryModel subCategoryModel = SubCategoryManagement.SelectSubCategoryById(productModel.IdSubCategory.ToString());
                        string           tax   = "0,13";
                        decimal          taxes = (productModel.NormalPrice * decimal.Parse(tax));
                        dgvAparts.Rows.Add(productModel.IdProduct.ToString(), productModel.Code, productModel.Description, subCategoryModel.Name, 1, productModel.NormalPrice, productModel.NormalPrice, 0, taxes.ToString("##,##0.00"));
                    }
                    codeTextBox.Focus();
                    codeTextBox.Text = string.Empty;
                    setInformation();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #13
0
        public Product getProduct(int id)
        {
            using CrmDbContext db = new CrmDbContext();
            ProductManagement prodMangr = new ProductManagement(db);

            return(prodMangr.FindProductById(id));
        }
Пример #14
0
        public ActionResult AddToCart(string code, int quantity)
        {
            InitialiseCart();
            var     cart    = Session["Cart"] as List <CartItem>;
            Product product = null;
            var     item    = cart.SingleOrDefault(x => x.Code == code);

            if (item != null)
            {
                item.Quantity += quantity;
            }
            else
            {
                product = ProductManagement.GetProduct(code);
                cart.Add(new CartItem
                {
                    Id        = product.Id,
                    Quantity  = quantity,
                    Name      = product.Name,
                    Code      = product.Code,
                    UnitPrice = product.Price
                });
                Session["Cart"] = cart;
            }
            return(Json(cart, JsonRequestBehavior.AllowGet));
        }
 public AdminProductController()
 {
     categoryManagement = new CategoryManagement();
     storageManagement  = new StorageManagement();
     cargoManagement    = new CargoManagement();
     productManagement  = new ProductManagement();
 }
Пример #16
0
        private static ShoppingCart ShoppingCartInit()
        {
            var StoreList = new Dictionary <int, Store>();

            StoreList.Add(1, new Store(1, "OO商店"));
            StoreList.Add(2, new Store(2, "XX商店"));
            var StoreManagement = new StoreManagement(StoreList);

            var productSampleList = new Dictionary <int, Product>();

            productSampleList.Add(1, new Product(1, "二手蘋果手機", 8700, 1));
            productSampleList.Add(2, new Product(2, "C# cookbook", 568, 1));
            productSampleList.Add(3, new Product(3, "HP 筆電\t", 16888, 1));
            productSampleList.Add(4, new Product(4, "哈利波特影集", 2250, 2));
            productSampleList.Add(5, new Product(5, "無間道三部曲", 1090, 2));
            var ProductManagement = new ProductManagement(productSampleList);
            var ShipmentList      = new Dictionary <int, Shipment>();

            ShipmentList.Add(1, new Shipment(1, "宅急便", 60));
            ShipmentList.Add(2, new Shipment(2, "郵局", 40));
            ShipmentList.Add(3, new Shipment(3, "超商店到店", 50));
            var shipmentManagement = new ShipmentManagement(ShipmentList);
            var shoppingCart       = new ShoppingCart(productSampleList, StoreList, ShipmentList, StoreManagement.GetStoreById, ProductManagement.GetProductById);

            return(shoppingCart);
        }
Пример #17
0
        public Product PutProduct(int id, ProductOption prodOpt)
        {
            using CrmDbContext db = new CrmDbContext();
            ProductManagement prodMangr = new ProductManagement(db);

            return(prodMangr.Update(prodOpt, id));
        }
Пример #18
0
        public ActionResult Paging(int num)
        {
            var list       = ProductManagement.GetProductsIncludeHidden();
            var categories = CategoryManagement.GetAllCategory();
            var products   = ApplyPaging(list, num).Select(x => ConvertToProductDTO(x, categories));

            return(Json(products, JsonRequestBehavior.AllowGet));
        }
Пример #19
0
 public void Update(Customer customer)
 {
     using (ProductManagement entitiesManagement = new ProductManagement())
     {
         entitiesManagement.Customers.Update(customer);
         entitiesManagement.SaveChanges();
     }
 }
Пример #20
0
 private void barButtonItem6_ItemClick(object sender, ItemClickEventArgs e)
 {
     using (var form = new ProductManagement())
     {
         form.ShowDialog();
         RefreshData();
     }
 }
        // DELETE api/product/id
        public IHttpActionResult Delete(Product product)
        {
            var productoManager = new ProductManagement();

            productoManager.Delete(product);
            apiResponse = new ApiResponse();
            return(Ok(apiResponse));
        }
Пример #22
0
 public void Update(Product product)
 {
     using (ProductManagement entitiesManagement = new ProductManagement())
     {
         entitiesManagement.Products.Update(product);
         entitiesManagement.SaveChanges();
     }
 }
Пример #23
0
        public void GetProducts_WhenSuccessful_ReturnProductList()
        {
            productManagement = new ProductManagement(_unitOfWorkMock.Object);

            IEnumerable <ProductDto> productObjectList = productManagement.GetProducts(1).GetAwaiter().GetResult();

            Assert.AreEqual("WASSILY CHAIR", productObjectList.ToList()[0].ProductName);
        }
        public void CreateProductException()
        {
            ProductManagement productManagement = new ProductManagement();
            List <Product>    products          = new List <Product>();
            var exception = Assert.Throws <System.Exception>(() => productManagement.CreateProduct(products));

            Assert.Equal("Product details not available", exception.Message);
        }
        public async Task Should_Return__Exception_When_ProductsNotAvailable()
        {
            var productManagement = new ProductManagement(_unitOfWorkMock.Object);

            _productRepositoryMock.Setup(x => x.GetProducts(1)).Returns((Task <IEnumerable <ProductDto> >)null);
            _unitOfWorkMock.Setup(m => m.ProductRepository).Returns(_productRepositoryMock.Object);
            await Assert.ThrowsAsync <NullReferenceException>(async() => await productManagement.GetProducts(1).ConfigureAwait(false));
        }
Пример #26
0
        static void Main(string[] args)
        {
            ProductManagement  ProductManagement;
            ShipmentManagement shipmentManagement;
            ShoppingCart       shoppingCart;

            SystemInit(out ProductManagement, out shipmentManagement, out shoppingCart);

            shoppingCart.PrintIntroduction();

            string selectedProductId = null;

            while (selectedProductId != "0")
            {
                Console.Write("請選擇商品代號:\n");

                selectedProductId = Console.ReadLine();
                if (selectedProductId == "0")
                {
                    break;
                }

                var productId = selectedProductId.TryParseInt() ?? -1;
                var product   = ProductManagement.GetProductById(productId);
                if (product != null)
                {
                    var selectedProductCount = -1;
                    var selectedShipment     = -1;
                    while (selectedProductCount < 0)
                    {
                        Console.Write("請選擇數量\n");
                        selectedProductCount = Console.ReadLine().TryParseInt() ?? -1;

                        Console.Write("請選擇物流\n");
                        shoppingCart.PrintAllShipment();

                        selectedShipment = Console.ReadLine().TryParseInt() ?? -1;
                        var shipment = shipmentManagement.GetShipmentById(selectedShipment);
                        if (shipment != null)
                        {
                            shoppingCart.AddCartItem(selectedShipment, productId, selectedProductCount);
                        }
                        else
                        {
                            Console.Write("格式錯誤,重新輸入\n");
                        }
                    }
                    shoppingCart.PrintAllShoppingItem();
                }
                else
                {
                    Console.Write("查無商品,重新輸入\n");
                }
            }

            Console.Write("按下ENTER結束\n");
            Console.ReadLine();
        }
Пример #27
0
        private void btnTTDonHang_Click(object sender, EventArgs e)
        {
            ProductManagement product = new ProductManagement(dgvDonHang.SelectedRows[0].Cells["MaVanDon"].Value.ToString());

            this.Hide();
            product.ShowDialog();
            this.Show();
            LoadListDonHang();
        }
Пример #28
0
 public Managment(string email)
 {
     InitializeComponent();
     //cbDepart.DataSource = Enum.GetValues(typeof(Department));
     managment          = new BazaarManagment();
     ProductManagment   = new ProductManagement();
     conn               = new ConnectionClass();
     this.current_email = email;
 }
Пример #29
0
 public void Delete(int id)
 {
     using (ProductManagement entitiesManagement = new ProductManagement())
     {
         Product productFirst = entitiesManagement.Products.First(p => p.Id == id);
         entitiesManagement.Products.Remove(productFirst);
         entitiesManagement.SaveChanges();
     }
 }
Пример #30
0
 public Product GetById(int id)
 {
     using (ProductManagement entitiesManagement = new ProductManagement())
     {
         Product productFirst = entitiesManagement.Products.First(p => p.Id == id);
         Console.WriteLine(productFirst);
         return(productFirst);
     }
 }