Beispiel #1
0
        public void ProcessOffline(PasteParam pasteParam)
        {
            var            listview   = (ListView)view;
            GridListEditor listEditor = listview.Editor as GridListEditor;
            var            gridView   = listEditor.GridView;

            int[] selectedRowHandles = gridView.GetSelectedRows();
            var   gridColumn         = gridView.FocusedColumn;
            var   copiedValues       = copyParser.ToArray();
            var   objs = view.SelectedObjects;

            int pasteCount = 0;

            // paste rows
            for (int r = 0; r < copiedValues.Length; r++)
            {
                // ignore row with empty string
                if (copiedValues[r].Length == 1 && string.IsNullOrWhiteSpace(copiedValues[r][0]))
                {
                    continue;
                }

                // select next row in gridview
                var obj = (IXPObject)objs[r];

                // paste cells
                offlinePasteUtils.PasteColumnsToRow(copiedValues[r], obj,
                                                    listview, pasteParam, gridColumn.VisibleIndex);

                pasteCount++;
            }
            offlinePasteUtils.Logger.Log("{0} rows updated", pasteCount++);
        }
Beispiel #2
0
        // note that the new row must be focused for this to work
        public void Process(int[] selectedRowHandles, PasteParam pasteParam)
        {
            var            listview     = (ListView)view;
            GridListEditor listEditor   = listview.Editor as GridListEditor;
            var            gridView     = listEditor.GridView;
            var            copiedValues = copyParser.ToArray();

            // paste rows
            for (int r = 0; r < copiedValues.Length; r++)
            {
                // ignore row with empty string
                if (copiedValues[r].Length == 1 && string.IsNullOrWhiteSpace(copiedValues[r][0]))
                {
                    continue;
                }

                // add new row in gridview
                gridView.FocusedRowHandle = selectedRowHandles[r];

                // paste cells
                pasteUtils.PasteColumnsToRow(copiedValues[r], gridView.FocusedRowHandle,
                                             listview, pasteParam);

                gridView.UpdateCurrentRow();
            }
        }
Beispiel #3
0
        private void PasteRowValues(PasteParam pasteParam)
        {
            // create Paste Processor
            var clipboard                 = new Clipboard();
            var clipboardParser           = new CopyParser(clipboard);
            var newRowPasteProcessor      = new NewRowPasteProcessor(clipboardParser, this.View);
            var existingRowPasteProcessor = new ExistingRowPasteProcessor(clipboardParser, this.View);


            string[][] copiedValues = clipboardParser.ToArray();
            if (copiedValues == null)
            {
                return;
            }

            GridListEditor listEditor = ((ListView)View).Editor as GridListEditor;

            if (listEditor != null)
            {
                var gridView = listEditor.GridView;

                if ((gridView.IsNewItemRow(gridView.FocusedRowHandle)))
                {
                    // paste to new rows
                    newRowPasteProcessor.Process(pasteParam);
                }
                else
                {
                    // paste to selected rows
                    int[] selectedRowHandles = gridView.GetSelectedRows();
                    existingRowPasteProcessor.Process(selectedRowHandles, pasteParam);
                }
            }
        }
Beispiel #4
0
        public void ProcessOffline(PasteParam pasteParam)
        {
            var            listview     = (ListView)view;
            GridListEditor listEditor   = listview.Editor as GridListEditor;
            var            gridView     = listEditor.GridView;
            var            copiedValues = copyParser.ToArray();
            var            newRowHandle = gridView.FocusedRowHandle;
            var            os           = listview.ObjectSpace;

            if (!gridView.IsNewItemRow(gridView.FocusedRowHandle))
            {
                return;
            }

            int pasteCount = 0;

            // paste rows
            for (int r = 0; r < copiedValues.Length; r++)
            {
                // ignore row with empty string
                if (copiedValues[r].Length == 1 && string.IsNullOrWhiteSpace(copiedValues[r][0]))
                {
                    continue;
                }
                var obj = (IXPObject)os.CreateObject(view.ObjectTypeInfo.Type);
                offlinePasteUtils.PasteColumnsToRow(copiedValues[r], obj,
                                                    listview, pasteParam);

                pasteCount++;
            }
            offlinePasteUtils.Logger.Log("{0} rows inserted", pasteCount++);
        }
Beispiel #5
0
        private void PasteRowValues(PasteParam pasteParam)
        {
            // create clipboard parser
            var clipboard       = new Clipboard();
            var clipboardParser = new CopyParser(clipboard);

            // validate

            string[][] copiedValues = clipboardParser.ToArray();
            if (copiedValues == null)
            {
                return;
            }

            if (copiedValues.GetLength(0) > PasteSettings.MaximumOnlineRows)
            {
                logger.Log("Rows exceeded the maximum of {0}. OFFLINE mode used.",
                           PasteSettings.MaximumOnlineRows);

                var sw = new Stopwatch();
                sw.Start();
                PasteOfflineRowValues(pasteParam, false);
                sw.Stop();
                logger.Log("Import completed in {0:0.00} seconds.", sw.Elapsed.TotalSeconds);

                new Xafology.ExpressApp.SystemModule.GenericMessageBox(
                    logger.LogMessage, "Import SUCCESSFUL");
                return;
            }
            // create Paste Processor
            var newRowPasteProcessor      = new NewRowPasteProcessor(clipboardParser, this.View);
            var existingRowPasteProcessor = new ExistingRowPasteProcessor(clipboardParser, this.View);

            GridListEditor listEditor = ((ListView)View).Editor as GridListEditor;

            if (listEditor != null)
            {
                var gridView = listEditor.GridView;

                if ((gridView.IsNewItemRow(gridView.FocusedRowHandle)))
                {
                    // paste to new rows
                    newRowPasteProcessor.Process(pasteParam);
                }
                else
                {
                    // paste to selected rows
                    existingRowPasteProcessor.Process(pasteParam);
                }
            }
        }
