Simple way of adding a row of textboxes dynamically for input

How to add a row of column dynamically when user click the link to add new row?

Below illustration were done in MVC framework whereby as it is not as easy as using the control directly in web form. These concerns are populate data into the drop down list, passing back all newly added data to the controller and retrieving all data for display when page load.

dynamicAdd

In my view page, I have added the below code.

dynamicAdd2In script section, I have added a few function calls in document.ready. when page load, those method will be trigger.

dynamicAdd3In initRelationship(), is to retrieve stored values to be display in the textboxes. The first ajax postback is to retrieve a list of objects of data to be display and second ajax postback is to retrieve a list of relationship type to be display in the dropdownlist. After that, it will loop through the list of relationship type to check which one is the selected one based on the data get from list of objects. After that, all the options will be added to a string of HTML code to be appended to the div tag.

dynamicAdd6When ‘add another account’ link is click, below code will be trigger to add a new row. I have used ajax to get the list of relationship type to added to dropdownlist options before append the string of HTML code to the div tag.

dynamicAdd4Below method is just solely to assigned values to the rows of textboxes if anything left out populated into the UI controls. Can ignore this is above have done it.dynamicAdd5How to pass all these data back to the controller to be process? For all the UI controls above, the name must be the same eg. p_Relationship, p_Relationship[1]…in array format. It will automatically populated into the list in the model.

dynamicAdd7

 

When it post back to controller, you will get all the data to be process!! dynamicAdd8

 

 

Advertisements

NHibernate to handle search and paging from stored procedure

Basically my task is to create a page that display data in grid, able to filter (search), and print the data I retrieve from a stored procedure using NHibernate.

cac

I will pass a filter with few parameter into the SP to retrieve the data to be display.

In xml file, I have added ‘sql-query’ query tag to query out the data. ‘query-param’ is the parameter to pass into the SP.

————————————————————————————————————

in .hbm.xml file:

<?xml version=”1.0″ encoding=”utf-8″?>
<hibernate-mapping namespace=”Domain.Entity” assembly=”Domain” xmlns=”urn:nhibernate-mapping-2.2″>
<class name=”Domain.Entity.ClientAccountReport, Domain” table=”ClientAccountReport_UI” schema=”dbo”>
<id name=”Id” column=”[Id]”>
<generator class=”native”/>
</id>
<property name=”SalesPerson”/>
<property name=”SalesPersonName”/>
<property name=”SalesPersonOpenDate”/>
<property name=”ClientAccountType”/>
<property name=”ClientCode” />
<property name=”ClientName”/>
<property name=”AppointCode”/>
<property name=”AppointName”/>
<property name=”AppointPersonCreatedDate”/>
<property name=”AppointPersonAmendedDate”/>
<property name=”AuditDate”/>
<property name=”AuditRecordID”/>
<property name=”FieldName”/>
<property name=”ActionType”/>
<property name=”OldValue”/>
<property name=”NewValue”/>
<property name=”Remarks”/>
<property name=”UserID”/>
<property name=”OpenDate”/>
<property name=”CloseDate”/>
<property name=”LastActiveDate”/>
<property name=”ClientDeleteDate”/>
</class>

<sql-query name=”ClientAccountReport_UI” callable=”true”>
<query-param name=”ClientCode” type=”String”/>
<query-param name=”ClientRefTypeCode” type=”String”/>
<query-param name=”ActionType” type=”String”/>
<query-param name=”AuditDate” type=”DateTime”/>
<return class=”ClientAccountReport”>
<return-property column=”ID” name=”Id” />
<return-property column=”SalesPerson” name=”SalesPerson” />
<return-property column=”SalesPersonName” name=”SalesPersonName” />
<return-property column=”SalesPersonOpenDate” name=”SalesPersonOpenDate” />
<return-property column=”ClientAccountType” name=”ClientAccountType” />
<return-property column=”ClientCode” name=”ClientCode” />
<return-property column=”ClientName” name=”ClientName” />
<return-property column=”AppointCode” name=”AppointCode” />
<return-property column=”AppointName” name=”AppointName” />
<return-property column=”AppointPersonCreatedDate” name=”AppointPersonCreatedDate” />
<return-property column=”AppointPersonAmendedDate” name=”AppointPersonAmendedDate” />
<return-property column=”AuditDate” name=”AuditDate” />
<return-property column=”AuditRecordID” name=”AuditRecordID” />
<return-property column=”FieldName” name=”FieldName” />
<return-property column=”ActionType” name=”ActionType” />
<return-property column=”OldValue” name=”OldValue” />
<return-property column=”NewValue” name=”NewValue” />
<return-property column=”Remarks” name=”Remarks” />
<return-property column=”UserID” name=”UserID” />
<return-property column=”OpenDate” name=”OpenDate” />
<return-property column=”CloseDate” name=”CloseDate” />
<return-property column=”LastActiveDate” name=”LastActiveDate” />
<return-property column=”ClientDeleteDate” name=”ClientDeleteDate” />
</return>
exec [ClientAccountReport_UI] @ClientCode=:ClientCode, @ClientRefTypeCode=:ClientRefTypeCode, @ActionType=:ActionType, @AuditDate=:AuditDate
</sql-query>
</hibernate-mapping>

————————————————————————————————————

In Dao.cs  class file

public void GetClientAccountReportByPage(IPage<ClientAccountReport> page, IList<IFilter> filters)
{
HibernateDaoHelp.SearchByPageForSP(page, “ClientAccountReport_UI”, filters);
}

————————————————————————————————————

In HibernateDaoHelp.cs class file

public void SearchByPageForSP(IPage<T> page, string hql, IList<FXBOSS.Utils.IFilter> Filters)
{
IQuery iQuery = this.GetSession().GetNamedQuery(hql);

if (Filters.Count > 0)
{
foreach (var obj in Filters)
{
if (obj.data.ToString().Trim().Length == 0)
{
iQuery.SetParameter(obj.field, String.Empty);
}
else
{
iQuery.SetParameter(obj.field, obj.data);
}
}
}

IList<T> ListOfObj = iQuery.List<T>();

if (page.pageSize != -1)
{
var list = ListOfObj.Skip((page.pageNo – 1) * page.pageSize).Take(page.pageSize).ToList();
page.totalCount = ListOfObj.Count();
page.result = list;
}
else
{
var list = ListOfObj.ToList();
page.totalCount = ListOfObj.Count();
page.result = list;
}
}

————————————————————————————————————

In controller.cs file

private Page<ClientAccountReport> filterPage(Page<ClientAccountReport> Page, string filters)
{
SystemSeg.GetClientAccountReportByPage(Page, FilterUtil.GetQuery<ClientAccountReport>(filters));
return Page;
}

————————————————————————————————————

Manual Cross Tab Dynamic Crystal Report

Lately I’m been involve in a lot of crystal reports and one of them is a cross-tab dynamic report which will grow vertically and horizontally. There are a lot of ways to do it. And I think the most easiest way is to use the cross-tab function in the Crystal report which directly pump in all your data and let the crystal report do the rest. Unfortunately, it is too late for me to realized there is such function to use, and I used the way of coding which will faced some challenges in the midst of preparing the format of data before putting it into crystal report and display it.

OK. Here is just something to share for those who wanna use such method to display your data. This is what I’ve done, and may not be the most efficient way to do. Btw, I’m using MVC c# and nHibernate for this case.

Below is the View in my database, which you can see where the report will be display according to do order ValueDate, BrokerName, and TradePLCcyCode.

data in database
data in database

And Below is the Crystal report format where data will be populated into and be display. I have created a sub report for this to make ease if next time there is a need of adding new extra report to this report. And the below diagram shows the section where data will be displayed. I have fix it to 10 rows for Currency, 6 Columns for Broker and Total. And yeah, it is group by ValueDate. These fields are also define in my dataset file(.xsd).

crystal report
crystal report
subreport
subreport

Now, we go to the coding part. Before I pump in my data from view to the report, I have to convert all the data from view into a datatable before assigning them row by row into an object. Below is the datatable generated from the view where all data are populated into. As you can see there are different ValueDate which we have to group them later.

datatable
datatable

Now is the challenging part where I have to split this ‘huge’ datatable into sections of smaller datatable to be displayed. So What I’ve done is, firstly I split it by ValueDate. It depends on how many ValueDate in my datatable.

split by value date
split by value date

Above code split the ‘huge’ datatable into smaller lists of datatables with different ValueDate. And from here, I will loop through the number of distinct ValueDate. However, the rows and columns may exceed what I’ve set in the Crystal report, so I have to split these smaller lists of datatables into the sections that fit in the report.

How to know how many section for my rows and columns? As above, I have set 6 rows and 10 columns. So a loop function is use to loop through the ‘huge’ datatable to do the following process:

1. splitting it into smaller datatables. It will split by rows then by columns.

E.g. table is 12 X 20, it will split into 4 smaller tables.

table is 12 X 10, it will split into 2 smaller tables.

2. assigning each smaller datatables in an object.

3. assigning all objects into a list of object.

After that, will pass this list of object into the crystal report to be print.

Below is a sample of the report generated.

 Capture3

Configure quickfix\n and stunnel to connect to currenex

I have use quickfix 4.4 and sTunnel for below example to connect to a Currenex demo account. Download the UIDemo project from github. I’m using quickfix\n for c#.

About FIX

FIX is an electronic messaging protocol for financial transactions. The Financial Information eXchange (FIX) is an open, widely used industry standard. More information is available on the FIX protocol website. Quick fix is an open source application that provide such service as above. So below is my config file setting.

Configuration

1. In quickfix.cfg [DEFAULT] ConnectionType=initiator ReconnectInterval=2 FileStorePath=store FileLogPath=c:\fixlog StartTime=00:00:00 EndTime=23:00:00 UseDataDictionary=Y DataDictionary=FIX44.xml SocketConnectHost= my external ip address SocketConnectPort= port to connect to sTunnel in your local pc ResetOnLogon=Y ResetOnLogout=Y ResetOnDisconnect=Y CheckLatency=N # standard config elements [SESSION] BeginString=FIX.4.4 SenderCompID= Hub FIX Taker ID Username= Hub FIX Taker ID Password= Hub FIX Taker Password TargetCompID=CNX (Name I define in sTunnel config file) HeartBtInt=20 SocketConnectPort=444 SocketConnectHost= my external ip address DataDictionary=FIX44.xml

2. In stunnel.conf [CNX] client = yes accept = your local pc external ip : port   eg.(10.160.103.65:444) connect = Currenex server ip address  eg.(dret-xxx-xxx-xxx.com:444)

3. Build a self-signed pem cert in sTunnel. createcert1createcert2Click ‘enter’ and your cert is done!!

4. Add 2 lines of code in QFApp.cs as below, which is your hub username and password.

fix2

5. Start your sTunnel service.

6. Run the UIDemo application. And it works!! fix

Web Programming guide – Inserting data using SQL data source controller

In developing web base system, retrieving and inserting data is a basic thing. As in ASP.NET, it makes development easy. As we’re going to explore one of the control-SqlDataSource control which I have tested it out with a simple web application form name ‘NewContract.aspx’ in SCM test n error 2 project.

NewContract.aspx
NewContract.aspx

Continue reading