示例#1
0
 private void btnSearchVisitor_Click(object sender, EventArgs e)
 {
     if (this.cmbxSearchType.SelectedItem != null && this.tbSearchVisitorText.Text != "")
     {
         // searchs for a correct visitor
         myVisitor = myDBHelper.getVisitorData((StatusTypes.SearchType) this.cmbxSearchType.SelectedItem, this.tbSearchVisitorText.Text);
         if (myVisitor != null)
         {
             // replaced by a method
             UpdateVisitorInfo();
             this.lbSearchLog.Items.Insert(0, System.DateTime.Now + " Search found visitor " + this.myVisitor.FirstName + " " + this.myVisitor.LastName);
             this.gbVisitorInfo.Enabled = true;
             this.gbPayments.Enabled    = true;
         }
         else
         {
             this.lbSearchLog.Items.Insert(0, System.DateTime.Now + " Search returned no visitors");
             this.gbPayments.Enabled    = false;
             this.gbVisitorInfo.Enabled = false;
             this.lbPaymentLog.Items.Clear();
         }
     }
     else
     {
         this.lbSearchLog.Items.Insert(0, System.DateTime.Now + " Search unsuccessful");
         this.gbPayments.Enabled    = false;
         this.gbVisitorInfo.Enabled = false;
         this.lbPaymentLog.Items.Clear();
     }
 }
示例#2
0
        /// <summary>
        /// Returns the whole data container for the visitor retrieved by the specified attribute-value pair
        /// If no such visitor is found, returns null
        /// </summary>
        /// <param name="whereClauseAttribute"></param>
        /// <param name="whereClauseValue"></param>
        /// <returns></returns>
        public VisitorData getVisitorData(StatusTypes.SearchType searchAttribute, string whereClauseValue)
        {
            // returns null if there no such email
            VisitorData valueToReturn = null;

            // removing the whitespaces from user input
            whereClauseValue = RemoveWhiteSpaces(whereClauseValue);
            string whereClauseAttribute = searchAttribute.ToString();

            // We need to think of some ways to prevent the sql injections and other messed up user entries
            String sql = "SELECT USER_ID, EMAIL, FNAME, LNAME, SECCODE, BRACELET_ID, STATUS FROM VISITORS WHERE UPPER("
                         + whereClauseAttribute + ") =" + " UPPER(\"" + whereClauseValue + "\")";
            MySqlCommand command = new MySqlCommand(sql, connection);


            try
            {
                connection.Open();
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    // should create a new instance of a DataContainer with retrieved values
                    if (reader["EMAIL"] != DBNull.Value)
                    {
                        string chipNum = "";
                        if (reader["BRACELET_ID"] == DBNull.Value)
                        {
                            chipNum = "NULL";
                        }
                        else
                        {
                            chipNum = (string)reader["BRACELET_ID"];
                        }
                        string seccode = "";
                        if (reader["SECCODE"] == DBNull.Value)
                        {
                            seccode = "N/A";
                        }
                        else
                        {
                            seccode = (string)reader["SECCODE"];
                        }
                        valueToReturn = new VisitorData((int)reader["USER_ID"], (string)reader["EMAIL"], (string)reader["FNAME"], (string)reader["LNAME"],
                                                        seccode, chipNum, (int)reader["STATUS"]);
                    }
                }
            }
            catch (Exception ex)
            {
                AutoClosingMessageBox.Show(ex.ToString(), "Oups!", messageShowTime);
            }
            finally
            {
                connection.Close();
            }


            return(valueToReturn);
        }
示例#3
0
 /// <summary>
 /// Assigns a new bracelet to the visitor
 /// </summary>
 private void AssignVisBracelet()
 {
     // first we deactivate his old one
     this.DeactiveVisBracelet();
     //new method
     try
     {
         if (this.scannedRFID.RFIDNumber != this.myVisitor.ChipNumber &&
             (this.scannedRFID.Status == StatusTypes.BraceletStatus.STAND_BY || this.scannedRFID.Status == StatusTypes.BraceletStatus.NOT_VALID))
         {
             if (this.myDBHelper.UpdateVisitorBracelet(this.scannedRFID, this.myVisitor.Email))
             {
                 string email = this.myVisitor.Email;
                 myVisitor = myDBHelper.getVisitorData(StatusTypes.SearchType.EMAIL, email);
                 UpdateVisitorInfo();
                 // kinda bad to access it directly, but alright for now
                 this.scannedRFID.Status       = StatusTypes.BraceletStatus.ACTIVE;
                 this.tbScannedRFIDStatus.Text = this.scannedRFID.Status.ToString();
                 this.lbActivityLog.Items.Insert(0, ">> Sucessfully Assigned");
                 this.lbReaderLog.Items.Insert(0, ">> Sucessfully Assigned");
             }
             else
             {
                 lbReaderLog.Items.Insert(0, "<< Could not assign");
             }
         }
         else
         {
             AutoClosingMessageBox.Show("This Bracelet can not be assigned, please scan a new one!", "NOT A VALID BRACELET", 1000);
             lbReaderLog.Items.Insert(0, "<< Tried to assign a not-valid bracelet");
         }
     }
     catch
     {
         AutoClosingMessageBox.Show("Something went wrong", "NOT A VALID BRACELET", 1000);
         lbReaderLog.Items.Insert(0, "<< Operation abort");
     }
 }