I am needing to be able to generate columns and values from dynamic data. My model is a List that contains a string and another list. The string is the column name, which I can get to display correctly. The list however I have not been able to get working correctly. I am getting one of three things all the time. 1) No values 2) The control name 3) The values but the values for each Column level item.
So with 3 columns and each column having 3 data point I can generate all three columns, but I get all three columns worth of data in each column.
Below is the code I am using for the data grid it's self as well as the code for adding the data to the outer and inner lists.
If anyone has any ideas of how to complete this I could really use the help at this point.
public List<rdzTest> getData()
{
for(int i = 0; i<5; i++)
{
rdzTest rt = new rdzTest();
//rt.name = new List<string>();
rt.name = "Property Name " + " -- " + i.ToString();
rt.values = new List<string>();
string s = "";// "<ul>";
for (int j = 0; j < 10; j++)
{
//s += "<li>values " + j.ToString() + " Property -- " + i.ToString() + "</li>";
s = "values " + j.ToString() + " Property -- " + i.ToString();
rt.values.Add(s);
}
//s += "</ul>";
//rt.values = s;
alpha.Add(rt);
//alpha.name = rt.name;
//alpha.values = rt.values;
}
return alpha;
}
<RadzenDataGrid TItem="rdzTest" Col Data=#alpha>
<Columns>
#foreach(rdzTest rt in alpha)
{
<RadzenDataGridColumn TItem="rdzTest" Property=#rt.name Title="#rt.name">
<Template>
<ul>
#foreach(string st in rt.values)
{
<li>
#st
</li>
}
</ul>
</Template>
</RadzenDataGridColumn>
}
</Columns>
</RadzenDataGrid>
I have a control file header.cntrl. it has details of header. Example below...
cat header.cntrl
id, name, age, location, phone number
Now I am getting files from different sources,
Source 1 is sending input.dat file in the following format
cat input.dat
id, name, age, location, status, phone number
1,Abc, 34,India, active, 9999999999
Source 2 is sending data in the following format
cat input_2.dat
id, age, name, qualification, status, phone number, location
2,24,xyz, L L B, Active, 88888-88888, India
So different sources are sending files in different formats. We would need to convert those input files to header.cntrl file format.
I was trying this using awk code, but for each source, I'll need to write an awk code. Can we do it with a single script which can be used for any new future source as well?
This reformat_data script can reformat the two "non-standard" input formats and any future source formats. The key idea is to use Perl hashes to store the appropriate headings and only print those that are needed as specified in the header.cntrl file.
cat $* | perl -ne '
BEGIN {
#std_header = ("id","name","age","location","phone number");
print join(",", #std_header), ",\n";
chomp($firstline=<>);
$firstline =~ s/,\s+/,/g;
#inputfile_header=split(/,/, $firstline);
%hash=();
}
chomp;
#row = split(/,/);
$i=0;
for $cell (#row) {
$cell =~ s/\s+//;
$header=$inputfile_header[$i];
$hash{$header} = $row[$i];
$i++;
}
foreach $cell (#std_header) {
print "$hash{$cell},";
}
print "\n";
'
Here are the results of running the reformat_data script using the two sample input files:
cat input.dat
id, name, age, location, status, phone number
1,Abc, 34,India, active, 9999999999
reformat_data input.dat
id,name,age,location,phone number,
1,Abc,34,India,9999999999,
cat input_2.dat
id, age, name, qualification, status, phone number, location
2,24,xyz, L L B, Active, 88888-88888, India
reformat_data input_2.dat
id,name,age,location,phone number,
2,xyz,24,India,88888-88888,
In this particular case you can check the number of fields in lines (provided that all lines of a file have the same number of fields) (awk code):
{
n = split($0, a, "[ \t]*,[ \t]*");
if (n < 7) {
print a[1] ", " a[2] ", " a[3] ", " a[4] ", " a[6];
}
else {
print a[1] ", " a[3] ", " a[2] ", " a[7] ", " a[6];
}
}
A more sophisticated solution is to use the first line as key identifier and take remaining fields "by name":
{
n = split($0, a, "[ \t]*,[ \t]*");
if (FNR == 1) {
for (i = 1; i <= n; ++i) {
lbl[a[i]] = i;
}
}
print a[lbl["id"]] ", " a[lbl["name"]] ", " a[lbl["age"]] ", " a[lbl["location"]] ", " a[lbl["phone number"]];
}
i have a scenario where there is an LOV with High Value as "Package" and TYPE="TO_NEW_PACKAGE" and i have to fetch the value of Low and there are 8 records in Low. I Have to display all the 8 records and their component cost for each record. All this should be gone as a display Message which will be output. Please let me know how to do this.
var sSearchExp = "[Type]= '" + "PACKAGE_PLAN" + "' AND [High] = '" + PACKAGEPLAN + "'"; SetSearchExpr(sSearchExp); ExecuteQuery(); var isRecord = FirstRecord(); while(isRecord) { Slow = GetFieldValue("Low"); Outputs.SetProperty ("NEW_PACKAGE_PLAN",Slow); Outputs.SetProperty("ErrorCode", "00"); Outputs.SetProperty("ErrorDesc", "Success"); i = i+1; isRecord = NextRecord(); }
this is storing only 1 record... i want all the eight records to be displayed!
This should get you started
var sSearchExp = "[Type]= '" + "PACKAGE_PLAN" + "' AND [High] = '" + PACKAGEPLAN + "'";
var Slow = "";
SetSearchExpr(sSearchExp);
ExecuteQuery();
var isRecord = FirstRecord();
while (isRecord) {
Slow += GetFieldValue("Low");
Slow += " ";
i = i + 1;
isRecord = NextRecord();
}
Outputs.SetProperty("NEW_PACKAGE_PLAN", Slow);
Outputs.SetProperty("ErrorCode", "00");
Outputs.SetProperty("ErrorDesc", "Success");
This sample code will print the values downwards:
var boAsset = TheApplication().GetBusObject("List Of Values");
var bcAsset = boAsset.GetBusComp("List Of Values");
with (bcAsset)
{
ActivateField("Value");
var sSearchExp = "[Type]= 'AAG_TABLE_TYPE'";
var Slow = "";
SetSearchExpr(sSearchExp);
ExecuteQuery();
var isRecord = FirstRecord();
while (isRecord)
{
Slow += GetFieldValue("Value");
Slow += "\n";
isRecord = NextRecord();
}
TheApplication().RaiseErrorText(Slow);
}
Output:
AAG Account
AAG Holdg
AAG Portf
AAG Txn
Changing Slow += "\n"; to Slow += " "; will print the values sideways.
Hope you get the trick here.
What's up with Flex's AreaChart bug, does anybody know how to fix it? It causes ones tooltips to display the wrong value for minFields.
I.e. for:
<mx:AreaSeries yField="TotalVariableCost" minField="TotalFixedCost" displayName="Total Cost">
It will show:
Total Cost
high: TotalVariableCost
low: TotalVariableCost
As opposed to:
Total Cost
high: TotalVariableCost
low: TotalFixedCost
This bug is suppose to be in lines 2058 to 2083 of AreaSeries.as - but that stuff is way beyond my comprehension.
--Stephen
Yep, it's a bug in AreaSeries. Due to the stupid way that flex charts are designed, the only real way to fix it is to set a custom dataTipFunction on the AreaChart.
Here's a copy of the relevant code with the bug fixed:
/**
* Create a data tip function for the given AreaSeries. Uses a copy of
* the formatDataTip code from AreaSeries with the minValue bug fixed.
*
* #param series
* #return a data tip function
*
*/
private function createAreaSeriesTipFunc(series:AreaSeries):Function {
var displayName:String = series.displayName;
var dataTransform:DataTransform = series.dataTransform;
var xField:String = series.xField;
var minField:String = series.minField;
// formatDataTip relies on AreaSeries member data so simulate that
// with a closure to minimize code modifications
return function(hd:HitData):String {
var dt:String = "";
var n:String = displayName;
if (n && n != "")
dt += "<b>"+ n + "</b><BR/>";
var xName:String = dataTransform.getAxis(CartesianTransform.HORIZONTAL_AXIS).displayName;
if (xName == "")
xName = xField;
if (xName != "")
dt += "<i>" + xName + ": </i>";
var item:AreaSeriesItem = AreaSeriesItem(hd.chartItem);
var lowItem:AreaSeriesItem = (minField != "") ?
item :
null;
dt += dataTransform.getAxis(CartesianTransform.HORIZONTAL_AXIS).formatForScreen(item.xValue) + "\n";
var yName:String = dataTransform.getAxis(CartesianTransform.VERTICAL_AXIS).displayName;
if (!lowItem)
{
if (yName != "")
dt += "<i>" + yName + ":</i> ";
dt += dataTransform.getAxis(CartesianTransform.VERTICAL_AXIS).formatForScreen(item.yValue) + "\n";
}
else
{
if (yName != "")
dt += "<i>" + yName + " (high):</i> ";
else
dt += "<i>high: </i>";
dt += dataTransform.getAxis(CartesianTransform.VERTICAL_AXIS).formatForScreen(item.yValue) + "\n";
if (yName != "")
dt += "<i>" + yName + " (low):</i> ";
else
dt += "<i>low:</i> ";
dt += dataTransform.getAxis(CartesianTransform.VERTICAL_AXIS).formatForScreen(lowItem.minValue) + "\n";
}
return dt;
};
}
I just changed formatForScreen(lowItem.yValue) to formatForScreen(lowItem.minValue) in one place. You can use it like this:
<mx:AreaChart dataProvider="{chartData}" showDataTips="true" dataTipFunction="{createAreaSeriesTipFunc(areaSeries)}">
<mx:series>
<mx:AreaSeries id="areaSeries" yField="TotalVariableCost" minField="TotalFixedCost" displayName="Total Cost" />
</mx:series>
</mx:AreaChart>
I am trying to read a text file using Dynamics AX. However, the following code replaces any spaces in the lines with commas:
// Open file for read access
myFile = new TextIo(fileName , 'R');
myFile.inFieldDelimiter('\n');
fileRecord = myFile.read();
while (fileRecord)
{
line = con2str(fileRecord);
info(line);
…
I have tried various combinations of the above code, including specifying a blank '' field delimiter, but with the same behaviour.
The following code works, but seems like there should be a better way to do this:
// Open file for read access
myFile = new TextIo(fileName , 'R');
myFile.inRecordDelimiter('\n');
myFile.inFieldDelimiter('_stringnotinfile_');
fileRecord = myFile.read();
while (fileRecord)
{
line = con2str(fileRecord);
info(line);
The format of the file is field format. For example:
DATAFIELD1 DATAFIELD2 DATAFIELD3
DATAFIELD1 DATAFIELD3
DATAFIELD1 DATAFIELD2 DATAFIELD3
So what I end up with unless I use the workaround above is something like:
line=DATAFIELD1,DATAFIELD2,DATAFIELD3
The underlying problem here is that I have mixed input formats. Some of the files just have line feeds {LF} and others have {CR}{LF}. Using my workaround above seems to work for both. Is there a way to deal with both, or to strip \r from the file?
Con2Str:
Con2Str will retrieve a list of values from a container and by default uses comma (,) to separate the values.
client server public static str Con2Str(container c, [str sep])
If no value for the sep parameter is specified, the comma character will be inserted between elements in the returned string.
Possible options:
If you would like the space to be the default separator, you can pass space as the second parameter to the method Con2Str.
One other option is that you can also loop through the container fileRecord to fetch the individual elements.
Code snippet 1:
Below code snippet loads the file contents into textbuffer and replace the carriage returns (\r) with new line (\n) character. The condition if (strlen(line) > 1) will help to skip empty strings due to the possible occurrence of consecutive newline characters.
TextBuffer textBuffer;
str textString;
str clearText;
int newLinePos;
str line;
str field1;
str field2;
str field3;
counter row;
;
textBuffer = new TextBuffer();
textBuffer.fromFile(#"C:\temp\Input.txt");
textString = textBuffer.getText();
clearText = strreplace(textString, '\r', '\n');
row = 0;
while (strlen(clearText) > 0 )
{
row++;
newLinePos = strfind(clearText, '\n', 1, strlen(clearText));
line = (newLinePos == 0 ? clearText : substr(clearText, 1, newLinePos));
if (strlen(line) > 1)
{
field1 = substr(line, 1, 14);
field2 = substr(line, 15, 12);
field3 = substr(line, 27, 10);
info('Row ' + int2str(row) + ', Column 1: ' + field1);
info('Row ' + int2str(row) + ', Column 2: ' + field2);
info('Row ' + int2str(row) + ', Column 3: ' + field3);
}
clearText = (newLinePos == 0 ? '' : substr(clearText, newLinePos + 1, strlen(clearText) - newLinePos));
}
Code snippet 2:
You could use File macro instead of hard coding the values \r\n and R that denotes the read mode.
TextIo inputFile;
container fileRecord;
str line;
str field1;
str field2;
str field3;
counter row;
;
inputFile = new TextIo(#"c:\temp\Input.txt", 'R');
inputFile.inFieldDelimiter("\r\n");
row = 0;
while (inputFile.status() == IO_Status::Ok)
{
row++;
fileRecord = inputFile.read();
line = con2str(fileRecord);
if (line != '')
{
field1 = substr(line, 1, 14);
field2 = substr(line, 15, 12);
field3 = substr(line, 27, 10);
info('Row ' + int2str(row) + ', Column 1: ' + field1);
info('Row ' + int2str(row) + ', Column 2: ' + field2);
info('Row ' + int2str(row) + ', Column 3: ' + field3);
}
}
Never tried to use the default RecordDelimiter as FieldDelimiter and not setting another RecordDelimiter explicitly. Normally rows (Records) are delimited by \n and fields are delimited by comma, tab, semicolon or some other symbol. You might also be hitting some weird behaviour when TextIO is assuming correct UTF-format. You didn't supply an example of some rows from you datafile, so guessing is hard.
Read more about TextIO here: http://msdn.microsoft.com/en-us/library/aa603840.aspx
EDIT:
With the additional example of file content, it seems to me the file is a fixed width file, where each column has its own fixed width. I would rather recommend using subStr if that is the case. Read about substr here: http://msdn.microsoft.com/en-us/library/aa677836.aspx
use StrAlpha to restrict blank values after you convert Con2Str