Combine data from multiple sources, display in ASP.Net GridView - c#

I am writing a currency converting module for one of our applications. I have a list of products, a list of currencies we are interested in seeing prices for, and a list of currency rates. I want the user to be able to select which currencies from the list they see in the GridView.
I also want to be able to amend my list of currencies and include a new currency, without having to make additional changes to this module. So my GridView display has to be dynamic.
Essentially I am planning on ending up with a GridView that has the following columns:
Part No - Description - USD Price - AUD Price - GBP Price
The USD price would be static as it's our base currency, the AUD and GBP are user selected and could have potentially any number of currencies listed.
I would normally use a DataSet and DataTables for this work, but I am sure there is a "better" way to do it using System.Collections.Generics.
Right now I have all of the data I need in List collections, but there does not seem to be a way to define how these collections relate to each other, or combine these collections into one so it can be bound to a GridView.
Should I be looking at something other than List to achieve this or do I need to go back to my original approach of a DataSet and DataTables.
Thanks!
******UPDATE / SOME CODE******
OK, someone asked for some code, so I will explain a little bit more about what I have setup so far.
List of Products & Currencies - These come from an SQL DB via LINQ, so they can be any of the System.Collections.Generics objects, e.g. List, IEnumerable etc.
Currency Rates - These I am pulling from the European Bank public XML file. I download the file, strip the data I need out of it and currently store that as a List object.
I could store the currency rates in the database table as well, but then I have to have some sort of background process that goes and updates the rates each day. This way the rates only get updated when someone accesses the report function (which is only going to happen occasionally). So I would rather grab the latest rates "on demand".
What I know I need to end up with is some object that has the following structure:
PartNo - Description - Base Price - Currency Price 1, Currency Price 2, Currency Price 3
Where the number of Currency Prices is undefined, as it's based on what currencies the user wants the report to display.
It's the undefined part that I am struggling with, essentially how can I create a structured object, that I don't know the complete structure of until runtime ?
Hope this makes more sense / helps!

Just thinking out loud here, but if you stored your "foreign" prices in a Dictionary or similar data structure like so:
class Product {
public String PartNo { get; set; }
public String Description { get; set; }
public Decimal BasePrice { get; set; }
public Dictionary<String, Decimal> ForeignPrices;
}
Then you could write a simple routine that would take a collection of the above objects and convert it into a DataTable that you could then bind to. Said routine would always create the following columns:
PartNo, Description, BasePrice
It would then loop through the items in the Dictionary, adding additional columns for each item. So if you had three items in ForeignPrices:
ForeignPrices.Items.Add("AUD", 10.50);
ForeignPrices.Items.Add("GBP", 6.20);
ForeignPrices.Items.Add("CAD", 5.95);
You would end up with three additional columns on your dynamically-created DataTable:
PartNo, Description, BasePrice, AUD, GBP, CAD
Of course you may want to do away with the BasePrice property and just make "USD" another item in ForeignPrices (in which case it would simply be called Prices).
HTH.

Related

Selected idea name should show all its attributes in List box

I have created tables for the attributes (Country, Currency, RiskLevel, Invest_Type, Price)
all these are added into another table named IdeaDetails as foreign keys which i could use to display all the attributes when a specific idea is selected.
example how i display it:
Tech name - USA
- 20000
- DOLLARS
- Low Risk
- Start-up Type
I have used a Query which letThis Query adds the country from the Country table to the selected Idea name in windows form me add the name of the idea and display the hard coded data in it. This images shows what the above query does
i wanted to know if there is a query where i could add the rest of the attributes like currency, riskLevel, invest type, price onto the same selected idea name.
Thank you.

Best design to implement system with dynamic columns in .NET

