Кто-нибудь знает, как запланировать автогенерацию для еженедельного и ежемесячного отчета?Я пытался использовать службу Windows, но проблема в том, что я не знаю, как настроить свой отчет для автоматического создания еженедельного и ежемесячного отчета.В этот момент я просто поместил дату только в значение setparametervalue.был бы признателен, если бы кто-то может направить меня по этому поводу и действительно обратитесь ниже для моего кодирования.Спасибо.
private Timer scheduleTimer = null;
private DateTime lastRun;
private bool flag;
static TableLogOnInfo crTableLogonInfo;
static ConnectionInfo crConnectionInfo;
static Tables crTables;
static Database crDatabase;
static string Server = ConfigurationManager.AppSettings["serverName"];
static string Database = ConfigurationManager.AppSettings["databaseName"];
static string UserID = ConfigurationManager.AppSettings["userID"];
static string Password = ConfigurationManager.AppSettings["password"];
public ReportWindowsService()
{
InitializeComponent();
scheduleTimer = new Timer();
scheduleTimer.Interval = 1 * 5 * 60 * 1000;
scheduleTimer.Elapsed += new ElapsedEventHandler(scheduleTimer_Elapsed);
}
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
flag = true;
lastRun = DateTime.Now;
scheduleTimer.Start();
}
protected void scheduleTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (flag == true)
{
BillingReport();
ReleaseImageReport();
lastRun = DateTime.Now;
flag = false;
}
else if (flag == false)
{
if (lastRun.Date < DateTime.Now.Date)
{
BillingReport();
ReleaseImageReport();
}
}
}
public static ConnectionInfo ReportLogin(ReportDocument crRpt)
{
crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = Server;
crConnectionInfo.DatabaseName = Database;
crConnectionInfo.UserID = UserID;
crConnectionInfo.Password = Password;
crDatabase = crRpt.Database;
crTables = crDatabase.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
crTableLogonInfo = crTable.LogOnInfo;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogonInfo);
}
return crConnectionInfo;
}
public static void BillingReport()//monthly report
{
ReportDocument crRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
crRpt.Load("C:\\rptBilling.rpt");
ReportLogin(crRpt);
crRpt.SetParameterValue("@CollectionStartDate", "2011/09/14");
crRpt.SetParameterValue("@CollectionEndDate", "2011/09/29");
crRpt.SetParameterValue("@SpokeCode", "14");
crRpt.SetParameterValue("@UseCollectionDate", "1");//value can be set 0 or 1
crRpt.SetParameterValue("@UseUploadDate", "0");//value can be set 0 or 1
crRpt.SetParameterValue("@UploadStartDate", "2011/09/23");
crRpt.SetParameterValue("@UploadEndDate", "2011/09/23");
crRpt.ExportToDisk(ExportFormatType.PortableDocFormat, "e:\\BillingReport.pdf");
}
public static void ReleaseImageReport()//weekly report
{
ReportDocument crRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
crRpt.Load("C:\\rptReleaseImage.rpt");
ReportLogin(crRpt);
crRpt.SetParameterValue("@CollectionStartDate", "2011/09/14");
crRpt.SetParameterValue("@CollectionEndDate", "2011/09/29");
crRpt.SetParameterValue("@SpokeCode", "14");
crRpt.SetParameterValue("@UseCollectionDate", "1");//value can be set 0 or 1
crRpt.SetParameterValue("@UseUploadDate", "0");//value can be set 0 or 1
crRpt.SetParameterValue("@UploadStartDate", "2011/09/23");
crRpt.SetParameterValue("@UploadEndDate", "2011/09/23");
crRpt.ExportToDisk(ExportFormatType.PortableDocFormat, "e:\\ReleaseImageReport.pdf");
}
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
scheduleTimer.Stop();
}