Пример #1
0
        private void GridCustomRowCellEditForEditing(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {
            if (e.Column.FieldName == nameof(invoices_details.itemunit_id))
            {
                RepositoryItemLookUpEdit repo = new RepositoryItemLookUpEdit();
                repo.NullText    = "";
                e.RepositoryItem = repo;
                var ins = new Session.ProductViewClass.ProductUOMView();
                var row = Grid.GetRow(e.RowHandle) as invoices_details;
                if (row == null)
                {
                    return;
                }
                var item = Session.ProductView.SingleOrDefault(x => x.id == row.itemid);
                if (item == null)
                {
                    return;
                }

                repo.DataSource    = item.Units;
                repo.ValueMember   = nameof(ins.unitid);
                repo.DisplayMember = nameof(ins.UnitName);

                repo.ForceInitialize();
                repo.PopulateColumns();

                repo.BestFitMode          = BestFitMode.BestFitResizePopup;
                repo.HighlightedItemStyle = DevExpress.XtraEditors.HighlightStyle.Standard;
                repo.Columns[nameof(ins.unitid)].Visible    = false;
                repo.Columns[nameof(ins.UnitName)].Caption  = "إسم الوحدة";
                repo.Columns[nameof(ins.factor)].Caption    = "معالج التحويل";
                repo.Columns[nameof(ins.buyprice)].Caption  = "سعر الشراء";
                repo.Columns[nameof(ins.sellprice)].Caption = "سعر البيع";
                repo.Columns[nameof(ins.barcode)].Caption   = "الباركود";
            }
            else if (e.Column.FieldName == nameof(details.itemid))
            {
                e.RepositoryItem = repoItems;
            }
        }
Пример #2
0
        private void GridCellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            var row = Grid.GetRow(e.RowHandle) as invoices_details;

            if (row == null)
            {
                return;
            }
            Session.ProductViewClass item_view = null;
            Session.ProductViewClass.ProductUOMView unit_View = null;
            if (e.Column.FieldName == "Code")
            {
                string itemCode = e.Value.ToString();
                if (Session.GlobalSettings.ReadFromScalBarcode &&
                    itemCode.Length == Session.GlobalSettings.BarcodeLength &&
                    itemCode.ToString().StartsWith(Session.GlobalSettings.ScaleBarcodePrefix))
                {
                    var itemCodeString = itemCode.ToString()
                                         .Substring(Session.GlobalSettings.ScaleBarcodePrefix.Length,
                                                    Session.GlobalSettings.ProductCodeLength);
                    itemCode = Convert.ToInt32(itemCodeString).ToString();
                    string ReadValue = itemCode.ToString().Substring(
                        Session.GlobalSettings.ScaleBarcodePrefix.Length +
                        Session.GlobalSettings.ProductCodeLength);
                    if (Session.GlobalSettings.IgnoreCheckDigit)
                    {
                        ReadValue = ReadValue.Remove(ReadValue.Length - 1, 1);
                    }
                    double value = Convert.ToDouble(ReadValue);
                    value = value / (Math.Pow(10, Session.GlobalSettings.DivideValueBy));
                    if (Session.GlobalSettings.ReadMode == Session.GlobalSettings.ReadValueMode.Weight)
                    {
                        row.item_Qty = value;
                    }
                    else if (Session.GlobalSettings.ReadMode == Session.GlobalSettings.ReadValueMode.Price)
                    {
                        item_view = Session.ProductView.FirstOrDefault(X => X.Units.Select(u => u.barcode).Contains(itemCode));
                        if (item_view != null)
                        {
                            unit_View = item_view.Units.First(x => x.barcode == itemCode);
                            switch (Type)
                            {
                            case Master.InvoiceType.Purshases:
                            case Master.InvoiceType.PurchasesReturn:
                                row.item_Qty = value / unit_View.buyprice;

                                break;

                            case Master.InvoiceType.Sales:
                            case Master.InvoiceType.SalesReturn:
                                row.item_Qty = value / unit_View.sellprice;

                                break;

                            default:
                                break;
                            }
                        }
                    }

                    if (item_view == null)
                    {
                        item_view = Session.ProductView.FirstOrDefault(X => X.Units.Select(u => u.barcode).Contains(itemCode));
                    }
                    if (item_view != null)
                    {
                        row.itemid = item_view.id;
                        if (unit_View == null)
                        {
                            unit_View = item_view.Units.First(x => x.barcode == itemCode);
                        }
                        row.itemunit_id = unit_View.unitid;

                        GridCellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, Grid.Columns[nameof(details.itemid)], row.itemid));
                        GridCellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, Grid.Columns[nameof(details.itemunit_id)], row.itemunit_id));

                        Barcode = string.Empty;
                        return;
                    }
                    Barcode = string.Empty;
                }
                /*** WAIT FOR UPDATE ***/

                if (row.itemid == 0)
                {
                    return;
                }
                item_view = Session.ProductView.SingleOrDefault(x => x.id == row.itemid);
                if (item_view != null)
                {
                    if (row.itemunit_id == 0)
                    {
                        row.itemunit_id = item_view.Units.First().unitid;
                        GridCellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, Grid.Columns[nameof(details.itemunit_id)], row.itemunit_id));
                    }
                    unit_View = item_view.Units.SingleOrDefault(x => x.unitid == row.itemunit_id);
                }



                /*****************************/

                switch (e.Column.FieldName)
                {
                //TO DO READ FROM BARCODE

                case nameof(details.itemid):
                    if (row.store_id == 0)
                    {
                        row.store_id = ((int?)Lkp_Branch.EditValue ?? 0);
                    }

                    break;

                case nameof(details.itemunit_id):
                    if (Type == Master.InvoiceType.Purshases || Type == Master.InvoiceType.PurchasesReturn)
                    {
                        row.price = unit_View.buyprice;
                    }

                    if (row.item_Qty == 0)
                    {
                        row.item_Qty = 1;
                    }
                    GridCellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, Grid.Columns[nameof(details.price)], row.price));

                    break;

                case nameof(details.price):
                case nameof(details.discount):
                case nameof(details.item_Qty):
                    row.discount_value = row.discount * (row.item_Qty * row.price);
                    GridCellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, Grid.Columns[nameof(details.discount_value)], row.discount_value));
                    break;

                case nameof(details.discount_value):
                    if (Grid.FocusedColumn.FieldName == nameof(details.discount_value))
                    {
                        row.discount = row.discount_value / (row.item_Qty * row.price);
                    }
                    row.total_price = (row.item_Qty * row.price) - row.discount_value;
                    break;

                default:
                    break;
                }
            }
        }