Beispiel #6
0
        private void PasteCommitRowValues(PasteParam pasteParam, bool isRoot = false)
        {
            int commitInterval = 100;
            // create Paste Processor
            var clipboard                 = new Clipboard();
            var clipboardParser           = new CopyParser(clipboard);
            var newRowPasteProcessor      = new NewRowPasteProcessor(clipboardParser, this.View, logger);
            var existingRowPasteProcessor = new ExistingRowPasteProcessor(clipboardParser, this.View, logger);

            string[][] copiedValues = clipboardParser.ToArray();
            if (copiedValues == null)
            {
                return;
            }

            GridListEditor listEditor = ((ListView)View).Editor as GridListEditor;

            if (listEditor != null)
            {
                var sw = new Stopwatch();
                sw.Start();

                var gridView = listEditor.GridView;

                if ((gridView.IsNewItemRow(gridView.FocusedRowHandle)))
                {
                    // paste to new rows
                    newRowPasteProcessor.ProcessOffline(pasteParam, commitInterval);
                }
                else
                {
                    existingRowPasteProcessor.ProcessOffline(pasteParam, commitInterval);
                }

                sw.Stop();
                logger.Log("Import completed in {0:0.00} seconds.", sw.Elapsed.TotalSeconds);
                logger.Log("Changes saved to database.");
                if (isRoot)
                {
                    new Xafology.ExpressApp.SystemModule.GenericMessageBox(
                        logger.LogMessage, "Import SUCCESSFUL");
                }
            }
        }
Beispiel #7
0
        public void PasteColumnsToRow(string[] copiedRowValues, IXPObject obj, ListView view, PasteParam pasteParam, int startColumnIndex)
        {
            var listEditor = ((ListView)view).Editor as GridListEditor;
            var objSpace   = ((ListView)view).ObjectSpace;
            var gridView   = listEditor.GridView;

            // iterate through columns in listview
            int gridColumnIndex   = startColumnIndex;
            int copiedColumnIndex = 0;

            var hasGroups = gridView.Columns.Where(x => x.GroupIndex != -1).Count() > 0;

            if (hasGroups)
            {
                throw new UserFriendlyException("Please ungroup columns before pasting rows");
            }

            var gridColumns = gridView.Columns
                              .Where(x => x.Visible && x.GroupIndex == -1 &&
                                     x.VisibleIndex >= startColumnIndex)
                              .OrderBy(x => x.VisibleIndex)
                              .Select(x => x);

            foreach (var gridColumn in gridColumns)
            {
                if (copiedColumnIndex >= copiedRowValues.Length)
                {
                    break;
                }

                var member   = listEditor.Model.Columns[gridColumn.Name];
                var isLookup = typeof(IXPObject).IsAssignableFrom(member.ModelMember.MemberInfo.MemberType);

                var copiedValue = copiedRowValues[copiedColumnIndex];

                // if column is visible in grid, then increment the copiedValue column counter
                if (gridColumn.Visible)
                {
                    gridColumnIndex++;
                    copiedColumnIndex++;
                }
                // skip non-editable, key column, invisible column or blank values
                // otherwise paste values

                var memberInfo = member.ModelMember.MemberInfo;
                if (member.AllowEdit &&
                    member.PropertyName != listEditor.Model.ModelClass.KeyProperty &&
                    !string.IsNullOrEmpty(copiedValue) &&
                    !string.IsNullOrWhiteSpace(copiedValue)
                    )
                {
                    PasteFieldMap fieldMap = null;
                    if (pasteParam != null)
                    {
                        fieldMap = pasteParam.FieldMaps.Where(m => m.TargetName.ToLower() == gridColumn.Name.ToLower()).FirstOrDefault();
                    }

                    #region Core Logic
                    if (fieldMap == null)
                    {
                        xpoFieldMapper.SetMemberValue(obj, memberInfo, copiedValue, true, true);
                    }
                    else
                    {
                        xpoFieldMapper.SetMemberValue(obj, memberInfo, copiedValue,
                                                      fieldMap.CreateMember, fieldMap.CacheObject);
                    }
                    #endregion
                }
            }
        }
Beispiel #8
0
 public void PasteColumnsToRow(string[] copiedRowValues, IXPObject obj, ListView view, PasteParam pasteParam)
 {
     PasteColumnsToRow(copiedRowValues, obj, view, pasteParam, 0);
 }
Beispiel #9
0
 public void PasteColumnsToRow(string[] copiedRowValues, int focusedRowHandle, ListView view, PasteParam pasteParam)
 {
     PasteColumnsToRow(copiedRowValues, focusedRowHandle, view, pasteParam, 0);
 }