how to find crystal report printing count? - winforms

I am using Crystal Report 2010 with C#, have a WinForm and want to show Page N of M to user in a Labelwhile printing crystal repots.
How can I impelemnt that?
the code I implemented in ReportViewer:
using System;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows.Forms;
using CrystalDecisions.Web;
namespace ComboSearch.Reports
{
public partial class ReportViewer : System.Web.UI.Page
{
ReportDocument rpt = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string path = Server.MapPath("Employee.rpt");
rpt.Load(path);
CrystalReportViewer1.ReportSource = rpt;
}
}
}
}
Thanks in advance.

Showing "Page N of M", while printing report can be done by inserting that as a field to the report itself, and position it upon your requirement.
To insert it, use special fields option to insert "Page N of M" field.

Related

How to write condition on Filter String in code Reports Winforms devexpress?

I designed a report form and map fields with columns of tables from dataset. Now I need to set condition, so I used FilterString. Inside report form DetailReport, I wrote code like this:
DetailReport.FilterString = "[InvoiceNumber] = " + temp;
Now I need this same code (FilterString) for whole form that is top left of form Report Task some properties are available in that Data Source there we add dataset, Data Member, Data Adapter then FilterString is available.
Now I am able to add FilterString in Designer but I need to add FilterString in code ??
I Tried this one but not working
FilterString= "[InvoiceNumber] = " + temp"
I seggest you set the report FilterString property when you call for your XtraReport (for example : when you click on the print button of your form). Here is an code example :
private void simpleButton1_Click(object sender, EventArgs e) {
// Create a report instance.
XtraReport1 report = new XtraReport1();
// Some code like setting the report datasource
// Specify the report's filter string.
report.FilterString = "[InvoiceNumber] = myValue";
// Show the report's print preview.
pt.ShowPreviewDialog();
}
This code was taken from the DevExpress online documentation article : XtraReportBase.FilterString Property
Once you set the filter for the report, in the for you need to have it do:
public string p = "";
....
using (XtraReport_yourreport x = new XtraReport_yourreport ())
{
p = x.FilterString;
}

Telerik Reports parameters from WindowsForm Codebehind to Report

I'm working on a Windows Forms Application where I want to load Reports into a Reportviewer after a click on a Button.
This is the Event that gets triggered by pressing on the button in the Code behind of the Windows Form:
private void button1_Click(object sender, EventArgs e)
{
Telerik.Reporting.InstanceReportSource reportSource = new
Telerik.Reporting.InstanceReportSource();
reportSource.ReportDocument = new Reportlibrary.Report1();
reportSource.Parameters.Add(new Telerik.Reporting.Parameter("OrderNumber","123456789"));
reportViewer1.ReportSource = reportSource;
reportViewer1.RefreshReport();
}
The problem now is that I have no Idea how I can access / get the parameter I added before Refreshing the Reportviewer.
The Report already has set a Datasource. I don't know if this matters.
This is what I have right now. I've tried everything and I'm just not getting further.
public Report1()
{
InitializeComponent();
Position[] all = new Position[]{
new Position("Test", "Test","test"),
};
this.DataSource = all;
MessageBox.Show("Number: " +
this.Report.ReportParameters["OrderNumber"].Value.ToString());
}
Is there any way to get this parameter straight after InitializeComponent(); ?
Do I need to add another Event to the report to access it? If yes which on is the best way to do this?
Any help very apreciated.
Thank you
Set the parameters of the report on an instance of the report itself (not the report source), such as:
TopPageViews report = new TopPageViews();
report.ReportParameters["StartDate"].Value = new DateTime(2013, 3, 1);
report.ReportParameters["EndDate"].Value = new DateTime(2013, 3, 1);
InstanceReportSource reportSource = new InstanceReportSource();
reportSource.ReportDocument = report;
this.reportViewer1.ReportSource = reportSource;
this.reportViewer1.RefreshReport();
In your report constructor, after InitializeComponent, subscribe a handler to the ItemDataBinding event:
this.ItemDataBinding += TopPageViews_ItemDataBinding;
And in your handler, you can obtain the value as you normally would:
DateTime startDateParm = (DateTime)this.ReportParameters["StartDate"].Value;
You can use the debugger to see the value.
i know its an old question but after experiencing the same issue this how i did it and passed two parameter of date.
private void button1_Click(object sender, EventArgs e)
{
Report2 report = new Report2();
report.ReportParameters["datefrom"].Value
=dateTimePicker1.Value;
report.ReportParameters["dateto"].Value = dateTimePicker2.Value;
var rSource = new InstanceReportSource();
rSource.ReportDocument = report;
reportViewer1.ReportSource = rSource;
reportViewer1.RefreshReport();
}

Connecting 2 Textboxes values temporarily

