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

推荐订阅源

Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
About on SuperTechFans
Apple Machine Learning Research
Apple Machine Learning Research
The Register - Security
The Register - Security
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园_首页
U
Unit 42
T
Tailwind CSS Blog
G
GRAHAM CLULEY
F
Full Disclosure
V
Vulnerabilities – Threatpost
T
Tenable Blog
月光博客
月光博客
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
K
Kaspersky official blog
Scott Helme
Scott Helme
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
N
News and Events Feed by Topic
有赞技术团队
有赞技术团队
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
LINUX DO - 最新话题
Recorded Future
Recorded Future
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Help Net Security
Help Net Security
The GitHub Blog
The GitHub Blog
Cisco Talos Blog
Cisco Talos Blog
SecWiki News
SecWiki News
P
Proofpoint News Feed
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
罗磊的独立博客
S
Security Affairs
M
MIT News - Artificial intelligence
L
LINUX DO - 热门话题
美团技术团队
Simon Willison's Weblog
Simon Willison's Weblog
T
Threat Research - Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
V
Visual Studio Blog

博客园 - 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();
        }

}