Exemple #1
0
        public void ReplaceRow(int ndxItem, T newItem)
        {
            Debug.Assert(IsConnected);
            Debug.Assert(ndxItem >= 0);
            Debug.Assert(ndxItem < RowCount);
            Debug.Assert(newItem != null);


            lock (m_rwLock)
            {
                T oldItem = GetRow(ndxItem);
                RowReplacing?.Invoke(ndxItem, oldItem);

                int ndx = DoReplace(ndxItem, newItem);
                Header.LastAccessTime = Header.LastWriteTime = DateTime.Now;

                if (ndx != ndxItem)
                {
                    RowDeleted?.Invoke(ndxItem);
                    RowInserted?.Invoke(ndx, newItem);
                }
                else
                {
                    RowReplaced?.Invoke(ndx, newItem);
                }
            }
        }
Exemple #2
0
 private void RemoveShippingHandlers()
 {
     RowInserted.RemoveHandler <POOrder>(POOrder_RowInserted);
     FieldUpdated.RemoveHandler <POOrder.shipDestType>(POOrder_ShipDestType_FieldUpdated);
     FieldUpdated.RemoveHandler <POOrder.siteID>(POOrder_SiteID_FieldUpdated);
     FieldUpdated.RemoveHandler <POOrder.shipToLocationID>(POOrder_ShipToLocationID_FieldUpdated);
 }
Exemple #3
0
        protected async Task OnSaveCommand()
        {
            if (Data == null)
            {
                return;
            }

            // get the list of edited values
            var editedCellValues = EditableColumns
                                   .Select(c => new { c.Field, editItemCellValues[c.ElementId].CellValue }).ToDictionary(x => x.Field, x => x.CellValue);

            var rowSavingHandler = editState == DataGridEditState.New ? RowInserting : RowUpdating;

            if (await IsSafeToProceed(rowSavingHandler, editItem, editedCellValues))
            {
                if (UseInternalEditing && editState == DataGridEditState.New && CanInsertNewItem && Data is ICollection <TItem> data)
                {
                    data.Add(editItem);
                }

                if (UseInternalEditing || editState == DataGridEditState.New)
                {
                    // apply edited cell values to the item
                    // for new items it must be always be set, while for editing items it can be set only if it's enabled
                    foreach (var column in EditableColumns)
                    {
                        column.SetValue(editItem, editItemCellValues[column.ElementId].CellValue);
                    }
                }

                if (editState == DataGridEditState.New)
                {
                    await RowInserted.InvokeAsync(new SavedRowItem <TItem, Dictionary <string, object> >(editItem, editedCellValues));

                    dirtyFilter = dirtyView = true;

                    // If a new item is added, the data should be refreshed
                    // to account for paging, sorting, and filtering
                    if (ManualReadMode)
                    {
                        await HandleReadData();
                    }
                }
                else
                {
                    await RowUpdated.InvokeAsync(new SavedRowItem <TItem, Dictionary <string, object> >(editItem, editedCellValues));
                }

                editState = DataGridEditState.None;

                if (EditMode == DataGridEditMode.Popup)
                {
                    PopupVisible = false;
                }
            }
        }
Exemple #4
0
        public void InsertRow(T item)
        {
            Debug.Assert(IsConnected);
            Debug.Assert(item != null);


            lock (m_rwLock)
            {
                int ndx = DoInsert(item);
                Header.LastAccessTime = Header.LastWriteTime = DateTime.Now;
                RowInserted?.Invoke(ndx, item);
            }
        }
