How to convert DataTable to List<T> in C# - list

For convert DataTable to List you can used the AutoMapper Library and you can do it automatically

Related

How to 'multitype' fixed-order, fixed-length list in Dart

In my Flutter project, I have enabled the lint package. Somewhere in my code, I have a map Map<String, List<dynamic>> options = ...;. The List is typed as dynamic, but in fact it is always a non-growable, length 2 list [String, IconData]. I use map as follows:
options.entries
.map((e) => SwitchListTile(
title: Text(e.value[0].toString()),
secondary: Icon(e.value[1]),
value: notificationSettings[e.key],
onChanged: (bool value) => onNotificationChanged(topic: e.key, enabled: value),
))
.toList());
I.e. the String in the list is the title of the listTile, the IconData is the icon to show, and the map keys are given to the notificationSettings to fetch the current setting, as well as to the onNotificationChanged handler that updates the setting.
The linter says that I shouldn't use dynamic variables at the places where I used e.value[i], so I was wondering if a non-growable, fixed-type list could be typed explicitly, e.g. by writing something like List<String, IconData>. I have tried some intuitive syntaxes, but none work, and I can't find anything on the internet.
Dart does not support tuples right now but it is being discussed.
For now, you should either create a class specific for your pair of data like this (please give it a better name which describes the purpose :) ):
class StringIconDataRelation {
final String string;
final IconData iconData;
const StringIconDataRelation(this.string, this.iconData);
}
Alternative, you can make a generic Pair class which can be used in your project:
class Pair<T1, T2> {
final T1 a;
final T2 b;
const Pair(this.a, this.b);
}
You can then have your options to have the type Map<String, Pair<String, IconData>>.
In general, it is often recommended to create specific classes for relations since it can be made the code more clear and you can implement other relevant methods. But if it is for simple stuff, it is often not a problem to use a Pair class.
You can also find a lot of packages on pub.dev which gives you tuples of different dimensions.

Correct Way to Use Google Reporting API Headers for Visualization Data Table Headers

Technologies: Google Reporting API V4 and Google Visualization API, combining PHP and Javascript. There are specific reasons we are not able to install and use the Google Client library.
The problem: the Visualization Api is giving me "invalid type Integer" when that is what the type the Google Reporting API is returning. I know that type integer is not supported in the Visualization API,
https://developers.google.com/chart/interactive/docs/reference#DataTable_addColumn
So the question is what is the correct approach to dynamically use the Reporting API headers to construct chart table headers? Do we need to map the data types every time?
In a nutshell: I query for Analytics data and get the following header structure:
[columnHeader] => Array
(
[dimensions] => Array
(
[0] => ga:date
)
[metricHeader] => Array
(
[metricHeaderEntries] => Array
(
[0] => Array
(
[name] => ga:users
[type] => INTEGER
)
[1] => Array
(
[name] => ga:sessions
[type] => INTEGER
)
)
)
)
When I attempt to create columns,
...
$mtype = $headers['metricHeader']['metricHeaderEntries'][0]['type'];
...
$column_object = "{'type':'$mtype','label':'$mname'}";
// produces {'type':'INTEGER','label':'ga:users'}
...
data.addColumn($column_object);
(Firefox) console logs "Invalid type, INTEGER, for column "Users."
I can "cheat" here by hard coding 'number' for type:
$column_object = "{'type':'number','label':'$mname'}";
Which works fine but I shouldn't have to (or am missing something) and presents some challenges in making metrics and dimensions dynamic. "Users" is indeed a number/integer. Can't help feeling it's something I overlooked that would easily map the columns from the data.
Sans responses, after much research and experimentation, thought I might post an outline of my solution (and offer it up for criticism/feedback.)
Keep in mind this is a chart "selector" between multiple chart types and multiple dimensions/metrics selections, a hard-coded one-off won't work. It has to be dynamic and perform all transformations for all chart types to work.
Analytics returns headers of types STRING, INTEGER, PERCENT, TIME, CURRENCY, FLOAT, which indeed need to be mapped to Visualization-compatible types of string, number, boolean, date, datetime, and timeofday. The server-side processing returns the raw JSON encoded Analytics data in the event other apps may consume it, and any mods to the data are performed in Javascript with a leg up from jQuery.
The problem I encountered is we "need to know" the original data type of a given column for proper formatting on chart output. This is further complicated by the header dimensions member not having a "type". For example, Analytics returns a dimension of "date" as a string "20190305" that needs to be converted to a proper Javascript Date object for chart output but in our case needs to display as a string "03/05/2019."
On receipt of Analytics data, I run a function to add the original data types from Analytics to all header columns as custom fields. These are not touched by the charts so it does not affect functionality. I then map the G.A. types to the Visualization types so they properly output the chart, and refer to my "custom types members" which contain the original data type for formatting in the chart.
The original types are referenced to properly format data using the hAxis options for the hAxis display, and Visualization [Date|Number]Formatter (s) for column data (tooltip values, etc.)
Effectively
percent -> type number, but formats as percent with %.
float -> type number, formats as decimal.
currency -> type number, formats as $currency.
date -> type Date(), formats as MM/DD/YYY
time -> type Date(), formats various (generally HH:MM:SS for our purposes)
string obviously string
Hope this is helpful for anyone diving into G.A./Visualization integration.

