示例#1
0
        private static void SetProductPicture(Product product)
        {
            if (product.ProductPic != null)
                return;

            product.ProductPic = Resources.NoImage;
            if (String.IsNullOrEmpty(product.PhotoPath))
                return;

            var fileInfo = new FileInfo(product.PhotoPath);
            product.ProductPic = fileInfo.Exists ? new Bitmap(product.PhotoPath) : Resources.NoImage;
        }
示例#2
0
        private void SetProductInfo(Product product)
        {
            if (product == null)
                return;

            txtForeignCode.Text = product.ForeignCode;
            lblProductName.Text = string.Format("{0}{1}{2}", product.ProductName, "\r", product.ProductCode);
            txtCategory.Text = product.CategoryStr;
            txtMark.Text = product.MarkStr;
            txtColor.Text = product.ColorStr;
            txtSize.Text = product.SizeStr;
            txtDiscount.Text = product.DiscountPercentage.ToString("N0", AppContext.CultureInfo);
            txtUPOut.Text = product.UnitPriceOut.ToString("N", AppContext.CultureInfo);
            txtQtyInStock.Text = product.QtyInStock.ToString("N0", AppContext.CultureInfo);
            if (product.PhotoPath == null)
                ptbProduct.Image = Resources.NoImage;
            else
                ptbProduct.ImageLocation = product.PhotoPath;
        }
示例#3
0
        private SaleItem CreateSaleItem(Product product, int qtySold, float discount)
        {
            var saleItem =
                new SaleItem
                {
                    ProductName = product.ProductName,
                    ProductId = product.ProductId,
                    QtySold = qtySold,
                    UnitPriceIn = product.UnitPriceIn,
                    ProductDisplayName =
                        string.IsNullOrEmpty(product.Description) ?
                        product.ProductName + "\r" + product.ProductCode :
                        product.Description + "\r" + product.ProductCode,
                    QtyBonus = CalculateQtyBonus(
                        qtySold,
                        Int32.Parse(product.QtyPromotion.ToString("N0", AppContext.CultureInfo)),
                        Int32.Parse(product.QtyBonus.ToString("N0", AppContext.CultureInfo)))
                };

            //Control the quantity of product to be sold
            if(product.QtyInStock < (saleItem.QtySold + saleItem.QtyBonus))
                return null;

            if (!string.IsNullOrEmpty(product.ForeignCode))
                saleItem.ProductDisplayName += " (" + product.ForeignCode + ")";

            var unitPriceIn =
                float.Parse(Math.Round(product.UnitPriceIn, 3).ToString("N3", AppContext.CultureInfo),
                            AppContext.CultureInfo);

            var publicUnitPriceOut =
                product.ExtraPercentage != 0 ?
                unitPriceIn + ((unitPriceIn * product.ExtraPercentage) / 100) :
                product.UnitPriceOut;

            saleItem.UnitPriceOut =
                float.Parse(
                    publicUnitPriceOut.ToString("N", AppContext.CultureInfo),
                    AppContext.CultureInfo);
            //publicUnitPriceOut =
            //    publicUnitPriceOut -
            //    ((publicUnitPriceOut * product.DiscountPercentage) / 100);
            publicUnitPriceOut =
                publicUnitPriceOut -
                ((publicUnitPriceOut * discount) / 100);

            if (publicUnitPriceOut == product.UnitPriceIn)
                publicUnitPriceOut = product.UnitPriceOut;

            //publicUnitPriceOut =
            //    float.Parse(Math.Round(publicUnitPriceOut, 0).ToString("N", AppContext.CultureInfo),
            //                AppContext.CultureInfo);
            publicUnitPriceOut =
                float.Parse(
                    publicUnitPriceOut.ToString("N", AppContext.CultureInfo),
                    AppContext.CultureInfo);

            //float.Parse(Math.Round(saleItem.PublicUPOut, 0).ToString("N", AppContext.CultureInfo),
            //            AppContext.CultureInfo);
            saleItem.PublicUpOut = publicUnitPriceOut;
            saleItem.Discount = discount;
            saleItem.SubTotal =
                saleItem.QtySold * publicUnitPriceOut;

            if (string.IsNullOrEmpty(product.PhotoPath))
                saleItem.ProdPicture = Resources.NoImage;
            else
            {
                var fileInfo = new FileInfo(product.PhotoPath);
                saleItem.ProdPicture = fileInfo.Exists ? Image.FromFile(product.PhotoPath) : Resources.NoImage;
            }
            cmbProduct.SelectedIndex = -1;
            saleItem.FkProduct = product;
            return saleItem;
        }
