C#

Parent Previous Next

Get Standing Instruction List



1. getStandingInstructionList.cs


These five packages are required to be used.









Step 1. Create class file to store content of the web response.











2. getStandingInstructionList.aspx.cs



These 13 packages are required to be used.









Code in Common



(1). Check if user id and password is inside session. When the user id and password is inside user session, it will automatically populate into the user id and pin textbox, so that the user need not manually type his user id and password repeatedly.









Step 2. Store Details which entered by the user. If user id, password, and OTP exist in session, user need not enter again (refer to common staff).








Step 3. Create URL which will be post to the server. User inputs need to be stored in the class created, and serialize into JSON format. In this function, only header is needed.









Step 4. Post to the server, and store response. URL is sent using web request function, and a response will be send back from the server. The response need to be deserialized into the ‘getStandingInstructionList’ class.









Step 5. Obtain error code. If error code is ‘010000’ which means invocation successful, populate attributes of the ‘getLoanAccountDetails’ class into the label. If error code is '010041', it means OTP has expired, and we will use the newOTP() function to prompt the user for the OTP again. Else, we will display the ErrorText and ErrorDetails.


The newOTP() function can be referred to under Common Stuff Section



           

   







Overview of  getStandingInstructionList.cs



using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using Newtonsoft.Json;


namespace Demo

{

   public class standingInstructionList

   {

       public standing_instruction_List_Content Content { get; set; }

   }


   public class standing_instruction_List_Content

   {

       public standing_instruction_List_ServiceResponse ServiceResponse { get; set; }

   }


   public class standing_instruction_List_ServiceResponse

   {

       public StandingInstructionList StandingInstructionList { get; set; }

       public standing_instruction_List_ServiceRespHeader ServiceRespHeader { get; set; }

   }


   public class StandingInstructionList

   {

       [JsonConverter(typeof(ArrayConverter<StandingInstruction>))]

       public List<StandingInstruction> StandingInstruction { get; set; }

   }


   public class StandingInstruction

   {

       public string StandingInstructionId { get; set; }

       public string ToAccount { get; set; }

       public string NextDateTime { get; set; }

       public string FromAccount { get; set; }

       public string Amount { get; set; }

       public string IsRecurring { get; set; }

       public string CustomerId { get; set; }

       public string LastDateTime { get; set; }

       public string TransactionReferenceNumber { get; set; }

       public string Memo { get; set; }

       public string WeeklyMonthly { get; set; }

   }


   public class standing_instruction_List_ServiceRespHeader

   {

       public string ErrorText { get; set; }

       public object ErrorDetails { get; set; }

       public string GlobalErrorId { get; set; }

   }


}



Download







Overview of  getStandingInstructionList.aspx.cs



using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using DotNetOpenAuth.OAuth2;

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

using System.Collections.Specialized;

using System.Configuration;

using System.Net;

using System.IO;

using System.Windows.Forms;

using System.Data;


namespace Demo

{

   public partial class getStandingInstructionList : System.Web.UI.Page

   {

       protected void Page_Load(object sender, EventArgs e)

       {

           if (Page.IsPostBack == false)

           {

               if (Session["userid"] != null)

               {

                   txtUserID.Text = (string)Session["userid"];

                   txtPassword.Text = (string)Session["pin"];

               }

           }

       }


       protected void btnSend_Click(object sender, EventArgs e)

       {

           try

           {

               //get user input

               string userID = txtUserID.Text;

               Session["userid"] = userID;

               string pin = txtPassword.Text;

               Session["pin"] = pin;

               string otp;

               if (Session["otp"] == null)

               {

                   otp = "";

               }

               else

               {

                   otp = Session["otp"].ToString();

               }


               //build header

               var header = new HeaderJson();

               header.userID = userID;

               header.PIN = pin;

               header.serviceName = "getStandingInstructionList";

               header.OTP = otp;


               var headerJson = new HeaderJsonObject();

               headerJson.Header = header;

               string strHeader = JsonConvert.SerializeObject(headerJson);


               //build URL

               string url = "http://tbankonline.com/SMUtBank_API/Gateway?Header=" + strHeader;


               //send web request

               var webRequest = (HttpWebRequest)WebRequest.Create(url);

               webRequest.ContentType = "application/json";

               webRequest.Method = "POST";


               var result = "";

               var httpResponse = (HttpWebResponse)webRequest.GetResponse();

               using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))