I want to create 2 Textboxes (txt1, txt2) and when I write in txt1 then txt2 should reflect the same text what i typed in txt1. For ex. When we create a new Solution in Visual Studio Professional, what name we give to Project, same name appears for Solution. But if we edit solution name, link between the 2 textboxes breaks.
I do have some idea about it, to do it with textChange event or in fact many similar events, but not sure that they are the best methods.
I am using Winforms, C# 4.0, Visual Studio 2010 (if this info matters)
If my question is not clear, just make a comment I will try to elaborate.
Thanks.
With the given definition of the requirement, adding TextChanged EventHandlers is the way to go.
private void txt1_TextChanged(object sender, EventArgs e)
{
txt2.Text = txt1.Text;
}
private void txt2_TextChanged(object sender, EventArgs e)
{
txt1.Text = txt2.Text;
}
Consider adding an event handler for txt1_TextChanged and txt2_KeyPress.
txt1_TextChanged would assign txt2.Text: txt2.Text = "c:\" + txt1.Text;
txt2_KeyPress would unsubscribe txt1_TextChanged: txt1.TextChanged -= txt1_TextChanged;.
I solved it, so thought to post it here
txt1_TextChanged(obje....)
{
txt2.Text = txt1.Text;
}
txt2_TextChanged(objec...)
{
if(txt2.Focused)
{
txt1.TextChanged -= new EventHandler(txt1_TextChanged);
}
}
Hope it helps.

Silverlight, connecting service.cs and XAML.cs for database

I've found a sample showing how to connect to SQL server (a local MDF), but it uses databinding, how can I use SQL in the normal way (insert, select, update, delete..., sqldatareader, without binding), I think all SQL staff should be performed in service.cs, so how can I use SQL from my XAML.cs? here is the service code:
and here service.cs:
public class ServiceCustomer : IServiceCustomer
{
public clsCustomer getCustomer(int intCustomer)
{
SqlConnection objConnection = new SqlConnection();
DataSet ObjDataset = new DataSet();
SqlDataAdapter objAdapater = new SqlDataAdapter();
SqlCommand objCommand = new SqlCommand("Select * from Customer where CustomerId=" + intCustomer.ToString());
objConnection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnStr"].ToString();
objConnection.Open();
objCommand.Connection = objConnection;
objAdapater.SelectCommand = objCommand;
objAdapater.Fill(ObjDataset);
clsCustomer objCustomer = new clsCustomer();
objCustomer.CustomerCode = ObjDataset.Tables[0].Rows[0][0].ToString();
objCustomer.Customer = ObjDataset.Tables[0].Rows[0][1].ToString();
objConnection.Close();
return objCustomer;
}
}
and my page.xaml.cs:
public Page()
{
InitializeComponent();
ServiceCustomerClient obj = new ServiceCustomerClient();
obj.getCustomerCompleted += new EventHandler<getCustomerCompletedEventArgs>(DisplayResults);
obj.getCustomerAsync(1);
}
void DisplayResults(object sender, getCustomerCompletedEventArgs e)
{
LayoutRoot.DataContext = e.Result;
}
how can I insert a value into my dayabase right from my page.xaml.cs? how can I make a connection between service and xaml objects and functions?
thanks
The Page.xaml.cs file is not autogenerated in a standard silverlight project (beyond it's initial creation via template), so any changes you make to the class will persist.
If your current project does some autogen of xaml classes then you can use the partial class feature of C# Partial Classes in C# Guide to add to the class without worrying that the autogen will remove your additions.
You would need to add another method within your service class that performs the insert, and then pass it the values from your form.
public class ServiceCustomer : IServiceCustomer
{
public clsCustomer getCustomer(int intCustomer)
{
...
}
public void addCustomer(clsCustomer newCustomer)
{
//Code to add the customer to the database
}
}
to call this from your code you could use the following code, all calls to the service in silverlight are Asynchronous calls therefore they are called in a seperate thread but since the following call has no return there is no need for a completed event handler.
public void foo
{
clsCustomer cust = new clsCustomer();
//Create your customer object here
ServiceCustomerClient obj = new ServiceCustomerClient();
obj.AddCustomerAsync(cust);
}
this function could then be called when ever you want to add a customer, E.g. when a button is clicked
public void somebutton_Click(object sender, RoutedEventArgs e)
{
foo();
}
If you need any more information let me know.

Failing to display a custom WPF dialog box more than one time

I am trying to display a custom dialog box multiple times using the following code:
TestWindow newTestWindow = new TestWindow(test);
newTestWindow.Owner = this;
newTestWindow.ShowDialog();
And I get the following exception when running the code above for the 2nd time:
Specified element is already the logical child of another element. Disconnect it first.
Chances are you are trying to display the same element in both dialogs (maybe the test parameter)? You would need to disconnect the element from the dialog when it's closed, so that it can be used in any subsequent dialogs.
Works fine for me:
public partial class MainWindow : Window
{
private Test _newTestWindow;
public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(OnLoaded);
}
private void OnLoaded( object sender, RoutedEventArgs e )
{
_newTestWindow = new Test { Owner = this };
_newTestWindow.ShowDialog();
_newTestWindow = new Test { Owner = this };
_newTestWindow.ShowDialog();
}
}

Resources