Пример #3
0
        private void GridView1_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            if (!(gridView1.GetRow(e.RowHandle) is DAL.InvoiceDetail row))
            {
                return;
            }
            Session.ProductViewClass itemV = null;
            Session.ProductViewClass.ProductUOMView unitV = null;
            if (e.Column.FieldName == "Code")
            {
                string ItemCode = e.Value.ToString();
                if (Session.GlobalSettings.ReadFormScaleBarcode &&
                    ItemCode.Length == Session.GlobalSettings.BarcodeLength &&
                    ItemCode.StartsWith(Session.GlobalSettings.ScaleBarcodePrefix))
                {
                    var itemCodeString = e.Value.ToString()
                                         .Substring(Session.GlobalSettings.ScaleBarcodePrefix.Length,
                                                    Session.GlobalSettings.ProductCodeLength);
                    ItemCode = Convert.ToInt32(itemCodeString).ToString();
                    string Readvalue = e.Value.ToString().Substring(
                        Session.GlobalSettings.ScaleBarcodePrefix.Length +
                        Session.GlobalSettings.ProductCodeLength);
                    if (Session.GlobalSettings.IgnoreCheckDigit)
                    {
                        Readvalue = Readvalue.Remove(Readvalue.Length - 1, 1);
                    }
                    double value = Convert.ToDouble(Readvalue);
                    value /= (Math.Pow(10, Session.GlobalSettings.DivideValueBy));
                    if (Session.GlobalSettings.ReadMode == Session.GlobalSettings.ReadValueMode.Weight)
                    {
                        row.ItemQty = value;
                    }

                    else if (Session.GlobalSettings.ReadMode == Session.GlobalSettings.ReadValueMode.Price)
                    {
                        itemV = Session.ProductsView.FirstOrDefault(x => x.Units.Select(u => u.Barcode).Contains(ItemCode));
                        if (itemV != null)
                        {
                            unitV = itemV.Units.First(x => x.Barcode == ItemCode);

                            switch (type)
                            {
                            case InvoiceType.Purchase:
                            case InvoiceType.PurchaseReturn:
                                row.ItemQty = value / unitV.BuyPrice;
                                break;

                            case InvoiceType.Sales:
                            case InvoiceType.SalesReturn:
                                row.ItemQty = value / unitV.SellPrice;

                                break;

                            default:
                                break;
                            }
                        }
                    }
                }

                if (itemV == null)
                {
                    itemV = Session.ProductsView.FirstOrDefault(x => x.Units.Select(u => u.Barcode).Contains(ItemCode));
                }

                if (itemV != null)
                {
                    row.ItemID = itemV.ID;
                    if (unitV == null)
                    {
                        unitV = itemV.Units.First(x => x.Barcode == ItemCode);
                    }

                    row.ItemUnitID = unitV.UnitID;

                    GridView1_CellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, gridView1.Columns[nameof(detailsInstance.ItemID)], row.ItemID));

                    GridView1_CellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, gridView1.Columns[nameof(detailsInstance.ItemUnitID)], row.ItemUnitID));

                    enteredCode = string.Empty;

                    return;
                }
                enteredCode = string.Empty;
            }

            itemV = Session.ProductsView.Single(x => x.ID == row.ItemID);

            if (row.ItemUnitID == 0)
            {
                row.ItemUnitID = itemV.Units.First().UnitID;
                GridView1_CellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, gridView1.Columns[nameof(detailsInstance.ItemUnitID)], row.ItemUnitID));
            }

            unitV = itemV.Units.Single(x => x.UnitID == row.ItemUnitID);

            switch (e.Column.FieldName)
            {
            case nameof(detailsInstance.ItemID):
                if (row.StoreID == 0 && lkp_Branch.IsEditValueValidAndNotZero())
                {
                    row.StoreID = Convert.ToInt32(lkp_Branch.EditValue);
                }
                break;

            case nameof(detailsInstance.ItemUnitID):
                if (type == Master.InvoiceType.Purchase || type == Master.InvoiceType.PurchaseReturn)
                {
                    row.Price = unitV.BuyPrice;
                }
                if (row.ItemQty == 0)
                {
                    row.ItemQty = 1;
                }
                GridView1_CellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, gridView1.Columns[nameof(detailsInstance.Price)], row.Price));
                break;

            case nameof(detailsInstance.Price):
            case nameof(detailsInstance.Discount):
            case nameof(detailsInstance.ItemQty):

                row.DiscountValue = row.Discount * (row.ItemQty * row.Price);

                GridView1_CellValueChanged(sender, new CellValueChangedEventArgs(e.RowHandle, gridView1.Columns[nameof(detailsInstance.DiscountValue)], row.DiscountValue));

                break;

            case nameof(detailsInstance.DiscountValue):
                if (gridView1.FocusedColumn.FieldName == nameof(detailsInstance.DiscountValue))
                {
                    row.Discount = row.DiscountValue / (row.ItemQty * row.Price);
                }
                row.TotalPrice = (row.ItemQty * row.Price) - row.DiscountValue;

                break;

            default:
                break;
            }
        }