惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
O
OpenAI News
WordPress大学
WordPress大学
P
Proofpoint News Feed
J
Java Code Geeks
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Register - Security
The Register - Security
Engineering at Meta
Engineering at Meta
H
Help Net Security
人人都是产品经理
人人都是产品经理
Vercel News
Vercel News
N
Netflix TechBlog - Medium
F
Full Disclosure
U
Unit 42
Latest news
Latest news
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
InfoQ
L
LINUX DO - 最新话题
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
K
Kaspersky official blog
Google Online Security Blog
Google Online Security Blog
小众软件
小众软件
I
Intezer
V
V2EX
S
SegmentFault 最新的问题
C
CERT Recently Published Vulnerability Notes
阮一峰的网络日志
阮一峰的网络日志
Security Archives - TechRepublic
Security Archives - TechRepublic
Recent Announcements
Recent Announcements
C
Check Point Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Recorded Future
Recorded Future
博客园 - Franky
Project Zero
Project Zero
S
Securelist
Attack and Defense Labs
Attack and Defense Labs
Spread Privacy
Spread Privacy
The Hacker News
The Hacker News
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
NISL@THU
NISL@THU
云风的 BLOG
云风的 BLOG
S
Secure Thoughts
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed

博客园 - rabbler

利用脚本禁止与启动Microsoft SQL Server相关服务 [译]Creating a Stock Widget in ASP.NET MVC Application DOM Document Object properties & DOM Element properties A-Grade Browser By Yahoo asp.net mvc 2.0 validate model asp.net mvc 2.0 Strongly-Typed HTML Helper Javascript code prettifier YUI3学习路线 Asp.net MVC 常用控件 Ubuntu 常用命令收集[菜鸟版] How to use JabRef (BibTeX) with Microsoft Word SQL Server 2008 sp1 集成安装 - rabbler Web Design: CSS Tutorials Using Asp.net Membership and RoleProvider to Build Login Pages Bart's PE - rabbler - 博客园 Portal课题的相关词汇 计算机核心期刊一览 IE8 Beta2 安装与卸载之旅 如何提高Asp.net2.0的效率
水晶报表的使用
rabbler · 2008-06-20 · via 博客园 - rabbler
  1. 首先当然是安装Crystal Report啦,不同的vs版本自带不同的CR,安装VS的时候选择安装就可以了。
  2. 然后就是新建一个report文件,该文件其实一个CrystalDocment类。一般常用的是使用PUSH模式,也就是利用DataSet作为Report文件数据源的方式。
  3. 新建一个DataSet,该DS里面可以存放很多表,这边不用跟你数据库的表一致,跟你要显示的内容一致就好了。举个例子,数据库有一个字段存放的是总价格,是浮点型,但是你的表单想显示的是中文的大写价格。当然有多种方法,其中的一种就是在DS里面的某个表添加一个string类型的字段来存放中文的大写价格。因为内容的填充是手动增加的。
  4. 新建一个窗体,拖放一个CrystalReportView控件,在代码中指定Report文件的位置,指定相应的DataSet,并给DataSet填充数据(因为一般作为报表,是需要显示符合某种条件的数据,例如某月份的营业额等等,手工指定数据的灵活性就体现出来了。)然后一点很重要的是要更新更改后的DataSet,利用AcceptChange()方法。 最后指定CrystalReportView.ReportSource属性为需要的DataSet即可。
  5. 至于报表显示的样式,就在report文件里面修改。可以很方便就是啦。能够使用css,但怎么用还没详细研究。 构想的一种设计方式是先在Word里面设计好了样式,再粘贴到report文件里就行了。

基本上报表的使用就是这样了。 附上一个步骤4的代码。

public partial class OrderReport : Form
    
{

        
private ReportDocument reportDoc = new ReportDocument();
        
//private string Path = Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf(@"\"));
        private string Path = Application.StartupPath;

        
private int _orderId = 0;
        
public int OrderId
        
{
            
get return _orderId; }
            
set { _orderId = value; }
        }


        
public OrderReport()
        
{
            InitializeComponent();
        }


        
private void crystalReportViewer1_Load(object sender, EventArgs e)
        
{
            ReportDAL reportingDAL 
= new ReportDAL();

            CompanysTableAdapter companyAdt 
= new CompanysTableAdapter();
            ProductsTableAdapter productAdt 
= new ProductsTableAdapter();
            OrdersTableAdapter orderAdt 
= new OrdersTableAdapter();
            OrderItemsTableAdapter orderitemAdt 
= new OrderItemsTableAdapter();

            Path 
= Path + @"\Report\";

            
try
            
{
                
string reportPath = Path + "OrderReport.rpt";
                reportDoc.Load(reportPath);

                
// Get Order
                OrderDs.OrdersDataTable orderTable = orderAdt.GetOneOrder(OrderId);
                
if (orderTable.Count < 1)
                
{
                    MessageBox.Show(
"订单不存在或订单信息读取失败!""打印送货单", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    
return;
                }

                reportingDAL.Orders.ImportRow(orderTable[
0]);
                reportingDAL.Orders[
0].OrderName = "NO:GB-2008-06-" + orderTable[0].OrderId.ToString();
                reportingDAL.Orders[
0].PriceName = ChineseNum.GetUpperMoney(Convert.ToDouble(orderTable[0].Price));

                
// Get Company Infos
                CompanyDs.CompanysDataTable companyTable = companyAdt.GetOneCompany(orderTable[0].CompanyId);

                reportingDAL.Companys.ImportRow(companyTable[
0]);

                
// Get Order Items Infos
                OrderDs.OrderItemsDataTable orderitemTable = orderitemAdt.GetOrderItemsByOrderId(OrderId);
                ProductDs.ProductsDataTable productTable;
                
foreach (OrderDs.OrderItemsRow row in orderitemTable)
                
{
                    reportingDAL.OrderItems.ImportRow(row);
                    productTable 
= productAdt.GetOneProduct(row.ProductId);
                    reportingDAL.OrderItems[reportingDAL.OrderItems.Count 
- 1].ProductName = productTable[0].ProductName;
                    reportingDAL.OrderItems[reportingDAL.OrderItems.Count 
- 1].Code = productTable[0].Code;
                    reportingDAL.OrderItems[reportingDAL.OrderItems.Count 
- 1].Price = productTable[0].Price.ToString("F2");
                    reportingDAL.OrderItems[reportingDAL.OrderItems.Count 
- 1].Spec = productTable[0].Spec;
                    reportingDAL.OrderItems[reportingDAL.OrderItems.Count 
- 1].OneProductTotalPrice = productTable[0].Price * row.Amount;
                }


                
// Accepte Changes
                reportingDAL.Orders.AcceptChanges();
                reportingDAL.Companys.AcceptChanges();
                reportingDAL.OrderItems.AcceptChanges();
                reportingDAL.Products.AcceptChanges();
                reportDoc.SetDataSource(reportingDAL);
                crystalReportViewer1.ReportSource 
= reportDoc;
            }

            
catch (Exception ex)
            
{
                MessageBox.Show(
"加载报表出错: " + ex.Message, "加载报表", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }


        
private void OrderReport_FormClosing(object sender, FormClosingEventArgs e)
        
{
            reportDoc.Dispose();
        }

}