예제 #1
0
 public override void Load(IEnumerable <long> ids)
 {
     Clear();
     DataService.Select <CatalogItemEntity>().Where(x => ids.Contains(x.Id)).ToList().ForEach(
         x =>
     {
         RepositoryItems.Add(x.Id, x);
     });
 }
예제 #2
0
 public override void Load()
 {
     Clear();
     DataService.Select <CatalogItemEntity>().ToList().ForEach(
         x =>
     {
         RepositoryItems.Add(x.Id, x);
     });
 }
예제 #3
0
 public void SetRepositoryItem(string fieldName, RepositoryItem item)
 {
     RepositoryItems.Add(item);
     Columns.Where(x => x.FieldName == fieldName).ToList().ForEach(x =>
     {
         x.ColumnEdit     = item;
         x.ShowButtonMode = ShowButtonModeEnum.ShowAlways;
     });
     item.EditValueChanged += delegate(object sender, EventArgs e)
     {
         PostEditor();
     };
 }
예제 #4
0
        //private RepositoryItemFontEdit repositoryItemFontEdit1;
        public PropertyGridControl()
        {
            if (!DesignMode)
            {
                Dock = DockStyle.Fill;
                //LookAndFeel.SkinName = "Lilian";
                //LookAndFeel.UseDefaultLookAndFeel = false;

                //repositoryItemFontEdit1 = new RepositoryItemFontEdit();
                RepositoryItemPictureEdit repositoryItemPictureEdit1 = new RepositoryItemPictureEdit();
                repositoryItemPictureEdit1.CustomHeight = 64;
                repositoryItemPictureEdit1.ReadOnly     = true;
                repositoryItemPictureEdit1.ShowMenu     = false;
                repositoryItemPictureEdit1.SizeMode     = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;

                LineStyleRepositoryItemEdit lineStypeEdit = new LineStyleRepositoryItemEdit();
                RepositoryItemPWColorEdit   colorEditor   = new RepositoryItemPWColorEdit();
                //RepositoryItemColorEdit colorEditor = new RepositoryItemColorEdit();
                colorEditor.ShowSystemColors = false;

                this.DefaultEditors.AddRange(new DevExpress.XtraVerticalGrid.Rows.DefaultEditor[]
                {
                    new DevExpress.XtraVerticalGrid.Rows.DefaultEditor(typeof(System.Drawing.Image),
                                                                       repositoryItemPictureEdit1)
                    , new DefaultEditor(typeof(DashKind), lineStypeEdit)
                    , new DefaultEditor(typeof(Color), colorEditor)
                });

                RepositoryItems.AddRange(new RepositoryItem[]
                {
                    repositoryItemPictureEdit1
                    , lineStypeEdit
                    , colorEditor
                });
                AutoGenerateRows = true;

                TreeButtonStyle = TreeButtonStyle.TreeView;
                lineStypeEdit.SelectedIndexChanged += new EventHandler(lineStypeEdit_SelectedIndexChanged);
                CellValueChanged += new DevExpress.XtraVerticalGrid.Events.CellValueChangedEventHandler(PropertyGridControl_CellValueChanged);
            }
            RegisterHelp();
        }
