How can I initialise two-dimentional typed Vector is AS3?
Now I can get working only this:
private var _mainArray : Array = new Array( MyConst.DIMENTION );
public function MyArray()
{
for ( var i : int = 0; i < MyConst.DIMENTION; i++ ) {
_mainArray[ i ] = new Vector.<int>( MyConst.DIMENTION );
}
}
...
_mainArray[ i ][ j ] = 0;
What you have is an Array of Vector of int. What you want is a Vector of Vector of int.
So your "outer" Vector has to declare that contains elements of type Vector.<int>
Something like this (of course you can use a for loop):
var v:Vector.<Vector.<int>> = new Vector.<Vector.<int>>(2);
v[0] = new Vector.<int>(2);
v[1] = new Vector.<int>(2);
v[0][0] = 0;
v[0][1] = 1;
v[1][0] = 2;
v[1][1] = 3;
trace(v);
private var _labelsRefs:Vector.<Vector.<Object>> = new Vector.<Vector.<Object>>( );
private var _labelsFrRefs:Vector.<Object> = new Vector.<Object>( );
private var _labelsEnRefs:Vector.<Object> = new Vector.<Object>( );
_labelsRefs [ _labelsRefs.length ] = _labelsFrRefs;
_labelsRefs [ _labelsRefs.length ] = _labelsEnRefs;
You can add 10 additional items if you want
_labelsFrRefs [ _labelsFrRefs.length ] = [ _label.#key, _label.#xml ];
Then you can search in the _labelsRefs:Vector
public function searchKeyXml ( langue:String, key:String, val:int ):String
searchKeyXml ( "fr", "three", 1 ); medias/xmls/fr/homepage1.xml
searchKeyXml ( "en", "three", 1 ); medias/xmls/en/homepage1.xml
Related
I have a method which has anonymous type and after it I add parameters to viewmodel.
public void ConvertirBono(List<Bono> ParamBonos,List<Empleado> ParamEmpleado)
{
Bonos = new List<BonoVM>();
var bonos2 = ParamBonos.Where(x => x.mdEstatusRegistro)
.Join(ParamEmpleado, x => x.EmpleadoID, y => y.ID, (x, y) => new
{
empleadoCompleto = y.nCodigoEmpleado.ToString() + y.vNombreEmpleado,
}).ToList();
foreach (var p in ParamBonos)
{
Bonos.Add(new BonoVM()
{
EmpleadoId = p.EmpleadoID,
vEmpleado = empleadoCompleto,
nBono1 = p.nBono1,
nBono2 = p.nBono2
});
}
}
What I want to do is to insert anonymous type empleadoCompleto when I add into ViewModel(foreach clause) but it always comes null. I try to declare that variable outside but it still comes null.
public void ConvertirBono(List<Bono> ParamBonos,List<Empleado> ParamEmpleado)
{
Bonos = new List<BonoVM>();
string empleadoCompleto = null;
var bonos2 = ParamBonos.Where(x => x.mdEstatusRegistro)
.Join(ParamEmpleado, x => x.EmpleadoID, y => y.ID, (x, y) => new
{
empleadoCompleto = y.nCodigoEmpleado.ToString() + y.vNombreEmpleado,
}).ToList();
foreach (var p in ParamBonos)
{
Bonos.Add(new BonoVM()
{
EmpleadoId = p.EmpleadoID,
vEmpleado = empleadoCompleto,
nBono1 = p.nBono1,
nBono2 = p.nBono2
});
}
}
What am I doing wrong?
From your code, it looks like all you are trying to do it merge the two list objects together and create a list of view models. There's no need to create anonymous types here at all, you can do it all with one line of code. This may not be quite right as your question is unclear, but it should at least get you on the right track.
public void ConvertirBono(List<Bono> ParamBonos,List<Empleado> ParamEmpleado)
{
Bonos = ParamBonos.Where(x => x.mdEstatusRegistro)
.Join(ParamEmpleado,
x => x.EmpleadoID,
y => y.ID,
(x, y) => new BonoVM
{
EmpleadoId = x.EmpleadoID,
vEmpleado = y.nCodigoEmpleado.ToString() + y.vNombreEmpleado,
nBono1 = x.nBono1,
nBono2 = x.nBono2
})
.ToList();
}
How to Add Custom Columns to RadExplorer I Added Two Columns Date And Owner To the RadExplorer. URL For Demo.
http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/applicationscenarios/customgridcolumns/defaultcs.aspx
Previous I am Getting FileName And Size When I added Two coloumn Headings By
private void AddGridColumn(string name, string uniqueName, bool sortable)
{
RemoveGridColumn(uniqueName);
// Add a new column with the specified name
GridTemplateColumn gridTemplateColumn1 = new GridTemplateColumn();
gridTemplateColumn1.HeaderText = name;
if (sortable)
gridTemplateColumn1.SortExpression = uniqueName;
gridTemplateColumn1.UniqueName = uniqueName;
gridTemplateColumn1.DataField = uniqueName;
Aspx_RadFileExplorer.Grid.Columns.Add(gridTemplateColumn1);
}
Function For ResolveRootDirectoryAsTree
<pre>
public override DirectoryItem ResolveRootDirectoryAsTree ( string xszPath )
{
PathPermissions zPathPermission = FullPermissions;
if ( xszPath.Equals ( "Document/Private" ) )
zPathPermission = PathPermissions.Read;
else if ( xszPath.Equals ( "Document/Public" ) )
zPathPermission = PathPermissions.Read | PathPermissions.Upload;
return new DirectoryItem(GetName(xszPath), GetDirectoryPath(xszPath), xszPath, GetDate(xszPath), zPathPermission, GetChildFiles(xszPath), GetChildDirectories(xszPath));
}
</pre>
Function For ResolveDirectory
public override DirectoryItem ResolveDirectory(string xszPath )
{
PathPermissions zPathPermission = FullPermissions;
if ( xszPath.Equals ( "Document/Private" ) )
zPathPermission = PathPermissions.Read;
else if ( xszPath.Equals ( "Document/Public" ) )
zPathPermission = PathPermissions.Read | PathPermissions.Upload;
DirectoryItem[] zdlDirectories = GetChildDirectories ( xszPath );
return new DirectoryItem ( GetName ( xszPath ), EndWithSlash ( GetDirectoryPath ( xszPath ) ), string.Empty, string.Empty, zPathPermission, GetChildFiles ( xszPath ), zdlDirectories );
}
private string GetName ( string xszPath )
{
if ( xszPath == null )
{
return string.Empty;
}
return xszPath.Substring ( xszPath.LastIndexOf ( '/' ) + 1 );
}
In This Function I Will Get OwnerID And Date as strings LoadDocuments().How to Display Owner ID to Owner Custom Field,And Date To Date Field
private void SafeLoadDocument ( string xszUserID )
{
try
{
DataTable zdtReturn = new DataTable();
if ( ViewState["m_DocumentTable"] == null )
ViewState["m_DocumentTable"] = EMSBLCRM.LoadDocuments( xszUserID );
zdtReturn = (DataTable)ViewState["m_DocumentTable"];
foreach (DataRow dr in zdtReturn.Rows)
{
double zdbFileSize = Convert.ToDouble(dr["fld_document_latest_attachment_size"]);
string zsztest = String.Format("{0:#,##0}", zdbFileSize);
dr["fld_document_latest_attachment_size"] = zsztest;
Convert.ToDouble(dr["fld_document_created_on"]);
string date = dr["fld_document_created_on"].ToString();
string date2 = date.Substring(0, 10);
}
Session["sesDocumentTable"] = ViewState["m_DocumentTable"];
}
catch ( Exception e )
{
Utilities.SendCrashEMail ( ref e );
}
}
Here's a link to the documentation and following is the code.
// Add a new 'custom column for the file owner'
GridTemplateColumn gridTemplateColumn2 = new GridTemplateColumn();
gridTemplateColumn2.HeaderText = "Owner Name";
gridTemplateColumn2.SortExpression = "Owner";
gridTemplateColumn2.UniqueName = "Owner";
gridTemplateColumn2.DataField = "Owner";
RadFileExplorer1.Grid.Columns.Add(gridTemplateColumn2);// Add the second column
//And the code for adding value for the file entry for the custom column.
public override DirectoryItem ResolveDirectory(string path)
{
// Update all file items with the additional information (date, owner)
DirectoryItem oldItem = base.ResolveDirectory(path);
foreach (FileItem fileItem in oldItem.Files)
{
// Get the information from the physical file
FileInfo fInfo = new FileInfo(Context.Server.MapPath(VirtualPathUtility.AppendTrailingSlash(oldItem.Path) + fileItem.Name));
// Add the information to the attributes collection of the item. It will be automatically picked up by the FileExplorer
// If the name attribute matches the unique name of a grid column
fileItem.Attributes.Add("Date", fInfo.CreationTime.ToString());
// Type targetType = typeof(System.Security.Principal.NTAccount);
// string value = fInfo.GetAccessControl().GetOwner(targetType).Value.Replace("\\", "\\\\");
string ownerName = "Telerik";
fileItem.Attributes.Add("Owner", ownerName);
}
return oldItem;
}
Hope this will be helpful for you.
I am using the Extjs4 multigrouping plugin from here.
I have used it successfully, however i want to show the summary of the totals of each column within the group header itself . how do i set up the appropriate CSS for that ?
In Multigrouping.js
getFragmentTpl: function() {
var me = this;
return {
indentByDepth: me.indentByDepth,
depthToIndent: me.depthToIndent,
renderGroupHeaderTpl: function(values, parent) {
return Ext.XTemplate.getTpl(me, 'groupHeaderTpl').apply(values, parent);
//var z = new Ext.XTemplate('{name} ({rows.grouplength})');
//return z.apply(values, parent);
}
};
},
In my grid
features: [
{
ftype:'multigrouping',
groupHeaderTpl: [
'{[this.readOut(values)]}',
{
readOut:function(values) {
debugger;
var sum1 =0 ,sum2=0,sum3=0;
for( var i = 0 ; i< values.records.length ; i++)
{
var val = parseFloat(values.records[i].data.d2012.mp);
sum1 += isNaN(val) ? 0.0 : val;
val = parseFloat(values.records[i].data.d2013.mp);
sum2 += isNaN(val) ? 0.0 : val;
val = parseFloat(values.records[i].data.d2014.mp);
sum3 += isNaN(val) ? 0.0 : val;
}
return values.name + '(' + values.records.length + ')' + ' ' + sum1.toFixed(2) + ' ' + sum2.toFixed(2) + ' ' + sum3.toFixed(2);
}
}
]
},
had to resort to a few hacks to get this to work. still waiting on an official answer.
The main reason i had to do this and not use the multigrouping summary is because
- i want to limit the number of records from the server. I can do some smart grouping of
my business objects at the server side.
- the main reason to do this is because of IE8's performance on larger sets of data.
- had already tried the extjs4 tree grid component which works well on chrome but had performance issues on IE8.
the hack is to
a) use an array property in the grid to store the dom elements which i want to manipulate
b) use a boolean to know when the layout is completed the first time
b) add listeners for afterlayout ( when your app can do an Ext.get('..dom element..') you know you are done )
The listener :
listeners :
{
afterlayout : function(eopts)
{
var x = this.mOwnArray;
if(!this.loadedwithVals && x.length > 0)
{
for(var i =0 ; i<x.length ; i++)
{
var dom = Ext.get(x[i].id);
var theId = dom.id;
theId = theId.match(/\d+/)[0];
var title = dom.query("td[class='x-grid-cell x-grid-cell-first']");
title[0].className = 'x-grid-cell x-grid-cell-gridcolumn-' + theId + ' x-grid-cell-first';
title[0].colSpan=1;
var groupedHeader = dom.query("div[class='x-grid-group-title']");
groupedHeader[0].innerHTML = x[i].name + '(' + x[i].length + ')';
for(var year=2012;year<=2018;year++)
{
var t = "t"+year;
var someText1 = '<td class=" x-grid-cell x-grid-cell-numbercolumn">';
var someText2 = '<div class="x-grid-cell-inner " style="text-align: left; ;">';
var someText3 = '<div class="x-grid-group-title">' + x[i].total[t] + '</div></div></td>';
var someText = someText1 + someText2 + someText3;
dom.insertHtml("beforeEnd",someText);
}
}
this.loadedwithVals = true;
}
}
And the feature as in
features: [
{
ftype:'multigrouping',
startCollapsed : true,
groupHeaderTpl: [
'{[this.readOut(values)]}',
{
readOut:function(values) {
var header = new Object();
header.id = values.groupHeaderId;
header.sum = [];
header.total = new Object();
for(var year = 2012 ; year <= 2018 ; year++)
{
var t = "t"+year;
header.total[t] = [];
}
// all the records in this header
for( var i = 0 ; i< values.records.length ; i++)
{
// for all the 'years' in this record
for(var year=2012;year<=2018;year++)
{
var d = "d"+year;
var ct = "t" + year;
var arecord = values.records[i].data;
var val = parseFloat(arecord[d].mp);
val = isNaN(val) ? 0.0 : val;
Ext.Array.push(header.total[ct],val);
}
}
// push the sum of the records into its top level group
for(var year = 2012 ; year <= 2018 ; year++)
{
var t = "t"+year;
var sum = Ext.Array.sum(header.total[t]);
header.total[t] = sum.toFixed(2);
}
header.name = values.name;
header.length = values.records.length;
var headerName = values.name;
if(values.hasOwnProperty('parent'))
{
var parent = values.parent;
headerName = headerName.replace(parent,'');
}
header.name = headerName;
header.length = values.records.length;
Ext.Array.push(grid.mOwnArray,header);
// really not used
return values.name + '(' + values.records.length + ')';
}
}
]
},
]
i want Replace بازي to بازی
var List = (from darkhast in Tbl_Darkhast.Where(d => d.Address.Replace("ی","ي").StartsWith( Address.Replace("ی","ي") ) )
select new
{
....
}
I think,You should write in select query
var List = (from darkhast in Tbl_Darkhast) )
select new Tbl_Darkhast
{
Address= darkhast.Address.Replace("ی","ي")
,Name = darkhast.Name
};
The distance and character displacement:
var List = (from darkhast in Tbl_Darkhast.Where(d => d.Address.Replace(" ", "").Replace("ي", "ی").Replace("ك", "ک").StartsWith(Address.Replace(" ", "").Replace("ي", "ی").Replace("ك", "ک")))
select new
{
....strong text
}
result is =>
var List = (from darkhast in Tbl_Darkhast.Where(d => d.Name_Moteghazi.Replace(" ", "").Replace("ي", "ی").Replace("ك", "ک").StartsWith(NameMoteghazi.Replace(" ", "").Replace("ي", "ی").Replace("ك", "ک")))
select new
{
Shomare_Darkhast = darkhast.Shomare_Darkhast,
Tarikhe_Darkhast = darkhast.Tarikhe_Darkhast,
Sharhe_NoeDarkhast = darkhast.TBL_NoeDarkhast.Sharhe_NoeDarkhast,
Mantaghe = darkhast.Mantaghe,
Hoze = darkhast.Hoze,
Block = darkhast.Block,
Melk = darkhast.Melk,
});
return (ObjectQuery)List;
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss] into a Date object. Here are the 3 ways I have tried doing it and the times it takes each method to parse 50,000 date time strings.
Does anyone know any faster ways of doing this or tips to speed up the methods?
castMethod1 takes 3673 ms
castMethod2 takes 3812 ms
castMethod3 takes 3931 ms
Code:
private function castMethod1(dateString:String):Date {
if ( dateString == null ) {
return null;
}
var year:int = int(dateString.substr(0,4));
var month:int = int(dateString.substr(5,2))-1;
var day:int = int(dateString.substr(8,2));
if ( year == 0 && month == 0 && day == 0 ) {
return null;
}
if ( dateString.length == 10 ) {
return new Date(year, month, day);
}
var hour:int = int(dateString.substr(11,2));
var minute:int = int(dateString.substr(14,2));
var second:int = int(dateString.substr(17,2));
return new Date(year, month, day, hour, minute, second);
}
-
private function castMethod2(dateString:String):Date {
if ( dateString == null ) {
return null;
}
if ( dateString.indexOf("0000-00-00") != -1 ) {
return null;
}
dateString = dateString.split("-").join("/");
return new Date(Date.parse( dateString ));
}
-
private function castMethod3(dateString:String):Date {
if ( dateString == null ) {
return null;
}
var mainParts:Array = dateString.split(" ");
var dateParts:Array = mainParts[0].split("-");
if ( Number(dateParts[0])+Number(dateParts[1])+Number(dateParts[2]) == 0 ) {
return null;
}
return new Date( Date.parse( dateParts.join("/")+(mainParts[1]?" "+mainParts[1]:" ") ) );
}
No, Date.parse will not handle dashes by default. And I need to return null for date time strings like "0000-00-00".
I've been using the following snipplet to parse UTC date strings:
private function parseUTCDate( str : String ) : Date {
var matches : Array = str.match(/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)Z/);
var d : Date = new Date();
d.setUTCFullYear(int(matches[1]), int(matches[2]) - 1, int(matches[3]));
d.setUTCHours(int(matches[4]), int(matches[5]), int(matches[6]), 0);
return d;
}
Just remove the time part and it should work fine for your needs:
private function parseDate( str : String ) : Date {
var matches : Array = str.match(/(\d\d\d\d)-(\d\d)-(\d\d)/);
var d : Date = new Date();
d.setUTCFullYear(int(matches[1]), int(matches[2]) - 1, int(matches[3]));
return d;
}
No idea about the speed, I haven't been worried about that in my applications. 50K iterations in significantly less than a second on my machine.
This was the fastest I could come up with after some fiddling:
private function castMethod4(dateString:String):Date {
if ( dateString == null )
return null;
if ( dateString.length != 10 && dateString.length != 19)
return null;
dateString = dateString.replace("-", "/");
dateString = dateString.replace("-", "/");
return new Date(Date.parse( dateString ));
}
I get 50k iterations in about 470ms for castMethod2() on my computer and 300 ms for my version (that's the same amount of work done in 63% of the time). I'd definitely say both are "Good enough" unless you're parsing silly amounts of dates.
I'm guessing Date.Parse() doesn't work?
Well then method 2 seems the best way:
private function castMethod2(dateString:String):Date {
if ( dateString == null ) {
return null;
}
if ( dateString.indexOf("0000-00-00") != -1 ) {
return null;
}
dateString = dateString.split("-").join("/");
return new Date(Date.parse( dateString ));
}
Because Date.parse() does not accept all possible formats, we can preformat the passed dateString value using DateFormatter with formatString that Data.parse() can understand, e.g
// English formatter
var stringValue = "2010.10.06"
var dateCommonFormatter : DateFormatter = new DateFormatter();
dateCommonFormatter.formatString = "YYYY/MM/DD";
var formattedStringValue : String = dateCommonFormatter.format(stringValue);
var dateFromString : Date = new Date(Date.parse(formattedStringValue));
var strDate:String = "2013-01-24 01:02:40";
function dateParser(s:String):Date{
var regexp:RegExp = /(\d{4})\-(\d{1,2})\-(\d{1,2}) (\d{2})\:(\d{2})\:(\d{2})/;
var _result:Object = regexp.exec(s);
return new Date(
parseInt(_result[1]),
parseInt(_result[2])-1,
parseInt(_result[3]),
parseInt(_result[4]),
parseInt(_result[5]),
parseInt(_result[6])
);
}
var myDate:Date = dateParser(strDate);
Here is my implementation. Give this a try.
public static function dateToUtcTime(date:Date):String {
var tmp:Array = new Array();
var char:String;
var output:String = '';
// create format YYMMDDhhmmssZ
// ensure 2 digits are used for each format entry, so 0x00 suffuxed at each byte
tmp.push(date.secondsUTC);
tmp.push(date.minutesUTC);
tmp.push(date.hoursUTC);
tmp.push(date.getUTCDate());
tmp.push(date.getUTCMonth() + 1); // months 0-11
tmp.push(date.getUTCFullYear() % 100);
for(var i:int=0; i < 6/* 7 items pushed*/; ++i) {
char = String(tmp.pop());
trace("char: " + char);
if(char.length < 2)
output += "0";
output += char;
}
output += 'Z';
return output;
}