Textbox item not linked to a dataset - c#

In the tablix if've got 2 fields (Quantity and Price) that is populated from the database (dataset fields) witch works great. Next to those two columns I added another column Total which I use to get the total of the quantity * Price
=Fields!Quantity.Value*Fields!Price.Value
That works fine as well.
I then added a 3 textboxes at the bottom of that column (within a rectangle) which I want to use to do a Subtotal (sum of the Total), The vat and the the Grand Total after tax had been added. The problem is, is that I cannot add a dataset to a textbox, thus I cant use the Field Section when doing the expression which leaves me that I have to use the dataset section in expression to do this. This is how this looks in the dataset section: (and give me the following error:
=Sum(Sum(Fields!Quantity.Value, "DataSetItemsRequested")*Sum(Fields!Price.Value, "DataSetItemsRequested"))
The Value expression for the textrun 'Textbox53.Paragraphs[0].TextRuns[0]' contains an aggregate function (or RunningValue or RowNumber functions) in the argument to another aggregate function (or RunningValue). Aggregate functions cannot be nested inside other aggregate functions.
Is there a way that I can use a simple sum of that Total column or how do I add the dataset to the textbox or which is the correct way of how I can do this?
=Sum(ReportItems!txtTotal.Value) doesn't work either....

Can you just add a Footer row to the Tablix and just add the following expression:
=Sum(Fields!Quantity.Value * Fields!Price.Value)
If you want this value outside the Tablix, you can use a similar expression:
=Sum(Fields!Quantity.Value * Fields!Price.Value, "DataSet1")
Expressions in action:
Result:

Rather than using TextBox, include your value in Tablix: insert another row inside/outside group and place your expression there.

Related

Excel VBA/C# Subtotal Function: What does TotalList parameter do?

I'm trying to get the subtotals for a table in C# using Microsoft.Interop.Excel, and there is a built in function for that.
[Here][1] is the link to the documentation for the Subtotal function.
I understand what GroupBy and Function parameters do, but what exactly is the TotalList parameter for? Microsoft describes it as:
"An array of 1-based field offsets, indicating the fields to which the subtotals are added."
How are these offsets being read? In pairs for row and column offset? In examples I see whole arrays of many numbers being used for this. How do I make use of this?
[1]: https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.range.subtotal?view=excel-pia
You pass an array of as many numbers as you have columns for which you want subtotals calculated. If you only have one column to subtotal, you can just pass in a single number in place of an array (at least, in VBA that works)
Eg: (in VBA) -
Range("A1").CurrentRegion.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(3, 5)
would group a table of data starting in A1, according to the first column, and add subtotals in the third and fifth columns.

Crystal Reports: This function cannot be used because it must be evaluated later

I am currently trying to report on stock quantities with a timeframe for each item in stock;
Stock at the selected minimum date within the timeframe
Stock at the selected max date within the timeframe
I have a single quantity field of an item from a transaction which I am adding to my report twice however both with differing formulas under select expert.
Stocks.Date = MINIMUM(Stocks.Date)
Stocks.Date = MAXIMUM(Stocks.Date)
I've grouped by product and have all fields in the group header. I have tried looking online for solutions but I haven't found anything that really solves the problem. If you need more information please ask, this is wrecking my brain.
Essentially what I want is(for each stock item):
Quantity field1:
SELECT Stock.Quantity WHERE Stock.Date = MINUMUM(Stock.Date)
Quantity field2:
SELECT Stock.Quantity WHERE Stock.Date = MAXIMUM(Stock.Date)
Hope this helps clarify what I'm after
Create two SQL expression fields:
// {%MIN_DATE}
(
SELECT MINIMUM(Date) FROM Stock
)
// {%MAX_DATE}
(
SELECT MAXIMUM(Date) FROM Stock
)
Then reference them in the record-selection formula:
{Stock.Date} IN [{%MIN_DATE},{%MAX_DATE}]
You can't include Crystal's aggregate functions in the record selection formula because it is self-referential. It's like saying "define set A as the largest element of set A". In your case, you're effectively saying, "Only include records in my report where the date is the most recent record in my report"... doesn't make sense.
Instead, you have to include all records and only "process" the ones where {StockSales.Date}=maximum({StockSales.Date},{StockSales.ItemID}). You can accomplish this by comparing the date of each record to the maximum date for that item ID and saving the stock quantity off in a variable if it is a match. You can then display the variable in the item's group footer.
The first step is to move all your Group Header 1 elements into Group Footer 1 instead. Then you'll need to create 2 new formulas to manage the variable:
//{#Update variable}
// Place this formula in the Details section
whileprintingrecords;
numbervar qty;
if {StockSales.Date}=maximum({StockSales.Date},{StockSales.ItemID})
then qty := {StockSales.Quantity}
//{Display variable}
// Place this formula in the Group Footer 1 section where you want the quantity to display
whileprintingrecords;
numbervar qty;
If your aim is to show the max and min in the report, then you can try the below Steps:
Go to the Group field, Right Click on the object ->Format Object->Display String-> Give the Formula:
CStr (Maximum ({Stocks.Date}));
To show both min and max in the same report, drag the Date field twice into the report and for one object give Minimum Date another with Max date.
For Maximum: CStr (Maximum ({Stocks.Date}));
For Minimum : CStr (Minimum ({Stocks.Date}));
Your Select Expert doesn't make any sense to me.
You are retriving the records from Min Date to Max Date in other words you are retriving the whole table data in to your report in this case what is the use of select expert.
If you don't mention any thing in select expert then also you can whole table data.
If you really want to filter some data then provide some paramters to the user so that you can filter in those parameters then your select expert will become something like.
Stocks.Date>={?StartDate} and Stocks.Date<={?EndDate}
If my understanding is wrong then edit the question clearly with your requirement.
Edit-------------------------------------------------------------------------------------
In this case don't use select expert, Do calculations in your report itself in formula fields.
create a formula as:
#Minimumn
if Stock.Date = MINUMUM(Stock.Date)
then <Stockitemahere>
For Maximum create another formula as:
#Maximum
if Stock.Date = MAXIMUM(Stock.Date)
then <Stockitemahere>
Place both formulas on design part of the report.
Take care date filtering shouldn't be in select expert

C# SubItems Issue

I'm a student learning C#, with previous experiences with VB. I'm trying to use a list view to display three pieces of information in three separate columns. The Item is a decimal (Object = 3.50m), and the subItems are the quantity and a price. I have managed to get the first two columns showing the data with:-
var item = lsvstarter.Items.Add(cmbStarter.Text);
item.SubItems.Add(cmbStrQuantity.Text);
The third column should show the worth of the item multiplied by the quantity, so it would be
1st Column "3.50"
2nd Column "3"
3rd Column (3.50 * 3) "10.5"
But the method I used for the first subitem will not work for the variable that should be displayed by the third column. This being
item.SubItems.Add(Startertotal);
The ListView includes 3 columns. I had this program working on VB since the scenario is the same but using translators didn't work successfully. All of the objects in the Design view are the same.
Also the calculation for the "Startertotal" variable has already been calculated in a loop beforehand. Does anyone know what I'm doing wrong and the fix?
MSDN: SubItems.Add takes either a string or a SubItem as its first parameter.
So you need to change the numeric value to a string in one way or another:
item.SubItems.Add(Startertotal + " ");
item.SubItems.Add(Startertotal + "");
item.SubItems.Add(Startertotal.ToString());
item.SubItems.Add(Startertotal.ToString("###0,00"));
item.SubItems.Add(String.Format("Sum: {0} ", Startertotal));
or whatever formatting you want..

crystal reports - formula field conditional statement on what records to sum

crystal reports formula field
Good day,
I am making a sales report on Crystal Report - VS2010 c#
I have this view in MS SQL
vSales
OrderNo
OrderDate
Amount
PaymentType
Payment type can either be Cash or Check
I performed select all because I need both in the same report
so how do I get the sum of Amount where PaymentType is equal to cash?
I used Sum for my total Amount, both check and cash, in the formula workshop
Sum ({vDailySales.Amount})
I can't modify my SELECT statement because I need all the record with cash & check payment
Create two formulas - CashAmount and CheckAmount, for example second one:
if {vDailySales.PaymentType}="cheque"
then {vDailySales.Amount}
else 0
On report, use aggregates of said formulas - like Sum({#CashAmount}).
There are two ways I would use; depending on what output I wanted.
The first way, and the simplest would be group on the payment type. Then create a sum in the footer of the group. You can use the "Running Total" tool or use the code below.
SUM({vDailySales.Amount}, {vDailySales.PaymentType})
This will show a result for each of the payment types, so in your case twice, once for cash and once for cheque.
I think through here you can use formulas in the "Evaluate" section of running total; where you would use a true/false statement for what you wanted to show. The statement for "cash" for example would be:
if {vDailySales.PaymentType}="Cash" then true else false
The other method, which would be simpler if you wanted a grand total would be to use a conditional sum.
Define the variables in the header:
SHARED numbervar sumcash;
SHARED numbervar sumcheque;
sumcheque:=0;
sumcash:=0;
Then for each line in the report; add a field to conditionally sum the amounts; using a formula like:
SHARED numbervar sumcash;
SHARED numbervar sumcheque;
if {vDailySales.PaymentType}="cheque" then
sumcheque = sumcheque + {vDailySales.Amount};
else
sumcash = sumcash + {vDailySales.Amount};
Then at the bottom of the report, make a formula to display each of the variables seperately.
A third option is to use a running-total field. Because of how they are calculated, they need to be in a footer section.
To create one, follow these steps:
select the {vDailySales.Amount} field on the canvas, right click, then select Insert, Running Total...
Set the Running Total Name field as appropriate, perhaps 'Sum of Cash'.
Ensure that the Type of Summary is 'sum'.
Select the 'Use a formula' option, click the conditional-formula button, then enter the following as the formula's text:
{vDailySales.PaymentType}="Cash"
Select 'Never' for the Reset option or 'On change of group' (selecting the appropriate group) if this RT field will tally an amount by group.
Place field in the Report Footer section.
Repeat the process for a second running-total field that will summarize cheques (change step 4 to reference "Cheque" instead of "Cash".

How to create LookUp fields in DataGridView?

In my DataGridView I'am displaying a buch of columns from one table. In this table I have a column which points to item in another table. As you may already guessed, I want to display in the grid in one column some text value from the second table instead of and ItemID.
I could not find a right example on the net how to do this.
Lets assume that I have two tables in databes:
Table Users:
UserID UserName UserWorkplaceID
1 Martin 1
2 John 1
3 Susannah 2
4 Jack 3
Table Workplaces:
WorkplaceID WorkplaceName
1 "Factory"
2 "Grocery"
3 "Airport"
I have one untyped dataset dsUsers, one binding source bsUsers, and two DataAdapters for filling dataset (daUsers, daWorkplaces).
Code which I am performing:
daUsers.Fill(dsUsers);
daWorkplaces.Fill(dsUsers);
bsUsers.DataSource = dsUsers.Tables[0];
dgvUsers.DataSource = bsUsers;
At this point I see in my dgvUsers three columns, UserID, UserName and UserWorkplaceID. However, instead of UserWorkplaceID and values 1,2,3 I would like to see "Factory", "Grocery" and so on...
So I've added another column to dgvUsers called "WorkplaceName" and in my code I am trying to bind it to the newly created relation:
dsUsers.Relations.Add("UsersWorkplaces", dsUsers.Tables[1].Columns["WorkplaceID"], dsUsers.Tables[0].Columns["UserWorkplaceID"]);
WorkplaceName.DataPropertyName = "UsersWorkplaces.WorkplaceName";
Unfortunately that doesn't work. Relation is created without errors but fields in this column are empty after running the program.
What I am doing wrong?
I would like to also ask about an example with LookUp combobox in DataGridView which allow me to change the UserWorkplaceID but instead of numeric value it will show a tex value which is under WorkplaceName.
Thanks for your time.
In my opinion, the best decision would be to use the DataGridViewComboBoxColumn column type. If you do it, you should create a data adapter with lookup data beforehand and then set DataSource, DataPropertyName, DisplayMember, and ValueMember properties of the DataGridViewComboBoxColumn. You could also set the DisplayStyle property to Nothing to make the column look like a common data column. That's it.
I don't know if you can do exactly what you want, which seems to be binding the DataGridView to two different DataTable instances simulataneously. I don't think the DataGridView class supports that -- or if it does it's a ninja-style move I haven't seen.
Per MSDN, your best bet is probably using the CellFormatting event on the DataGridView and check for when the cell being formatted is in the lookup column, then you could substitute your value from the other table. Use an unbound column for the WorkplaceName column, hide the UserWorkplaceID column and then implement the CellFormatting event handle to look up the value in the row, e.g.:
private void dgv_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
if (dgv.Columns[e.ColumnIndex].Name.Equals("WorkplaceName")
{
// Use helper method to get the string from lookup table
e.Value = GetWorkplaceNameLookupValue(
dataGridViewScanDetails.Rows[e.RowIndex].Cells["UserWorkplaceID"].Value);
}
}
If you've got a lot of rows visible, this might impact performance but is probably a decent way to get it working.
If this doesn't appeal to you, maybe use the DataTable.Merge() method to merge your lookup table into your main table. A quick glance at one of my ADO.NET books suggests this should work, although I have not tried it. But I'm not sure if this is too close to the idea suggested previously which you shot down.
As for your second question about the lookup combobox, you should really post it in a separate question so it gets proper attention.
You could make SQL do the job instead. Use a join to return a table with Workplace names instead of IDs, output that table into a dataset and use it instead.
eg.
SELECT A.UserID, A.UserName, B.WorkplaceID
FROM Users A
JOIN Workplaces B ON A.UserWorkplaceID = B.WorkplaceID
Then use its output to fill dsUsers.

Categories