Пример #1
0
        /// <summary>
        /// Lấy dữ liệu từ file csv và thêm vào Database QRCode, Ngày, Kết quả
        /// </summary>
        /// <param name="options"></param>
        /// <param name="linearray"></param>
        private void ThemVaoDB(string options, string[] linearray)
        {
            Console.WriteLine("Them vao DB");
            string qrCode = "", dateTime = "", result = "";

            switch (options)
            {
            case "Left":
                qrCode   = linearray[2];
                dateTime = linearray[0];
                if (linearray[3] == "1")
                {
                    result = "true";
                }
                else
                {
                    result = "false";
                }
                break;

            case "Right":
                qrCode   = linearray[11];
                dateTime = linearray[9];
                if (linearray[12] == "1")
                {
                    result = "true";
                }
                else
                {
                    result = "false";
                }
                break;

            default:
                break;
            }

            // Khai bao Query
            MySqlConnection conn     = DBMySQLUtils.GetDBConnection();
            string          querySQL = $"insert into latus.kltechdb (QRCode,Datetime,Result) value ('{qrCode}','{dateTime}',{result});";
            //Console.WriteLine($"Query : {querySQL}");
            MySqlCommand    sqlCommand = new MySqlCommand(querySQL, conn);
            MySqlDataReader myReader;

            conn.Open();
            myReader = sqlCommand.ExecuteReader();
            while (myReader.Read())
            {
            }
            conn.Close();
        }
Пример #2
0
        /// <summary>
        /// Hàm trả về số lần lặp lại QRCode trong SQL
        /// </summary>
        /// <param name="QRInput"></param>
        /// <returns></returns>
        private int GetNumberQRCodeRepeat(string QRInput)
        {
            string          temp;
            int             count;
            MySqlConnection conn       = DBMySQLUtils.GetDBConnection();
            string          querySQL   = $"select count(*) from latus.kltechdb where QRCode='{QRInput}';";
            MySqlCommand    sqlCommand = new MySqlCommand(querySQL, conn);
            MySqlDataReader myReader;

            conn.Open();
            myReader = sqlCommand.ExecuteReader();
            while (myReader.Read())
            {
                count = int.Parse(myReader.GetString(0));
                Console.WriteLine(myReader.GetString(0));
                return(count);
            }
            conn.Close();
            return(0);
        }