Developing an ISeries Intranet Based LOB Application

The first question that we would need to answer is “What technology do I want to use?” Old programmers may fall back to webforms and an ODBC connector. That works and does the job although the technology behind this approach is quite old and lacking in features.

The next option to be considered is Silverlight. This can be accomplished with some “jumping through hoops” using RIA, service references, and web services. The biggest issue that I, personally, encountered with this approach was publishing the Silverlight application, which worked flawlessly in the development environment, to the server.

Now you may be thinking “okay, what works then?” This programmer’s answer would be to use F# as the data retrieval backend which returns a list to be displayed using MVC3/Razor technology. In this part we will cover the F# code used to connect to our iSeries and gather the data from it. Additionally we will show the MVC3 code to be placed in the controller to retrieve that data into an enumerated list. Of course, the F# code demonstrated here will be two simple SQL statements but you can easily make it as detailed as necessary with multi-table joins and filtering with a WHERE clause. In order to make the connection process smoother we use a local DSN to define the connection parameters. Peruse the following F# module

namespace WebData
open System.IO
open System.Data
open System.Data.Odbc
open System.Data.SqlClient
module Read =
let ReadCustList =
let conn = new OdbcConnection(“FILEDSN=C:\lx833f.dsn;UID=;PWD=”)
let comm = “select ccust,cnme,cad1,cad2,cste,czip,cphon from rcm”
let reader = new OdbcDataAdapter(comm,conn)
let ds = new DataSet()
reader.Fill(ds) |> ignore
ds
let ReadCustSgl custnbr =
let conn = new OdbcConnection(“FILEDSN=C:\lx833f.dsn;UID=;PWD=”)
let comm = “select ccust,cnme,cad1,cad2,cste,czip,cphon from rcm where ccust=’” + custnbr + “‘”
let reader = new OdbcDataAdapter(comm,conn)
let ds = new DataSet()
reader.Fill(ds) |> ignore
ds

Compiling this into a DLL and attaching it to an MVC3 controller will allow it to be pulled into a list with the following code placed in an MVC3 controller.

public ActionResult About()
{
var clist = Read.ReadCustSgl(“140263″);
List< mdlCustList> csend = new List< mdlCustList>();
foreach(DataRow rw in clist.Tables[0].Rows)
{
mdlCustList citem = new mdlCustList();
citem.CustNbr = rw.ItemArray[0].ToString();
citem.CustNm=rw.ItemArray[1].ToString();
citem.CustAd1 = rw.ItemArray[2].ToString();
citem.CustAd2 = rw.ItemArray[3].ToString();
citem.CustSt=rw.ItemArray[4].ToString();
citem.CustZip = rw.ItemArray[5].ToString();
citem.CustPhn = rw.ItemArray[6].ToString();
csend.Add(citem);
}
return View(csend);
}

One thing missing from here is the M in MVC ‘” Model. In the above code you will see that we are using mdlCustList as the object for our csend list and our individual citem. This is a model that we have designed using the following C# class.

namespace MvcApplication1.Models
{
  public class mdlCustList
        {
              public string CustNbr {get;set;}
                public string CustNm { get; set; }
           public string CustAd1 { get; set; }
          public string CustAd2 { get; set; }
          public string CustSt { get; set; }
           public string CustZip { get; set; }
          public string CustPhn { get; set; }
  }
} 

That is all that it takes to use F# to retrieve the data and MVC3/Razor/C# to return it. Notice that we have not shown the view but you can easily create a strongly typed view within the Visual Studio designer using a right-click on the About actionresult.

Share with your friends

Leave a comment