Пример #1
0
        public AddProduct(ProductGroup productGroup, IProduct product = null)
        {
            InitializeComponent();

            _groups = ProductGroupRepository.Instance.GetAll();
            _currentProductGroup = _groups.Where(p => p.Id == productGroup.Id).FirstOrDefault();

            foreach (var item in _groups)
            {
                _cbbGroup.Items.Add(item.Name);
            }
            _cbbGroup.SelectedIndex = _groups.IndexOf(_currentProductGroup);

            _oldProduct = product;
            if (product != null)
            {
                _txtPrice.Text        = product.Price.ToCurrency();
                _txtPriceProvide.Text = product.PriceProvide.ToCurrency();
                _txtProductName.Text  = product.Name;
                _cbbGroup.Enabled     = false;
                _btnAdd.Text          = "Sửa";
            }
            else
            {
                _txtPrice.Text        = "0.000";
                _txtPriceProvide.Text = "0.000";
            }
        }
Пример #2
0
        public InputOrderDialog(long orderId = 0)
        {
            InitializeComponent();

            var props = ProductPropertiesRepository.Instance.GetAll();

            _allColors = props.Where(p => p.Type == ProductType.Color).ToList();
            _allSizes  = props.Where(p => p.Type == ProductType.Size).ToList();

            _currentListGroups = _cbbGroup.LoadGroupToCBB();

            if (_currentListGroups.Count > 0)
            {
                _currentProductGroup = _currentListGroups.FirstOrDefault();
            }
            LoadProductByGroup();

            if (_currentListProduct?.Count > 0)
            {
                _currentProduct = _currentListProduct.FirstOrDefault();
                LoadColorSizeByProduct();
            }

            _currentListModel       = new List <InputProductModel>();
            _txtItemPrice.Text      = "0.000";
            _txtTotalPrice.Text     = "0.000";
            _txtSum.Text            = "0.000";
            _txtSum.Enabled         = false;
            _txtSumQuantity.Enabled = false;
            _orderId = orderId;
            if (_orderId != 0)
            {
                LoadOldOrder();
            }
        }
Пример #3
0
 private void _cbbProduct_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (_currentListProduct != null && _currentListProduct.Count > 0)
     {
         var cbb = sender as System.Windows.Forms.ComboBox;
         _currentProduct = _currentListProduct.ElementAtOrDefault(cbb.SelectedIndex);
         LoadColorSizeByProduct();
     }
 }
Пример #4
0
        private void _cbbProduct_SelectedIndexChanged(object sender, EventArgs e)
        {
            var cbb = sender as System.Windows.Forms.ComboBox;

            if (_currentListProduct != null && cbb.SelectedIndex < _currentListProduct.Count)
            {
                _currentProduct = _currentListProduct.ElementAtOrDefault(cbb.SelectedIndex);
                LoadListProduct(_currentProduct);
            }
            ;
        }
Пример #5
0
 void LoadProductByGroup()
 {
     if (_currentProductGroup != null)
     {
         _currentListProduct = _cbbProduct.LoadProductToCBB(_currentProductGroup.Id);
         if (_currentListProduct?.Count > 0)
         {
             _currentProduct = _currentListProduct.FirstOrDefault();
             LoadColorSizeByProduct();
         }
     }
 }
Пример #6
0
        void LoadProductByGroup()
        {
            if (_currentProductGroup != null)
            {
                _currentListProduct = ProductRepository.Instance.GetProductsByGroup(_currentProductGroup.Id);
                _cbbProduct.LoadProductToCBB(_currentListProduct);

                if (_currentListProduct?.Count > 0)
                {
                    _currentProduct = _currentListProduct.FirstOrDefault();
                }
            }
        }
Пример #7
0
        void LoadListProduct(IProduct product, ProductProperties color = null)
        {
            if (product == null)
            {
                return;
            }
            List <ProductSale> products;

            if (color == null)
            {
                products = ProductSaleRepository.Instance.GetSellProduct(product.Id);
            }
            else
            {
                products = ProductSaleRepository.Instance.GetSellProduct(product.Id, color.Id);
            }

            _currentListProductModel = new List <InputProductModel>();

            foreach (var item in products)
            {
                _currentListProductModel.Add(new InputProductModel()
                {
                    Id          = item.Id,
                    ProductName = product.Name,
                    Quantity    = item.Quantity,
                    ItemPrice   = product.Price.ToCurrency(),
                    InputPrice  = item.Price,
                    ColorName   = color != null ? color.Name : _allColors.Where(p => p.Id == item.ColorId).FirstOrDefault()?.Name,
                    ColorId     = color != null ? color.Id : _allColors.Where(p => p.Id == item.ColorId).FirstOrDefault().Id,
                    SizeName    = _allSizes.Where(p => p.Id == item.SizeId).FirstOrDefault().Name,
                    SizeId      = _allSizes.Where(p => p.Id == item.SizeId).FirstOrDefault().Id,
                });
            }

            BindingList <InputProductModel> dataSource = new BindingList <InputProductModel>(_currentListProductModel);

            _gridProduct.DataSource = dataSource;
        }
Пример #8
0
 private void _btnAdd_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(_txtProductName.Text) && !string.IsNullOrWhiteSpace(_txtPrice.Text))
     {
         try
         {
             if (_oldProduct == null)
             {
                 var name         = _txtProductName.Text;
                 var groupId      = _currentProductGroup.Id;
                 var price        = _txtPrice.Text.ToPrice();
                 var priceProvide = _txtPriceProvide.Text.ToPrice();
                 var product      = new IProduct(groupId, name, price, priceProvide);
                 ProductRepository.Instance.Insert(product);
                 this.Close();
                 DialogResult = DialogResult.Yes;
             }
             else
             {
                 _oldProduct.Name         = _txtProductName.Text;
                 _oldProduct.Price        = _txtPrice.Text.ToPrice();
                 _oldProduct.PriceProvide = _txtPriceProvide.Text.ToPrice();
                 ProductRepository.Instance.Update(_oldProduct);
                 DialogResult = DialogResult.Yes;
             }
         }
         catch (Exception ex)
         {
             string            message = ex.ToString();
             string            caption = "Error";
             MessageBoxButtons buttons = MessageBoxButtons.OK;
             DialogResult      result;
             result = MessageBox.Show(message, caption, buttons);
         }
     }
 }
Пример #9
0
        private void gridView1_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e)
        {
            var productId = _gridProduct.GetIdFocus();

            _currentProduct = _currentListProduct.Where(p => p.Id == productId).FirstOrDefault();
        }