Thursday, November 27, 2008

ASPxCallback && ASPxCallbackPanel

I was to do a web form for filling site information in some regions. To do that, i must select Province/City first in ComboBox and then a Region/District that belongs to the Province/City respectively; means when i select Province in combobox1, only regions in that province must be retrieved from server to combobox2.

I use Developer Express components regularly and if i used the latest versions of DevXpress ASPx components, it would be made easy by using ASPxCallbackPanel. But my DevXpress version is DevX 7.2 and there is no ASPxCallbackPanel component as is MS AJAX UpdatePanel. So i solved it with ASPxCallback component.

site_main.aspx:

<dxcb:aspxcallback id="ASPxCallback1" runat="server" clientinstancename="Callback1" oncallback="ASPxCallback1_Callback"></dxcb:aspxcallback>
<clientsideevents callbackcomplete="function(s, e) { var items= e.result.split("|") var i; for (i= 0; i< items[0]; i++) { cbbRegion.AddItem(items[2*i+ 2], items[2*i+ 1]); } }"></clientsideevents>



<dxe:aspxcombobox id="cbbCity" runat="server" height="19px" width="100px" datasourceid="dsrcCity" textfield="city_name" valuefield="city_code"></dxe:aspxcombobox>
<clientsideevents selectedindexchanged="function(s, e) { //alert(s.GetValue()); cbbRegion.ClearItems(); Callback1.SendCallback(s.GetValue()); }"></clientsideevents>


<asp:objectdatasource id="dsrcCity" runat="server" oldvaluesparameterformatstring="original_{0}" selectmethod="GetData" typename="CdsCityTableAdapters.vw_cityTableAdapter"></asp:objectdatasource>



<dxe:aspxcombobox id="cbbRegion" runat="server" clientinstancename="cbbRegion" datasourceid="dsrcRegion" textfield="region_name" valuefield="region_code" width="120px"></dxe:aspxcombobox>

<asp:objectdatasource id="dsrcRegion" runat="server" deletemethod="Delete" insertmethod="Insert" oldvaluesparameterformatstring="original_{0}" selectmethod="GetDataByCity" typename="CdsRegionTableAdapters.hr_regionTableAdapter" updatemethod="Update"></asp:objectdatasource>
<deleteparameters></deleteparameters>
<asp:parameter name="Original_region_id" type="Decimal"></asp:parameter>

<updateparameters></updateparameters>
<asp:parameter name="region_code" type="String"></asp:parameter>
<asp:parameter name="region_name" type="String"></asp:parameter>
<asp:parameter name="city_code" type="String"></asp:parameter>
<asp:parameter name="Original_region_id" type="Decimal"></asp:parameter>

<selectparameters></selectparameters>
<asp:parameter name="city_code" type="String"></asp:parameter>

<insertparameters></insertparameters>
<asp:parameter name="region_code" type="String"></asp:parameter>
<asp:parameter name="region_name" type="String"></asp:parameter>
<asp:parameter name="city_code" type="String"></asp:parameter>



<dxe:aspxmemo id="mmAntenna" runat="server" height="74px" width="729px"></dxe:aspxmemo>

site_main.aspx.cs:
protected void ASPxCallback1_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
{
CdsRegionTableAdapters.hr_regionTableAdapter regionTableAdapter = new CdsRegionTableAdapters.hr_regionTableAdapter();
CdsRegion.hr_regionDataTable regionDataTable= new CdsRegion.hr_regionDataTable();
regionTableAdapter.FillByCity(regionDataTable, e.Parameter);
String res = regionDataTable.Rows.Count.ToString();
for (int i = 0; i < regionDataTable.Rows.Count; i++)
{
res = res + "|"+ regionDataTable.Rows[i]["region_code"]+ "|"+ regionDataTable.Rows[i]["region_name"]+ "";
}
e.Result = res;
}

