public List<Visitor> GetAllZoneVisitorNumber(int zoneVisitorNumberId)
        {
            SqlConnection connection = new SqlConnection(databaseConString);
            string query = "SELECT * FROM tbl_visitor WHERE visitor_zoneId LIKE '%" + zoneVisitorNumberId + "%'";
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            List<Visitor> visitorList = new List<Visitor>();

            while (reader.Read())
            {
                Visitor visitors = new Visitor();
                visitors.VisitorId = int.Parse(reader["visitor_id"].ToString());
                visitors.VisitorName = reader["visitor_name"].ToString();
                visitors.VisitorEmail = reader["visitor_email"].ToString();
                visitors.ContactNumber = reader["visitor_contactNo"].ToString();

                visitorList.Add(visitors);
            }
            reader.Close();
            connection.Close();

            return visitorList;
        }
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (visitorNameTextBox.Text == "" || visitorEmailTextBox.Text == "" || contactNumberTextBox.Text == "")
            {
                MessageBox.Show("All fields are required!");
            }

            else
            {
                Visitor visitors = new Visitor();

                visitors.VisitorName = visitorNameTextBox.Text;
                visitors.VisitorEmail = visitorEmailTextBox.Text;
                visitors.ContactNumber = contactNumberTextBox.Text;

                string selectZoneId = "";
                foreach (Zone item in zoneCheckedListBox.CheckedItems)
                {
                    selectZoneId += item.ZoneId.ToString() + ",";
                }

                visitors.VisitorZoneId = selectZoneId;

                MessageBox.Show(visitorEntryManager.Save(visitors));
            }
        }
        public Visitor GetVisitorEmail(string visitorEmail)
        {
            SqlConnection connection = new SqlConnection(databaseConString);
            string query = "SELECT * FROM tbl_visitor WHERE visitor_email = '" + visitorEmail + "'";
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            Visitor visitors = null;

            while (reader.Read())
            {
                if (visitors == null)
                {
                    visitors = new Visitor();
                }
                visitors.VisitorId = int.Parse(reader["visitor_id"].ToString());
                visitors.VisitorEmail = reader["visitor_email"].ToString();
            }
            reader.Close();
            connection.Close();

            return visitors;
        }
        public int Insert(Visitor visitors)
        {
            SqlConnection connection = new SqlConnection(databaseConString);
            string query = "INSERT INTO tbl_visitor VALUES ('" + visitors.VisitorName + "','" + visitors.VisitorEmail +
                           "','" + visitors.ContactNumber + "','" + visitors.VisitorZoneId + "')";
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            int rowAffected = command.ExecuteNonQuery();
            connection.Close();

            return rowAffected;
        }
 public string Save(Visitor visitors)
 {
     bool checkVisitorEmail = IsCheckVisitorEmail(visitors.VisitorEmail);
     if (checkVisitorEmail)
     {
         return "Email Allready Exists!";
     }
     if (visitorEntryGateway.Insert(visitors) > 0)
     {
         return "Added Successfully!";
     }
     else
     {
         return "Could Not Added";
     }
 }