private void DoPreBarCodePrinting(
            float currentPrintedQty,
            float requestedQty,
            float totalQty,
            bool requestPrinting,
            bool setPrintingStatus)
        {
            if (dgvProduct.CurrentRow == null)
                return;

            if (requestPrinting)
            {
                currentPrintedQty += requestedQty;
                var barCode = new BarCode();
                for (var qtyCounter = 0; qtyCounter < requestedQty; qtyCounter++)
                {
                    barCode =
                        new BarCode
                        {
                            BarCodeValue = _productList[dgvProduct.CurrentRow.Index].ProductCode,
                            DisplayStr =
                                _productList[dgvProduct.CurrentRow.Index].CategoryStr,
                            AdditionalStr = (currentPrintedQty.ToString("N0") + " / " + totalQty.ToString("N0")),
                            UnitPrice = "$ " + (_productList[dgvProduct.CurrentRow.Index]).UnitPriceOut.ToString("N", AppContext.CultureInfo),
                            Description = _productList[dgvProduct.CurrentRow.Index].Description
                        };

                    var foreignCode = _productList[dgvProduct.CurrentRow.Index].ForeignCode;
                    if (!string.IsNullOrEmpty(foreignCode))
                        barCode.DisplayStr += " (" + foreignCode + ")";

                    if (_barCodeList.IndexOf(barCode) == -1)
                        _barCodeList.Add(barCode);
                }

                var previousPrintedQty = currentPrintedQty - requestedQty;
                var barCodeValue = _productList[dgvProduct.CurrentRow.Index].ProductCode;
                for (var counter = 0; (counter < _barCodeList.Count) && (previousPrintedQty != 0); counter++)
                {
                    if (barCodeValue != _barCodeList[counter].BarCodeValue)
                        continue;

                    _barCodeList[counter] = barCode;
                    previousPrintedQty -= 1;
                }
            }
            else
            {
                currentPrintedQty -= requestedQty;
                var tmpQty = requestedQty;
                for (var counter = 0; counter < _barCodeList.Count; counter++)
                {
                    if (dgvProduct.CurrentRow.Cells["ProductCode"].Value.ToString() !=
                        _barCodeList[counter].BarCodeValue)
                        continue;
                    if (tmpQty != 0)
                    {
                        _barCodeList.RemoveAt(counter);
                        tmpQty -= 1;
                        counter -= 1;
                    }
                    else if (currentPrintedQty != 0)
                        _barCodeList[counter].AdditionalStr =
                            currentPrintedQty.ToString("N0") +
                            " / " +
                            totalQty.ToString("N0");
                    else
                        _barCodeList[counter].AdditionalStr = string.Empty;
                }
            }

            if (currentPrintedQty != 0)
                _productList[dgvProduct.CurrentRow.Index].PublicQty =
                    currentPrintedQty.ToString("N0") +
                    " / " +
                    totalQty.ToString("N0");
            else
                _productList[dgvProduct.CurrentRow.Index].PublicQty = string.Empty;

            if (setPrintingStatus)
                _productList[dgvProduct.CurrentRow.Index].PrintCheck = requestPrinting;
            rdbPrintSelected.Text = string.Format(
                "{0}{1}{2}",
                "កូដជ្រើសរើស (", _barCodeList.Count.ToString("N0", AppContext.CultureInfo), ")");
            dgvProduct.Refresh();
        }
        private void UpdateSelectedProduct(Product curProduct, float preQtyInStock)
        {
            if (curProduct == null)
                throw new ArgumentNullException("curProduct", Resources.MsgInvalidProduct);

            try
            {
                bool isIncremented;
                if ((curProduct.QtyInStock - preQtyInStock) < 0)
                {
                    isIncremented = false;
                    for (var counter = 0; counter < _barCodeList.Count; counter++)
                    {
                        if (curProduct.ProductCode != _barCodeList[counter].BarCodeValue)
                            continue;

                        if (_barCodeList.Count >= preQtyInStock)
                            _barCodeList.RemoveAt(counter);

                        counter -= 1;
                        preQtyInStock -= 1;
                        if ((curProduct.QtyInStock - preQtyInStock) == 0)
                            break;
                    }
                }
                else
                {
                    isIncremented = true;
                    if (String.IsNullOrEmpty(curProduct.PublicQty))
                        return;

                    for (var counter = 0; counter < (curProduct.QtyInStock - preQtyInStock); counter++)
                    {
                        var barCode =
                            new BarCode
                            {
                                BarCodeValue = curProduct.ProductCode,
                                DisplayStr = curProduct.CategoryStr,
                                UnitPrice = "$ " + curProduct.UnitPriceOut.ToString("N", AppContext.CultureInfo)
                            };

                        if (string.IsNullOrEmpty(curProduct.ForeignCode))
                            barCode.DisplayStr += " (" + curProduct.ForeignCode + ")";
                        _barCodeList.Add(barCode);
                    }
                }

                if (!String.IsNullOrEmpty(curProduct.PublicQty))
                {
                    var tmpQty = curProduct.PublicQty;
                    var printedQty = float.Parse(tmpQty.Split('/')[0]);

                    if (isIncremented)
                        printedQty += (curProduct.QtyInStock - preQtyInStock);
                    else
                    {
                        if (printedQty > _barCodeList.Count)
                            printedQty = _barCodeList.Count;
                    }

                    curProduct.PublicQty =
                        printedQty + " / " + curProduct.QtyInStock;
                }

                rdbPrintSelected.Text = string.Format(
                    "{0}{1}{2}",
                    "កូដជ្រើសរើស (",
                    _barCodeList.Count.ToString("N0", AppContext.CultureInfo),
                    ")");
            }
            catch (Exception exception)
            {
                FrmExtendedMessageBox.UnknownErrorMessage(
                    Resources.MsgCaptionUnknownError,
                    exception.Message);
            }
        }
        private void BtnPrintClick(object sender, EventArgs e)
        {
            try
            {
                if (!UserService.AllowToPerform(Resources.PermissionPrintProductCode))
                {
                    const string briefMsg = "អំពី​សិទ្ឋិ​ប្រើ​ប្រាស់";
                    var detailMsg = Resources.MsgUserPermissionDeny;
                    using (var frmMessageBox = new FrmExtendedMessageBox())
                    {
                        frmMessageBox.BriefMsgStr = briefMsg;
                        frmMessageBox.DetailMsgStr = detailMsg;
                        frmMessageBox.IsCanceledOnly = true;
                        frmMessageBox.ShowDialog(this);
                        return;
                    }
                }

                if (rdbProduct.Checked)
                {
                    DoPrintProduct();
                    return;
                }

                if (rdbPrintAll.Checked)
                {
                    _barCodeList.Clear();
                    foreach (var t in _productList)
                    {
                        var product = t;
                        if(product == null)
                            continue;

                        for (var qtyCounter = 0; qtyCounter < product.QtyInStock; qtyCounter++)
                        {
                            //var product = _ProductList[counter];
                            var barCode =
                                new BarCode
                                    {
                                        BarCodeValue = product.ProductCode,
                                        DisplayStr = product.CategoryStr,
                                        AdditionalStr = (product.QtyInStock.ToString("N0") + " / " + product.QtyInStock.ToString("N0")),
                                        UnitPrice = "$ " + (t).UnitPriceOut.ToString("N", AppContext.CultureInfo),
                                        Description = product.ProductName + @" \ " + product.SizeStr
                                    };

                            var foreignCode = product.ForeignCode;
                            if (!string.IsNullOrEmpty(foreignCode))
                                barCode.DisplayStr += " (" + foreignCode + ")";
                            _barCodeList.Add(barCode);
                        }

                        (t).PrintCheck = true;
                        (t).PublicQty =
                            (t).QtyInStock +
                            " / " +
                            (t).QtyInStock;
                    }
                    dgvProduct.Refresh();
                }

                var barCodeTemplate = AppContext.BarCodeTemplate;

                //var barCodePrintingTypeList =
                //    _CommonService.GetAppParametersByType(
                //        Int32.Parse(Resources.AppParamBarcodePrintingType, AppContext.CultureInfo));

                //var barCodePrintingType = string.Empty;
                //if (barCodePrintingTypeList != null)
                //{
                //    if(barCodePrintingTypeList.Count != 0)
                //    {
                //        var appParameter = (AppParameter) barCodePrintingTypeList[0];
                //        if (appParameter != null)
                //            barCodePrintingType = appParameter.ParameterValue;
                //    }
                //}

                if (string.IsNullOrEmpty(barCodeTemplate))
                    barCodeTemplate = Resources.ConstBarCodeTemplate1;

                if (!Resources.ConstBarCodeTemplate6.Equals(barCodeTemplate))
                    PrintBarCode.InializePrinting(_barCodeList, barCodeTemplate);
                else
                {
                    var fileName = Resources.ConstBarcodeExcelFile;
                    var printBarCode = new PrintBarCode();
                    printBarCode.PrintBarcodeHandler(
                        Application.StartupPath + @"\" + fileName,
                        string.Empty,
                        _barCodeList);
                }

                SetFocusToProductList();
            }
            catch (Exception exception)
            {
                FrmExtendedMessageBox.UnknownErrorMessage(
                    Resources.MsgCaptionUnknownError,
                    exception.Message);
            }
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            var cardList = new List<BarCode>();
            for (int counter = 0; counter < _DiscountCardList.Count; counter++)
            {
                if (rdbPrintSelected.Checked)
                {
                    if (dgvDiscountCard.Rows[counter].Cells["PrintCheck"].Value == null)
                        continue;

                    if (!bool.Parse(dgvDiscountCard.Rows[counter].Cells["PrintCheck"].Value.ToString()))
                        continue;
                }

                var barCode = new BarCode
                                  {
                                      BarCodeValue = ((DiscountCard) _DiscountCardList[counter]).CardNumber,
                                      DisplayStr = ""
                                  };
                cardList.Add(barCode);
            }
            PrintDiscountCard.InializePrinting(cardList);
        }