The mechanic is, when selected a city, selectedindexchanged="function(s, e) { //alert(s.GetValue()); cbbRegion.ClearItems(); Callback1.SendCallback(s.GetValue()); } is called. In it, cbbRegion is cleaned up and value of cbbCity is sent to server. Then, on server, ASPxCallback1_Callback is called and it sends corresponding "|" separated region names and codes back to the client using e.Result string. After that, callbackcomplete="function(s, e) { var items= e.result.split("|") var i; for (i= 0; i< items[0]; i++) { cbbRegion.AddItem(items[2*i+ 2], items[2*i+ 1]); } } is called automatically. As you see, the function parses e.Result and adds each to cbbRegion. I think the way i used is not good. But it was working so quick. I prefer coding style, but when result is good, it's ok to hardcode kk.

Tuesday, October 21, 2008

Тусламж хэрэгтэй байна

Юу вэ гэхлээр мань хүн MT буюу машин орчуулга (Компьютерээр текст орчуулах) сонирхдог юм л даа. Цаг зав гарсан үед ном товхимол шагайж, арга чарга судалдаг гэхүүдээ. Сүүлийн үед сонирхол дээд цэгтээ тулаад цагийг умартан судалгаа хийх болов. Энэ мэдээж ганц хүний чөлөөт цагаараа хийчихдэг ажил биш боловч нэгдүгээрт нэн шаардлагатай судлагдахуун, хоёрдугаарт миний туйлын хүсэл тул өөрийн эрхгүй ханцуй шамлан оров.

Судалгааны явц эхлэл төдий боловч ирээдүйдээ хэрэг болох (одоо ч гэсэн туршилт хийхэд жаахан хэрэг болоод л байна) Өгөгдлийн сан бүрдүүлэх ажлыг нэн түрүүнд хийх шаардлагатай байна. Тиймээс Өгөгдлийн сан бүрдүүлэхэд хамгийн хэрэгтэй эд болох Англи-Монгол, Монгол-Англи орчуулга цуглуулж эхэлж байна. Үүнд таны болон хэн нэгний орчуулсан ном, өгүүлэллээс эхлээд нэг өгүүлбэр ч байсан их тус болох нь дамжиггүй. Тиймээс надад туслая, мөн өөрийн хувь нэмрээ Англи-Монгол өгүүлбэр орчуулагчид оруулъя гэж бодож байвал otgontugs(at)gmail(dot)com* хаягаар явуулна уу.

Таны явуулсан материалийг судалгаанаас өөр зорилгоор ашиглахгүй бөгөөд ямар нэг зохиогчийн эрх тухай зүйл байвал гадагш тараахгүй хав дарж чадна гэдэгээ амлая.

Хэрэв та Машин орчуулгын ямар үр ашигтай өөрийн биеээр мэдрэхийг хүсвэл http://translate.google.com/translate_t хаягаар ороод үзээрэй. Гэхдээ харамсалтай нөгөө л Монгол гэдэг хэл байхгүй л байгаа.

* - (at)-ийн оронд "@", (dot)-ийн оронд "."

Monday, October 20, 2008

Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'

This error occurred while executing following MSSQL code.

declare @sql varchar(8000);
declare @params varchar(4000);

