How To Develop Apps For Hand Held Scanner For Scanning Barcodes: Part 1

In this article we will learn how to develop an application for Windows Mobile CE. (Pocket PC and all types of scanners and and so on.)

We will use C# for coding and Microsoft SQL Compact Edition as backend tools. Today all over the world all the enterprises are using barcodes for managing warehouses (inventory). And use scanners for scanning the barcode, so this article helps you to make an app for scanning barcodes.

Requirements

Visual Studio 2008, and Active sync should be install in your system.

You can download Active sync using this link.. http://www.microsoft.com/en-in/download/details.aspx?id=15

1. First of all go for Visual Studio 2008 and take a new project.



2. Click on Smart Device then click on Smart Device project and provide a name for the app.



3. Then you will get a screen like this:



4. First of all design the interface for the login.



5. At the load event of the login call a function like this:

Public SqlCeEngine engine = new SqlCeEngine("Data Source = \\My Documents\\Test.sdf");

        string ConnStr = "Data Source = \\My Documents\\Test.sdf";

 

        SqlCeConnection Conn;

        SqlCeCommand Cmd;

        SqlCeDataAdapter Adp;

//==========================================================================

private void Frm_Login_Load(object sender, EventArgs e)

        {

                      

            Create_Databae();  

ceate_first_user()

          

        } 

//==================================================================================

public void Create_Databae()

        {

            if (!File.Exists("\\My Documents\\Test.sdf"))

            {

                try

                {

                    Conn = new SqlCeConnection(ConnStr);

                    engine.CreateDatabase();

                    Conn.Open();

                    string create_table_user_master = "Create table user_master(user_id INT IDENTITY (1,1),login_name NVARCHAR(50),password NVARCHAR(50),
                    Role NVARCHAR(50))"
;

                    Cmd = new SqlCeCommand(create_table_user_master, Conn);

                    Cmd.ExecuteNonQuery();

 

 

                    //Create Table Inward Detail

                    Cmd.ExecuteNonQuery();  

 

                    Conn.Close();

 

 

 

                    ceate_first_user();

                }

                catch (Exception ex)

                {

                    MessageBox.Show(ex.ToString());

                }

            }

           

//===========================================================================

public void ceate_first_user()

        {

            string name = "Admin";

            string pass = "Admin";

            string Role = "Admin";

            Conn = new SqlCeConnection(ConnStr);

            if (Conn.State == ConnectionState.Closed)

            {

                Conn.Open();

 

            }

string query = "insert into         user_master(login_name,password,Role)values(@name,@pass,@role)";

            Cmd = new SqlCeCommand(query, Conn);

            Cmd.Parameters.AddWithValue("@name", name);

            Cmd.Parameters.AddWithValue("@pass", pass);

            Cmd.Parameters.AddWithValue("@role", Role);

            Cmd.ExecuteNonQuery();

            Conn.Close();

        }

//=========================================================================== private void btn_login_Click(object sender, 
EventArgs
 e)

        {

 

            validation();

        }

//=========================================================================== public void validation()

        {

            if (txt_login_name.Text == string.Empty)

            {

                MessageBox.Show("Please Enter the Login Id First");

                txt_login_name.Focus();

            }

            else if (txt_pass.Text == string.Empty)

            {

                MessageBox.Show("Please Enter The Password First");

                txt_pass.Focus();

            }

            else

            {

                int a = chk_login();

                if (a == 1)

                {

                    

                    Frm_Menu obj_menu = new Frm_Menu();

                    obj_menu.Show();

                }

           else

           {

    MessageBox.Show("User Id Or Password Is wrong ! Please Try Again");

                    txt_login_name.Text = "";

                    txt_pass.Text = "";

                    txt_login_name.Focus();

           }

          }

        }

//===========================================================================

 

private void btn_exit_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }

//===========================================================================

6. Then run the project and you will get a screen like this:



Select the first option and click on Deploy.

After deployment your app will be run.



Click on the Login Button.

Then you will get a screen as below.


Up Next
    Ebook Download
    View all
    Learn
    View all