private void btnSearch_Click(object sender, EventArgs e)
        {
            string qry = "";

            if (cboSearch.Text == "First Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                           "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                           " WHERE fldFirstName='" + txtSearch.Text.Replace("'","''") + "' ORDER BY fldLastName";
            }

            if (cboSearch.Text == "Last Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldLastName LIKE'%" + txtSearch.Text.Replace("'", "''") + "%' ORDER BY fldFirstName";
            }

            if (cboSearch.Text == "Nick Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldNickName LIKE '%" + txtSearch.Text.Replace("'", "''") + "%' ORDER BY fldFirstName,fldLastName";
            }

            if (cboSearch.Text == "Birth Day")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldBirthday LIKE '%" + dtSearch.Value.ToShortDateString() + "%' ORDER BY fldFirstName, fldLastName";
            }

            if (cboSearch.Text == "Barcode")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldStudentID='" + txtSearch.Text.Replace("'", "''") + "'";

                string q = qry;

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                //js.ExecuteQuery(q);
                js.RiD.Read();

                lblStudentID.Text = js.RiD["fldStudentID"].ToString();
                txtFirstName.Text = js.RiD["fldFirstName"].ToString();
                txtLastName.Text = js.RiD["fldLastName"].ToString();
                txtMiddleName.Text = js.RiD["fldMiddleName"].ToString();
                txtNickName.Text = js.RiD["fldNickName"].ToString();
                dtBirthdate.Value = Convert.ToDateTime(js.RiD["fldBirthday"].ToString());
                cboGender.Text = js.RiD["Gender"].ToString();
                txtChurch.Text = js.Lookup("fldChurch", "tblChurch", "fldID='" + js.RiD["fldChurch"].ToString() + "'");
                fldAddressDetails = js.RiD["fldAddressDetails"].ToString();
                fldContactDetails = js.RiD["fldContactDetails"].ToString();
                fldNationality = js.RiD["fldNationality"].ToString();
                cboNationality.Text = js.RiD["fldNationality"].ToString();
                txtPoints.Text = js.RiD["fldPoints"].ToString();
                fldKidsID = js.RiD["fldID"].ToString();

                int age = js.GetAge(dtBirthdate.Value);

                txtAge.Text = age.ToString();

                txtAllergies.Text = js.RiD["fldAllergies"].ToString();

                string status = js.RiD["fldUpdateStatus"].ToString();

                txtStatus.Text = js.Lookup("fldStatus", "tblStatus", "fldID='" + status + "'");

                txtRemarks.Text = js.RiD["fldRemarks"].ToString();

                if (age >= 10)
                {
                    //chkTick.Enabled = true;
                }
                else
                {
                    //chkTick.Enabled = false;
                }
                //FOR LOADING PICTURE
                string picture = js.GetPath() + "/Kids/" + js.RiD["fldPicture"].ToString();
                string temppic = Application.StartupPath + "/Pictures/tmp/Kids/tmp1.jpg";
                if (System.IO.File.Exists(picture))
                {
                    pbImage.Image.Dispose();
                    System.IO.File.Copy(picture, temppic, true);
                    pbImage.Image = System.Drawing.Image.FromFile(temppic);
                }

                js.CloseConnection();

                //For the Address Details
                q = "SELECT * FROM tblAddress WHERE fldID='" + fldAddressDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtAddress1.Text = js.RiD["fldAddress1"].ToString();
                    txtAddress2.Text = js.RiD["fldAddress2"].ToString();
                    txtCity.Text = js.RiD["fldCity"].ToString();
                    txtZipCode.Text = js.RiD["fldZipCode"].ToString();
                }

                js.CloseConnection();

                //For Contact Details
                q = "SELECT * FROM tblContactDetails WHERE fldID='" + fldContactDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtContactNo.Text = js.RiD["fldContactNumber"].ToString();
                }

                js.CloseConnection();

                return;

            }

            //js.searchquery = qry;

            frmResults frm = new frmResults();
            frm.Tag = qry;
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string q = frm.Tag.ToString();

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                lblStudentID.Text = js.RiD["fldStudentID"].ToString();
                txtFirstName.Text = js.RiD["fldFirstName"].ToString();
                txtLastName.Text = js.RiD["fldLastName"].ToString();
                txtMiddleName.Text = js.RiD["fldMiddleName"].ToString();
                txtNickName.Text = js.RiD["fldNickName"].ToString();
                dtBirthdate.Value = Convert.ToDateTime(js.RiD["fldBirthday"].ToString());
                cboGender.Text = js.RiD["Gender"].ToString();
                txtChurch.Text = js.Lookup("fldChurch", "tblChurch", "fldID='" + js.RiD["fldChurch"].ToString() + "'");
                fldAddressDetails = js.RiD["fldAddressDetails"].ToString();
                fldContactDetails = js.RiD["fldContactDetails"].ToString();
                fldNationality = js.RiD["fldNationality"].ToString();
                cboNationality.Text = js.RiD["fldNationality"].ToString();
                txtPoints.Text = js.RiD["fldPoints"].ToString();
                fldKidsID = js.RiD["fldID"].ToString();

                int age = js.GetAge(dtBirthdate.Value);

                txtAge.Text = age.ToString();

                txtAllergies.Text = js.RiD["fldAllergies"].ToString();

                string status = js.RiD["fldUpdateStatus"].ToString();

                txtStatus.Text = js.Lookup("fldStatus", "tblStatus", "fldID='" + status + "'");
                txtRemarks.Text = js.RiD["fldRemarks"].ToString();

                if (age >= 10)
                {
                    //chkTick.Enabled = true;
                }
                else
                {
                    //chkTick.Enabled = false;
                }

                //FOR LOADING PICTURE
                string picture = js.GetPath() + "/Kids/" + js.RiD["fldPicture"].ToString();
                string temppic = Application.StartupPath + "/Pictures/tmp/Kids/tmp1.jpg";
                if (System.IO.File.Exists(picture))
                {
                    //pbImage.Dispose();
                    pbImage.Image.Dispose();
                    System.IO.File.Copy(picture, temppic, true);
                    pbImage.Image = System.Drawing.Image.FromFile(temppic);
                }

                js.CloseConnection();

                //For the Address Details
                q = "SELECT * FROM tblAddress WHERE fldID='" + fldAddressDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtAddress1.Text = js.RiD["fldAddress1"].ToString();
                    txtAddress2.Text = js.RiD["fldAddress2"].ToString();
                    txtCity.Text = js.RiD["fldCity"].ToString();
                    txtZipCode.Text = js.RiD["fldZipCode"].ToString();
                }

                js.CloseConnection();

                //For Contact Details
                q = "SELECT * FROM tblContactDetails WHERE fldID='" + fldContactDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtContactNo.Text = js.RiD["fldContactNumber"].ToString();
                }

                js.CloseConnection();

            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtSearch.Text == "")
            {
                js.showExclamation("Cannot generate result with an empty field");
                return;
            }

            string qry = "";

            if (cboSearch.Text == "First Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                           "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                           " WHERE fldFirstName='" + txtSearch.Text.Replace("'", "''") + "' ORDER BY fldLastName";
            }

            if (cboSearch.Text == "Last Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldLastName='" + txtSearch.Text.Replace("'", "''") + "' ORDER BY fldFirstName";
            }

            if (cboSearch.Text == "Nick Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldNickName='" + txtSearch.Text.Replace("'", "''") + "' ORDER BY fldFirstName,fldLastName";
            }

            if (cboSearch.Text == "Birth Day")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldBirthday='" + dtSearch.Value.ToShortDateString() + "' ORDER BY fldFirstName,fldLastName";
            }

            if (cboSearch.Text == "Barcode")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldStudentID='" + txtSearch.Text.Replace("'", "''") + "' ORDER BY fldFirstName,fldLastName";

                string q = qry;

                try
                {
                    js.ExecuteQuery(q);
                }
                catch(Exception ex )
                {
                    MessageBox.Show(ex.Message,"", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                js.RiD.Read();

                fetcherID = new string[3];
                pbFetcher1.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");
                pbFetcher2.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");
                pbFetcher3.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");
                pbImage.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");

                lblStudentID.Text = js.RiD["fldStudentID"].ToString();
                txtFirstName.Text = js.RiD["fldFirstName"].ToString().Replace("''","'");
                txtLastName.Text = js.RiD["fldLastName"].ToString().Replace("''", "'");
                txtMiddleName.Text = js.RiD["fldMiddleName"].ToString();
                txtNickName.Text = js.RiD["fldNickName"].ToString();

                DateTime bdate;

                if (DateTime.TryParse(js.RiD["fldBirthday"].ToString(), out bdate))
                {
                    dtBirthdate.Value = bdate;
                }

                //dtBirthdate.Value = Convert.ToDateTime(js.RiD["fldBirthday"].ToString());
                cboGender.Text = js.RiD["Gender"].ToString();
                txtChurch.Text = js.Lookup("fldChurch", "tblChurch", "fldID='" + js.RiD["fldChurch"].ToString() + "'");
                fldAddressDetails = js.RiD["fldAddressDetails"].ToString();
                fldContactDetails = js.RiD["fldContactDetails"].ToString();
                fldNationality = js.RiD["fldNationality"].ToString();
                cboNationality.Text = js.RiD["fldNationality"].ToString();
                txtPoints.Text = js.RiD["fldPoints"].ToString();
                fldKidsID = js.RiD["fldID"].ToString();

                int status = 0;
                bool parse;

                parse = int.TryParse(js.Lookup("fldUpdateStatus", "tblKids", "fldID='" + fldKidsID + "'"), out status);

                if (!parse)
                {
                    status = 0;
                }

                txtStatus.Text = js.Lookup("fldStatus", "tblStatus", " fldID='" + status + "'");

                int age = js.GetAge(dtBirthdate.Value);
                string group = "";

                if (Convert.ToDecimal(age) < 2)
                {
                    group = "Nursery";
                }

                else if ((Convert.ToDecimal(age) >= 2) && (Convert.ToDecimal(age) < 3))
                {
                    group = "Toddlers";
                }

                else if ((Convert.ToDecimal(age) >= 3) && (Convert.ToDecimal(age) <= 4))
                {
                    group = "Preschool";
                }

                else if ((Convert.ToDecimal(age) >= 5) && (Convert.ToDecimal(age) <= 6))
                {
                    group = "Kinder";
                }

                else if ((Convert.ToDecimal(age) >= 7) && (Convert.ToDecimal(age) <= 9))
                {
                    group = "Primary";
                }

                else if ((Convert.ToDecimal(age) >= 10) && (Convert.ToDecimal(age) <= 12))
                {
                    group = "Preteens";
                }

                else
                {
                    group = "Adult";
                }

                txtGroup.Text = group;

                //FOR LOADING PICTURE

                pbImage.Image.Dispose();

                string picture = js.GetPath() + "/Kids/" + js.RiD["fldPicture"].ToString().Replace("'","''");

                string temppic = Application.StartupPath + "/Pictures/tmp/Kids/tmp1.jpg";

                //try { System.IO.File.Delete(temppic); }
                //catch (Exception ex) { }

                if (System.IO.File.Exists(picture))
                {
                    //pbImage.Dispose();
                    pbImage.Image.Dispose();
                    //System.IO.File.Copy(picture, temppic, true);
                    pbImage.Image = System.Drawing.Image.FromFile(picture);
                }

                js.CloseConnection();

                //For the Address Details
                q = "SELECT * FROM tblAddress WHERE fldID='" + fldAddressDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtAddress1.Text = js.RiD["fldAddress1"].ToString();
                    txtAddress2.Text = js.RiD["fldAddress2"].ToString();
                    txtCity.Text = js.RiD["fldCity"].ToString();
                    txtZipCode.Text = js.RiD["fldZipCode"].ToString();
                }

                js.CloseConnection();

                //For Contact Details
                q = "SELECT * FROM tblContactDetails WHERE fldID='" + fldContactDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtContactNo.Text = js.RiD["fldContactNumber"].ToString();
                }

                js.CloseConnection();

                GetFectchers();

                dgvFetchers.Rows.Clear();

                for (int i = 0; i <= (fetcherID.Length - 1); i++)
                {
                    string qq = "SELECT f.*,a.*,r.fldRelationship as Relationship,c.fldContactNumber FROM tblFetcher f " +
                                 " LEFT OUTER JOIN tblAddress a ON a.fldID=f.fldAddressDetails " +
                                 " LEFT OUTER JOIN tblContactDetails c ON c.fldID = f.fldContactDetails " +
                                 " LEFT OUTER JOIN tblRelationship r ON r.fldID = f.fldRelationship" +
                                 " WHERE f.fldID = '" + fetcherID[i] + "'";
                    js.ExecuteQuery(qq);
                    js.RiD.Read();

                    if (js.RiD.HasRows)
                    {
                        dgvFetchers.Rows.Add(js.RiD["fldID"], js.RiD["fldFirstName"], js.RiD["fldLastName"], js.RiD["fldMiddleName"], js.RiD["Relationship"], js.RiD["fldContactNumber"], js.RiD["fldAddress1"], js.RiD["fldAddress2"], js.RiD["fldCity"], js.RiD["fldZipCode"], js.RiD["fldPicture"].ToString().Replace("'","''"));
                    }

                }

                if (dgvFetchers.Rows.Count != 0)
                {
                    if (dgvFetchers.Rows.Count == 1)
                    {
                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher1.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString());
                        }
                    }
                    else if (dgvFetchers.Rows.Count == 2)
                    {
                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher1.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString());
                        }

                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[1].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher2.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[1].Cells["Picture"].Value.ToString());
                        }
                    }
                    else
                    {
                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher1.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString());
                        }

                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[1].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher2.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[1].Cells["Picture"].Value.ToString());
                        }

                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[2].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher3.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[2].Cells["Picture"].Value.ToString());
                        }
                    }
                }

                StartReader();

                return;

            }

            //js.searchquery = qry;

            frmResults frm = new frmResults();
            frm.Tag = qry;
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string q = frm.Tag.ToString();

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                fetcherID = new string[3];
                pbFetcher1.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");
                pbFetcher2.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");
                pbFetcher3.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");
                pbImage.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");

                lblStudentID.Text = js.RiD["fldStudentID"].ToString();
                txtFirstName.Text = js.RiD["fldFirstName"].ToString().Replace("''", "'");
                txtLastName.Text = js.RiD["fldLastName"].ToString().Replace("''", "'");
                txtMiddleName.Text = js.RiD["fldMiddleName"].ToString();
                txtNickName.Text = js.RiD["fldNickName"].ToString();

                DateTime bdate;

                if (DateTime.TryParse(js.RiD["fldBirthday"].ToString(),out bdate))
                {
                    dtBirthdate.Value = bdate;
                }

                cboGender.Text = js.RiD["Gender"].ToString();
                txtChurch.Text = js.Lookup("fldChurch", "tblChurch", "fldID='" + js.RiD["fldChurch"].ToString() + "'");
                fldAddressDetails = js.RiD["fldAddressDetails"].ToString();
                fldContactDetails = js.RiD["fldContactDetails"].ToString();
                fldNationality = js.RiD["fldNationality"].ToString();
                cboNationality.Text = js.RiD["fldNationality"].ToString();
                txtPoints.Text = js.RiD["fldPoints"].ToString();
                fldKidsID = js.RiD["fldID"].ToString();

                int status = 0;
                bool parse;

                parse = int.TryParse(js.Lookup("fldUpdateStatus", "tblKids", "fldID='" + fldKidsID + "'"),out status);

                if(!parse)
                {
                    status = 0;
                }

                txtStatus.Text = js.Lookup("fldStatus", "tblStatus", " fldID='" + status + "'");

                int age = js.GetAge(dtBirthdate.Value);
                string group = "";

                if (Convert.ToDecimal(age) < 2)
                {
                    group = "Nursery";
                }

                else if ((Convert.ToDecimal(age) >= 2) && (Convert.ToDecimal(age) < 3))
                {
                    group = "Toddlers";
                }

                else if ((Convert.ToDecimal(age) >= 3) && (Convert.ToDecimal(age) <= 4))
                {
                    group = "Preschool";
                }

                else if ((Convert.ToDecimal(age) >= 5) && (Convert.ToDecimal(age) <= 6))
                {
                    group = "Kinder";
                }

                else if ((Convert.ToDecimal(age) >= 7) && (Convert.ToDecimal(age) <= 9))
                {
                    group = "Primary";
                }

                else if ((Convert.ToDecimal(age) >= 10) && (Convert.ToDecimal(age) <= 12))
                {
                    group = "Preteens";
                }

                else
                {
                    group = "Adult";
                }

                txtGroup.Text = group;

                //FOR LOADING PICTURE
                string picture = js.GetPath() + "/Kids/" + js.RiD["fldPicture"].ToString().Replace("'","''") + "";
                string temppic = Application.StartupPath + "/Pictures/tmp/Kids/tmp1.jpg";

                try { System.IO.File.Delete(temppic); } catch(Exception ex){}

                if (System.IO.File.Exists(picture))
                {
                    //pbImage.Dispose();
                    pbImage.Image.Dispose();
                    //System.IO.File.Copy(picture, temppic, true);
                    pbImage.Image = System.Drawing.Image.FromFile(picture);
                }

                js.CloseConnection();

                //For the Address Details
                q = "SELECT * FROM tblAddress WHERE fldID='" + fldAddressDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtAddress1.Text = js.RiD["fldAddress1"].ToString();
                    txtAddress2.Text = js.RiD["fldAddress2"].ToString();
                    txtCity.Text = js.RiD["fldCity"].ToString();
                    txtZipCode.Text = js.RiD["fldZipCode"].ToString();
                }

                js.CloseConnection();

                //For Contact Details
                q = "SELECT * FROM tblContactDetails WHERE fldID='" + fldContactDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtContactNo.Text = js.RiD["fldContactNumber"].ToString();
                }

                js.CloseConnection();

                GetFectchers();

                dgvFetchers.Rows.Clear();

                for (int i = 0; i <= (fetcherID.Length - 1); i++)
                {
                    string qq = "SELECT f.*,a.*,r.fldRelationship as Relationship,c.fldContactNumber FROM tblFetcher f " +
                                 " LEFT OUTER JOIN tblAddress a ON a.fldID=f.fldAddressDetails " +
                                 " LEFT OUTER JOIN tblContactDetails c ON c.fldID = f.fldContactDetails " +
                                 " LEFT OUTER JOIN tblRelationship r ON r.fldID = f.fldRelationship" +
                                 " WHERE f.fldID = '" + fetcherID[i] + "'";

                    try
                    {
                        js.ExecuteQuery(qq);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    //js.ExecuteQuery(qq);
                    js.RiD.Read();

                    if (js.RiD.HasRows)
                    {
                        dgvFetchers.Rows.Add(js.RiD["fldID"], js.RiD["fldFirstName"], js.RiD["fldLastName"], js.RiD["fldMiddleName"], js.RiD["Relationship"], js.RiD["fldContactNumber"], js.RiD["fldAddress1"], js.RiD["fldAddress2"], js.RiD["fldCity"], js.RiD["fldZipCode"], js.RiD["fldPicture"].ToString().Replace("'","''"));
                    }

                }

                if (dgvFetchers.Rows.Count != 0)
                {
                    if (dgvFetchers.Rows.Count == 1)
                    {
                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher1.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString());
                        }
                    }
                    else if (dgvFetchers.Rows.Count == 2)
                    {
                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher1.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString());
                        }

                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[1].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher2.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[1].Cells["Picture"].Value.ToString());
                        }
                    }
                    else
                    {
                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher1.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[0].Cells["Picture"].Value.ToString());
                        }

                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[1].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher2.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[1].Cells["Picture"].Value.ToString());
                        }

                        if (System.IO.File.Exists(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[2].Cells["Picture"].Value.ToString()))
                        {
                            pbFetcher3.Image = Image.FromFile(js.GetPath() + "/Fetchers/" + dgvFetchers.Rows[2].Cells["Picture"].Value.ToString());
                        }
                    }
                }

                StartReader();

            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string qry = "";

            if (txtSearch.Text == "")
            {
                js.showExclamation("Cannot generate result with an empty field");
                return;
            }

            if(cboSearch.Text == "First Name")
            {

                 qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                            "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                            " WHERE fldFirstName='" + txtSearch.Text.Replace("'","''") + "' ORDER BY fldLastName";
            }

            if(cboSearch.Text == "Last Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldLastName='" + txtSearch.Text.Replace("'", "''") + "' ORDER BY fldFirstName";
            }

            if (cboSearch.Text == "Nick Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldNickName='" + txtSearch.Text.Replace("'", "''") + "' ORDER BY fldFirstName,fldLastName";
            }

            if (cboSearch.Text == "Birth Day")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldBirthday='" + dtSearch.Value.ToShortDateString() + "' ORDER BY fldFirstName, fldLastName";
            }

            if (cboSearch.Text == "Barcode")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldStudentID='" + txtSearch.Text.Replace("'", "''") + "'";

                string q = qry;

                try
                {
                    js.ExecuteQuery(q);
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                //js.ExecuteQuery(q);
                js.RiD.Read();
                fetcherID = new string[3];
                pbImage.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");

                lblStudentID.Text = js.RiD["fldStudentID"].ToString();
                txtFirstName.Text = js.RiD["fldFirstName"].ToString().Replace("''", "'");
                txtLastName.Text = js.RiD["fldLastName"].ToString().Replace("''", "'");
                txtMiddleName.Text = js.RiD["fldMiddleName"].ToString();
                txtNickName.Text = js.RiD["fldNickName"].ToString();

                DateTime bdate;

                if (DateTime.TryParse(js.RiD["fldBirthday"].ToString(), out bdate))
                {
                    dtBirthdate.Value = bdate;
                }

                cboGender.Text = js.RiD["Gender"].ToString();
                txtChurch.Text = js.Lookup("fldChurch", "tblChurch", "fldID='" + js.RiD["fldChurch"].ToString() + "'");
                fldAddressDetails = js.RiD["fldAddressDetails"].ToString();
                fldContactDetails = js.RiD["fldContactDetails"].ToString();
                fldNationality = js.RiD["fldNationality"].ToString();
                cboNationality.Text = fldNationality;//js.Lookup("fldNationality", "tblNationality", "fldID='" + js.RiD["fldNationality"].ToString() + "'");
                txtPoints.Text = js.RiD["fldPoints"].ToString();
                fldKidsID = js.RiD["fldID"].ToString();

                int age = js.GetAge(dtBirthdate.Value);

                txtAge.Text = age.ToString();

                txtAllergies.Text = js.RiD["fldAllergies"].ToString();

                string status = js.RiD["fldUpdateStatus"].ToString();

                txtStatus.Text = js.Lookup("fldStatus","tblStatus","fldID='" + status + "'");

                txtRemarks.Text = js.RiD["fldRemarks"].ToString();

                string group = "";

                if(age>=10)
                {
                    chkTick.Enabled = false;
                }
                else
                {
                    chkTick.Enabled = false;
                }

                if (Convert.ToDecimal(age) < 2)
                {
                    group = "Nursery";
                }

                else if ((Convert.ToDecimal(age) >= 2) && (Convert.ToDecimal(age) < 3))
                {
                    group = "Toddlers";
                }

                else if ((Convert.ToDecimal(age) >= 3) && (Convert.ToDecimal(age) <= 4))
                {
                    group = "Preschool";
                }

                else if ((Convert.ToDecimal(age) >= 5) && (Convert.ToDecimal(age) <= 6))
                {
                    group = "Kinder";
                }

                else if ((Convert.ToDecimal(age) >= 7) && (Convert.ToDecimal(age) <= 9))
                {
                    group = "Primary";
                }

                else if ((Convert.ToDecimal(age) >= 10) && (Convert.ToDecimal(age) <= 12))
                {
                    group = "Preteens";
                }

                else
                {
                    group = "Adult";
                }

                txtGroup.Text = group;

                //FOR LOADING PICTURE
                string picture = GetPath() + "/Kids/" +  js.RiD["fldPicture"].ToString();
                string temppic = Application.StartupPath + "/Pictures/tmp/Kids/tmp1.jpg";

                //try { System.IO.File.Delete(temppic); }
                //catch (Exception ex) { }

                if(System.IO.File.Exists(picture))
                {
                    pbImage.Image.Dispose();
                    ///System.IO.File.Copy(picture, temppic,true);
                    pbImage.Image = System.Drawing.Image.FromFile(picture);
                }

                js.CloseConnection();

                //For the Address Details
                q = "SELECT * FROM tblAddress WHERE fldID='" + fldAddressDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if(js.RiD.HasRows)
                {
                    txtAddress1.Text = js.RiD["fldAddress1"].ToString();
                    txtAddress2.Text = js.RiD["fldAddress2"].ToString();
                    txtCity.Text = js.RiD["fldCity"].ToString();
                    txtZipCode.Text = js.RiD["fldZipCode"].ToString();
                }

                js.CloseConnection();

                //For Contact Details
                q = "SELECT * FROM tblContactDetails WHERE fldID='" + fldContactDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtContactNo.Text = js.RiD["fldContactNumber"].ToString();
                }

                js.CloseConnection();

                return;

            }

            //js.searchquery = qry;

            frmResults frm = new frmResults();
            frm.Tag = qry;
            if (frm.ShowDialog()== System.Windows.Forms.DialogResult.OK)
            {
                string q = frm.Tag.ToString();

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();
                fetcherID = new string[3]; //destroy string
                pbImage.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");

                lblStudentID.Text = js.RiD["fldStudentID"].ToString();
                txtFirstName.Text = js.RiD["fldFirstName"].ToString().Replace("''", "'");
                txtLastName.Text = js.RiD["fldLastName"].ToString().Replace("''", "'");
                txtMiddleName.Text = js.RiD["fldMiddleName"].ToString();
                txtNickName.Text = js.RiD["fldNickName"].ToString();
                DateTime bdate;

                if (DateTime.TryParse(js.RiD["fldBirthday"].ToString(), out bdate))
                {
                    dtBirthdate.Value = bdate;
                }

                cboGender.Text = js.RiD["Gender"].ToString();
                txtChurch.Text = js.Lookup("fldChurch", "tblChurch", "fldID='" + js.RiD["fldChurch"].ToString() + "'");
                fldAddressDetails = js.RiD["fldAddressDetails"].ToString();
                fldContactDetails = js.RiD["fldContactDetails"].ToString();
                fldNationality = js.RiD["fldNationality"].ToString();
                cboNationality.Text = fldNationality;//js.Lookup("fldNationality", "tblNationality", "fldID='" + js.RiD["fldNationality"].ToString() + "'");
                txtPoints.Text = js.RiD["fldPoints"].ToString();
                fldKidsID = js.RiD["fldID"].ToString();

                int age = js.GetAge(dtBirthdate.Value);
                string group = "";

                txtAge.Text = age.ToString();

                txtAllergies.Text = js.RiD["fldAllergies"].ToString();

                string status = js.RiD["fldUpdateStatus"].ToString();

                txtStatus.Text = js.Lookup("fldStatus", "tblStatus", "fldID='" + status + "'");

                txtRemarks.Text = js.RiD["fldRemarks"].ToString();

                if (age >= 10)
                {
                    chkTick.Visible = false;
                }
                else
                {
                    chkTick.Visible = false;
                }

                if (Convert.ToDecimal(age) < 2)
                {
                    group = "Nursery";
                }

                else if ((Convert.ToDecimal(age) >= 2) && (Convert.ToDecimal(age) < 3))
                {
                    group = "Toddlers";
                }

                else if ((Convert.ToDecimal(age) >= 3) && (Convert.ToDecimal(age) <= 4))
                {
                    group = "Preschool";
                }

                else if ((Convert.ToDecimal(age) >= 5) && (Convert.ToDecimal(age) <= 6))
                {
                    group = "Kinder";
                }

                else if ((Convert.ToDecimal(age) >= 7) && (Convert.ToDecimal(age) <= 9))
                {
                    group = "Primary";
                }

                else if ((Convert.ToDecimal(age) >= 10) && (Convert.ToDecimal(age) <= 12))
                {
                    group = "Preteens";
                }

                else
                {
                    group = "Adult";
                }

                txtGroup.Text = group;

                //FOR LOADING PICTURE
                string picture = GetPath() + "/Kids/" + js.RiD["fldPicture"].ToString().Replace("'","''");
                string temppic = Application.StartupPath + "/Pictures/tmp/Kids/tmp1.jpg";

                //try { System.IO.File.Delete(temppic); }
                //catch (Exception ex) { }

                if (System.IO.File.Exists(picture))
                {
                    //pbImage.Dispose();
                    pbImage.Image.Dispose();
                    //System.IO.File.Copy(picture, temppic, true);
                    pbImage.Image = System.Drawing.Image.FromFile(picture);
                }

                js.CloseConnection();

                //For the Address Details
                q = "SELECT * FROM tblAddress WHERE fldID='" + fldAddressDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //js.ExecuteQuery(q);
                js.RiD.Read();

                if(js.RiD.HasRows)
                {
                    txtAddress1.Text = js.RiD["fldAddress1"].ToString();
                    txtAddress2.Text = js.RiD["fldAddress2"].ToString();
                    txtCity.Text = js.RiD["fldCity"].ToString();
                    txtZipCode.Text = js.RiD["fldZipCode"].ToString();
                }

                js.CloseConnection();

                //For Contact Details
                q = "SELECT * FROM tblContactDetails WHERE fldID='" + fldContactDetails + "'";

                try
                {
                    js.ExecuteQuery(q);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtContactNo.Text = js.RiD["fldContactNumber"].ToString();
                }

                js.CloseConnection();

            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string qry = "";

            if(cboSearch.Text == "First Name")
            {

                 qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                            "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                            " WHERE fldFirstName='" + txtSearch.Text + "'";
            }

            if(cboSearch.Text == "Last Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldLastName='" + txtSearch.Text + "'";
            }

            if (cboSearch.Text == "Nick Name")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldNickName='" + txtSearch.Text + "'";
            }

            if (cboSearch.Text == "Birth Day")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldBirthday='" + dtSearch.Value.ToShortDateString() + "'";
            }

            if (cboSearch.Text == "Barcode")
            {

                qry = "SELECT k.*,g.fldGender as Gender FROM tblKids  k " +
                             "LEFT OUTER JOIN tblGender g ON g.fldID=k.fldGender" +
                             " WHERE fldStudentID='" + txtSearch.Text + "'";

                string q = qry;

                js.ExecuteQuery(q);
                js.RiD.Read();

                lblStudentID.Text = js.RiD["fldStudentID"].ToString();
                txtFirstName.Text = js.RiD["fldFirstName"].ToString();
                txtLastName.Text = js.RiD["fldLastName"].ToString();
                txtMiddleName.Text = js.RiD["fldMiddleName"].ToString();
                txtNickName.Text = js.RiD["fldNickName"].ToString();
                dtBirthdate.Value = Convert.ToDateTime(js.RiD["fldBirthday"].ToString());
                cboGender.Text = js.RiD["Gender"].ToString();
                txtChurch.Text = js.Lookup("fldChurch", "tblChurch", "fldID='" + js.RiD["fldChurch"].ToString() + "'");
                fldAddressDetails = js.RiD["fldAddressDetails"].ToString();
                fldContactDetails = js.RiD["fldContactDetails"].ToString();
                fldNationality = js.RiD["fldNationality"].ToString();
                cboNationality.Text = js.Lookup("fldNationality", "tblNationality", "fldID='" + js.RiD["fldNationality"].ToString() + "'");
                txtPoints.Text = js.RiD["fldPoints"].ToString();
                fldKidsID = js.RiD["fldID"].ToString();

                //FOR LOADING PICTURE
                string picture = js.RiD["fldPicture"].ToString();
                string temppic = Application.StartupPath + "/Pictures/tmp/Kids/tmp1.jpg";
                if(System.IO.File.Exists(picture))
                {
                    pbImage.Image.Dispose();
                    System.IO.File.Copy(picture, temppic,true);
                    pbImage.Image = System.Drawing.Image.FromFile(temppic);
                }

                js.CloseConnection();

                //For the Address Details
                q = "SELECT * FROM tblAddress WHERE fldID='" + fldAddressDetails + "'";
                js.ExecuteQuery(q);
                js.RiD.Read();

                if(js.RiD.HasRows)
                {
                    txtAddress1.Text = js.RiD["fldAddress1"].ToString();
                    txtAddress2.Text = js.RiD["fldAddress2"].ToString();
                    txtCity.Text = js.RiD["fldCity"].ToString();
                    txtZipCode.Text = js.RiD["fldZipCode"].ToString();
                }

                js.CloseConnection();

                //For Contact Details
                q = "SELECT * FROM tblContactDetails WHERE fldID='" + fldContactDetails + "'";
                js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtContactNo.Text = js.RiD["fldContactNumber"].ToString();
                }

                js.CloseConnection();

                return;

            }

            //js.searchquery = qry;

            frmResults frm = new frmResults();
            frm.Tag = qry;
            if (frm.ShowDialog()== System.Windows.Forms.DialogResult.OK)
            {
                string q = frm.Tag.ToString();

                js.ExecuteQuery(q);
                js.RiD.Read();

                lblStudentID.Text = js.RiD["fldStudentID"].ToString();
                txtFirstName.Text = js.RiD["fldFirstName"].ToString();
                txtLastName.Text = js.RiD["fldLastName"].ToString();
                txtMiddleName.Text = js.RiD["fldMiddleName"].ToString();
                txtNickName.Text = js.RiD["fldNickName"].ToString();
                dtBirthdate.Value = Convert.ToDateTime(js.RiD["fldBirthday"].ToString());
                cboGender.Text = js.RiD["Gender"].ToString();
                txtChurch.Text = js.Lookup("fldChurch", "tblChurch", "fldID='" + js.RiD["fldChurch"].ToString() + "'");
                fldAddressDetails = js.RiD["fldAddressDetails"].ToString();
                fldContactDetails = js.RiD["fldContactDetails"].ToString();
                fldNationality = js.RiD["fldNationality"].ToString();
                cboNationality.Text = js.Lookup("fldNationality", "tblNationality", "fldID='" + js.RiD["fldNationality"].ToString() + "'");
                txtPoints.Text = js.RiD["fldPoints"].ToString();
                fldKidsID = js.RiD["fldID"].ToString();

                //FOR LOADING PICTURE
                string picture = js.RiD["fldPicture"].ToString();
                string temppic = Application.StartupPath + "/Pictures/tmp/Kids/tmp1.jpg";
                if (System.IO.File.Exists(picture))
                {
                    //pbImage.Dispose();
                    pbImage.Image.Dispose();
                    System.IO.File.Copy(picture, temppic, true);
                    pbImage.Image = System.Drawing.Image.FromFile(temppic);
                }

                js.CloseConnection();

                //For the Address Details
                q = "SELECT * FROM tblAddress WHERE fldID='" + fldAddressDetails + "'";
                js.ExecuteQuery(q);
                js.RiD.Read();

                if(js.RiD.HasRows)
                {
                    txtAddress1.Text = js.RiD["fldAddress1"].ToString();
                    txtAddress2.Text = js.RiD["fldAddress2"].ToString();
                    txtCity.Text = js.RiD["fldCity"].ToString();
                    txtZipCode.Text = js.RiD["fldZipCode"].ToString();
                }

                js.CloseConnection();

                //For Contact Details
                q = "SELECT * FROM tblContactDetails WHERE fldID='" + fldContactDetails + "'";
                js.ExecuteQuery(q);
                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    txtContactNo.Text = js.RiD["fldContactNumber"].ToString();
                }

                js.CloseConnection();

            }
        }