1、用二次开发服务方式做打印模板的方法:一、先做好打印模板 二、发布打印模板,创建打印参照,并记录打印模板分类标识,和打印模板编号 三、写代码,这一步是最关键的一步。1、打开 VS,新建一个 Visual C# 项目。2、把自动生成的类 Class1.cs,删除掉,3、删除后添加新组件;CommonFunction.cs4、复制以下代码到指定的地方:public class CommonFunction/ / 设置控件在卡片容器中的布局/ / 卡片容器/ 增加的控件/ 布局横坐标/ 布局纵坐标public static void Layout(UFSoft.UBF.UI.ControlModel.
2、IContainer container, IUFControl ctrl, uint x, uint y)Layout(container, ctrl, x, y, 1, 1, Unit.Pixel(0), Unit.Pixel(0), true);/ / 设置控件在卡片容器中的布局/ / 卡片容器/ 增加的控件/ 布局横坐标/ 布局纵坐标/ 控件宽/ 控件高public static void Layout(UFSoft.UBF.UI.ControlModel.IContainer container, IUFControl ctrl, uint x, uint y, int width,
3、 int height)Layout(container, ctrl, x, y, 1, 1, Unit.Pixel(width), Unit.Pixel(height), false);/ / 设置控件在卡片容器中的布局/ / 卡片容器/ 增加的控件/ 布局横坐标/ 布局纵坐标/ 单元格横向跨度/ 单元格纵向跨度/ 控件宽/ 控件高/ 是否自适应大小public static void Layout(UFSoft.UBF.UI.ControlModel.IContainer container, IUFControl ctrl, uint x, uint y, int xspan, int
4、yspan,Unit width, Unit height, bool isAutoSize)IGridLayout gl = container.Layout as IGridLayout;if (gl = null) return;GridLayoutInfo glInfo = new GridLayoutInfo(uint)x, (uint)y, (uint)xspan, (uint)yspan, width, height);glInfo.AutoSize = isAutoSize;gl.Controls.Add(Control)ctrl, glInfo);/ / 在父容器中查找控件/
5、 / 父容器/ 控件/ 找到的控件public static IUFControl FindControl(IPart part, string parentControl, string control)IUFCard card = (IUFCard)part.GetUFControlByName(part.TopLevelContainer, parentControl);if (card = null)return null;foreach (IUFControl ctrl in card.Controls)if (ctrl.ID.Equals(control, StringCompar
6、ison.OrdinalIgnoreCase)return ctrl;return null;using System;using System.Collections.Generic;using System.Text;using System.ComponentModel;using UFSoft.UBF.UI.IView;using UFSoft.UBF.UI.ControlModel;using System.Web.UI.WebControls;using UFSoft.UBF.UI.Controls;using UFSoft.UBF.UI.WebControls;using Sys
7、tem.Web.UI;5、把 D:打印模板UFIDA.U9.PM.KY.RCVUIExpandUFIDA.U9.PM.KY.RCVUIExpandbinDebug 文件夹中的.dll 文件全部复制到 D:PrjUFIDA.U9.GL.KY.HJF.VoucherPrintUFIDA.U9.GL.KY.HJF.VoucherPrintbinDebug 目录下。6、添加引用:选择binDebug 目录下刚才所添加的所有.dll 文件。7、确定后重新生成解决方案。8、添加类。9、添加 KYRCVExtend.cs 代码:打开 D:打印模板UFIDA.U9.PM.KY.RCVUIExpandUFIDA
8、.U9.PM.KY.RCVUIExpand 目录下的KYRCVExtend.cs 文件把下面代码复制到:public class KYRCVExtend : UFSoft.UBF.UI.Custom.ExtendedPartBaseReceivementMainUIFormWebPart rcvWebPart;private IUFButton EMOButton;DataSet ds = new DataSet(); /打印数据public override void AfterInit(UFSoft.UBF.UI.IView.IPart Part, EventArgs args)base.
9、AfterInit(Part, args);rcvWebPart = (ReceivementMainUIFormWebPart)Part;EMOButton = new UFWebButtonAdapter();EMOButton.ID = “EMOButton“;EMOButton.Text = “自定义打印“;EMOButton.AutoPostBack = true;EMOButton.Click += new EventHandler(EMOButton_Click);IUFCard card = (IUFCard)Part.GetUFControlByName(Part.TopLe
10、velContainer, “Card0“);/Toolbar2card.Controls.Add(EMOButton);CommonFunction.Layout(card, EMOButton, 20, 0);void EMOButton_Click(object sender, EventArgs e)rcvWebPart.DataCollect();/当前事件先执行数据收集 rcvWebPart.IsDataBinding = true; /当前事件执行后会进行数据绑定rcvWebPart.IsConsuming = false;IExportSettings settings = E
11、xportServiceFactory.GetInstance().CreateExportSettingsObject();settings.ExportStyle = enumExportStyle.Excel;settings.FileName = “标准收货自定义打印“;settings.PrintTemplateCatalogType = “U9.SCM.PM.ReceivementPrint“; /打印模板分类 ID:打印模板实体 keysettings.DefaultPrintTemplateID = “32ce262e-63ce-4951-883d-0ef88f538d26“;
12、 /打印模板 IDsettings.PrintData = CallPrintSV(); /打印数据settings.ShowPrintStyleWhenDataIsNull = true; /当数据为空时打印表样settings.TitleVisible = true; /显示列头表 UIActionEventArgs ex = new UIActionEventArgs();ex.Tag = settings;tryExportServiceFactory.DoPrintCommand(sender, (BaseAction)rcvWebPart.Action, ex); /打印 Doca
13、tch (Exception eex)rcvWebPart.Model.ErrorMessage.Message = “调用打印时出错。错误原因:“ + eex.Message;/ / 通过服务获取的数据/ / private DataSet CallPrintSV()string sql = “select ROW_NUMBER()Over(ORDER BY A1.DocNo) as SerialNumber,A.DocLineNo as Receivement_RcvLines_DocLineNo,A1.DocNo as Receivement_DocNo,A1.BusinessDate
14、as Receivement_BusinessDate,A3.Name as Receivement_RcvLines_WhMan_Name ,CONVERT(varchar(10), getdate(), 120) as PrintDate,A.SrcDoc_SrcDocNo as Receivement_RcvLines_SrcDoc_SrcDocNo,A5.Name as Receivement_RcvLines_Wh_Name , as ArrivalTime,A.Payer_ShortName as Receivement_RcvLines_Payer_ShortName,A.Pay
15、er_Code as Receivement_RcvLines_Payer_Code,A.ItemInfo_ItemCode as ItemInfo_ItemCode,A.ItemInfo_ItemName as ItemInfo_ItemName,A6.SPECS as CBO_ItemMaster_SPECS,A8.Name as Receivement_RcvLines_StoreUOM_Name,A.RcvQtyTU as Receivement_RcvLines_RcvQtyTU,A.Memo as Receivement_RcvLines_Memofrom PM_RcvLine A
16、left join PM_Receivement A1on A1.ID = A.Receivementleft join CBO_Operators A2on A2.ID = A.WhMan left join CBO_Operators_Trl A3on A3.ID = A2.IDleft join CBO_Wh A4on A4.ID = A.Whleft join CBO_Wh_Trl A5on A5.ID = A4.IDleft join CBO_ItemMaster A6on A6.ID = A.ItemInfo_ItemIDleft join Base_UOM A7on A7.ID
17、= A.StoreUOMleft join Base_UOM_Trl A8on A8.ID = A7.ID where A.SplitFlag = 2 and A.RcvQtyTU != 0and A1.ID = “ + this.rcvWebPart.Model.Receivement.FocusedRecord.ID;DataAccessor.RunSQL(DataAccessor.GetConn(), sql, null,out ds);return ds;10、把它复制以下位置然后再添加引用。11、替换名称:12、添加容器代码:#region 添加按钮 : 批处理/实例化按钮IUFBu
18、tton btnBatchMO = new UFWebButtonAdapter(); btnBatchMO.ID = “btnBatchMO“;btnBatchMO.AutoPostBack = true;/找到容器IUFToolbar _Toolbar = (IUFToolbar)moBListWebPart.FindControl(“Toolbar1“);/添加到按钮到容器btnBatchMO = UIControlBuilder.BuilderToolbarButton(_Toolbar, “True“, “btnBatchMO“, “True“, “True“, 45, 28, “7
19、“, “, true, false, “36BA88E0-FC28-402e-B9BA-3745A6771687“, “36BA88E0-FC28-402e-B9BA-3745A6771687“, “9307E981-85AA-4f19-ADB7-340D159F4A01“);UIControlBuilder.SetButtonAccessKey(btnBatchMO);btnBatchMO.UIModel = moBListWebPart.Model.ElementID;btnBatchMO.Action = “;btnBatchMO.Text = “批处理“;(UFWebToolbarAd
20、apter)_Toolbar).Items.Add(btnBatchMO as System.Web.UI.WebControls.WebControl);/事件btnBatchMO.Click += new EventHandler(btnBatchMO_Click);#endregion13、把下面的数字串覆盖到:第一和第二个数字串。第三个不变。/添加到按钮到容器btnBatchMO = UIControlBuilder.BuilderToolbarButton(_Toolbar, “True“, “btnBatchMO“, “True“, “True“, 45, 28, “7“, “,
21、true, false, “36BA88E0-FC28-402e-B9BA-3745A6771687“, “36BA88E0-FC28-402e-B9BA-3745A6771687“, “9307E981-85AA-4f19-ADB7-340D159F4A01“);14、把下面的 7,改为在介面中要显示的位置“24” 。15、复制下面代码:void EMOButton_Click(object sender, EventArgs e)rcvWebPart.DataCollect();/当前事件先执行数据收集 rcvWebPart.IsDataBinding = true; /当前事件执行后会进
22、行数据绑定rcvWebPart.IsConsuming = false;IExportSettings settings = ExportServiceFactory.GetInstance().CreateExportSettingsObject();settings.ExportStyle = enumExportStyle.Excel;settings.FileName = “标准收货自定义打印“;settings.PrintTemplateCatalogType = “U9.SCM.PM.ReceivementPrint“; /打印模板分类 ID:打印模板实体 keysettings.
23、DefaultPrintTemplateID = “32ce262e-63ce-4951-883d-0ef88f538d26“; /打印模板 IDsettings.PrintData = CallPrintSV(); /打印数据settings.ShowPrintStyleWhenDataIsNull = true; /当数据为空时打印表样settings.TitleVisible = true; /显示列头表 UIActionEventArgs ex = new UIActionEventArgs();ex.Tag = settings;tryExportServiceFactory.DoP
24、rintCommand(sender, (BaseAction)rcvWebPart.Action, ex); /打印 Docatch (Exception eex)rcvWebPart.Model.ErrorMessage.Message = “调用打印时出错。错误原因:“ + eex.Message;16、把发布打印参照时记录的、打印模板分类 ID 和实体 KEY 替换下面字符串。17、更换 ID18、替换 SQL 查询语句。从 Select 开始。19、把下面替换20、重新生成解决方案。21、把以下两个文件复制到要发布的服务器的 d:UFIDAU9PortalUILib文件夹中。22、复制以下文件名到 extendedPartFullName把以下代码再把它复制到服务器中的 protalWebPartExtend.config 文件中添加【已经存在,则无需添加】