Jeg kan sagtens sende dig hele projektet hvis du vil, men det er ret stort og kræver at du har styr på kode for at kunne finde rundt i det :)
Først laver du en ny rapport. Lav så mange nye parameter fields som du skal bruge og smid dem ind i rapporten. Herefter gemmer du rapporten.
http://nhlogic.aspdotnet.dk/pics/Crystal1.gifFra koden kalder jeg Printlejeaftale.cs med variablerne som input i constructoren:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
namespace DanBilUdlejning
{
/// <summary>
/// Summary description for Printlejeaftale.
/// </summary>
public class Printlejeaftale : System.Windows.Forms.Form
{
private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Printlejeaftale(
string Lnr,
string Knr,
string Knavn,
string Kadresse,
string koerekortnr,
string dato,
string ekspederetaf,
string Kategori,
string Regnr,
string Maerke,
string Model,
string koertkm,
string mdrpris,
string kmpris,
string depositum,
string aftalestart
)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
ParameterFields paramFields = new ParameterFields();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
ParameterRangeValue rangeVal = new ParameterRangeValue();
paramField.ParameterFieldName = "Lnr";
discreteVal.Value = Lnr;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "Knr";
discreteVal.Value = Knr;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "Knavn";
discreteVal.Value = Knavn;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "Kadresse";
discreteVal.Value = Kadresse;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "koerekortnr";
discreteVal.Value = koerekortnr;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "dato";
discreteVal.Value = dato;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "Ekspederetaf";
discreteVal.Value = ekspederetaf;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "Kategori";
discreteVal.Value = Kategori;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "Regnr";
discreteVal.Value = Regnr;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "Maerke";
discreteVal.Value = Maerke;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "Model";
discreteVal.Value = Model;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "koertkm";
discreteVal.Value = koertkm;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "mdrpris";
discreteVal.Value = mdrpris;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "kmpris";
discreteVal.Value = kmpris;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "depositum";
discreteVal.Value = depositum;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
paramField = new ParameterField();
discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "aftalestart";
discreteVal.Value = aftalestart;
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
crystalReportViewer1.ParameterFieldInfo = paramFields;
crystalReportViewer1.ReportSource = "..\\..\\printlejekontrakt.rpt";
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Printlejeaftale));
this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
this.SuspendLayout();
//
// crystalReportViewer1
//
this.crystalReportViewer1.ActiveViewIndex = -1;
this.crystalReportViewer1.DisplayGroupTree = false;
this.crystalReportViewer1.Location = new System.Drawing.Point(0, 0);
this.crystalReportViewer1.Name = "crystalReportViewer1";
this.crystalReportViewer1.ReportSource = null;
this.crystalReportViewer1.ShowCloseButton = false;
this.crystalReportViewer1.ShowExportButton = false;
this.crystalReportViewer1.ShowGotoPageButton = false;
this.crystalReportViewer1.ShowGroupTreeButton = false;
this.crystalReportViewer1.ShowPageNavigateButtons = false;
this.crystalReportViewer1.ShowRefreshButton = false;
this.crystalReportViewer1.ShowTextSearchButton = false;
this.crystalReportViewer1.Size = new System.Drawing.Size(864, 680);
this.crystalReportViewer1.TabIndex = 0;
//
// Printlejeaftale
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(864, 678);
this.Controls.Add(this.crystalReportViewer1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Printlejeaftale";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Udskriv Lejeaftale";
this.ResumeLayout(false);
}
#endregion
}
}
Jeg vil gerne sende dig hele projektet hvis du er klar på det :) Det kan være det giver lidt mere mening når du selv kan se hvordan rapporten helt præcis er opbygget.
Vh