Load XML into Database

Load xml file into store procedure to insert into table.

Sample xml file:

<?xml version='1.0' encoding='UTF-8' ?>
<FctTypes>
 <reportType>SSS</reportType>
 <tradingDate>01-Jun-2017</tradingDate>
 <period>1</period>
 <Details>
   <facilityType>AAA</facilityType>
   <grossInjection>111.11</grossInjection>
   <netInjection>222.22</netInjection>
 </Details>
 <Details>
   <facilityType>BBB</facilityType>
   <grossInjection>333.33</grossInjection>
   <netInjection>555.55</netInjection>
 </Details>
 <Details>
   <facilityType>CCC</facilityType>
   <grossInjection>122.11</grossInjection>
   <netInjection>244.22</netInjection>
 </Details>
</FctTypes>
<FctTypes>
 <reportType>SSS</reportType>
 <tradingDate>01-Jun-2017</tradingDate>
 <period>2</period>
 <Details>
   <facilityType>AAA</facilityType>
   <grossInjection>111.11</grossInjection>
   <netInjection>222.22</netInjection>
 </Details>
 <Details>
   <facilityType>BBB</facilityType>
   <grossInjection>333.33</grossInjection>
   <netInjection>555.55</netInjection>
 </Details>
 <Details>
   <facilityType>CCC</facilityType>
   <grossInjection>122.11</grossInjection>
   <netInjection>244.22</netInjection>
 </Details>
</FctTypes>

In database store procedure:

@strMG01 contain the string of content in xml file which pass from the application.

DECLARE @docHandle INT
DECLARE @xml XML = @strMG01

 CREATE TABLE #TempMG01(
 [Period] [smallint] NULL,
 [ReportType] [varchar](2) NULL,
 [TradingDate] [datetime] NULL,
 [FacilityType] [varchar](60) NULL,
 [GrossInjection] [varchar](60) NULL,
 [NetInjection] [varchar](60) NULL
 )

 INSERT INTO #TempMG01

 SELECT 
 a.Period,
 a.ReportType,
 a.TradingDate,
 a.FacilityType,
 a.GrossInjection,
 a.NetInjection
 FROM(

 SELECT 
 tbl.TempMG01.value('reportType[1]', 'VARCHAR(2)') ReportType,
 tbl.TempMG01.value('tradingDate[1]', 'DATETIME') TradingDate,
 tbl.TempMG01.value('period[1]', 'smallint') Period,
 i.pd.value('facilityType[1]', 'VARCHAR(60)') FacilityType,
 i.pd.value('grossInjection[1]','VARCHAR(60)') GrossInjection,
 i.pd.value('netInjection[1]','VARCHAR(60)') NetInjection
 FROM @xml.nodes('//FctTypes') AS tbl(TempMG01)
 CROSS APPLY @xml.nodes('//FctTypes/Details') AS i(pd)
 ) a

after this you can just insert it into the table you intended with a insert statement.

Sample inserted record as below:

Untitled.jpg

 

Authorization failure for Ajax request in MVC application

I encounter an ajax request authorization failure and causes bad user experience. I had click on a button which require ajax response in my ASP.net MVC application which already timout. Below is the way to handle it properly without getting any bugs.

I have created a OnAuthorizationModule action filter to check on each action to determine which pipeline to go. If IsAjaxRequest is true, it will throw HttpException, else it will redirect to error page.

 

ajax1

JQuery global error handle will receive the exception and display error message accordingly.

ajax2

 

ajax3.JPG

Responsive display: Inline-block

How to develop a responsive site which size can be adjusted while the display is still able to maintain its sequence and order, displaying a meaning page without running out of order?

Basically just have to add an attribute in the style of the div tag will do. For the main div, add display:inline-block in style, while the div’s in the main div will have to add float:left in style. While all the UI controls, images, words are in div tag.

div

 

An example from below which I have tried:

Normal web page view

before

Smaller size web page view (mobile)

after

 The code for above UI: Responsive display Inline-block

Web site for own testing:jsfiddle

 

 

A help in sharing how you feel after coming to my blog

Hi All,

I’m just trying to do a simple survey to see where I can improve to make my blog a better one. I do welcome if you have any comment whether good or bad or constructive criticism, please post below in the reply section. It would be better to specify which area can be improve. Thanks. 🙂

Last day of the holiday

 

As I’m musing what is my new job going to be like, how would the job be? how is the working environment? Are the people over there helpful? can I survive? What is my strategy? the journey to workplace is quite far too and will this job affect my study? Is this the right time to move to a new company?  Seem like more and more things were added into my thought. I’m not sure what my future is. How to proceed with my life as I’m already nearly half way through and things are getting tougher. Continue reading