예제 #5
0
        private void InitComponent(bool isInsert)
        {
            repositoryItemColorEdit.ShowCustomColors = false;
            repositoryItemColorEdit.ShowSystemColors = false;
            RepositoryItems.Add(repositoryItemColorEdit);
            RepositoryItems.Add(repositoryItemCheckEdit);

            repositoryItemCheckEdit.AutoHeight = false;
            repositoryItemCheckEdit.NullStyle  = StyleIndeterminate.Unchecked;

            nameColumn         = Columns.AddField("Name");
            nameColumn.Visible = true;
            nameColumn.OptionsColumn.AllowEdit = false;
            typeColumn         = Columns.AddField("Type");
            typeColumn.Visible = false;
            typeColumn.OptionsColumn.AllowEdit = false;
            lengthColumn         = Columns.AddField("Length");
            lengthColumn.Visible = true;
            lengthColumn.OptionsColumn.AllowEdit = false;
            colorColumn         = Columns.AddField("Color");
            colorColumn.Visible = false;
            colorColumn.OptionsColumn.AllowEdit = true;
            activeColumn         = Columns.AddField("Checked");
            activeColumn.Visible = false;
            //if(ModuleManager.CurrentModuleName ==
            activeColumn.OptionsColumn.AllowEdit = isInsert;


            Dock = DockStyle.Fill;
            //OptionsBehavior.AutoChangeParent = false;
            //OptionsBehavior.AutoNodeHeight = false;
            //OptionsBehavior.AutoSelectAllInEditor = false;
            //OptionsBehavior.CloseEditorOnLostFocus = false;
            //OptionsBehavior.Editable = true;
            //OptionsBehavior.ExpandNodeOnDrag = false;
            //OptionsBehavior.ImmediateEditor = false;
            //OptionsBehavior.KeepSelectedOnClick = false;
            //OptionsBehavior.MoveOnEdit = false;
            //OptionsBehavior.ResizeNodes = false;
            //OptionsBehavior.SmartMouseHover = false;
            OptionsView.ShowButtons      = false;
            OptionsView.ShowColumns      = true;
            OptionsView.ShowFocusedFrame = false;
            OptionsView.ShowHorzLines    = false;
            OptionsView.ShowRoot         = false;
            OptionsView.ShowVertLines    = false;
            OptionsMenu.EnableColumnMenu = false;
            OptionsMenu.EnableFooterMenu = false;
            TreeLevelWidth = 12;

            ImageList imgList;

            imgList = new ImageList();
            imgList.Images.Add(Resource.GetImage(Resource.Images.Image16));
            imgList.Images.Add(Resource.GetImage(Resource.Images.Video16));
            imgList.Images.Add(Resource.GetImage(Resource.Images.MessageIcon16x16));
            imgList.Images.Add(Resource.GetImage(Resource.Images.InsertTimeSliceGroup16));
            imgList.Images.Add(Resource.GetImage(Resource.Images.PlaylistIcon16x16));
            imgList.Images.Add(Resource.GetImage(Resource.Images.SchedulerIcon16x16));
            SelectImageList  = imgList;
            ContextMenuStrip = new LibraryContextMenuStrip(this);
        }
        private void InitCommands()
        {
            AddCommand = new DelegateCommand(() =>
            {
                AddEditWindow aer      = new AddEditWindow();
                IRepositoryItem result = aer.Show(null);

                if (result != null)
                {
                    if (SelectedItem != null)
                    {
                        result.Parent = SelectedItem;
                        SelectedItem.Items.Add(result);
                    }
                    else
                    {
                        result.Parent = null;
                        RepositoryItems.Add(result);
                    }
                    App.Log.Log(String.Format("В репозиторий добавлен элемент <{0}>", result));
                    OnPropertyChanged("IsEmptyList");
                    Save();
                }
            });

            RemoveCommand = new DelegateCommand(() =>
            {
                if (SelectedItem == null)
                {
                    return;
                }

                if (App.ShowQuestion("Вы действительно хотите удалить запись с именем '" + SelectedItem.Title + "'?") == System.Windows.MessageBoxResult.Yes)
                {
                    IRepositoryItem parent = SelectedItem.Parent;
                    if (parent != null)
                    {
                        parent.Items.Remove(SelectedItem);
                    }
                    else
                    {
                        RepositoryItems.Remove(SelectedItem);
                    }
                    App.Log.Log(String.Format("Из репозитория удалён элемент <{0}>", SelectedItem));
                    Save();
                }
            }, (param) =>
            {
                return(SelectedItem != null);
            });

            EditCommand = new DelegateCommand(() =>
            {
                if (SelectedItem == null)
                {
                    throw new InvalidOperationException("EditCommand - SelectedItem == null");
                }
                App.Log.Log(String.Format("Попытка изменения элемента репозитория: <{0}>", SelectedItem));
                AddEditWindow aer      = new AddEditWindow();
                aer.Owner              = App.Current.MainWindow;
                IRepositoryItem result = aer.Show(SelectedItem.Clone());

                if (result != null)
                {
                    IRepositoryItem parent = SelectedItem.Parent;
                    if (parent != null)
                    {
                        int index = parent.Items.IndexOf(SelectedItem);
                        if (index > 0)
                        {
                            parent.Items[index] = result;
                        }
                        SelectedItem = result;
                    }
                    else
                    {
                        SelectedItem = result;
                    }
                    App.Log.Log(String.Format("Изменённый элемент репозитория: <{0}>", result));
                    Save();
                }
            }, (param) =>
            {
                return(SelectedItem != null);
            });

            LoadCommand = new DelegateCommand(() =>
            {
                if (SelectedItem == null)
                {
                    throw new InvalidOperationException("EditCommand - SelectedItem == null");
                }

                if (SelectedItem.Type == RepositoryItemType.Group)
                {
                    throw new ArgumentException("Выбрана не запись, а группа!");
                }

                SqlViewModel = (SelectedItem as RepositoryItem).SqlViewModel;

                FuncSqlViewModelSelected?.Invoke(this, new SelectFuncSqlViewModelEventArgs(SelectedItem.Title, SqlViewModel));

                App.Log.Log(String.Format("Выбран элемент репозитория: <{0}>", SelectedItem));
            }, (param) =>
            {
                return(SelectedItem is RepositoryItem);
            });

            ImportCommand = new DelegateCommand(() =>
            {
                if (RepositoryItems != null && RepositoryItems.Count > 0)
                {
                    if (App.ShowQuestion("Очистить список перед импортом'?") == System.Windows.MessageBoxResult.Yes)
                    {
                        RepositoryItems.Clear();
                    }
                }
                Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
                ofd.AddExtension    = true;
                ofd.CheckFileExists = true;
                ofd.Filter          = String.Format("Файл списка запросов (*{0})|*{0}", RequestsRepository.REPOSITORY_FILE_EXTENSION);
                ofd.FilterIndex     = 0;
                bool?show           = ofd.ShowDialog(Application.Current.MainWindow);
                if (show != null && show.HasValue && show.Value == true)
                {
                    App.Log.Log("Попытка импорта списка запросов из файла '" + ofd.FileName + "'");
                    bool success = true;
                    IList <IRepositoryItem> list = Common.RepositoryCommon.BaseDeserializer <List <IRepositoryItem> > .GzJsonDeSerialize(
                        ofd.FileName,
                        (e) =>
                    {
                        success = false;
                        App.ToLogException(e);
                        App.ShowError(String.Format("Не удалось импортировать список запросов.\n\t{0}", e.Message), "ОШИБКА");
                    });
                    if (list != null)
                    {
                        var notImported = new List <IRepositoryItem>();
                        foreach (var item in list)
                        {
                            if (_repository.AddRepositoryItem(item) == false)
                            {
                                notImported.Add(item);
                            }
                        }
                        int toImportCount    = GetRequestsCountInList(list);
                        int notImportedCount = GetRequestsCountInList(notImported);
                        int allCount         = GetRequestsCountInList(RepositoryItems);
                        string message       = String.Format("Завершён. Импортировано {0} запросов из списка. Не удалось импортировать {1} запросов. Всего сейчас в списке {2} запросов.",
                                                             toImportCount - notImportedCount, notImportedCount, allCount);
                        App.Log.Log(message);
                        App.ShowInfo(message, "ИМПОРТ");
                    }
                    else if (success)
                    {
                        string message = "Ничего не импортировано. Файл пуст!";
                        App.Log.Log(message);
                        App.ShowInfo(message, "ИМПОРТ");
                    }
                }
            });
            ExportCommand = new DelegateCommand(() =>
            {
                Microsoft.Win32.SaveFileDialog ofd = new Microsoft.Win32.SaveFileDialog();
                ofd.AddExtension = true;
                ofd.Filter       = String.Format("Файл списка запросов (*{0})|*{0}", RequestsRepository.REPOSITORY_FILE_EXTENSION);
                ofd.FilterIndex  = 0;
                bool?show        = ofd.ShowDialog(Application.Current.MainWindow);
                if (show != null && show.HasValue && show.Value == true)
                {
                    App.Log.Log("Попытка экспорта списка запросов в файл '" + ofd.FileName + "'");
                    bool success = true;
                    Common.RepositoryCommon.BaseDeserializer <List <IRepositoryItem> > .GzJsonSerialize(
                        RepositoryItems.ToList(),
                        ofd.FileName,
                        (e) =>
                    {
                        success = false;
                        App.ToLogException(e);
                        App.ShowError(String.Format("Не удалось экспортировать список запросов.\n\t{0}", e.Message), "ОШИБКА");
                    });
                    if (success)
                    {
                        string message = String.Format("Экспортировано {0} запросов.", RepositoryItems.Count);
                        App.Log.Log(message);
                        App.ShowInfo(message, "ЭКСПОРТ");
                    }
                }
            }, (param) =>
            {
                if (RepositoryItems == null)
                {
                    return(false);
                }
                else
                {
                    return(RepositoryItems.Count != 0);
                }
            });
        }