以采购订单和采购申请单这两个业务对象为例。
[code] private void Export()
{
PrintExportInfo pExInfo = GetExportEntityInfo();
BillView dynamicWebFormView = (BillView)this.View;
dynamicWebFormView.ExportNotePrint(pExInfo);
}
private PrintExportInfo GetExportEntityInfo(string formId, List
{
IDynamicFormView view = CreateView(this.Context, formId);
//单据内码与套打模板标识一一对应
PrintExportInfo pExInfo = new PrintExportInfo();
pExInfo.view = view;
pExInfo.PageId = view.PageId;
pExInfo.FormId = view.BillBusinessInfo.GetForm().Id;
pExInfo.BillIds = billIds;//单据内码
pExInfo.TemplateIds = tempIds;//套打模板ID
pExInfo.FileType = ExportFileType.PDF;//文件格式
pExInfo.ExportType = ExportType.ByPage;//导出格式
return pExInfo;
}
private PrintExportInfo GetExportEntityInfo()
{
//采购订单
PrintExportInfo pExInfo1 = GetExportEntityInfo("PUR_PurchaseOrder", new List
//采购申请单
PrintExportInfo pExInfo2 = GetExportEntityInfo("PUR_Requisition", new List
PrintExportInfo pExInfo = new PrintExportInfo(); string importViewClass = "Kingdee.BOS.Web.List.ListView,Kingdee.BOS.Web"; ((IListViewService)View).Initialize(OpenParameter, Provider); private ListOpenParameter CreateOpenParameter(OperationStatus status, Context ctx, string formId, FormMetadata _metadata) ListOpenParameter openPara = new ListOpenParameter(formId, _metadata.GetLayoutInfo().Id); // 单据 // 操作相关参数 openPara.SetCustomParameter("SessionManager", CommonSession.GetCurrent(ctx.UserToken).SessionManager); private IResourceServiceProvider GetListServiceProvider(DynamicFormOpenParameter param) /// /// ///
pExInfo.PageId = this.View.PageId;
pExInfo.FormId = this.View.BillBusinessInfo.GetForm().Id;
pExInfo.FileType = ExportFileType.PDF;//文件格式
pExInfo.ExportType = ExportType.ByPage;//导出格式
string fileName = Guid.NewGuid().ToString() + ".PDF";
string filePath= PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, fileName);//文件存储路径
//outServicePath = PathUtils.GetServerPath(KeyConst.TEMPFILEPATH, PathUtils.UrlEncode(fileName));
pExInfo.FilePath = filePath;//文件输出路径
pExInfo.ExportToSingleFile = true;//导出到同一个文件
pExInfo.ExportSingleFileList = new List
return pExInfo;
} #region 创建listview
public IDynamicFormView CreateView(Context ctx, string formId)
{
FormMetadata _metadata = (FormMetadata)ServiceHelper.MetaDataServiceHelper.Load(ctx, formId);
var OpenParameter = CreateOpenParameter(OperationStatus.VIEW, ctx, formId, _metadata);
var Provider = GetListServiceProvider(OpenParameter);
Type type = Type.GetType(importViewClass);
IListViewService View = (IListViewService)Activator.CreateInstance(type);
((IListViewService)View).LoadData();
return (IDynamicFormView)View;
}
{
Form form = _metadata.BusinessInfo.GetForm();
openPara = new ListOpenParameter(formId, string.Empty);
openPara.Context = ctx;
openPara.ServiceName = form.FormServiceName;
openPara.PageId = Guid.NewGuid().ToString();
openPara.FormMetaData = _metadata;
openPara.LayoutId = _metadata.GetLayoutInfo().Id;
openPara.ListFormMetaData = (FormMetadata)FormMetaDataCache.GetCachedFormMetaData(ctx, FormIdConst.BOS_List);
openPara.SetCustomParameter(FormConst.PlugIns, form.CreateListPlugIns());
openPara.SetCustomParameter("filterschemeid", "");
openPara.SetCustomParameter("listfilterparameter", new ListRegularFilterParameter());
// 修改主业务组织无须用户确认
openPara.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
return openPara;
}
{
FormServiceProvider provider = new FormServiceProvider();
provider.Add(typeof(IDynamicFormView), CreateListView(param));
provider.Add(typeof(DynamicFormViewPlugInProxy), new ListViewPlugInProxy());
provider.Add(typeof(DynamicFormModelPlugInProxy), new ListModelPlugInProxy());
provider.Add(typeof(IDynamicFormModelService), GetListModel(param));
provider.Add(typeof(IListFilterModelService), GetListFilterModel());
var type = TypesContainer.GetOrRegister("Kingdee.BOS.Business.DynamicForm.DefaultValue.DefaultValueCalculator,Kingdee.BOS.Business.DynamicForm");
provider.Add(typeof(IDefaultValueCalculator), Activator.CreateInstance(type));
// 注册IDBModelService
type = TypesContainer.GetOrRegister("Kingdee.BOS.Business.DynamicForm.DBModel.DBModelService,Kingdee.BOS.Business.DynamicForm");
provider.Add(typeof(IDBModelService), Activator.CreateInstance(type));
return provider;
}
/// 获取视图
///
///
private IDynamicFormView CreateListView(DynamicFormOpenParameter param)
{
Form form = param.FormMetaData.BusinessInfo.GetForm();
if (form.FormGroups != null && form.FormGroups.Count > 0)
{
return new TreeListView();
}
else
{
return new Kingdee.BOS.Web.List.ListView();
}
}
/// 获取视图模型
///
///
private IDynamicFormModelService GetListModel(DynamicFormOpenParameter param)
{
Form form = param.FormMetaData.BusinessInfo.GetForm();
if (form.FormGroups != null && form.FormGroups.Count > 0)
{
var type = TypesContainer.GetOrRegister("Kingdee.BOS.Model.List.TreeListModel,Kingdee.BOS.Model");
return (IDynamicFormModelService)Activator.CreateInstance(type);
}
else
{
var type = TypesContainer.GetOrRegister("Kingdee.BOS.Model.List.ListModel,Kingdee.BOS.Model");
return (IDynamicFormModelService)Activator.CreateInstance(type);
}
}
/// 创建过滤条件模型
///
///
private IListFilterModelService GetListFilterModel()
{
Type type = TypesContainer.GetOrRegister("Kingdee.BOS.Model.ListFilter.ListFilterModel,Kingdee.BOS.Model");
return (IListFilterModelService)Activator.CreateInstance(type);
}
#endregion[/code]
推荐阅读