2 回答

TA貢獻2037條經(jīng)驗 獲得超6個贊
customerReport = new ReportDocument();
string reportPath = Server.MapPath("PrintGif\\CrystalReport.rpt");
customerReport.Load(reportPath);
customerReport.SetDataSource(dt);
ParameterFields paramFields = new ParameterFields();
ParameterField paramField1 = new ParameterField();
ParameterField paramField2 = new ParameterField();
ParameterField paramField3 = new ParameterField();
ParameterField paramField4 = new ParameterField();
ParameterField paramField5 = new ParameterField();
ParameterField paramField6 = new ParameterField();
ParameterField paramField7 = new ParameterField();
ParameterField paramField8 = new ParameterField();
ParameterDiscreteValue discreteVal1 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal2 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal3 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal4 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal5 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal6 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal7 = new ParameterDiscreteValue();
ParameterDiscreteValue discreteVal8 = new ParameterDiscreteValue();
ParameterRangeValue rangeVal = new ParameterRangeValue();
// 設(shè)置參數(shù)字段的名稱,它必須
//和報表中的參數(shù)相符。
paramField1.ParameterFieldName = "year";
paramField2.ParameterFieldName = "month";
paramField3.ParameterFieldName = "day";
paramField4.ParameterFieldName = "Hour";
paramField5.ParameterFieldName = "Minute";
paramField6.ParameterFieldName = "sname";
paramField7.ParameterFieldName = "Amount";
paramField8.ParameterFieldName = "CNAmount";
// 設(shè)置第一個離散值并將其傳遞給該參數(shù)。
discreteVal1.Value = dt.Rows[0]["TIME"].ToString().Substring(0, 4);
discreteVal2.Value = dt.Rows[0]["TIME"].ToString().Substring(4, 2);
discreteVal3.Value = dt.Rows[0]["TIME"].ToString().Substring(6, 2);
discreteVal4.Value = dt.Rows[0]["TIME"].ToString().Substring(8, 2);
discreteVal5.Value = dt.Rows[0]["TIME"].ToString().Substring(10, 2);
discreteVal6.Value = dt.Rows[0]["name"].ToString();
string Amount = (Convert.ToDouble(dt.Rows[0]["PRC"].ToString()) * Convert.ToDouble(dt.Rows[0]["VOL"].ToString())).ToString();
decimal AmountN = 0;
discreteVal8.Value = PublicClass.ConvertToCn(Amount,out AmountN);
discreteVal7.Value = AmountN;
paramField1.CurrentValues.Add(discreteVal1);
paramField2.CurrentValues.Add(discreteVal2);
paramField3.CurrentValues.Add(discreteVal3);
paramField4.CurrentValues.Add(discreteVal4);
paramField5.CurrentValues.Add(discreteVal5);
paramField6.CurrentValues.Add(discreteVal6);
paramField7.CurrentValues.Add(discreteVal7);
paramField8.CurrentValues.Add(discreteVal8);
// 將該參數(shù)添加到參數(shù)字段集合。
paramFields.Add(paramField1);
paramFields.Add(paramField2);
paramFields.Add(paramField3);
paramFields.Add(paramField4);
paramFields.Add(paramField5);
paramFields.Add(paramField6);
paramFields.Add(paramField7);
paramFields.Add(paramField8);
// 將參數(shù)字段集合放入查看器控件。
CrystalReportViewer1.ReportSource = customerReport;
this.CrystalReportViewer1.ParameterFieldInfo = paramFields;
//設(shè)置成 139.7 x 215.9 毫米的紙張,也就是“半刀紙”,約 A4 的一半。
customerReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperStatement;
//設(shè)置報表方向為橫向,注意系統(tǒng)沒有真正的“半刀紙”,只有把上述紙張橫著看才符合要求。打印時不需要設(shè)置為橫打
customerReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.HasViewList = false;
try
{
//CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
customerReport.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
customerReport.PrintToPrinter(1, true, 0, 0);
}
catch
{
}

TA貢獻1993條經(jīng)驗 獲得超6個贊
水晶報表的話不是很清楚,一般情況下用的都是finereport,控件名通常與參數(shù)結(jié)合使用,控件名即為參數(shù)名,通過控件可以獲得該控件,從而獲得控件值傳遞給對應(yīng)參數(shù),或者通過控件名獲得控件后通過JS設(shè)置控件的屬性。
添加回答
舉報