Create print page using Stimulsoft and C# - c#

The grid-view that I have is filtered by some options and then it will be passed to a print program named "Stimulsoft" but when the filter is activated, the filtered records are not shown in the print page.
The code is shown below:
StiReport report = new StiReport();
tbldoreTableAdapter.Fill(doredataset.tbldore);
tbl_masolTableAdapter.Fill(doredataset.tbl_masol);
report.Load("Report.mrt");
report.RegData("DataSourc1", radGridView1.DataSource);
report.RegData(doredataset.tbldore);
report.RegData(doredataset.tbl_masol);
report.Show();
I need the filtered records to be shown in the print page.

You need to pass your query to the report before loading the report.
fisrt, define a variable (E.g. var1) in your report and change your dataset sql command as below:
select * from mytable {var1}
then in your code pass it like this:
StiReport1.Dictionary.Variables("Var1").Value = " where field1 = '" + TextBoxX1.Text + "'";
StiReport1.Compile();
StiReport1.Render();
StiReport1.Show();
P.S.: load your report in a "StiReport" object.

Related

How to define custom parameters in Stimulsoft report and send value from webfrom application

I want to generate and show printable reports to my client using Stimulsoft report and Asp.net web application C#.
I Already designed a MRT file by generating custom columns from Data from dataset.datatable corresponding to store procedure result.
Here my Columns resulted from store procedure and all of the report columns are the same.
|deviceId|,|deviceName|,|deviceDesc|,|deviceTypeName|,|priceValue|
And I set all of the types of columns in the report as string.
Here is my Store procedure:
ALTER PROCEDURE [dbo].[DeviceAllLastPrice]
#userName BIGINT
AS
BEGIN
SELECT D.deviceId,d.deviceName, d.deviceDesc, d.deviceImg, dt.deviceTypeId, dt.deviceTypeName, p.priceId, p.priceValue, p.PriceDateTime FROM Device d
INNER JOIN DeviceType dt
ON d.deviceTypeId = dt.deviceTypeId
OUTER APPLY
(SELECT TOP 1 dp.priceId, dp.priceValue,dp.PriceDateTime FROM DevicePrice dp
WHERE dp.deviceId = d.deviceId AND dp.userName = #userName
ORDER BY dp.priceId DESC
) p
WHERE p.priceValue IS NOT NULL
END
All of the columns in the report file are in DataSource1 and I add another extra parameter called "SolarDate" as a string, outside the store procedure.
Now here is the problem. When I load the data from the database using entity framework and bound them with the report everything is ok except my custom parameter "SolarDate" which I gave it a value in page load, won't show in the report.
Here is my C# code in page load.
protected void Page_Load(object sender, EventArgs e)
{
using (var db = new DbModel())
{
var data = db.DeviceAllLastPrice(1).ToList();
StiReport report = new StiReport();
report.RegData("myReport", data);
report.Load(Server.MapPath("~/Reports/Report.mrt"));
report.Compile();
report["SolarDate"] = clsEasy.makeDateToPersian(DateTime.Now);
report.Render();
StiWebViewer1.Report = report;
}
}

How does select formula in C# work using reports

I would like to ask a question about the following function related to reports in C#.
crystalReportViewer1.SelectionFormula = "{Cars.CarCode} = " + CarCode;
Does this formula add a filter condition to the current query code that is used in the report, or does it create a whole new query?
If not is there an other method of further filtering a report?
This will add a filter condition to the query. If carcode is a string you need to change it to :
crystalReportViewer1.SelectionFormula = string.Format("{Cars.CarCode} = '{0}'",CarCode);

how to remove (not hiding) columns from a DevExpress gridView?

