Windows Phone 7 App – SG NRIC Checker by Microsoft Student Partners

Recently, I have been very much involved with Windows Phone 7. From developing Windows Phone 7 app for codeXtremeApps competition to listening Chris Ismael presenting about Windows Phone 7 in MSP meeting to coming up with developers’ bootcamp on Windows Phone 7 in my institution.
Let me take you through how do we create a simple phone app which is a SG NRIC checker. Pratibha had written a blogpost here on the tools needed to develop for Windows Phone 7 platform. So once you have those, you can get started with the following steps to create this app –
Step 1: Open Visual studio 2010, click on New Project and select Silverlight for Windows Phone and Windows Phone Application. You may want to rename it to NRICCheckerWP7

clip_image002

Step 2: Notice that it will open up a default Mainpage.xaml. This is again, a template used for developing WP7 Applications. Now, go to “Toolbox”, drag and drop again, a textbox and a button into the phone.

clip_image004

Step 3: Rename the button to btnCheck and insert Check as the text. Rename the textbox to txtNRIC by editing their properties via properties window after you click on the respective controls.

Step 4: Again, double click on the Check button. This will lead us the part where we do our logic. Lets change the event handler. You should have this after you change it.

[cc lang=’csharp’ ]
private void btnCheck_Click(object sender, RoutedEventArgs e)

{

if (txtNRIC.Text.Length == 9)

{

string inputIC = txtNRIC.Text;

string nric = “” + inputIC[1] + inputIC[2] + inputIC[3] + inputIC[4] + inputIC[5] + inputIC[6] + inputIC[7];

string lastLetter = “” + inputIC[8];

checkNRIC(nric, lastLetter);

}

else

{

MessageBox.Show(“Invalid NRIC”);

}

}

[/cc]

Step 5: You will realise that you are missing the checkNRIC method which takes in a string nric and a string lastLetter. checkNRIC is where we put in the logics for checking if the NRIC is valid or invalid. Do a search online and you can find the algorithms for checkNRIC.
These are the 2 methods needed. Copy and paste this in.

[cc lang=’csharp’ ]
private void checkNRIC(string s, string lastLetter)

{

int sum, remainder;

int[] weight = new int[7];

string outputletters = “JZIHGFEDCBA”;

string nric;

sum = 0;

weight[0] = 2;

for (int i = 1; i < 7; i++)

{

weight[i] = 8 – i;

}

if (IsInteger(s) == true)

{

nric = s;

for (int i = 0; i < 7; i++)

{

sum += Int32.Parse(nric[i].ToString()) * weight[i];

}

remainder = sum % 11;

if (lastLetter.ToUpper() == outputletters[remainder].ToString().ToUpper())

{

MessageBox.Show(“Valid IC”);

}

else

{

MessageBox.Show(“Invalid IC”);

}

}

}

public bool IsInteger(string theValue)

{

try

{

Convert.ToInt32(theValue);

return true;

}

catch

{

return false;

}

}

[/cc]

Lastly, go ahead and click on Ctrl + F5!!!
As you can see here, this is just a very simple app with very basic checking. You should be able to improvise here and be creative and do much stuff to it! J

Guo Hong Lim & Koh Kiat Siang, Temasek Polytechnic Student Partner Leads

Related Posts

One Response to “Windows Phone 7 App – SG NRIC Checker”

  1. Avatar

    David Football Field

    Step 5
    Line 17: for (int i = 1; i < 7; i++) and Line 31

    may i know what is &lt? and with this the App can’t seems to compile and run.

    Reply

Leave a Reply