private void LoadGoodsByProductId(string id)
        {
            DepartmentStockCheckingEventArgs checkingEventArgs = new DepartmentStockCheckingEventArgs();
            checkingEventArgs.InputBarcode = id;
            EventUtility.fireEvent(LoadGoodsByProductIdEvent, this, checkingEventArgs);
            DepartmentStockView stock = checkingEventArgs.ScannedStockView;
            if (stock == null)
            {
                if(!checkingEventArgs.UnconfirmTempBarcode)
                MessageBox.Show("Không tìm thấy mã vạch trong kho", "Lỗi");
                return;
            }

            txtProductType.Text = stock.ProductMaster.ProductType.TypeName;
            txtProductName.Text = stock.ProductMaster.ProductName;
            txtStockQuantity.Text = stock.Quantity.ToString("##,##0");
            txtDescription.Text = stock.ProductMaster.Description;
            pictureBox1.ImageLocation = stock.ProductMaster.ImagePath;
            if(!CheckUtility.IsNullOrEmpty(pictureBox1.ImageLocation))
            {
                if (File.Exists(pictureBox1.ImageLocation))
                {
                    pictureBox1.Load();
                }
            }

            int stockDefIndex = -1;
            if (dgvStocks.CurrentCell != null)
            {
                stockDefIndex = dgvStocks.CurrentCell.RowIndex;
            }
            if (HasInStockDefectList(stock, stockList, out stockDefIndex))
            {
                if (stockDefIndex > -1 && stockDefIndex < stockList.Count)
                {
                    stockList[stockDefIndex].GoodQuantity += 1;
                    dgvStocks.CurrentCell = dgvStocks[5, stockDefIndex];
                }

            }
            else // create new stock defect row
            {
                    stockList.AddNew();
                    DepartmentStockView defect = checkingEventArgs.ScannedStockView;
                    stockList[stockList.Count - 1] = defect;

                    stockList[stockList.Count - 1].GoodQuantity = 1;
                    stockList[stockList.Count - 1].OldErrorQuantity = stockList[stockList.Count - 1].ErrorQuantity = 0;
                    stockList[stockList.Count - 1].OldDamageQuantity = stockList[stockList.Count - 1].DamageQuantity = 0;
                    stockList[stockList.Count - 1].OldLostQuantity = stockList[stockList.Count - 1].LostQuantity = 0;
                    stockList[stockList.Count - 1].OldUnconfirmQuantity = stockList[stockList.Count - 1].UnconfirmQuantity = 0;

                    txtStockQuantity.Text = stockList[stockList.Count - 1].Quantity.ToString("##,##0");
                    dgvStocks.CurrentCell = dgvStocks[5, stockList.Count - 1];
            }

            // update scanned type and product
            //UpdateScanType(stock);
            ScanType scannedType = GetFromScanList(scanTypesList, stock);
            if(scannedType == null)
            {
                // create new scantype and add to scanTypeList
                ScanType scanType = new ScanType();
                scanType.ScannedProducts = new ArrayList();
                scanType.UnscanProducts = new ArrayList();
                scanType.TypeName = stock.ProductMaster.ProductType.TypeName;
                DepartmentStockCheckingEventArgs eventArgs = new DepartmentStockCheckingEventArgs();
                eventArgs.ScannedType = scanType;
                EventUtility.fireEvent(LoadProductNamesInTypeEvent, this, eventArgs);
                scanTypesList.Add(eventArgs.ScannedType);
                scannedType = eventArgs.ScannedType;
            }

                IList unscanList = scannedType.UnscanProducts;
                string productName = stock.ProductMaster.ProductName + "_" + stock.ProductMaster.ProductColor.ColorName +
                                     "_" + stock.ProductMaster.ProductSize.SizeName;
                int scanIndex = GetIndexFromList(unscanList, productName);
                if (scanIndex >= 0)
                {
                    scannedType.ScannedProducts.Add(unscanList[scanIndex]);
                    unscanList.RemoveAt(scanIndex);
                }

            cboTypeList.Refresh();
            cboTypeList.Invalidate();
            cboTypeList_SelectedIndexChanged(null, null);

            bdsStockDefect.EndEdit();
            dgvStocks.Refresh();
            dgvStocks.Invalidate();
            txtBarcode.Text = "";
            txtBarcode.Focus();
        }
        private void UpdateScanType(DepartmentStockView stock)
        {
            ScanType scannedType = GetFromScanList(scanTypesList, stock);
            if (scannedType != null)
            {
                IList unscanList = scannedType.UnscanProducts;
                string productName = stock.ProductMaster.ProductName + "_" + stock.ProductMaster.ProductColor.ColorName +
                                     "_" + stock.ProductMaster.ProductSize.SizeName;
                int scanIndex = GetIndexFromList(unscanList, productName);
                if (scanIndex >= 0)
                {
                    scannedType.ScannedProducts.Add(unscanList[scanIndex]);
                    unscanList.RemoveAt(scanIndex);
                }
            }
            else
            {
                // create new scantype and add to scanTypeList
                ScanType scanType = new ScanType();
                scanType.ScannedProducts = new ArrayList();
                scanType.UnscanProducts = new ArrayList();
                scanType.TypeName = stock.ProductMaster.ProductType.TypeName;
                DepartmentStockCheckingEventArgs eventArgs = new DepartmentStockCheckingEventArgs();
                eventArgs.ScannedType = scanType;
                EventUtility.fireEvent(LoadProductNamesInTypeEvent, this, eventArgs);
                scanTypesList.Add(eventArgs.ScannedType);

            }
            cboTypeList.Refresh();
            cboTypeList.Invalidate();
            cboTypeList_SelectedIndexChanged(null, null);
        }
        private void cboTypeList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboTypeList.SelectedIndex < 0) return;
            ScanType scanType = (ScanType)cboTypeList.SelectedItem;
            if (previousScanType == null) previousScanType = scanType;
            if (!scanType.TypeName.Equals(previousScanType.TypeName))
            {
                lstProductList.Nodes.Clear();
            }
                IList scannedProducts = scanType.ScannedProducts;
                IList unscannedProducts = scanType.UnscanProducts;

                int count = 0;
                foreach (string scannedProduct in scannedProducts)
                {
                   lstProductList.Nodes.RemoveByKey(scannedProduct);
                }
                foreach (string unscannedProduct in unscannedProducts)
                {
                    if(!lstProductList.Nodes.ContainsKey(unscannedProduct))
                        lstProductList.Nodes.Add(unscannedProduct, unscannedProduct);
                    lstProductList.Nodes[unscannedProduct].ForeColor = Color.Red;
                }

            lstProductList.Refresh();
            lstProductList.Invalidate();
        }