CreateStreamCallback 是个委托,直接外边写方法就行,此方法不是很好用,给你段我写的代码参考:
public class BillPrintBase : Strong.Authorize.BasePage
{
List<ReportDataSource> subSourceList = new List<ReportDataSource>();
/// <summary>
/// 动态打印报表文件
/// </summary>
/// <param name="mainReportSource">主报表数据源</param>
/// <param name="mainReportTemplatePath">主报表文件路径</param>
/// <param name="parameterList">可供传递的参数列表,默认sid代表单据ID,pm代表打印模式0-不是单独打印;1-单独打印;2-全部</param>
/// <param name="fileType">待导出的文件类型可选值为:PDF,WORD,EXCEL</param>
/// <param name="fileName">待导出文件命名</param>
/// <param name="lstSubReportSource">子报表数据源列表</param>
public void DynamicPrintBillFile(ReportDataSource mainReportSource, string mainReportTemplatePath, List<ReportParameter> parameterList, string fileType,string fileName,List<ReportDataSource> lstSubReportSource)
{
foreach (ReportDataSource re in lstSubReportSource)
{
subSourceList.Add(re);
}
List<ReportDataSource> lstSubSource = new List<ReportDataSource>();
string reportFormat = string.IsNullOrEmpty(fileType)? "PDF" : fileType;
string extname = "";
switch (fileType)
{
case "PDF": extname = ".pdf";break;
case "EXCEL": extname = ".xls"; break;
case "WORD": extname = ".doc"; break;
default: extname = ".pdf"; break;
}
string outputfile = fileName+"-" + DateTime.Now.ToString("yyyyMMddhhmmss") + extname;//"Report.";
ReportViewer rview = new ReportViewer();
rview.ProcessingMode = ProcessingMode.Local;
rview.LocalReport.ReportPath = Server.MapPath(mainReportTemplatePath);
if (parameterList.Count > 0)
rview.LocalReport.SetParameters(parameterList);
rview.LocalReport.DataSources.Clear();
rview.LocalReport.DataSources.Add(mainReportSource);
rview.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(subreportProcessingEventHandler);
string mimeType, encoding, extension, deviceInfo;
string[] streamids;
Warning[] warnings;
deviceInfo = @"<DeviceInfo>
<SimplePageHeaders>True</SimplePageHeaders>
<MarginTop>1cm</MarginTop>
<MarginLeft>1cm</MarginLeft>
<MarginRight>1cm</MarginRight>
<MarginBottom>1cm</MarginBottom>
</DeviceInfo>";
byte[] bytes = rview.LocalReport.Render(reportFormat, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
MemoryStream ms = new MemoryStream();
ms.Write(bytes,0,bytes.Length);
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + outputfile);
HttpContext.Current.Response.ContentType = mimeType;
HttpContext.Current.Response.BinaryWrite(bytes);
ms.Close();
ms.Dispose();
HttpContext.Current.Response.End();
}
public virtual void subreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
{
foreach (var subsource in subSourceList)
{
try
{
e.DataSources.Add(subsource);
LocalReport lp = ((LocalReport)sender);
string path = e.ReportPath;
if (path == "MarketProductAuditFlow")
{
string sid = lp.GetParameters()["sid"].Values[0];
string pm = lp.GetParameters()["pm"].Values[0];
e.DataSources.Add(new ReportDataSource("AuditFlowSet", getAuditFlowPrintList(sid, pm)));
}
}
catch { }
}
}
/// <summary>
/// 流程节点显示数据源
/// </summary>
/// <param name="sid">表单ID编号</param>
/// <param name="pattern">打印模式</param>
/// <returns></returns>
public List<AuditFlowPrintModel> getAuditFlowPrintList(string sid,string pattern)
{
List<AuditFlowModel> lstMol = WFTaskRepository.getAuditFlowModelList(new Guid(sid), int.Parse(pattern));
List<AuditFlowPrintModel> lstPMol = new List<AuditFlowPrintModel>();
Assistant.TransferListModel(lstMol, ref lstPMol);
foreach (AuditFlowPrintModel m in lstPMol)
{
m.FlowSetpNo = m.ItemNO.ToString();
m.HandleDate = Base.SFormat.GetShortDate(m.HandleDate, "yyyy-MM-dd HH:mm");
m.HandleUserID = Base.SFormat.GetEmpName(m.HandleUserID);
}
return lstPMol;
}
/// <summary>
/// 物料产品关系子表详细数据源
/// </summary>
/// <param name="m">BillAndPrdtRelationModel对象</param>
/// <returns></returns>
public List<ProductBillDetailModel> getBillMaterialDetailList(BillAndPrdtRelationModel m)
{
BillAndPrdtRelationRepository bprRS = new BillAndPrdtRelationRepository();
return bprRS.getProductBillDetailList(m);
}
}
直接打印的地方调用DynamicPrintBillFile方法即可。
如何实现扫描二维码,实现网址自动跳转
非对称加密和对称加密在加密和解密过程、加密解密速度、传输的安全性上都有所不同,具体介绍如下:
1、加密和解密过程不同
对称加密过程和解密过程使用的同一个密钥,加密过程相当于用原文+密钥可以传输出密文,同时解密过程用密文-密钥可以推导出原文。但非对称加密采用了两个密钥,一般使用公钥进行加密,使用私钥进行解密。
2、加密解密速度不同
对称加密解密的速度比较快,适合数据比较长时的使用。非对称加密和解密花费的时间长、速度相对较慢,只适合对少量数据的使用。
3、传输的安全性不同
对称加密的过程中无法确保密钥被安全传递,密文在传输过程中是可能被第三方截获的,如果密码本也被第三方截获,则传输的密码信息将被第三方破获,安全性相对较低。
非对称加密算法中私钥是基于不同的算法生成不同的随机数,私钥通过一定的加密算法推导出公钥,但私钥到公钥的推导过程是单向的,也就是说公钥无法反推导出私钥。所以安全性较高。
百度百科-对称加密
百度百科-非对称加密
WCF实现上传功能
可以把网址生成一个二维码,有两种方式,一个是把网址生成静态码,优点是扫码可以直接跳转,缺点是如果网址越长,生成的二维码越密集,另外如果网址没有备案过,那就可能在某些app中无法直接跳转,还有一种方式是把网址生成活码,优点是二维码一旦生成,内容是可以随时修改,如果网站地址失效可以随时替换,缺点是扫码后会显示一个链接,需要点击链接后再跳转到对应网站。
这里比较推荐的是用活码形式,虽然需要二次跳转,但是稳定性有保障,并且可以随时修改网址地址原二维码是不变的。
制作活码的步骤也很简单:
进入网站登录到操作后台。
点击制作二维码。
添加网址。
添加网址后在二维码内容里会出现一个链接按钮,扫码后点击链接按钮就可以跳转到对应的网址。你还可以在二维码里放入一些介绍文字,,甚至是音视频,扫码就直接能查看。
功能介绍 主要是使用WCF框架实现从客户端上传到服务端并在服务端显示的基本功能 一 首先创建两Windows窗体应用程序 WinFormClient (客户端 发送端)和 WinFormReceiver (接收端) 如图设计FormClient(发送端窗体)的界面 上边是一个panel容器中添加了一个TextBox和 两个Button 下边是一个PictureBox控件(用于浏览上传之前的)
然后添加浏览按钮下的后台代码 实现客户端浏览的功能 View Code string fileName = ;//定义一个全局变量 //浏览选择上传内容 private void btnBrowser_Click(object sender EventArgs e) { //string fileName = ;//定义一个字段用于获取上传的文件名 OpenFileDialog openFileDialog = new OpenFileDialog() //创建一个OpenFileDialog对象专门用于打开文件 if (openFileDialog ShowDialog() == DialogResult OK)//打开的文件对话框如果选择了OK按钮(确定) 则为真 执行大括号中的内容 { fileName = openFileDialog FileName; txtPicName Text = fileName;//在textBox中显示文件名 pictureBox Load(fileName) //使该在客户端pictuBox中显示 } else return;//未选中文件则返回 } 将WinFomClient设为启动项目 运行 当你选择后 该会显示在发送端的窗体中 供发送者浏览 如需更改上传可重新选取 该将会被覆盖掉 (上传功能将在下文实现) FormReceiver接收端的窗体只需添加一个PictureBox控件 用于显示客户端上传的
二 在解决方案中添加两个类库 ITransferPic(接口) TransferPic(继承接口) 一个控制台应用程序 TransferPicHost(宿主程序) 该实例采用的是 自身托管宿主 并非 IIS宿主 ITransferPic ( ) 添加引用 using System ServiceModel;? using System IO; ( ) 创建一个 ITransferPicService 接口 View Code [ServiceContract] public interface ITransferPicService { [OperationContract]//操作契约 Stream GetPic() [OperationContract] void SendPic(Stream transferPic) } TransferPic ( ) 添加引用 using ITransferPic;? using System IO; ( ) 创建一个 TransferPicService 类 继承接口 ITransferPicService 并实现该接口 View Code public class TransferPicService : ITransferPicService { public static Stream PicSource = new MemoryStream() /// <summary> /// 从服务端下载到本地 (上传和下载都是拷贝的过程) /// </summary> /// <returns></returns> public Stream GetPic() { MemoryStream ms = new MemoryStream() PicSource Position = ;//指明从第 位开始拷贝 PicSource CopyTo(ms) //服务端将客户端的Stream复制一份 ms Position = ;//注意如果缺少该条代码接收端将无法显示上传 return ms;//然后在返回客户端 } /// <summary> /// 从客户端上传到服务端(将客户端的Stream拷贝给服务端的Stream) /// </summary> /// <param name= transferPic ></param> public void SendPic(Stream transferPic) { PicSource Position = ; transferPic CopyTo(PicSource) } } TransferPicHose 自身托管宿主 利用WCF提供的ServiceHost<T>提供的Open()和Close()方法 可以便于开发者在控制台应用程序 Windows应用程序乃至于ASP NET应用程序中托管服务 不管自宿主的环境是何种应用程序 实质上托管服务的方式都是一致的 如该实例中用到的代码部分 添加引用 using System ServiceModel; using ITransferPic; using System ServiceModel Description; View Code class Program { static void Main(string[] args) { NetTcpBinding bind = new NetTcpBinding() bind MaxBufferSize = ; bind TransferMode = TransferMode Streamed; bind MaxReceivedMessageSize = ; bind Security Mode = SecurityMode None; //超出using 范围程序会自动释放 using (ServiceHost host = new ServiceHost(typeof(TransferPic TransferPicService))) { host AddServiceEndpoint(typeof(ITransferPicService) bind net tcp://localhost: /transferPic ) //该地址为宿主地址 和客户端接收端地址保持一致 if (host Description Behaviors Find<ServiceMetadataBehavior>() == null) { ServiceMetadataBehavior behavior = new ServiceMetadataBehavior() behavior HttpGetEnabled = true; behavior HttpGetUrl = new Uri(//localhost: /transferPic/metadata/ ) host Description Behaviors Add(behavior) } host Opened += delegate { Console WriteLine( 程序已成功启动! ) }; host Open() Console ReadLine() } } } 三 实现上传 WinFormClient 后台上传按钮部分 添加引用 using System IO; using System ServiceModel; using ITransferPic; View Code //执行上传功能 private void btnUpload_Click(object sender EventArgs e) { //pictureBox Load(fileName) //读取流 上传文件流到服务器 FileStream fs = new FileStream(fileName FileMode Open FileAccess Read) //创建一个文件 并把文件放在文件流里边 Stream *** = new MemoryStream() //创建一个滤层流 将文件从第 位拷贝到 *** 中 fs Position = ;//获取或设置此流的当前位置 fs CopyTo( *** ) //拷贝完成之后进行上传 EndpointAddress epAddr = new EndpointAddress( net tcp://localhost: /transferPic ) //此处也可以用IIS做服务 NetTcpBinding bind = new NetTcpBinding() //绑定方式 bind MaxBufferPoolSize = ;//最大缓冲 bind TransferMode = TransferMode Streamed;//传输模式为流式处理 bind MaxReceivedMessageSize = ;//定义了服务端接收Message的最大长度 防止文件过大 bind Security Mode = SecurityMode None;//安全模式设置为不进行验证 //创建一个工厂 ITransferPicService proxy = ChannelFactory<ITransferPicService> CreateChannel(bind epAddr) *** Position = ; proxy SendPic( *** ) //WCF客户端调用该方法 把客户端 *** 上传到服务端去 } WinFormReceiver 后台 添加引用 using ITransferPic; using System IO; using System ServiceModel; View Code private void FormReceiver_Load(object sender EventArgs e) { Thread myThread = new Thread(ShowPic) //创建一个线程 myThread IsBackground = true;//设置后台线程(防止主程序关闭后 仍在运行) myThread Start() //启动线程 } public void ShowPic() { #region 同客户端一样 创建WCF客户端 EndpointAddress epAddr = new EndpointAddress( net tcp://localhost: /transferPic ) NetTcpBinding bind = new NetTcpBinding() bind MaxBufferPoolSize = ; bind TransferMode = TransferMode Streamed; bind MaxReceivedMessageSize = ; bind Security Mode = SecurityMode None;//创建一个通道 ITransferPicService proxy = ChannelFactory<ITransferPicService> CreateChannel(bind epAddr) #endregion while (true) { Stream streamFromServer = proxy GetPic() //返回一个文件流 MemoryStream ms = new MemoryStream() //滤层流拷贝一份 ms Position = ; streamFromServer CopyTo(ms) //将该文件流拷贝给到ms; if (ms Length == ) { System Threading Thread Sleep( ) // 百毫秒执行一次 continue; } Bitmap tn = new Bitmap(ms) //创建一个位图 把ms变成 pictureBox Image = tn; System Threading Thread Sleep( ) // 百毫秒执行一次 Sleep表示当前线程挂起指定的时间 } } 四 运行程序 打开TransferPicHost 文件中bin目录 启动 TransferPicHost exe 此时会弹出一个控制台应用程序的窗体 并提示 功能已成功启动! 分别启动发送端和接收端项目程序 (将 WinFormClient 或者 WinFormReceiver 设为启动项目 并启动另一个项目文件夹bin目录下的 WinFormReceiver exe 或者 WinFormClient exe ) 点击发送端 浏览按钮 进行选择 之后点击 上传按钮 这时 你会发现客户端上传的显示在了接收端的窗体上 程序运行成功 lishixinzhi/Article/program/net/201311/12342
本文来自作者[姓玉卿]投稿,不代表灯塔号立场,如若转载,请注明出处:https://dqjxkj.net/news/1516.html
评论列表(3条)
我是灯塔号的签约作者“姓玉卿”
本文概览:CreateStreamCallback 是个委托,直接外边写方法就行,此方法不是很好用,给你段我写的代码参考:public class BillPrintBase : Str...
文章不错《C# 求解 关於微软自带报表 rdlc 中LocalReport.Render()方法的使用》内容很有帮助