Hi this post is about creating a sqlite database in iPhone and manipulating it.
This is a tutorial for absolute beginners
As this is contains a lot of coding the code is not put in the blog but its fully commented and available for download.
The Code Demonstrates the following
- Create a Sqlite Database
- Add values to the database
- Search for values in the database
- Delete values from the database
- Show all the values in a Picker
- show all the values in a Table
Here are the UI’s of the project
You Can download the source code
HERE
Please leave a comment.
Hello readers this is the part two of the login App of android using the information on the remote SQl server database
Now we have our SQL server database and the WCF service that verifies the login so now its time to start the Android App
For this you have to create a normal app and create a UI with two textboxes , a label and a button.
The XML for the UI is given below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<EditText
android:id="@+id/txtUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="User Name"
>
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
/>
<Button
android:id="@+id/btnLogin"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/lblStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
The text boxes are for user name and password
Before we go to the next step we have to add internet permission to the App that is add internet permission to the Manifest file.
Here the code for that (you can use the UI too)
<uses-permission android:name="android.permission.INTERNET" />
Now the UI is ready we can continue to the coding
package com.Android.JSONApp;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class JSONSampleAppActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
//Property declaration
Button btnLogin;
TextView lblStatus;
EditText txtUserName,txtPassword;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnLogin=(Button)findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(this);
lblStatus=(TextView)findViewById(R.id.lblStatus);
txtUserName=(EditText)findViewById(R.id.txtUserName);
txtPassword=(EditText)findViewById(R.id.txtPassword);
}
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.btnLogin:
String userName=txtUserName.getText().toString();
String password=txtPassword.getText().toString();
if(verifyLogin(userName,password))
{
lblStatus.setText("Login Successful");
}
else
{
lblStatus.setText("Login Failed");
}
break;
}
}
public static String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
public static boolean verifyLogin(String UserName,String Password)
{
try
{
System.out.println("guru");
DefaultHttpClient httpClient=new DefaultHttpClient();
//Connect to the server
//here the 10.0.2.2 is the local host
HttpGet httpGet=new HttpGet("http://10.0.2.2:51220/Service1.svc/checkLogin?name="+UserName+"&pass="+Password);
//Get the response
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream stream=httpEntity.getContent();
//Convert the stream to readable format
String result= convertStreamToString(stream);
if(result.charAt(1)=='1')
{
return true;
}
else
{
return false;
}
}
catch(Exception e)
{
return false;
}
}
}
Now run the app and try it
i’ve used the login information in my DB
so i get this output
Here is the link to download the source code
http://www.mediafire.com/?ocmzcc4jl9blsrh
Hi readers I’ve started writing after a long gap
This post is all about connecting Android to SQl server
What we are going to do is a sample app that checks a login and Validate a user based on the provided Username and password
First thing we need to do is to set up the database
For the sample you’ll need this database
CREATE DATABASE JSONSampleDB; USE JSONSampleDB CREATE TABLE UserLogins ( UserName VARCHAR(100) PRIMARY KEY, Password VARCHAR(10) );
after that we’ll need to start working on the WCF service which is the Bridge between the App and the SQL server
First you’ll have to create a WCF webservice
then if you notice the solution explorer you will be able to see this file structure
as you can see there is a CS file called “IService1.cs” and another file “Service1.svc”
The “IService1.cs” is the interface which is the skeleton for the class. if you open it you’ll find some method declarations as we wont be needing them you can remove them.What is important is the “[OperationContract]” only these ones will be shown to the others.
Now we’ll need to add a reference before we continue that is “System.ServiceModel.Web”
Now what we need is a method to validate the login. After adding the code it’ll look like this
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "checkLogin?name={name}&pass={pass}")]
string checkLogin(string name,string pass);
}
Now what is important is the Webinvoke this how we are saying how the method would be accessed via web and what type of data is passes. “WebMessageFormat.Json” is what is saying that the format is JSON you can change it to XML as well.Notice that the parameter names and the UriTemplate parameter names are equal, this is how the data is passed
then we have to implement the method in “Service1.svc.cs” here also you’ll see the old methods you can remove them as well and add this code
public string checkLogin(string name, string pass)
{
DataAccess dataAccess = new DataAccess();
return dataAccess.checkLogin(name, pass);
}
The data access is a class for accessing the database, here’s the code for that
public class DataAccess
{
SqlConnection con;
public DataAccess()
{
con = new SqlConnection("Data Source=localhost;Initial Catalog=JSONSampleDB;Integrated Security=True");
}
public string checkLogin(string userName, string password)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand command = new SqlCommand("SELECT * FROM UserLogins where UserName='" + userName + "' AND Password='" + password + "'", con);
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
return "1";
}
else
{
return "0";
}
}
}
Now the Methods are set but still we have a small task to be done that is modifying the webconfig file, here i’ll put only the changing parts the attached project will have the whole file.
Now you can run the Service and test it make sure you have some sample data in the database and access the method we created by using the url.
Your port number may be different. replace the username and password with appropriate values
You’ll get 0 or 1 according to the information you have provided.
http://localhost:51220/Service1.svc/checkLogin?name=username&pass=password
You can download the WCF service project from here
http://www.mediafire.com/?b4q1opp1u4gia6a
The Android part will be covered in Part 2
Leave a comment
Guruparan Girithran
Hi readers this is a function developed to get the age on a given date.
feel free to use it.
Inputs are Date of Birth and the date to compare
if you want to get the Age as of Today set the second argument as DateTime.Today.
public static int calculateAge(DateTime DateOfBirth,DateTime DateAsOF)
{
int years = DateAsOF.Year - DateOfBirth.Year-1;
if (DateAsOF.Month > DateOfBirth.Month)
{
years++;
}
else if (DateAsOF.Month == DateOfBirth.Month)
{
if (DateAsOF.Day>=DateOfBirth.Day)
{
years++;
}
}
return years;
}
Hi Readers, This is a method coded by me in my first year to compare two date values in char array and give the comparison in integer.
cmpDate(char *date1, char *date2)
{
//date1>date2=-1 date1=date2=0 date1IndexOf("/");
int i2=dt1->LastIndexOf("/");
int i3=dt2->IndexOf("/");
int i4=dt2->LastIndexOf("/");
int dt1month=System::Convert::ToInt32(dt1->Substring(0,i1));
int dt1day=System::Convert::ToInt32(dt1->Substring(i1+1,i2-i1-1));
int dt1year=System::Convert::ToInt32(dt1->Substring(i2+1));
int dt2month=System::Convert::ToInt32(dt2->Substring(0,i3));
int dt2day=System::Convert::ToInt32(dt2->Substring(i3+1,i4-i3-1));
int dt2year=System::Convert::ToInt32(dt2->Substring(i4+1));
if(dt1year>dt2year)
return -1;
else
{
if(dt1year==dt1year)
{
if(dt1month>dt2month)
return -1;
else if(dt1month==dt2month)
{
if(dt1day>dt2day)
{
return -1;
}
if(dt1day<dt2day)
return 1;
}
}
}
return 1;
}
Hi This is a small application i made that will show the steps of the insertion sort algorithm. Thanks to Tharindu Edirisinge who pointed out the mistakes.
DOWNLOAD
Hi Readers
This post will discuss how to make a simple camera Application with Touchless SDK .
Touchless SDK can be used to do many things with your webcam this is just the basic thing.
First you’ll have to download the touchless SDK.
You can get it HERE.
You’ll get a zip file which will have the touchless demo , 2 DLL files and some other files the DLL files are the one which are important to us. Try that demo to know the power of touchless
Now create a new windows forms application . Then copy the two DLL files to the project folder and add the reference of touchless.dll file to the project.
Now create the form similar to this the names of the controls are given so that it’ll be easy to understand.
You’ll have to add a filesavedialog as well.
Now the coding the comments in the code provide the line by line explanation.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; //Importing the DLL using TouchlessLib; namespace CameraApp { public partial class Form1 : Form { //The touchless manager has the properties of the camera info etc TouchlessMgr manager; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //initialize the touchless manager object manager = new TouchlessMgr(); //Listing the available cameras in the combobox foreach (Camera item in manager.Cameras) { cmbCamera.Items.Add(item); } } private void cmbCamera_SelectedIndexChanged(object sender, EventArgs e) { //initializing the camera to be used based on the selection manager.CurrentCamera = (Camera)cmbCamera.SelectedItem; //Setting the Event handler for the camera manager.CurrentCamera.OnImageCaptured += new EventHandler(CurrentCamera_OnImageCaptured); } void CurrentCamera_OnImageCaptured(object sender, CameraEventArgs e) { //Giving the feed of the camera to the picturepox picFeed.Image = manager.CurrentCamera.GetCurrentImage(); } private void btnCapture_Click(object sender, EventArgs e) { //Displaying the Current image in the other text box picPreview.Image = manager.CurrentCamera.GetCurrentImage(); } private void btnSave_Click(object sender, EventArgs e) { //getting the current image of preview picturebox Bitmap b = (Bitmap)picPreview.Image; //Dispalying the save file dialog saveFileDialog1.Filter = "JPEG Image|*.jpg"; saveFileDialog1.Title = "Save an Image File"; saveFileDialog1.ShowDialog(); //Saving the image if (saveFileDialog1.FileName != "") b.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg); else MessageBox.Show("Nmae Not specified"); } } }
If you run the application and click the Capture button you’ll be able to see the application like this

You can download a sample project HERE
Please leave a Comment.