I load my data into a GridView using DataSet. At first databinding, it works well. But when I run query that return different columns, the GridView show the new column plus the old one. I've tried the gridView1.Columns.Clear() method, but it doesn't solve the problem.
Here are some of the code:
// loading data into dataset
dataSet dsGrid = new dataSet();
string dtMember = "kpi";
// note: "thequery" is query generated based on user's selection
using (MySqlDataAdapter da = new MySqlDataAdapter(thequery, myCn))
{
da.Fill(dsGrid, dtMember);
}
// set the gridControl's datasource
gc_report.DataSource = null;
// clear the columns
gridView1.Columns.Clear();
// bind the data
gc_report.DataSource = dsGrid;
gc_report.DataMember = dtMember;
When I run my application, it runs well, but if the query return different column, the old column still appear although I've put the Clear() method of the gridView1.Columns collection.
How to set the gridView1 , so the grid always shows the current query?

Filter Crystal Report by combobox values

i have 2 comboboxes cmb1 and cmb2, a button and a crystalreportviewer , cmb1 displays Std and cmb2 displays Div,both values are extracted from database.I am new to crystal report and confusd how to use selection field and all ..i want that when i select either or both comboboxes and click the button the data should be filtered in crystal report and displayed in the crystalreportviewer..eg. i select '5' in cmb1 and 'A' in cmb2 then records from class 5 A only should be displayed ..
C# VS2008 , default crystal report with VS2008 ..
Thank you in advance
There can be two ways to do this thing
1) Firstly you have to filter the data table with respect combo's value at front end and then reassign the filtered data table to crystal report by using SetDataSource() function.
rptMembership objMembership = new rptMembership();
DataView dv =new DataView(ReportDataTable);
// Filtering data on combo values.
dv.Filter = "combo1id = 1 and combo2id = 2"
objMembership.SetDataSource(dv.ToTable());
rptViewer.ReportSource = objMembership;
2) Secondly you can do by filtering the record at database end as per your combo value and then re assign new data table to crystal.
There is no direct way of filtering the records at crystal report level.
Try this code in the combo-box:
report rd = new report();
// set database login information
rd.SetDatabaseLogon("username", "password", #"NOHA-PC\SQLEXPRESS", "dbname");
// write formula to pass parameters to report
crystalReportViewer1.SelectionFormula = "{tablename.columnname} =" + comboBox1.SelectedValue;
crystalReportViewer1.ReportSource = rd;

Filling a DataTable based on row values in a DataSet

I want to show some news posts on the front page of a website. The news have different categories but are stored in the same mysql database. All news items are loaded into a dataset but from there I just want to extract some specific news and show them in a ListView control.
At the moment I'am using the workaround solution of using a foreach loop on the dataset and formatting the result with html in the code behind. It works but I want all html formatting to be done in the aspx file, thus I'am looking for a better solution.
DataSet articles = db.loadAllArticles();
foreach (DataRow item in articles.Tables["articles"].Select("category = 1"))
{
result += "<h1 class='headline'>" + item["headline"] + "</h1><h2 class='introduction'>" + item["introduction"] + "</h2><p class='content'>" + item["content"] + "</p><p class='authorAndDate'>" + item["author"] + " " + item["datePosted"].ToString().Substring(0,10) + "</p><br/>";
}
lblDisplay.Text = result;
What I was hoping I could do was simply something like this:
DataSet articles = db.loadAllArticles();
ListView1.DataSource = articles.Tables["articles"].Select("category = 1");
ListView1.DataBind();
But the ListView control is not too happy about trying to bind DataRow to it or something.
The best workaround I can think of is to create a new Table within the "articles" DataSet which contains only articles of the chosen category, so something like this:
DataSet articles = db.loadAllArticles();
articles.Tables.Add("frontPageArticles");
articles.Tables["frontPageArticles"] = ???
And then thats where it stops. How can I fill the new datatable with rows from the other datatable where the value of a column is x?
-Eric.
You should be looking at binding you ListView to a DataView, it is filterable and sortable.
You can design your web form using control like repeater, datalist etc. and can bind these control to your datatable on codebehind.
An example can be found here

Categories