               {

                   result = streamReader.ReadToEnd();

               }


               //deserialize result

               standingInstructionList s = new standingInstructionList();

               s = JsonConvert.DeserializeObject<standingInstructionList>(result);


               string errorID = s.Content.ServiceResponse.ServiceRespHeader.GlobalErrorId.ToString();


               //invocation successful, output result

               if (errorID == "010000")

               {

                   // create header of the table

                   DataTable dt = new DataTable();

                   DataColumn col1 = new DataColumn("Standing Instruction ID", typeof(string));

                   DataColumn col2 = new DataColumn("To Account", typeof(string));

                   DataColumn col3 = new DataColumn("Next Date Time", typeof(string));

                   DataColumn col4 = new DataColumn("From Account", typeof(string));

                   DataColumn col5 = new DataColumn("Amount", typeof(string));

                   DataColumn col6 = new DataColumn("Is Recurring", typeof(string));

                   DataColumn col7 = new DataColumn("Customer ID", typeof(string));

                   DataColumn col8 = new DataColumn("Last Date Time", typeof(string));

                   DataColumn col9 = new DataColumn("Transaction Reference Number", typeof(string));

                   DataColumn col10 = new DataColumn("Memo", typeof(string));

                   DataColumn col11 = new DataColumn("Weekly/Monthly", typeof(string));

                   dt.Columns.Add(col1);

                   dt.Columns.Add(col2);

                   dt.Columns.Add(col3);

                   dt.Columns.Add(col4);

                   dt.Columns.Add(col5);

                   dt.Columns.Add(col6);

                   dt.Columns.Add(col7);

                   dt.Columns.Add(col8);

                   dt.Columns.Add(col9);

                   dt.Columns.Add(col10);

                   dt.Columns.Add(col11);


                   //count number of items in the list

                   int count = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction.Count();

                   for (int i = 0; i <= count - 1; i++)

                   {

                       DataRow row = dt.NewRow();

                       dt.Rows.Add(row);

                       dt.Rows[i][col1] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].StandingInstructionId?.ToString() ?? "-";

                       dt.Rows[i][col2] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].ToAccount?.ToString() ?? "-";

                       dt.Rows[i][col3] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].NextDateTime?.ToString() ?? "-";

                       dt.Rows[i][col4] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].FromAccount?.ToString() ?? "-";

                       dt.Rows[i][col5] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].Amount?.ToString() ?? "-";

                       dt.Rows[i][col6] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].IsRecurring?.ToString() ?? "-";

                       dt.Rows[i][col7] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].CustomerId?.ToString() ?? "-";

                       dt.Rows[i][col8] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].LastDateTime?.ToString() ?? "-";

                       dt.Rows[i][col9] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].TransactionReferenceNumber?.ToString() ?? "-";

                       dt.Rows[i][col10] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].Memo?.ToString() ?? "-";

                       dt.Rows[i][col11] = s.Content.ServiceResponse.StandingInstructionList.StandingInstruction[i].WeeklyMonthly?.ToString() ?? "-";

                   }

                   gvStandingIntructionList.DataSource = dt;

                   gvStandingIntructionList.DataBind();

               }


               //OTP expired

               else if (errorID == "010041")

               {

                   otp = utilities.newOTP();

                   Session["otp"] = otp;

               }


               else

               {

                   lblTest.Text = s.Content.ServiceResponse.ServiceRespHeader.ErrorText.ToString();

                   string errorMessage = s.Content.ServiceResponse.ServiceRespHeader.ErrorDetails.ToString();

                   MessageBox.Show(errorMessage);

               }

           }


           catch (Exception ex)

           {

               lblExceptionMsg.Text = ex.ToString();

           }

       }

   }

}



Download

Created with the Personal Edition of HelpNDoc: Free help authoring tool