How to use liferay dynamic data list in another dynamic data list form template

I have 2 dynamic data lists (jobs and persons) in liferay 6.2.3
I want to use 'jobs' list as a select control in persons form template(when you add a new person you will select a job from select).
Is this possible? I can't figure it out, if so, how can I do this?
Form template for dynamic data list is a XML.

create generic list object from datatable which has different schema at runtime

Datatable should be converted to a generic list. The datatable may have different schema at runtime.so extracting the class type for the generic list becomes difficult. Because as the columns differ at run time, I could'nt create property for the class type accordingly. I want to know how to do that. i am using c#.

JasperReports: Passing in a list of lists as a datasource

I need to populate a few subreports with lists of different objects. Basically lets say i have the following:
Subreport on used Vehicles
Subreport on new Vehicles
I create a vehicle bean class with variables as strings and create getter and setter methods for the same. Then in my datasource I pass in a List<List<String>> as detailRows. detailRows contains a list for new vehicles and a list for used vehicles. So lets say, i pass detailRows in the data source.
Question is how do i pass these two lists to the two sub-reports? Can i use
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{newVehiclesList}) as a datasource for sub report 1 and
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{usedVehiclesList}) as datasource for sub report 2?
Is there anything else that needs to be done apart from what i mentioned? Do i need to create and pass any variables? Is the appropriate use of the list of lists as i have listed above or is it $F{detailRows}.get(0)?
I created a field detailRows in the main report as type list. I then pass the following to the subreport data source expression, new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{detailRows}
Is there any way i can pass the newVehiclesList from detailRows to the sub-report?
Thanks!
Selecting your SubReport you can set the property "Connection type" as "Use a data source expression" and inside the property "Data Source Expression" you set this:
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{yourFieldHere})
Where your "yourFieldHere" is a list (don't forget to set the "Field Class" inside your field properties as a java.util.List as well)
Ok, then you need create two fields with the Field Class as java.util.List, one for each list (newVehiclesList and usedVehiclesList).
Put your two SubReports wherever you want and click on each one doing the following steps:
Change the "Connection type" to "Use a datasource expression" then change the "Data Source Expression" to new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{yourField})
Done.
ps: In order to use the fields inside your newVehiclesList and usedVehiclesList you have to create them inside of their own subReports.
i was the same problems with you and i solved it using the tag List of jasper, i used datasource in my class java, for example:
parameter.put("MyList", new JRBeanCollectionDataSource(ListObjects));
in JRXML
In palete of Jasper, choose the tag LIST and drag and drop in your relatory
after choose
create new dataset
create new dataset from a connection… ...
in data adapter choose new data adapter - collection of javabeans
use a JRDatasource expression
go in lis of parameters and choose you list op objects (MyList)
now go to outline of jasper and
- dataset properties
- edit and query filter ... ...
- javabean
- search you class (I using eclipse, so it's easy to search my class)
- add fields to use