示例#4
0
 private void SetProductInfo(Product product)
 {
     lblProductName.Text = product.ProductName + @" \ " + product.ColorStr;
     lblPrice.Text = Resources.ConstPrefixDollar + product.UnitPriceOut.ToString("N", AppContext.CultureInfo);
     lblReference.Text = product.ProductCode;
     if ((product.ProductPic == null) || (String.IsNullOrEmpty(product.PhotoPath)))
         ptbDisplay.Image = Resources.NoImage;
     else
     {
         var fileInfo = new FileInfo(product.PhotoPath);
         if (fileInfo.Exists)
             ptbDisplay.ImageLocation = product.PhotoPath;
         else
             ptbDisplay.Image = Resources.NoImage;
     }
 }
示例#5
0
        private void SetProductInfo(Product product)
        {
            if (product == null)
                return;

            txtForeignCode.Text = product.ForeignCode;
            lblProductName.Text = product.ProductName + Resources.ConstTextBreak + product.ProductCode;
            cmbCategory.SelectedValue = product.CategoryId;
            cmbMark.SelectedValue = product.MarkId;
            cmbColor.SelectedValue = product.ColorId;
            cmbSize.SelectedValue = product.SizeId;
            txtDescription.Text = product.Description;
            txtUPIn.Text = product.UnitPriceIn.ToString("N3", AppContext.CultureInfo);
            txtExtraPercentage.Text = product.ExtraPercentage.ToString("N0", AppContext.CultureInfo);
            txtDiscount.Text = product.DiscountPercentage.ToString("N0", AppContext.CultureInfo);
            txtUPOut.Text = product.UnitPriceOut.ToString("N", AppContext.CultureInfo);
            _defaultUnitPriceOut = product.UnitPriceOut;
            txtQtyInStock.Text = product.QtyInStock.ToString("N0", AppContext.CultureInfo);
            txtPhotoPath.Text = product.PhotoPath;
            if (product.PhotoPath == null)
                ptbProduct.Image = Resources.NoImage;
            else
                ptbProduct.ImageLocation = product.PhotoPath;

            txtQtyPromotion.Text = product.QtyPromotion.ToString("N0", AppContext.CultureInfo);
            txtQtyBonus.Text = product.QtyBonus.ToString("N0", AppContext.CultureInfo);
        }
示例#6
0
        private void CmbProductSelectedIndexChanged(object sender, EventArgs e)
        {
            if ((String.IsNullOrEmpty(cmbProduct.DisplayMember)) ||
                (String.IsNullOrEmpty(cmbProduct.ValueMember)) ||
                (cmbProduct.SelectedIndex == -1))
                return;

            try
            {
                var product = (Product)cmbProduct.SelectedItem;
                if (product == null)
                    return;

                const string briefMsg = "អំពីពត៌មាន";
                var detailMsg = Resources.MsgConfirmEditExistingProduct;
                using (var frmMessageBox = new FrmExtendedMessageBox())
                {
                    frmMessageBox.BriefMsgStr = briefMsg;
                    frmMessageBox.DetailMsgStr = detailMsg;
                    if (frmMessageBox.ShowDialog(this) != DialogResult.OK)
                    {
                        txtForeignCode.Text = string.Empty;
                        return;
                    }
                }

                _product = product;
                SetProductInfo(_product);
            }
            catch (Exception exception)
            {
                FrmExtendedMessageBox.UnknownErrorMessage(
                    Resources.MsgCaptionUnknownError,
                    exception.Message);
            }
        }