set @sql= 'select @perf_max= max(avrg)
from (
select avg(coalesce(ea_score, 0)) as avrg
from employee_appraisal
where ea_ap_id= 1 and ea_year='+cast(@yahr as varchar)+' and ea_emp_id in '+ @filter+
'group by ea_emp_id) v1';
set @params= '@perf_max float output';
exec sp_executesql @sql,@params,@perf_max output

I found the error was caused of calling sp_executesql with parameter type of varchar, NOT Nvarchar. @sql is dynamic query which is maximum length of 6K chars in my case. But NVARCHAR is 4K, so it's not enough.
Can anybody provide me solution?
Thanks in advance

Monday, October 13, 2008

Machine Translation/NLP Resources

Here is something useful for NLP/MT:

http://wt.jrc.it/lt/acquis/
http://www.mt-archive.info/
http://nl.ijs.si/telri/Vanilla/
http://www.essex.ac.uk/linguistics/clmt/MTBook/
http://portal.acm.org/
http://www.cs.unt.edu/~rada/wpt/WordAlignment.Guidelines.txt
http://www.iro.umontreal.ca/~simardm/lrec98/
http://www.informatik.uni-trier.de/~ley/db/conf/acl/acl2005.html
http://www.informatik.uni-trier.de/~ley/db/conf/acl/acl2006.html
http://www.informatik.uni-trier.de/~ley/db/conf/acl/acl2007.html
http://en.wikipedia.org/wiki/Bilingual_Evaluation_Understudy
http://nl.ijs.si/telri/
http://en.wikipedia.org/wiki/AntConc
http://corpora.wordpress.com/category/antconc/
http://nltk.sourceforge.net/

Related Mongolian:
http://acl.ldc.upenn.edu/P/P06/P06-1083.pdf
http://crlp.num.edu.mn/
http://www.infocon.mn/tts/ (Mongolian TTS engine in progress)
http://if-lab.slis.tsukuba.ac.jp/fujii/paper/ijcnlp2008khab.pdf

Friday, July 4, 2008

Difference between Response.Redirect and Server.Transfer

I've a secured page that requires users to be logged in.
At the beginning of the page, checks if an user is authenticated and is in right role. When not authenticated, control is redirected to login.aspx which is included Login form.

if (!User.Identity.IsAuthenticated)
{
if (!User.IsInRole("admin"))
{
Server.Transfer("login.aspx");
}
}

This piece of code is telling you cannot see the page if you are not an administrator.
Another one is:

if (!User.Identity.IsAuthenticated)
{
if (!User.IsInRole("admin"))
{
Response.Redirect("login.aspx");
}
}

The difference is Redirect tells client to see login.aspx, Transfer directly executes login.aspx and returns result. I choose Server.Transfer, cus it can be faster.

One more thing:

if (!User.Identity.IsAuthenticated)
{
if (!User.IsInRole("admin"))
{
Response.Redirect("login.aspx?ref=any_page.aspx");
}
}
In login.aspx.cs:
LoginView1.DestinationPageUrl= Request.Params["ref"];

In this case, control jumps to any_page.aspx. I didn't experience it when using Server.Transfer.
I'm not sure its possible.

Wednesday, June 18, 2008

Failed to access IIS metabase problem

I was using VS2008. it had installed .NET framework 3.5 version. This error occurred when i try to view web application that is in IIS. I googled for it and found following soln. It's working perpectly ;)

Possible Cause:-
When you install IIS AFTER .NET 2.0 framework, the rights of the ASPNET user had not been set correctly.

Resolution
Repair (Uninstall if repair does not work for you) .NET Framework 2.0

Simply run the following from command line to reset the IIS registry settings for aspnet user. Usually framework directory for .Net Framework 2.0 resides under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i

Thursday, May 29, 2008

Tree in a datagrid

I used DevExpress.XtraTreeList.TreeList component to show tree structured DB table on a form. It was so easy.

create table treesamp (
nodeid number(5),
parentnodeid number(5),
datatext varchar2(50)
);

Sample table data:
1 0 "Root"
2 1 "Leaf 1"
3 1 "Leaf 2"
4 2 "Leaf 1 of Leaf 1"
5 2 "Leaf 2 of Leaf 1"
6 3 "Leaf 1 of Leaf 2"
7 3 "Leaf 2 of Leaf 2"
8 4 "Leaf 1 of Leaf 1 of Leaf 1"
...

Place your TreeList on a form and just set following values:

treelist1.DataSource= treeDataTable;
treelist1.KeyFieldName= "nodeid";
treelist1.ParentFieldName= "parentid";
treelist1.PreviewFieldName= "datatext";
RootValue= 0; // if id of parent is zero, it must be root node

To print the tree treeList1.ShowPrintPreview();
It prints it in XtraReport Preview, the same as in form grid.