Exemple #5
0
        protected async Task OnSaveCommand()
        {
            if (Data is ICollection <TItem> data)
            {
                // get the list of edited values
                var editedCellValues = EditableColumns
                                       .Select(c => new { c.Field, editItemCellValues[c.ElementId].CellValue }).ToDictionary(x => x.Field, x => x.CellValue);

                if (IsSafeToProceed(RowSaving, editItem, editedCellValues))
                {
                    if (UseInternalEditing && editState == DataGridEditState.New && CanInsertNewItem)
                    {
                        data.Add(editItem);
                    }

                    if (UseInternalEditing || editState == DataGridEditState.New)
                    {
                        // apply edited cell values to the item
                        // for new items it must be always be set, while for editing items it can be set only if it's enabled
                        foreach (var column in EditableColumns)
                        {
                            column.SetValue(editItem, editItemCellValues[column.ElementId].CellValue);
                        }
                    }

                    if (editState == DataGridEditState.New)
                    {
                        await RowInserted.InvokeAsync(new SavedRowItem <TItem, Dictionary <string, object> >(editItem, editedCellValues));

                        dirtyFilter = dirtyView = true;
                    }
                    else
                    {
                        await RowUpdated.InvokeAsync(new SavedRowItem <TItem, Dictionary <string, object> >(editItem, editedCellValues));
                    }

                    editState = DataGridEditState.None;

                    if (EditMode == DataGridEditMode.Popup)
                    {
                        PopupVisible = false;
                    }
                }
            }
        }
Exemple #6
0
        private void UpdateFreeItemLines(CRServiceCase current)
        {
            var groupedByInventory = new Dictionary <int, decimal>();

            foreach (CRServiceCaseDiscountDetail item in
                     PXSelect <CRServiceCaseDiscountDetail,
                               Where <CRServiceCaseDiscountDetail.serviceCaseID, Equal <Required <CRServiceCaseDiscountDetail.serviceCaseID> > > > .
                     Select(this, current.ServiceCaseID))
            {
                if (item.FreeItemID != null)
                {
                    var val = item.FreeItemQty ?? 0;
                    if (groupedByInventory.ContainsKey(item.FreeItemID.Value))
                    {
                        groupedByInventory[item.FreeItemID.Value] += val;
                    }
                    else
                    {
                        groupedByInventory.Add(item.FreeItemID.Value, val);
                    }
                }
            }

            bool freeItemChanged = false;

            RowDeleted.RemoveHandler(typeof(CRServiceCaseItem), CRServiceCaseItem_RowDeleted);
            RowInserted.RemoveHandler(typeof(CRServiceCaseItem), CRServiceCaseItem_RowInserted);
            RowUpdated.RemoveHandler(typeof(CRServiceCaseItem), CRServiceCaseItem_RowUpdated);
            try
            {
                foreach (CRServiceCaseItem line in FreeItems.Select())
                {
                    if (line.ManualDiscount == false && line.InventoryID != null)
                    {
                        if (groupedByInventory.ContainsKey(line.InventoryID.Value))
                        {
                            if (groupedByInventory[line.InventoryID.Value] == 0)
                            {
                                FreeItems.Delete(line);
                                freeItemChanged = true;
                            }
                        }
                        else
                        {
                            FreeItems.Delete(line);
                            freeItemChanged = true;
                        }
                    }
                }

                int?defaultWarehouse = GetDefaultWarehouse();
                foreach (KeyValuePair <int, decimal> kv in groupedByInventory)
                {
                    CRServiceCaseItem freeLine = GetFreeLineByItemID(kv.Key, current.ServiceCaseID);

                    if (freeLine == null)
                    {
                        if (kv.Value > 0)
                        {
                            var line = new CRServiceCaseItem();
                            line.InventoryID    = kv.Key;
                            line.IsFree         = true;
                            line.SiteID         = defaultWarehouse;
                            line.ActualQuantity = kv.Value;

                            FreeItems.Insert(line);

                            freeItemChanged = true;
                        }
                    }
                    else
                    {
                        freeLine.ActualQuantity = kv.Value;                         //TODO: need set other fields

                        FreeItems.Update(freeLine);

                        freeItemChanged = true;
                    }
                }
            }
            finally
            {
                RowDeleted.AddHandler(typeof(CRServiceCaseItem), CRServiceCaseItem_RowDeleted);
                RowInserted.AddHandler(typeof(CRServiceCaseItem), CRServiceCaseItem_RowInserted);
                RowUpdated.AddHandler(typeof(CRServiceCaseItem), CRServiceCaseItem_RowUpdated);
            }

            if (freeItemChanged)
            {
                Details.View.RequestRefresh();
            }
        }
Exemple #7
0
 protected virtual void OnRowInserted(RowWrittenEventArgs e)
 {
     RowInserted?.Invoke(this, e);
 }