示例#7
0
        private void BtnSaveClick(object sender, EventArgs e)
        {
            try
            {
                if ((cmbCategory.SelectedIndex == -1) || (cmbMark.SelectedIndex == -1)
                    || (cmbColor.SelectedIndex == -1) || (cmbSize.SelectedIndex == -1))
                {
                    const string briefMsg = "អំពីពត៌មាន";
                    var detailMsg = Resources.MsgInvalidData;
                    using (var frmMessageBox = new FrmExtendedMessageBox())
                    {
                        frmMessageBox.BriefMsgStr = briefMsg;
                        frmMessageBox.DetailMsgStr = detailMsg;
                        frmMessageBox.IsCanceledOnly = true;
                        frmMessageBox.ShowDialog(this);
                        return;
                    }
                }

                if (_product == null)
                    _product = new Product();

                _product.CategoryId = int.Parse(cmbCategory.SelectedValue.ToString());
                _product.CategoryStr = cmbCategory.Text;
                _product.MarkId = int.Parse(cmbMark.SelectedValue.ToString());
                _product.MarkStr = cmbMark.Text;
                _product.ColorId = int.Parse(cmbColor.SelectedValue.ToString());
                _product.ColorStr = cmbColor.Text;
                _product.SizeId = Int32.Parse(cmbSize.SelectedValue.ToString());
                _product.SizeStr = cmbSize.Text;
                _product.ProductName = _product.CategoryStr + @" \ " + _product.MarkStr + @" \ " + _product.ColorStr;
                _product.UnitPriceIn = float.Parse(txtUPIn.Text);
                _product.ExtraPercentage = float.Parse(txtExtraPercentage.Text);
                _product.UnitPriceOut = float.Parse(txtUPOut.Text);
                _product.DiscountPercentage = float.Parse(txtDiscount.Text);
                _product.QtyInStock = float.Parse(txtQtyInStock.Text);
                _product.QtyPromotion = float.Parse(txtQtyPromotion.Text);
                _product.QtyBonus = float.Parse(txtQtyBonus.Text);
                _product.ForeignCode = txtForeignCode.Text;
                _product.Description = txtDescription.Text;
                if (txtPhotoPath.Text.Length == 0)
                {
                    _product.PhotoPath = _product.PhotoPath;
                    _product.ProductPic = Resources.NoImage;
                }
                else
                {
                    var fileInfo = new FileInfo(txtPhotoPath.Text);
                    if (fileInfo.Exists)
                    {
                        _product.PhotoPath = txtPhotoPath.Text;
                        _product.ProductPic = Image.FromFile(_product.PhotoPath);
                    }
                    else
                        _product.ProductPic = Resources.NoImage;
                }

                if (_productService == null)
                    _productService = ServiceFactory.GenerateServiceInstance().GenerateProductService();

                _product.DisplayName = _product.ProductName + "\r" +
                                       "Size: " + _product.SizeStr + "\r" +
                                       "Code: " + _product.ProductCode;
                if (!string.IsNullOrEmpty(_product.ForeignCode))
                    _product.DisplayName += " (" + _product.ForeignCode + ")";

                if (!_isFromSale)
                {
                    _productService.ManageProduct(
                        _product,
                        _product.ProductId != 0 ? Resources.OperationRequestUpdate : Resources.OperationRequestInsert);
                }

                DialogResult = DialogResult.OK;
            }
            catch (Exception exception)
            {
                FrmExtendedMessageBox.UnknownErrorMessage(
                    Resources.MsgCaptionUnknownError,
                    exception.Message);
            }
        }
示例#8
0
        private void UpdatePrintProduct(Product product)
        {
            if (product == null)
                return;

            if (_barCodeList == null)
                return;

            foreach (var barCode in _barCodeList.Where(barCode => barCode.BarCodeValue == product.ProductCode))
            {
                barCode.DisplayStr = product.CategoryStr;

                if (!string.IsNullOrEmpty(product.ForeignCode))
                    barCode.DisplayStr += " (" + product.ForeignCode + ")";
            }
        }
示例#9
0
        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);
            }
        }