Exemple #1
0
        private void Frm_ProductsList_Load(object sender, EventArgs e)
        {
            dgv.OptionsBehavior.Editable = false;
            dgv.OptionsSelection.EnableAppearanceFocusedCell = false;       // Prevent the focused cell from being highlighted.
            dgv.FocusRectStyle               = DrawFocusRectStyle.RowFocus; // Draw a dotted focus rectangle around the entire row.
            Btn_Save.Visibility              = DevExpress.XtraBars.BarItemVisibility.Never;
            Btn_Delete.Visibility            = DevExpress.XtraBars.BarItemVisibility.Never;
            dgv.OptionsDetail.ShowDetailTabs = false;

            dgv.DoubleClick              += Dgv_DoubleClick;
            dgv.CustomColumnDisplayText  += Dgv_CustomColumnDisplayText;
            dgv.RowCellStyle             += Dgv_RowCellStyle;
            dgv.CustomDrawColumnHeader   += Dgv_CustomDrawColumnHeader;
            Grid_Products.ViewRegistered += Grid_Products_ViewRegistered;

            var ins = new Session.ProductViewClass();

            dgv.Columns[nameof(ins.code)].Caption     = "كود الصنف";
            dgv.Columns[nameof(ins.name)].Caption     = "إسم الصنف";
            dgv.Columns[nameof(ins.category)].Caption = "فئة الصنف";
            dgv.Columns[nameof(ins.type)].Caption     = "نوع الصنف";
            dgv.Columns[nameof(ins.details)].Caption  = "وصف الصنف";
            dgv.Columns[nameof(ins.status)].Caption   = "حالة الصنف";
            dgv.Columns[nameof(ins.id)].Visible       = false;
        }
Exemple #2
0
        private void Frm_ProductList_Load(object sender, EventArgs e)
        {
            //Session.ProductsView.ListChanged += ProductsView_ListChanged;
            gridView1.OptionsBehavior.Editable = false;
            btn_save.Visibility    = DevExpress.XtraBars.BarItemVisibility.Never;
            btn_Delete.Visibility  = DevExpress.XtraBars.BarItemVisibility.Never;
            gridView1.DoubleClick += GridView1_DoubleClick;
            RefreshData();
            gridView1.CustomColumnDisplayText     += GridView1_CustomColumnDisplayText;
            gridControl1.ViewRegistered           += GridControl1_ViewRegistered;
            gridView1.OptionsDetail.ShowDetailTabs = false;

            var ins = new Session.ProductViewClass();

            gridView1.Columns[nameof(ins.CategoryName)].Caption = "الفئة";
            gridView1.Columns[nameof(ins.Code)].Caption         = "الكود";
            gridView1.Columns[nameof(ins.Descreption)].Caption  = "الوصف";
            gridView1.Columns[nameof(ins.IsActive)].Caption     = "نشط";
            gridView1.Columns[nameof(ins.Name)].Caption         = "الاسم";
            gridView1.Columns[nameof(ins.Type)].Caption         = "النوع";
            gridView1.Columns[nameof(ins.ID)].Visible           = false;
        }
Exemple #3
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;
                }
            }
        }
Exemple #4
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;
            }
        }