我正在使用 Crystal Reports ReportDocument 对象来加载、运行报表并将报表导出为 PDF。报告时间是网络服务器的时间。我们有用户运行来自不同时区的报告。有没有办法设置报告的时区?
using (SqlCommand cmd = new SqlCommand(job.sproc, con))
{
cmd.CommandType = CommandType.StoredProcedure;
foreach (KeyValuePair<string, string> p in sprParams)
{
cmd.Parameters.AddWithValue(p.Key, p.Value);
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ReportDocument rpt = new ReportDocument();
rpt.Load(Path.Combine(RPT_LOCATION, job.repFileName));
rpt.Database.Tables[0].SetDataSource(ds.Tables[0]);
int i = 1;
foreach (string subReport in job.subReports)
{
using (ReportDocument srpt = rpt.OpenSubreport(subReport))
{
srpt.SetDataSource(ds.Tables[i++]);
}
}
ParameterFieldDefinitions parmFields = rpt.DataDefinition.ParameterFields;
ParameterValues pvals = new ParameterValues();
foreach (ParameterFieldDefinition def in parmFields)
{
if (!def.IsLinked())
{
ParameterDiscreteValue pval = new ParameterDiscreteValue();
if (rptParams.ContainsKey(def.Name))
{
pval.Value = rptParams[def.Name];
}
else
{
switch (def.ParameterValueKind)
{
case ParameterValueKind.BooleanParameter:
pval.Value = false;
break;
case ParameterValueKind.CurrencyParameter:
pval.Value = 0;
break;
case ParameterValueKind.DateParameter:
pval.Value = DateTime.Now.ToShortDateString();
break;
case ParameterValueKind.DateTimeParameter:
pval.Value = DateTime.Now;
break;
case ParameterValueKind.NumberParameter:
pval.Value = 0;
break;
case ParameterValueKind.TimeParameter:
pval.Value = DateTime.Now.ToShortTimeString();
break;
default:
pval.Value = String.Empty;
break;
}
}
pvals.Add(pval);
def.ApplyCurrentValues(pvals);
}
}
//save file
job.fileName = ExfiltrateReport(rpt, exfilType);
job.created = DateTime.UtcNow;
rpt.Dispose();
}