Esempio n. 1
0
 public virtual void AddItemAt(ObservableInfo newItem, int position)
 {
     if (position > -1 && position < firstItemIndex)
     {
         ItemsCollection.Insert(position, newItem);
         firstItemIndex++;
     }
     else if (position < LastItemIndex)
     {
         ItemsCollection.Insert(position, newItem);
     }
     else if (position <= ItemsCount)
     {
         ItemsCollection.Insert(position, newItem);
     }
 }
Esempio n. 2
0
        public void AddNewItemTask(string itemName, string serialNumber, string itemType)
        {
           
            //string var = new InputBox("text").ShowDialog();
            using (var db = new DataContext())
            {
                if (SelectedItem == null)
                {
                    var selectedItem = db.ItemTypes.FirstOrDefault(x => x.ItemCode == itemType).ItemTypeID;
                    Item item = new Item();
                    item.ItemName = itemName;
                    item.SerialNumber = serialNumber;
                    item.ItemTypeID = selectedItem;
                    item.CreationDate = DateTime.Now;
                    if (Client != null)
                    {
                        item.ClientID = Client.ClientID;
                        SelectOccupiedDateBox inputBox = new SelectOccupiedDateBox();
                        inputBox.ShowDialog();
                        Console.WriteLine(inputBox.SelectedOccupiedDate);
                    }
                    db.Items.Add(item);
                    db.SaveChanges();
                    updateForm();
                    InitializeItemCollection(item.ItemID);
                    MessageBox.Show("Dodano nowy produkt magazynowy.");
                }
                else
                {

                        var selectedItem = db.ItemTypes.FirstOrDefault(x => x.ItemCode == itemType).ItemTypeID;
                        var item = db.Items.Where(x => x.ItemID == SelectedItem.ItemID).FirstOrDefault();
                        item.ItemName = itemName;
                        item.SerialNumber = serialNumber;
                        item.ItemTypeID = selectedItem;

                    if (Client != null)
                    {
                            item.ClientID = Client.ClientID;
                            SelectOccupiedDateBox inputBox = new SelectOccupiedDateBox();
                            inputBox.ShowDialog();
                        var x = inputBox.SelectedOccupiedDate;
                        Console.WriteLine(x);
                    }
                    else
                    { 
                        item.ClientID = null;
                        Nullable<DateTime> dt = null;
                        item.OccupiedDate = dt;
                    }

                    db.SaveChanges();
                        
                    ItemModel itemModel = new ItemModel();
                    itemModel.ItemID = item.ItemID;
                    itemModel.ItemName = item.ItemName;
                    itemModel.ItemType = item.ItemType.ItemCode;
                    itemModel.SerialNumber = item.SerialNumber;
                    itemModel.CreationDate = item.CreationDate;
                    if(item.Client != null)
                        itemModel.ClientName = item.Client.FullName;
                    var index = ItemsCollection.IndexOf(SelectedItem);
                    ItemsCollection.Remove(SelectedItem);
                    ItemsCollection.Insert(index, itemModel);
                    SelectedItem = null;
                    updateForm();
                    MessageBox.Show($"Pomyslnie edytowano artykuł:\nID: {itemModel.ItemID}\nNazwa artykułu: {itemModel.ItemName}");
                }

                
            }
            
        }
Esempio n. 3
0
        internal void InsertItems(object parent, List <object> items, int itemsLevel, ViewItem target)
        {
            if (items == null || items.Count == 0 || (parent == this && target != null && target.Selected))
            {
                return;
            }
            if (ItemsCollection.Sort.SortType != SortProperties.SortTypes.None)
            {
                MessageBox.Show("Корректная вставка объектов возможна только после отмены сортировки");
                return;
            }
            if (ItemsCollection.Filter.Any)
            {
                MessageBox.Show("Корректная вставка объектов возможна только после отмены фильтрации");
                return;
            }
            List <UndoRedoManager.RemoveCommand> removeCommands = null;

            UndoRedoManager.PasteCommand pasteCommand = null;
            IsInserting = true;
            bool select = false;

            if (parent == this)
            {
                removeCommands = Remove(false, true);
            }
            if (ItemsCollection.Count == 0)
            {
                if (PasteOptions.PasteType == PasteOptions.PasteTypes.InChildren || (PasteOptions.PasteType == PasteOptions.PasteTypes.InLevel && (itemsLevel == 1 || itemsLevel == int.MaxValue)))
                {
                    ItemsCollection.Insert(0, items);
                    if (IsUndoRedo)
                    {
                        pasteCommand = new UndoRedoManager.PasteCommand(items, null, 0);
                    }
                    select = true;
                }
            }
            else if ((target == null ? ItemsCollection.Count - 1 : target.Index) is int index && index >= 0)
            {
                if (PasteOptions.PasteType == PasteOptions.PasteTypes.InLevel)
                {
                    object           selectItem = ItemsCollection.GetItem(index);
                    IChildCollection selectColl = selectItem as IChildCollection;
                    if (selectColl == null || itemsLevel <= selectColl.DropLevel)
                    {
                        while (selectColl != null && itemsLevel != selectColl.DropLevel)
                        {
                            selectColl = selectColl.Parent as IChildCollection;
                        }
                        if (selectColl == null || (itemsLevel == 1 && selectColl.DropLevel == 1))
                        {
                            if (ItemsCollection.SourceContainer.IndexOf(selectColl == null ? selectItem : selectColl) is int iIndex && iIndex != -1)
                            {
                                ItemsCollection.Insert(iIndex + 1, items);
                                if (IsUndoRedo)
                                {
                                    pasteCommand = new UndoRedoManager.PasteCommand(items, null, iIndex + 1);
                                }
                                select = true;
                            }
                        }
                        else if (selectColl.DropLevel == itemsLevel && selectColl.Parent is IChildCollection pcoll)
                        {
                            for (int j = 0; j < pcoll.Count; j++)
                            {
                                if (pcoll[j] == selectColl)
                                {
                                    pcoll.InsertRange(j + 1, items);
                                    if (IsUndoRedo)
                                    {
                                        pasteCommand = new UndoRedoManager.PasteCommand(items, pcoll, j + 1);
                                    }
                                    select = true;
                                    break;
                                }
                            }
                        }
                    }
                    else if (selectColl != null && itemsLevel == selectColl.DropLevel + 1)
                    {
                        int iIndex = selectColl.Count;
                        selectColl.InsertRange(iIndex, items);
                        selectColl.Dropped = true;
                        if (IsUndoRedo)
                        {
                            pasteCommand = new UndoRedoManager.PasteCommand(items, selectColl, iIndex);
                        }
                        select = true;
                    }
                }
                else if (PasteOptions.PasteType == PasteOptions.PasteTypes.InChildren && ItemsCollection.GetItem(index) is IChildCollection collection)
                {
                    int iIndex = collection.Count - 1;
                    collection.InsertRange(iIndex, items);
                    collection.Dropped = true;
                    if (IsUndoRedo)
                    {
                        pasteCommand = new UndoRedoManager.PasteCommand(items, collection, iIndex);
                    }
                    select = true;
                }
            }
            if (select)
            {
                Select(items);
            }
            if (IsUndoRedo && (removeCommands != null || pasteCommand != null))
            {
                UndoRedoManager.RegistredNewCommand(new UndoRedoManager.MoveCommand(removeCommands, pasteCommand));
            }
            IsInserting = false;
        }