Tuesday, May 25, 2010

DataView sort no sorting

A common problem with developers using System.Data.DataView from ADO.Net when using the sorting feature, they think that the information is sorted physically but is not true, because the object creates only a view of the information, if we point to the Table of the view we are going to the original information without the sort applied.
See the example:

System.Data.DataTable dt = obj.getInfoAsTable();
System.Data.DataView dv = dt.DefaultView();
dv.Sort = “[name], [dateOpt] DESC”;


This is an incorrect way to access the info because we are going back to the original info without the sorting:

Foreach(System.Data.DataRow r in dv.Table.Rows)
{
String name = r[“name”].toString();
}


This is the correct way of getting the sorted data:

Foreach(System.Data.DataRow r in dv.ToTable().Rows)
{
String name = r[“name”].toString();
}


The rows never physically get sorted. The view provides a sorted view of the data. The table never changes. You have to access the data through the view
to see it sorted. See the diagram below:



Tuesday, May 18, 2010

Macro strings in file registry settings


When we hard code some paths for a CAB file we can have some problems if the user is installing in the application on an external memory or if it is installed on a different language.
To avoid this problem we can use Macro Strings.
They way these macro strings work is that if you specify a registry value like %InstallDir% the CAB installation process will replace the %InstallDir% part of your string with the device’s specified installation directory.

This is a list of some of the string macros on English devices:


%InstallDir% [directory application installed into]
%AppName% [name of application]
%CE1% \Program Files
%CE2% \Windows
%CE4% \Windows\StartUp
%CE5% \My Documents
%CE8% \Program Files\Games
%CE11% \Windows\Start Menu\Programs
%CE14% \Windows\Start Menu\Programs\Games
%CE15% \Windows\Fonts
%CE17% \Windows\Start Menu

Shortcuts in windows mobile


When you create a shortcut on windows mobile, it will be showed up in different parts depending on the folder where you paste it, these are some folders:
\Windows\StartUp
shortcuts to applications placed in this directory will automatically be started whenever the Windows Mobile device is reset.

\Windows\Start Menu
shortcuts placed in this directory will appear in the Windows start menu.

\Windows\Start Menu\Settings
Shortcuts placed in this folder will appear on the System tab of the Settings application that is accessible via the Start Menu.



Friday, May 14, 2010

Do something before the form is closed


In order to do something before the form is closing we can use the next event in the form:
public event FormClosingEventHandler FormClosing

The FormClosing event occurs as the form is being closed. When a form is closed, it is disposed, releasing all resources associated with the form.

The following code example demonstrates the use of this member. In the example, an event handler reports on the occurrence of the FormClosing event:

private void Form1_FormClosing(Object sender, FormClosingEventArgs e) {
System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "CloseReason", e.CloseReason );

messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Cancel", e.Cancel );

messageBoxCS.AppendLine();
messageBox.Show(messageBoxCS.ToString(), "FormClosing Event" );

}

Call a parent functions from child form



In order to call a parent function from a child form you have to pass the form1 instance to form2 in the constructor.


Form1:

namespace CallingForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Form2 tmp = new Form2(this);
tmp.ShowDialog();
}

internal void msg()
{
MessageBox.Show("Hello from parent form");
}

}
}



Form 2:

namespace CallingForm
{
public partial class Form2 : Form
{
private Form1 frmParent;

public Form2(Form1 frm1)
{
InitializeComponent();
frmParent = frm1;
}

private void button1_Click(object sender, EventArgs e)
{
frmParent.msg();
}
}
}




Thursday, April 29, 2010

How to generate servlet source from a JSP


Understanding the XML view

The core JSP syntax is made up of scriptlets, actions, directives, expressions and declarations defined by the JSP specification. Web browsers do not understand JSP syntax as they do HTML. For the browser to display the contents of a JSP page, JRun must first compile the JSP source as a servlet which JRun then uses to generate the response. The response is HTML or whatever markup language is requested. However, the JSP-to-servlet compilation process is not a direct one. The JSP must first be transformed into XML.

The following steps occur when a JSP is requested for the first time:

  1. A client requests a JSP for the first time.
  2. JRun converts the JSP into a temporary XML representation called the XML view.
  3. JRun validates the XML view of the JSP page.
  4. JRun transforms the XML view into a .java class file that extends jrun.jsp.runtime.HttpJSPServlet and implements jrun.jsp.runtime.JRunJspPage. You can view the servlet's source code as described in "Viewing servlet source code".
  5. JRun compiles the new class into a servlet.
  6. The servlet generates the output based on the client request.

The following image shows the lifecycle of a JSP page when it is first requested by a client and finally compiled into a servlet. The servlet then returns the request to the client.

This images shows the flow of a JSP page when it is first requested by a client. The JSP page goes from *.JSP to XML View to *.JAVA to a compiled servlet. Then the servlet returns the request to the client.

Viewing servlet source code

You can view the source code of the servlet representation of the JSP page. You cannot view the XML view of the JSP page because it is only maintained in memory temporarily while JRun constructs the servlet.

JRun does not keep servlets generated from JSP source code by default. This section shows you how to configure JRun to keep the Java files and where to view them.

To keep generated JSPs:

  1. In the jrun_root/servers/jrun_server/SERVER-INF/default-web.xml file, set the JSPServlet's keepGenerated initialization parameter to true, as shown in the following example:
     <servlet>
         <servlet-name>JSPServlet</servlet-name>
         <servlet-class>jrun.jsp.JSPServlet</servlet-class>
         <init-param>
               <param-name>keepGenerated</param-name>
               <param-value>true</param-value>
         </init-param>
     </servlet>
  2. Delete the JSP class files in the web application's /WEB-INF/jsp directory.

    Doing this removes the already-generated servlet class files. JRun checks for the existence of the class file before recompiling a JSP. If the class files were still available, JRun would not recompile the JSP. JRun also checks the data/time stamp of the JSP, so you can change the JSP source code and save the JSP file to cause JRun to regenerate the Java source code and recompile the class.

  3. Restart the JRun server.
  4. Request the JSP.
  5. Open the JSP's generated Java class file (*.java) in the web application's /WEB-INF/jsp directory. JRun names the source code files starting with "jrun__" and appends version information to the name.

Source: http://livedocs.adobe.com



Tuesday, April 27, 2010

How to created a shortcut on Pocket PC


Some programs don't create a shortcut on the Pocket Pc, at the same time we don't have a quick option to create on inside of the Pocket PC, here we have a couple ways to create a shortcut on the device.


You need to synchronize your Pocket PC, when is ready, Go to My Computer on your desktop and click Mobile Device. Navigate to the program for which you want to create the shortcut.
Right-click the program and select Create Shortcut. Right-click the shortcut and select Cut. Go to the \Windows\Start Menu\ folder under Mobile Device on your desktop, right-click inside the folder, and select Paste to paste the shortcut into the Pocket PC's Start menu.


You can use a small application provided by Scott & Ce Appt. named "NewShortcut" to create shortcuts without the need for ActiveSync, you can get it from the next link:


http://www.scottandmichelle.net/scott/cestuff.html