Beispiel #1
0
 // LOAD MSGS //
 public Messages[] LoadMsgs(int chatId)
 {
     using (MySqlConnection conn = new MySqlConnection(connStr))
     {
         conn.Open();
         ChatId = chatId;
         var             reader = new MySqlCommand($"SELECT user.id, user.login, msg.id AS msg_id, msg.text, msg.time FROM `msg` INNER JOIN `user` ON (user.id = sender_id) WHERE (chat_id = {chatId})", conn).ExecuteReader();
         List <Messages> m      = new List <Messages>();
         while (reader.Read())
         {
             int      senderId    = reader.GetInt32("id");
             String   senderLogin = reader.GetString("login");
             String   msgText     = reader.GetString("text");
             DateTime time        = reader.GetDateTime("time");
             // setup data
             m.Add(displayNewDateIfRequired(time));
             // msgs
             if (senderId == UserId)
             {
                 m.Add(new Outbox(msgText, time.ToString("HH:mm:ss"), reader.GetInt32("msg_id"), this));
             }
             else if (senderId == 0)
             {
                 m.Add(new ChatInfo(msgText));
             }
             else
             {
                 m.Add(new Inbox(senderLogin, msgText, time.ToString("HH:mm:ss")));
             }
         }
         reader.Close();
         return(m.ToArray());
     }
 }
Beispiel #2
0
        public string Select_Date_Format_2(string query)
        {
            string str = "";

            if (this.OpenConnection())
            {
                MySqlDataReader reader = new MySqlCommand(query, this.connection).ExecuteReader();
                while (reader.Read())
                {
                    str = reader.GetDateTime(0).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
                }
                reader.Close();
                this.CloseConnection();
                return(str);
            }
            return(str);
        }
Beispiel #3
0
        public void LoadBanedIP(ref object banips)
        {
            MySqlConnection connection = DAO.GetConnection();

            try
            {
                connection.Open();
                string          cmdText         = "SELECT * FROM banned_ip";
                MySqlDataReader mySqlDataReader = new MySqlCommand(cmdText, connection).ExecuteReader();
                while (mySqlDataReader.Read())
                {
                    string   @string  = mySqlDataReader.GetString("mask");
                    DateTime dateTime = mySqlDataReader.GetDateTime("time_end");
                    object[] array;
                    bool[]   array2;
                    NewLateBinding.LateCall(banips, null, "Add", array = new object[2]
                    {
                        @string,
                        new BannedIP(@string, dateTime)
                    }, null, null, array2 = new bool[2]
                    {
                        true,
                        false
                    }, IgnoreReturn: true);
                    if (array2[0])
                    {
                        @string = (string)Conversions.ChangeType(RuntimeHelpers.GetObjectValue(array[0]), typeof(string));
                    }
                }
                mySqlDataReader.Close();
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                log.Error((object)ex2);
                ProjectData.ClearProjectError();
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #4
0
 public static void GetRequests(long id)
 {
     using (var connection = new MySqlConnection(ConnectionDB.Connection))
     {
         connection.Open();
         using (var reader = new MySqlCommand($"SELECT * FROM Requests WHERE IDEmpl = {id}", connection).ExecuteReader())
         {
             while (reader.Read())
             {
                 Application.Current.Dispatcher.Invoke(() => RequestsList.Add(
                                                           new URequest(reader.GetInt64("ID"), reader.GetString("Text"), reader.GetDateTime("Date"), reader.GetInt64("State").ToString(), SetBackGround(reader.GetInt64("State")))));
             }
         }
         connection.Close();
     }
 }