报表系统是信息系统的重要组成部分,在编制报表系统时,我们希望报表生成器与报表的逻辑部分分离,
这样不管采用何种报表 输出技术,业务逻辑部分都可以不受影响,例如在输出报表时,用户经常希望 与ms office 兼容,
将报表输出到ms excel或ms word中而office系统的升级会导致报表系统的升级,
为了提高应用系统的适应性,可以采用桥接模式,降低ms office 软件的升级对系统的影响.
using
System;
using System.Collections;
using System.Data;
using System.Drawing.Drawing2D;
using System.Drawing;
namespace ReportBridge
{
public interface HReport
{
void WriteTitle(string title);
void WriteAuthor(string author);
void WriteHead(ArrayList h);
void WriteContent(DataSet ds);
}
public interface ReportWriter
{
void NewReport(string filename);
void Write(int col,int row,string cotent,Font f,Color c);
void SaveReport();
}
public class Report:HReport
{
private ReportWriter m_writer;
public Report(ReportWriter t_rw)
{
m_writer=t_rw;
}
HReport 成员
}
public class BMPReportWriter:ReportWriter
{
ReportWriter 成员
}
public class ExcelReportWriter:ReportWriter
{
ReportWriter 成员
}
public class Invoker
{
public void Run()
{
BMPReportWriter m_brw=new BMPReportWriter();
HReport m_r=new Report(m_brw);
m_r.WriteAuthor("myauthor");
}
}
}
using System.Collections;
using System.Data;
using System.Drawing.Drawing2D;
using System.Drawing;
namespace ReportBridge
{
public interface HReport
{
void WriteTitle(string title);
void WriteAuthor(string author);
void WriteHead(ArrayList h);
void WriteContent(DataSet ds);
}
public interface ReportWriter
{
void NewReport(string filename);
void Write(int col,int row,string cotent,Font f,Color c);
void SaveReport();
}
public class Report:HReport
{
private ReportWriter m_writer;
public Report(ReportWriter t_rw)
{
m_writer=t_rw;
}
HReport 成员
}
public class BMPReportWriter:ReportWriter
{
ReportWriter 成员
}
public class ExcelReportWriter:ReportWriter
{
ReportWriter 成员
}
public class Invoker
{
public void Run()
{
BMPReportWriter m_brw=new BMPReportWriter();
HReport m_r=new Report(m_brw);
m_r.WriteAuthor("myauthor");
}
}
}