I'm looking for best option that is available today with SQL Server Backend & C# has front end for storing data which has dynamic columns. Currently My Scenario is like
I have Object say "Item" which holds Pricing information for multiple currency like
ID Name AUD USD CAD INR
1 Item1 1 1 1 1
As of today we have fixed number of currency (# of Currency to display is based on XML Configured Currency File), we currently implemented table with fixed number of currency. Let assume tomorrow if there is new currency added say EURO without doing much changes to front End, ( I can assume datatable in this scenario) and no major changes to backend tables, do we have any new features either in SQL Server or C# which supports dynamic columns ?
One Approach which I'm thinking of (Old approach) Create ITEM Class with ItemID , ItemName and Dictionary/Expando Object/ Property BAG with Currency prices like
Item1 RAM 12
Is it better to seralize those PropertyBag/Expando Object in XML or JSON, which is faster to Save and Retrieve.
I would like to view all Currencies for each item in Relational/Table Format while I Query.
How can i have datatable with PropertyBag.
Stop storing the value in different currency columns.
Have the base local currency for where you are operating and use a currency api to offer different currencies and calculate prices.
With an API, you can offer all currencies that are provided with a live exchange rate.
Exchange rates change all of the time, so to avoid having to update prices in you tables, get the live exchange rate and use that.

What is the best way to implement an application that saves data for customized products with different kinds of data fields?

Suppose we have a database with two tables Product and ProductField. Table ProductField contains several fields related to each Product in the Product table. So For one product it's Id repeats several times in ProductField. That's a nice schema for saving customized products with several different fields for each one.
But there is a problem with this naive solution. For example in the above image you can see that product fields have different types, string for Name and numerical value for Price field. Therefore we have to save the type of each field, somewhere in our application. I thought it would be good idea to save this types in another table as follows:
This solves the problem of unknown types. But there still exist type casting problem. Because we still need to save all values in the field value of the first table which is a string column. So we have to cast the values to the required type in our application. This is the code we need:
// string fieldType retrieved from database
// string fieldValue retrieved from database
if (fieldType == "string")
{
// do something with fieldValue
}
else if (fieldType == "int")
{
// do something with int.Parse(fieldValue)
}
.
.
The third solution is to use one table for each field type. The following picture illustrates the solution I have in my mind.
As you can see one disadvantage of this solution is that you can not create new field types straightforward. You have to create new tables and change database schema in run time if you want to add new field types.
But one advantage of this solution is that you do not need to cast the string value to int or double or whatever the real format of the saved value is.
What do you think about the third solution? Does it make sense?
Assuming you really really need to have one table that caters for different product types with different characteristics, a simple way to go would be to have 3 tables:
header table that includes all products (product id is a primary key)
table for quantifiable fields (floats) with N rows per product (price, size, percentile, ...)
table for un-quantifiable fields (varchar) with N rows per product (description, warnings, ...)
something like this:

Generate report week wise using a date field RDLC report

I have a RDLC report that displays count of Test Packs issued each day. I want to change this report in such a way that it should show the count of test packs issued per week instead of per day. How can i achieve that?
Here is the result of the current report (exported to excel).
The report is generated Island wise, then issue date wise test packs count.
The property in my ViewModel returns a collection that contains Test Pack records with fields like
public class TestPack
{
public string TestPackNo { get;set; }
public string Island { get;set; }
public string IssueDate { get;set; }
}
There two ways to achieve this.
Work with underlying data - for example, add column "MondayofCurrentWeek" (since every week would have Monday) and group by that column instead. (This would be my preferred solution.)
Add group by "week start" expression. You might need to add function to report's code to find it base on current date function. Since the language for report's code is VB, this may help: https://msdn.microsoft.com/en-us/library/aa227527(v=vs.60).aspx

Getting String Sets into Presentation Layer

We're working on an hospital information system that is being written on C# and using NHibernate to map objects to database. MVC pattern is being used to separate business logic from UI. Here is the problem,
How do you get variable sized different set of strings to UI?
For example a Contact object have a property named City that holds which city contact lives. In country that the app is written for has more than 80 cities. How could you write those cities to a combo box? (or a data grid, tables, ...) In this example the city number is fixed. There is no need to add another city for a long time. (If the city list changes, recompiling is not a problem)
For example a Contact object have another property named FooBar which is going to be hold 1000 different string values and these values is going to be selected from a combo box for that property. And this set can be grown if users want. How do you load the combo box with these values? (If the string list statically written to combo box object, recompiling is a problem)
I have different solutions as below
All string values statically written to combo box in code or designer
Get the values from a resource file
Write those values to an XML file (Actually same as above, but no need to recompile)
Make a City object and get the values into a list from CITY table with NHibernate
Make a class named StringHolder which has a Type and Value property. All string values(including City and FooBar) would be written in just one table named STRINGHOLDER. And get those values with a key like "CITY" or "FOOBAR" with NHibernate.
Which one would you choose? Or could you suggest me another one?
Thanks all
I would vote for solution #4. That's the way I have always done it in similar situations. It just seems like a cleaner solution.
If the locations are actually going to be used for anything, get them into the database. If the data "isn't really used", but cities lookup is provided to make the user interface better, then the XML file option is not a bad way to go either.
By used, I mean stuff like list all emplyees in New York and stuff like that. If it's "dead data", just to be displayed, go for the solutions that will require the least amount of work and least risk - which might be the file option.
How do you feel of using List<string> for a list of City? Load this list of strings in your DAL or BL and then pass it on to UI.
Same solution should be good for FooBar values too.
In case you have IDs associated with City or FooBar, say NY and its numeric ID in DB is 1, then you can use KeyValuePair<TKey, TValue>. With generics you can dictate what data goes in this KeyValuePair. City name or FooBar's string value can be key and numeric ID can be value.
Just 2 cents.

Categories

Resources