我需要一个控件,允许我从用户文件系统中选择文件或文件夹(或两者)。是否有某种控制可用于现有屏幕和新屏幕?
答案 0 :(得分:4)
我已经将文件和文件夹选择器组合在同一个控件中,但我认为这很容易让你理解如何做任何一个。 我使用SOOrderEntry的扩展我的例子,但它对于新屏幕或其他现有屏幕的原则是相同的。
在PXDataSource元素中,添加Datatrees和PXTreeDataMember元素,如下所示:
<px:PXDataSource ID="ds" runat="server" Visible="True" Width="100%" TypeName="PX.Objects.SO.SOOrderEntry" PrimaryView="Document">
<DataTrees>
<px:PXTreeDataMember TreeView="FilesTree" TreeKeys="FileKey" />
</DataTrees>
</px:PXDataSource>
在formView元素中,添加PXTreeSelector:
<px:PXFormView ID="PXFormView2" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" DataMember="Document" Caption="Order Summary"
NoteIndicator="True" FilesIndicator="True" LinkIndicator="True" EmailingGraph="PX.Objects.CR.CREmailActivityMaint,PX.Objects"
ActivityIndicator="True" ActivityField="NoteActivity" DefaultControlID="edOrderType" NotifyIndicator="True"
TabIndex="14900">
<Template>
<px:PXTreeSelector runat="server" TreeDataSourceID="ds" TreeDataMember="FilesTree" InitialExpandLevel="0" MinDropWidth="413" PopulateOnDemand="True" ShowRootNode="False" AllowEditValue="True" SelectOnFocus="False" DataField="ParentFolder" ID="edPathSelector">
<DataBindings>
<px:PXTreeItemBinding DataMember="FilesTree" TextField="FileName" ValueField="FilePath" DescriptionField="FilePath" ImageUrlField="Icon" />
</DataBindings>
</px:PXTreeSelector>
</Template>
</px:PXFormView>
这是我的DAC和图表扩展。如您所见,该图几乎只将.NET函数调用为可枚举的文件和文件夹。要专门控制文件夹或文件,您只需要返回正确的元素。
using PX.Data;
using PX.Web.UI;
using System;
using System.Collections;
using System.IO;
using System.Linq;
namespace PX.Objects.SO
{
[Serializable]
public class RowFilesTree : IBqlTable
{
[PXString(IsKey = true, IsUnicode = true)]
[PXUIField(DisplayName = "FileKey")]
public string FileKey { get; set; }
public class fileKey : IBqlField { }
[PXString]
[PXUIField(DisplayName = "Path")]
public string FilePath { get; set; }
public class filePath : IBqlField { }
[PXString]
[PXUIField(DisplayName = "Name")]
public string FileName { get; set; }
public class fileName : IBqlField { }
[PXString(250)]
public virtual string Icon { get; set; }
public abstract class icon : IBqlField {}
}
public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
public PXSelect<RowFilesTree> FilesTree;
protected virtual IEnumerable filesTree([PXString]string FilePath)
{
if (string.IsNullOrEmpty(FilePath))
{
var folders = Directory.GetLogicalDrives();
foreach (var folder in folders)
{
yield return new RowFilesTree()
{
FileKey = folder.Replace(':', '>'),
FileName = folder,
FilePath = folder,
Icon = Sprite.Tree.GetFullUrl(Sprite.Tree.Folder)
};
}
}
else
{
var folders = new string[0];
var files = new string[0];
try
{
var decode = FilePath.Replace('>', ':');
folders = Directory.GetDirectories(decode);
files = Directory.GetFiles(decode);
}
catch
{
}
foreach (var folder in folders)
{
yield return new RowFilesTree()
{
FileKey = folder.Replace(':', '>'),
FileName = Path.GetFileName(folder),
FilePath = folder,
Icon = Sprite.Tree.GetFullUrl(Sprite.Tree.Folder)
};
}
foreach (var file in files)
{
yield return new RowFilesTree()
{
FileKey = file.Replace(':', '>'),
FileName = Path.GetFileName(file),
FilePath = file,
Icon = Sprite.Tree.GetFullUrl(Sprite.Tree.Leaf)
};
}
}
}
}
}
以下是最终结果: