예제 #1
0
        /// <summary>
        /// 导出当前对象
        /// </summary>
        public static void ExportObject(object obj
                                        , string defaultFileName = null
                                        , params string[] defaultFileExtentions)
        {
            string fileName = defaultFileName;

            string[] fileExtentions;
            if (defaultFileExtentions.IsNotNullOrEmpty())
            {
                fileExtentions = defaultFileExtentions;
            }
            else
            {
                fileExtentions = new string[]
                {
                    FileExtentions.CONFIG
                    , FileExtentions.XML
                    , FileExtentions.All
                };
            }
            if (UIPublic.ShowSaveFileDialog("导出", ref fileName
                                            , fileExtentions) == DialogReturn.OK)
            {
                if (fileName.IsNullOrEmpty())
                {
                    UIPublic.ShowErrorDialog("输入了错误的文件名");
                }
                else
                {
                    IOPublic.WriteObjectToFile(fileName, obj);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 添加菜单到子菜单中(包含下级菜单)
        /// </summary>
        /// <param name="barSubItem">子菜单</param>
        /// <param name="uiItem">菜单项</param>
        /// <param name="container">视图容器</param>
        public static void AddMenuToSubItem(object barSubItem, IUIItem uiItem, IViewContainer container)
        {
            BarItem barItem = null;

            if (uiItem is FolderItem)
            {
                var menuItem = uiItem as FolderItem;
                if (menuItem.ChildMenuItems.IsNotNull())
                {
                    var newSubItem = new BarSubItem();
                    foreach (var childFunctionItem in menuItem.ChildMenuItems)
                    {
                        AddMenuToSubItem(newSubItem, childFunctionItem, container);
                    }
                    barItem = newSubItem;
                }
            }
            if (barItem == null)
            {
                barItem = new BarButtonItem();
            }

            barItem.Caption    = uiItem.Caption;
            barItem.Glyph      = uiItem.Icon;
            barItem.LargeGlyph = uiItem.LargeIcon;
            barItem.ItemClick += (sender, e) =>
            {
                try {
                    if (uiItem is BaseController)
                    {
                        var controller = uiItem as BaseController;
                        controller.CreateAndOpenView(container);
                    }
                } catch (Exception err) {
                    UIPublic.ShowErrorDialog(err.FormatException());
                }
            };

            if (barSubItem is BarSubItem)
            {
                var barItemLink = barSubItem.As <BarSubItem>().AddItem(barItem);
                barItemLink.RecentIndex = 1;
            }
            else if (barSubItem is Bar)
            {
                var barItemLink = barSubItem.As <Bar>().AddItem(barItem);
            }
            else
            {
                throw new Exception("此对象不支持添加子菜单");
            }
        }
예제 #3
0
        /// <summary>
        /// 导入对象
        /// </summary>
        public static void ImportObject(Action <object> action
                                        , string defaultFileName = null
                                        , params string[] defaultFileExtentions)
        {
            string fileName = defaultFileName;

            string[] fileExtentions;
            if (defaultFileExtentions.IsNotNullOrEmpty())
            {
                fileExtentions = defaultFileExtentions;
            }
            else
            {
                fileExtentions = new string[]
                {
                    FileExtentions.CONFIG
                    , FileExtentions.XML
                    , FileExtentions.All
                };
            }
            if (UIPublic.ShowOpenFileDialog("导入", ref fileName
                                            , fileExtentions) == DialogReturn.OK)
            {
                if (!File.Exists(fileName))
                {
                    UIPublic.ShowErrorDialog("选择的文件不存在");
                }
                else
                {
                    var obj = IOPublic.ReadObjectFromFile(fileName);
                    try {
                        action(obj);
                    }
                    catch (Exception err) {
                        UIPublic.ShowErrorDialog(err.Message);
                    }
                }
            }
        }