Esempio n. 1
0
 int UpdateIndexToSelect(IDataListItem itemToRemove, IDataListItem item)
 {
     if (itemToRemove.Index == item.Index)
     {
         var item1 = item;
         return(WorkflowInputs.IndexOf(WorkflowInputs.Last(c => c.Recordset == item1.Recordset)));
     }
     return(WorkflowInputs.IndexOf(itemToRemove));
 }
        /// <summary>
        /// Used for removing a row for the collection
        /// </summary>
        /// <param name="itemToRemove">The item that will be removed from the collection</param>
        /// <param name="indexToSelect"></param>
        public bool RemoveRow(IDataListItem itemToRemove, out int indexToSelect)
        {
            indexToSelect = 1;
            var itemsRemoved = false;

            if (itemToRemove != null && itemToRemove.IsRecordset)
            {
                // ReSharper disable InconsistentNaming
                IEnumerable <IDataListItem> NumberOfRows = WorkflowInputs.Where(c => c.Recordset == itemToRemove.Recordset && c.Field == itemToRemove.Field);
                // ReSharper restore InconsistentNaming
                var numberOfRows = NumberOfRows.Count();
                List <IDataListItem> listToRemove = WorkflowInputs.Where(c => c.RecordsetIndex == numberOfRows.ToString(CultureInfo.InvariantCulture) && c.Recordset == itemToRemove.Recordset).ToList();

                if (numberOfRows == 2)
                {
                    IEnumerable <IDataListItem> firstRow = WorkflowInputs.Where(c => c.RecordsetIndex == "1" && c.Recordset == itemToRemove.Recordset);
                    bool removeRow = firstRow.All(item => string.IsNullOrWhiteSpace(item.Value));

                    if (removeRow)
                    {
                        IEnumerable <IDataListItem> listToChange = WorkflowInputs.Where(c => c.RecordsetIndex == "2" && c.Recordset == itemToRemove.Recordset);

                        foreach (IDataListItem item in listToChange)
                        {
                            item.Value = string.Empty;
                        }
                        foreach (IDataListItem item in listToRemove)
                        {
                            WorkflowInputs.Remove(item);
                            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                            if (itemToRemove.RecordsetIndex == item.RecordsetIndex)
                            {
                                IDataListItem item1 = item;
                                indexToSelect = WorkflowInputs.IndexOf(WorkflowInputs.Last(c => c.Recordset == item1.Recordset));
                            }
                            else
                            {
                                indexToSelect = WorkflowInputs.IndexOf(itemToRemove);
                            }
                            itemsRemoved = true;
                        }
                    }
                }
                else if (numberOfRows > 2)
                {
                    IEnumerable <IDataListItem> listToChange = WorkflowInputs.Where(c => c.RecordsetIndex == (numberOfRows - 1).ToString(CultureInfo.InvariantCulture) && c.Recordset == itemToRemove.Recordset);
                    foreach (IDataListItem item in listToChange)
                    {
                        item.Value = string.Empty;
                    }
                    foreach (IDataListItem item in listToRemove)
                    {
                        WorkflowInputs.Remove(item);
                        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                        if (itemToRemove.RecordsetIndex == item.RecordsetIndex)
                        {
                            IDataListItem item1 = item;
                            indexToSelect = WorkflowInputs.IndexOf(WorkflowInputs.Last(c => c.Recordset == item1.Recordset));
                        }
                        else
                        {
                            indexToSelect = WorkflowInputs.IndexOf(itemToRemove);
                        }
                        itemsRemoved = true;
                    }
                }
            }
            return(itemsRemoved);
        }