Esempio n. 1
0
        private void DgvSaleItemCellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (_saleOrder != null)
                return;

            if (_saleItemBindingList == null)
                return;

            if (_saleItemBindingList.Count == 0)
                return;

            using (var frmCatalog = new FrmCatalog())
            {
                frmCatalog.IsFromSale = true;
                frmCatalog.Product =
                    _saleItemBindingList[dgvSaleItem.SelectedRows[0].Index].FkProduct;

                if (frmCatalog.ShowDialog(this) == DialogResult.OK)
                {
                    var selectedIndex =
                        dgvSaleItem.SelectedRows[0].Index;
                    var saleItem = _saleItemBindingList[selectedIndex];
                    var product = frmCatalog.Product;

                    saleItem.Discount = product.DiscountPercentage;

                    var publicUnitPriceOut =
                        product.UnitPriceIn + ((product.UnitPriceIn*product.ExtraPercentage) / 100);

                    publicUnitPriceOut =
                        publicUnitPriceOut -
                        ((publicUnitPriceOut * product.DiscountPercentage) / 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);
                    saleItem.PublicUpOut = publicUnitPriceOut;
                    //saleItem.UnitPriceOut = product.UnitPriceOut;
                    saleItem.UnitPriceOut =
                        product.UnitPriceIn + ((product.UnitPriceIn * product.ExtraPercentage) / 100);
                    saleItem.UnitPriceOut =
                        float.Parse(
                            saleItem.UnitPriceOut.ToString("N", AppContext.CultureInfo),
                            AppContext.CultureInfo);
                    //saleItem.SubTotal = saleItem.QtySold * saleItem.UnitPriceOut;
                    saleItem.SubTotal = saleItem.QtySold * publicUnitPriceOut;
                    dgvSaleItem.Refresh();
                    CalculateSale();
                }
            }
            ScanFocusHandler();
        }
Esempio n. 2
0
        private void ProductManagement(IEquatable<string> operationRequest)
        {
            try
            {
                if ((dgvProduct.CurrentRow == null) && (!operationRequest.Equals(Resources.OperationRequestInsert)))
                    return;

                using (var frmCatalog = new FrmCatalog())
                {
                    float preQtyInStock = 0;
                    if (_productList.Count != 0)
                        preQtyInStock = (_productList[dgvProduct.CurrentRow.Index]).QtyInStock;
                    if (operationRequest.Equals(Resources.OperationRequestUpdate))
                        frmCatalog.Product = _productList[dgvProduct.CurrentRow.Index];

                    if (frmCatalog.ShowDialog(this) == DialogResult.OK)
                    {
                        try
                        {
                            if (frmCatalog.Product == null)
                            {
                                IListToBindingList(
                                    _productService.GetCatalogs(chbInstockOnly.Checked));
                            }
                            else
                            {
                                if (operationRequest.Equals(Resources.OperationRequestUpdate))
                                {
                                    UpdateSelectedProduct(
                                        frmCatalog.Product,
                                        preQtyInStock);

                                    if (frmCatalog.Product.QtyInStock == 0)
                                    {
                                        for (var counter = 0; counter < _productList.Count; counter++)
                                        {
                                            if (_productList[counter].ProductId == frmCatalog.Product.ProductId)
                                                _productList.RemoveAt(counter);
                                        }
                                    }
                                }
                                else
                                {
                                    if (frmCatalog.Product.QtyInStock == 0)
                                        _productList.Add(frmCatalog.Product);
                                }
                            }
                            dgvProduct.Refresh();
                            SetProductInfo();

                            UpdateResultInfo();
                            EnableActionButton();
                        }
                        catch (Exception exception)
                        {
                            FrmExtendedMessageBox.UnknownErrorMessage(
                                Resources.MsgCaptionUnknownError,
                                exception.Message);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                FrmExtendedMessageBox.UnknownErrorMessage(
                    Resources.MsgCaptionUnknownError,
                    exception.Message);
            }
        }