Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="TextQuery"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public bool ExecuteWithRead(string TextQuery, out DataTable result)
        {
            result = new DataTable();
            if (!ExecuteQuery(QueryParser(TextQuery)))
            {
                return(false);
            }
            for (int i = 0; i < MyReader.FieldCount; i++)
            {
                result.Columns.Add(MyReader.GetName(i), MyReader.GetFieldType(i));
            }

            while (MyReader.Read())
            {
                DataRow dr = result.NewRow();
                for (int col = 0; col < MyReader.FieldCount; col++)
                {
                    dr[col] = MyReader.GetValue(col);
                }
                result.Rows.Add(dr);
            }
            MyReader.Close();

            return(true);
        }
Beispiel #2
0
        } // Обратная совместимость

        /// <summary>
        /// Возвращает просто конкретное значение без всякой таблицы
        /// </summary>
        /// <param name="TextQuery"></param>
        /// <returns></returns>
        public object ExecuteScalar(string TextQuery)
        {
            if (!ExecuteQuery(QueryParser(TextQuery)))
            {
                throw new TransportExcception(ExcStr);
            }
            object result = null;

            if (MyReader.Read())
            {
                result = MyReader.GetValue(0);
            }
            MyReader.Close();
            return(result);
        } // ExecuteScalar
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="TextQuery"></param>
        /// <param name="result"></param>
        public void ExecuteWithReadNew(string TextQuery, out DataTable result)
        {
            result = new DataTable();
            if (!ExecuteQuery(QueryParser(TextQuery)))
            {
                throw new TransportExcception(ExcStr);
            }
            for (int i = 0; i < MyReader.FieldCount; i++)
            {
                result.Columns.Add(MyReader.GetName(i), MyReader.GetFieldType(i));
            }

            while (MyReader.Read())
            {
                DataRow dr = result.NewRow();
                for (int col = 0; col < MyReader.FieldCount; col++)
                {
                    dr[col] = MyReader.GetValue(col);
                }
                result.Rows.Add(dr);
            }
            MyReader.Close();
        } // Обратная совместимость
Beispiel #4
0
        private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender; //Our main port

            try
            {
                string id = sp.ReadLine(); //reading the date from arduino (TAG ID)

                string Query = "select name from users where name='" + id + "'";

                MySqlCommand    MyCommand = new MySqlCommand(Query, connection);
                MySqlDataReader MyReader;

                MyReader = MyCommand.ExecuteReader();     // Here our query will be executed
                if (MyReader.Read())
                {
                    if (id == MyReader.GetValue(0).ToString())
                    {                                      // if the id matches
                        MessageBox.Show("Access Granted ");
                        MyReader.Close();                  // mandatory to close the data reader associated with the connexion before going any further
                        sp.WriteLine("1");                 // telling the arduino to open the door
                        var    date        = DateTime.Now; // getting the time
                        string Queryinsert = "insert into log(id,name,date,hour) values('" + id + "','" + date.Date + "','" + date.Date + "','" + date.Hour + "');";

                        MySqlCommand MyCommandinsert = new MySqlCommand(Query, connection);

                        MyCommandinsert.ExecuteReader(); // Here our query will be executed and data saved into the database.
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }