Tuesday, September 22, 2009

Flex: Call Pop-up Window on Flex

Steps on how to add a pop-up window on Flex:

1.  Create a new component, then choose a component type on based on.  Choosing a TitleWindow would be perfect for a pop-up window.  Then save.  (on this sample, it's saved as mypopup)

2.  To call the pop-up, add the following code.


var sScreen:IFlexDisplayObject = PopUpManager.createPopUp(this, mypopup, true);
PopUpManager.centerPopUp(sScreen);

The code would simply call the pop-up mypopup. The pop-up is centered on the component that called it, represented by this.  The pop-up's modality is set to true, meaning the main application is disabled until the pop-up closes.



if you wish to center the pop-up window on the application, instead of the one that called it, change this to UIComponent(this.parentApplication)

example:
var Screen:IFlexDisplayObject = PopUpManager.createPopUp(UIComponent(this.parentApplication), mypopup, true);

You would need to add import mx.core.UIComponent; on your code to.


3. Code to close the pop-up.

PopUpManager.removePopUp(this);   
Read more »

Friday, May 22, 2009

PHP, Flex: Printing Memo Data With Line Breaks to PDF from Flex Program

Situation:
Your data is encoded from a Flex/Air program
Data have line breaks (typed in memo box for example)
Would want to print data to PDF file

Problem:
Data won't print with line breaks. Grrrrrrrr...

My Solution:

// Setting line breaks on string from a text area
function setLineBreaksPDF($s="") {
$s = nl2br($s);
$s = str_replace("<br />", "\n", $s);
return $s;
}



I'm not sure if there are any other work around for this problem that I had encountered. And I can't understand why would I need to nl2br the data, and would bring back \n. But that works to me.
Read more »

Saturday, March 07, 2009

Actionscript: Add One Day to Date

The script below is a sample on how to add one day to a date.

private function buttonClick():void {
// text is a date with format 'mm/dd/yyyy'
dtsTranDate.text = addDate(dtsTranDate.text);
}


private function addDate(dt:String):String {
var arrDate:Array = (dt).split('/');
var m:int = int(arrDate[0]); // month
var d:int = int(arrDate[1]); // day
var y:int = int(arrDate[2]); // year
var lastday:int;

// get last day of the month
var dd:Date = new Date(y, m, 0);
lastday = dd.getDate();

d = d + 1;

if (d > lastday) {
d = 1;

if (m < 12) {
m = m + 1;
}
else {
m = 1;
y = y + 1;
}
}

var newdate:String;
newdate = ((m < 10)?('0'+m.toString()):m.toString()) + '/' + ((d < 10)?('0'+d.toString()):d.toString()) + '/' + y.toString();

return newdate;
}



I would like to thank Molaro for the script on getting the last day of the month.



=)
Read more »

Friday, February 27, 2009

PHP: Get Last Date of the Month

This small but terrible function returns the last day of the month.

cal_days_in_month(CAL_GREGORIAN, $month, $year);



CAL_GREGORIAN - calendar to use
$month - month of the last day to return
$year - yearof the last day to return


This saves the case and if =)



=)
Read more »

Thursday, February 26, 2009

Actionscript: Flex Data Grid Cell Editing

Here's a code on how to edit a data grid cell(s). This also edits the datasource (arraycollection) automatically.


/* data grid */

<mx:AdvancedDataGrid id="grdData" designViewDataType="flat" height="100%" width="100%" enabled="true" dataProvider="{_arrDetailData}" editable="false">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Color" dataField="colordesc" width="120" editable="false"/>
<mx:AdvancedDataGridColumn width="90" headerText="Received" dataField="qtyapply" textAlign="right" editable="true">
<mx:itemRenderer>
<mx:Component>
<mx:Label text="{parentApplication.formatTextNumberDisplayNo(data.qtyapply,0)}" textAlign="right" click="outerDocument.editCell(4)"/>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
</mx:columns>
</mx:AdvancedDataGrid>




/* script function */

public function editCell(column:Number):void {
grdData.editedItemPosition = {columnIndex:column, rowIndex:grdData.selectedIndex}
}





I would like to thank the site where I learned this stuff.
Read more »

Monday, February 23, 2009

SQL: Sequence Number on a Select Query

If you need to put a sequence number on the records from your SELECT query, you can do the following technique.

select @n := 0;
select @n:=@n+1 as rec, contactname from contact;


The first statement initializes the variable "n". The second statement uses the variable on the first statement.

A sample output record from the select statement is as follows:







reccontactname
1Marilou
2Ivan
3Harris
4Nelson
5Peter
Read more »

Tuesday, January 20, 2009

Delphi: Assign Display Format and Edit Format of a Table Field "MANUALLY"

It's best to always optimize your Delphi program size into the smallest size as it can be.

When you are working with lots of tables, queries and datasets, you might end up with a lot of those database-related components. And one reason that makes a programmer add all of those components is to just fill in the "DisplayFormat" and "EditFormat" properties of numeric, integer and date fields of a table.

So, to save all those bytes, you can simply do it manually.

TFloatField(Table1.FieldByName('amount')).DisplayFormat := '#,0.00;- #,0.00;0.00';

TFloatField(Table1.FieldByName('amount')).EditFormat := '#0.00';



TFloatField = says the field is of numeric format.

DisplayFormat = to set the field's format when the record is in display/view mode

EditFormat = to set the field's format when the record is in edit and insert mode

#,0.00;- #,0.00;0.00 = the format you can set when on display/view mode. The format for creating a format like this is positive value;negative value;zero or no value separated with semicolon

#0.00 = the format you can set when on edit and insert mode.
Read more »