Exemplo n.º 1
0
        static public Request getItem()
        {
            Request r = new Request();

            try
            {
                MySqlDataReader rdr = new MySqlCommand("SELECT `id`,`steam_id`,`type`,`priority` FROM `queue` WHERE `id` IN (SELECT `queue_id` FROM `queue_status` WHERE `active`=1 AND `status`=" + (int)RequestStatus.Waiting + ") ORDER BY `priority` DESC, `id` ASC LIMIT 1", QueueConnection).ExecuteReader();
                while (rdr.Read())
                {
                    r.ID        = rdr.GetInt32(0);
                    r.User      = rdr.GetUInt64(1);
                    r.TradeType = (Bot.TradeTypes)rdr.GetInt32(2);
                    r.Priority  = rdr.GetInt32(3);
                }
                rdr.Close();
                r.Data = new string[Int32.Parse((new MySqlCommand("SELECT COUNT(`data`) FROM `queue_items` WHERE `queue_id`=" + r.ID, conn)).ExecuteScalar().ToString())];
                rdr    = (new MySqlCommand("SELECT `data` FROM `queue_items` WHERE `queue_id`=" + r.ID, conn)).ExecuteReader();
                int i = 0;
                while (rdr.Read())
                {
                    r.Data[i++] = rdr.GetString(0);
                }
                rdr.Close();
            }
            catch (Exception e)
            {
                log.Error("Error getting new request: " + e.Message);
            }

            return(r);
        }
Exemplo n.º 2
0
 public static Account GetAccountFromDb(string ndc)
 {
     Locker.EnterReadLock();
     try
     {
         Account         account    = null;
         string          query      = "SELECT * FROM Accounts WHERE Username = '******'";
         MySqlDataReader dataReader = new MySqlCommand(query, AuthDatabaseProvider.Connection).ExecuteReader();
         while (dataReader.Read())
         {
             account                    = new Account();
             account.Username           = ndc;
             account.Password           = dataReader["Password"].ToString();
             account.Nickname           = dataReader["Nickname"].ToString();
             account.Role               = (ServerRoleEnum)dataReader.GetInt32("Role");
             account.Id                 = dataReader.GetInt32("Id");
             account.Banned             = dataReader.GetBoolean("Banned");
             account.MaxCharactersCount = dataReader.GetInt32("MaxCharactersCount");
             account.PointsCount        = dataReader.GetInt32("PointCount");
         }
         dataReader.Close();
         return(account);
     }
     finally
     {
         Locker.ExitReadLock();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 查询某signal的所有KeyName
        /// </summary>
        /// <param name="Signal"></param>
        /// <param name="mycom"></param>
        /// <returns></returns>
        private List <CKeyName> SelectKeyNames(string Signal, MySqlConnection OpenedConn)
        {
            string          sql      = string.Format("select ID,KeyName,Odr from KeyTable where ExcelSignal='{0}' order by Odr", Signal);
            List <CKeyName> keyNames = null;
            //需要关闭
            MySqlDataReader reader = new MySqlCommand(sql, OpenedConn).ExecuteReader();

            try
            {
                if (reader.HasRows)
                {
                    keyNames = new List <CKeyName>();
                    while (reader.Read())
                    {
                        CKeyName one = new CKeyName();
                        one.Id      = reader.GetInt32(0);
                        one.KeyName = reader.GetString(1);
                        one.Odr     = reader.GetInt32(2);
                        keyNames.Add(one);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                reader.Close();
            }
            return(keyNames);
        }
Exemplo n.º 4
0
        internal static int GetPlayerData(string username, string key)
        {
            if (IsConnected())
            {
                MySqlDataReader rdr = new MySqlCommand($"SELECT * FROM player_data WHERE name = '{username}'", con).ExecuteReader();
                PlayerData      p   = new PlayerData();
                while (rdr.Read())
                {
                    p.name           = rdr.GetString(0);
                    p.wins           = rdr.GetInt32(1);
                    p.kills          = rdr.GetInt32(2);
                    p.deaths         = rdr.GetInt32(3);
                    p.tasksCompleted = rdr.GetInt32(4);
                }
                rdr.Close();
                switch (key)
                {
                case "wins":
                    return(p.wins);

                case "kills":
                    return(p.kills);

                case "deaths":
                    return(p.deaths);

                case "tasks":
                    return(p.tasksCompleted);
                }
            }
            return(-1);
        }
        public List <Tuoterivi> haeKaikki()
        {
            try {
                using (MySqlConnection yhteys = new MySqlConnection(this.YhteysAsetukset)) {
                    yhteys.Open();

                    string SqlLause = "SELECT * FROM tuoteluettelo";

                    MySqlDataReader tulokset = new MySqlCommand(SqlLause, yhteys).ExecuteReader();

                    List <Tuoterivi> apulista = new List <Tuoterivi>();

                    while (tulokset.Read())
                    {
                        Tuoterivi apu = new Tuoterivi();

                        apu.id             = tulokset.GetInt32("id");
                        apu.vari           = tulokset.GetString("vari");
                        apu.koko           = tulokset.GetString("koko");
                        apu.hinta          = tulokset.GetFloat("hinta");
                        apu.varastotilanne = tulokset.GetInt32("varastotilanne");
                        apu.kuva           = tulokset.GetInt32("kuva");
                        apulista.Add(apu);
                    }

                    return(apulista);
                }
            } catch (Exception e) {
                throw new Exception("Tietojen hakemisessa tietokannasta tapahtui virhe", e);
            }
        }
Exemplo n.º 6
0
Arquivo: DB.cs Projeto: Modem-i4/msg
 // 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());
     }
 }
Exemplo n.º 7
0
        private ExcelTable SelectExcelTable(String signal, MySqlConnection OpenedConn)
        {
            string          sql    = String.Format("select ID,CurrentFile,ExcelSignal,Total_hold,Diff_hold,History from ExcelTable where ExcelSignal = '{0}'", signal);
            MySqlDataReader reader = new MySqlCommand(sql, OpenedConn).ExecuteReader();
            ExcelTable      result = null;

            try
            {
                while (reader.Read())
                {
                    result             = new ExcelTable();
                    result.Id          = reader.GetInt32(0);
                    result.CurrentFile = reader.GetString(1);
                    result.Signal      = reader.GetString(2);
                    result.Total_hold  = reader.GetString(3);
                    result.Diff_hold   = reader.GetString(4);
                    result.History     = reader.GetString(5);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally {
                reader.Close();
            }
            return(result);
        }
Exemplo n.º 8
0
        public List <PayInfo> LoadPayInfo()
        {
            List <PayInfo>  list       = new List <PayInfo>();
            MySqlConnection connection = DAO.GetConnection();

            try
            {
                connection.Open();
                string          cmdText         = "SELECT * FROM pay_infos";
                MySqlDataReader mySqlDataReader = new MySqlCommand(cmdText, connection).ExecuteReader();
                while (mySqlDataReader.Read())
                {
                    string  @string = mySqlDataReader.GetString("account_name");
                    int     @int    = mySqlDataReader.GetInt32("day_pay");
                    PayInfo item    = new PayInfo(@string, @int);
                    list.Add(item);
                }
                mySqlDataReader.Close();
                return(list);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                log.Error((object)ex2.ToString());
                ProjectData.ClearProjectError();
                return(list);
            }
            finally
            {
                connection.Close();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// add file content record to DB
        /// </summary>
        /// <param name="content">content of the file to be written</param>
        /// <returns></returns>
        private int addFiles(String content)
        {
            int id = 0;

            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                using (MySqlDataReader dataReader = new MySqlCommand("SELECT MAX(id_files) FROM files", conn).ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        id = dataReader.GetInt32(0);
                    }
                }
                id++;
                using (MySqlCommand comm = conn.CreateCommand())
                {
                    comm.CommandText = "INSERT INTO files(id_files, content) VALUES(@id, @content)";
                    comm.Parameters.AddWithValue("@id", id);
                    comm.Parameters.AddWithValue("@content", content);
                    comm.ExecuteNonQuery();
                }
            }
            return(id);
        }
Exemplo n.º 10
0
        // Token: 0x060000F0 RID: 240 RVA: 0x000170E4 File Offset: 0x000152E4
        public async Task <bool> Load()
        {
            bool result2;

            using (MySqlConnection result = SQL.GetConnection().GetAwaiter().GetResult())
            {
                using (MySqlDataReader mySqlDataReader = new MySqlCommand("SELECT * FROM clans WHERE ID = '" + this.ID.ToString() + "'", result).ExecuteReader())
                {
                    if (!mySqlDataReader.HasRows)
                    {
                        mySqlDataReader.Close();
                        result2 = false;
                    }
                    else
                    {
                        mySqlDataReader.Read();
                        this.ID           = mySqlDataReader.GetInt64(0);
                        this.Name         = mySqlDataReader.GetString(1);
                        this.Description  = mySqlDataReader.GetString(2);
                        this.CreationTime = mySqlDataReader.GetInt64(3);
                        this.Points       = mySqlDataReader.GetInt32(4);
                        this.ClanMembers  = XElement.Parse(mySqlDataReader.GetString(5));
                        this.LeaderName   = mySqlDataReader.GetString(6);
                        mySqlDataReader.Close();
                        result2 = true;
                    }
                }
            }
            return(result2);
        }
Exemplo n.º 11
0
        public Dictionary <int, GameInfo> LoadGameservers()
        {
            Dictionary <int, GameInfo> dictionary = new Dictionary <int, GameInfo>();
            MySqlConnection            connection = DAO.GetConnection();

            try
            {
                connection.Open();
                string          cmdText         = "SELECT * FROM gameservers";
                MySqlDataReader mySqlDataReader = new MySqlCommand(cmdText, connection).ExecuteReader();
                while (mySqlDataReader.Read())
                {
                    int    @int    = mySqlDataReader.GetInt32("id");
                    string @string = mySqlDataReader.GetString("mask");
                    string string2 = mySqlDataReader.GetString("password");
                    dictionary.Add(@int, new GameInfo(@int, @string, string2));
                }
                mySqlDataReader.Close();
                return(dictionary);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                log.Error((object)ex2);
                ProjectData.ClearProjectError();
                return(dictionary);
            }
            finally
            {
                connection.Close();
            }
        }
Exemplo n.º 12
0
        public static Boolean AddAccountToUserObject(string email, string password)
        {
            try
            {
                User user = User.getInstance();

                MySqlConnection conn = new MySqlConnection(connectionString);

                conn.Open();

                string sql = "SELECT * FROM accounts WHERE acc_email= '" + email + "' AND acc_password='******';";

                MySqlDataReader rdr = new MySqlCommand(sql, conn).ExecuteReader();

                rdr.Read();

                user.SetEmail(rdr.GetString("acc_email"));

                user.setLoginStatus(true);

                user.SetID(rdr.GetInt32(0));

                conn.Close();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 13
0
        public List <Asiakas> HaeKaikkiAsiakkaat()
        {
            try
            {
                const string sqlLause = "SELECT * FROM asiakkaat;";

                var tulokset = new MySqlCommand(sqlLause, Yhteys).ExecuteReader();

                var asiakkaat = new List <Asiakas>();

                while (tulokset.Read())
                {
                    asiakkaat.Add(new Asiakas(tulokset.GetInt16("id"), tulokset.GetString("etunimi"),
                                              tulokset.GetString("sukunimi"),
                                              tulokset.GetString("sahkoposti"),
                                              tulokset.GetString("puh"),
                                              tulokset.GetString("katuosoite"),
                                              tulokset.GetInt32("postinumero"),
                                              tulokset.GetString("paikkakunta")));
                }

                return(asiakkaat);
            }
            catch (Exception e)
            {
                throw new Exception("Virhe asiakkaiden hakemisessa. ", e);
            }
        }
Exemplo n.º 14
0
        // Users

        static public Tuple <int, string, bool> Login(string username, string password)
        {
            var query = "select id, username, password, is_admin from users where username = '******' AND password = SHA2('" +
                        MySqlHelper.EscapeString(password) +
                        "', 256);";

            Tuple <int, string, bool> result = null;

            if (OpenConnection())
            {
                var reader = new MySqlCommand(query, connection).ExecuteReader();

                if (reader.Read())
                {
                    result = new Tuple <int, string, bool>(reader.GetInt32("id"), reader.GetString("username"), reader.GetBoolean("is_admin"));
                }

                reader.Close();
            }

            CloseConnection();
            return(result);
        }
Exemplo n.º 15
0
        public static bool AddQtty(string code, int qtty, MySqlConnection conn)
        {
            conn.Open();
            string          query1 = "SELECT * FROM Piece" + " WHERE " + "Code ='" + code + "'";
            MySqlDataReader reader = new MySqlCommand(query1, conn).ExecuteReader();
            int             stock  = 0;

            while (reader.Read())
            {
                stock = reader.GetInt32("Enstock");
            }
            reader.Close();
            int newStock = qtty + stock;

            Console.WriteLine("check new quantity");
            if (newStock >= 0)
            {
                Console.WriteLine("updating...");
                string           query2 = "UPDATE Piece SET Enstock = '" + newStock + "' WHERE Code ='" + code + "'";
                MySqlDataAdapter SDA    = new MySqlDataAdapter(query2, conn);
                SDA.SelectCommand.ExecuteNonQuery();
                conn.Close();
                return(true);
            }
            else
            {
                conn.Close();
                return(false);
            }
        }
Exemplo n.º 16
0
        private void FetchData()
        {
            try
            {
                var    P = new PoprawkaSQL();
                string SqlString;
                SqlString = P.SelectStudent(Settings.Default.IdSchool.ToString(), Settings.Default.SchoolYear);

                using (var R = new MySqlCommand(SqlString, conn).ExecuteReader())
                {
                    lstStudent.Clear();
                    while (R.Read())
                    {
                        lstStudent.Add(new MakeUp
                        {
                            StudentID    = R.GetInt32("IdStudent"),
                            StudentName  = R.GetString("Student"),
                            StudentClass = R.GetString("Klasa"),
                            SubjectName  = R.GetString("Przedmiot"),
                            TeacherName  = R.GetString("Nauczyciel")
                        });
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 17
0
 internal static PlayerData GetPlayerData(string username)
 {
     if (IsConnected())
     {
         MySqlDataReader rdr = new MySqlCommand($"SELECT * FROM player_data WHERE name = '{username}'", con).ExecuteReader();
         PlayerData      p   = new PlayerData();
         while (rdr.Read())
         {
             p.name           = rdr.GetString(0);
             p.wins           = rdr.GetInt32(1);
             p.kills          = rdr.GetInt32(2);
             p.deaths         = rdr.GetInt32(3);
             p.tasksCompleted = rdr.GetInt32(4);
         }
         rdr.Close();
         return(p);
     }
     return(null);
 }
Exemplo n.º 18
0
Arquivo: DB.cs Projeto: Ouzx/Alfa-Vega
        /// <summary>
        /// İstenilen tablodan ID ve Name'i çeker.
        /// </summary>
        public void GetAll(string _table, Selected.Mode mode)
        {
            string cmd = "SELECT ID, NAME FROM " + _table;

            Connect();
            using (MySqlDataReader reader = new MySqlCommand(cmd, connection).ExecuteReader())
            {
                switch (mode)
                {
                case Selected.Mode.Name:
                    Selected.NameInt.Clear();
                    Selected.NameName.Clear();
                    while (reader.Read())
                    {
                        Selected.NameInt.Add(reader.GetInt32(0));
                        Selected.NameName.Add(reader.GetString(1));
                    }
                    break;

                case Selected.Mode.Type:
                    Selected.TypeInt.Clear();
                    Selected.TypeName.Clear();
                    while (reader.Read())
                    {
                        Selected.TypeInt.Add(reader.GetInt32(0));
                        Selected.TypeName.Add(reader.GetString(1));
                    }
                    break;

                case Selected.Mode.Owner:
                    Selected.OwnerInt.Clear();
                    Selected.OwnerName.Clear();
                    while (reader.Read())
                    {
                        Selected.OwnerInt.Add(reader.GetInt32(0));
                        Selected.OwnerName.Add(reader.GetString(1));
                    }
                    break;
                }
            }
            Disconnect();
        }
Exemplo n.º 19
0
Arquivo: DB.cs Projeto: Modem-i4/msg
 // AUTH end //
 // LOAD CHATS //
 public Chat[] LoadChats()
 {
     using (MySqlConnection conn = new MySqlConnection(connStr))
     {
         conn.Open();
         var         reader = new MySqlCommand($"SELECT max(msg.time) AS time, chat.chat_id, chat.chat_name, chat.new_msgs FROM `chat` INNER JOIN `msg` ON chat.chat_id = msg.chat_id WHERE (user_id = {UserId}) GROUP BY chat.chat_id ORDER BY time DESC", conn).ExecuteReader();
         List <Chat> chats  = new List <Chat>();
         while (reader.Read())
         {
             chats.Add(new Chat(reader.GetInt32("chat_id"), reader.GetString("chat_name"), reader.GetInt32("new_msgs"), this));
         }
         reader.Close();
         return(chats.ToArray());
     }
 }
Exemplo n.º 20
0
Arquivo: DB.cs Projeto: Ouzx/Alfa-Vega
        /// <summary>
        /// İstenilen tablonun toplam sütun sayısını döndürür.
        /// </summary>
        /// <param name="_table">tablo</param>
        /// <returns></returns>
        public int GetColumnCount(string _table)
        {
            int    i = 0;
            string s = "SELECT count(*) FROM information_schema.columns WHERE table_name = '" + _table + "'";

            Connect();
            using (MySqlDataReader reader = new MySqlCommand(s, connection).ExecuteReader())
            {
                if (reader.Read())
                {
                    i = reader.GetInt32(0);
                }
            }
            Disconnect();
            return(i);
        }
Exemplo n.º 21
0
            internal static List <int> GetIDs(int AccountNumber)
            {
                List <int> IDs          = new List <int>();
                var        ResultReader = new MySqlCommand($"select UserCharacterID FROM usercharacter WHERE UserAccountID = {AccountNumber}")
                {
                    Connection = Connection
                }.ExecuteReader();

                while (ResultReader.Read())
                {
                    IDs.Add(ResultReader.GetInt32(0)); //The 0 here is an Ordinal
                }
                ResultReader.Close();

                return(IDs);
            }
Exemplo n.º 22
0
Arquivo: DB.cs Projeto: Modem-i4/msg
 // ADD CHAT //
 public Users[] LoadUsers(String search, int[] selectedUsers)
 {
     using (MySqlConnection conn = new MySqlConnection(connStr))
     {
         conn.Open();
         var          reader = new MySqlCommand($"SELECT id, login FROM `user` WHERE (login LIKE '%{search}%' AND id != 0 AND id != {UserId})", conn).ExecuteReader();
         List <Users> users  = new List <Users>();
         while (reader.Read())
         {
             int id = reader.GetInt32("id");
             var c  = new Users(id, reader.GetString("login"), selectedUsers.Contains(id));
             users.Add(c);
         }
         reader.Close();
         return(users.ToArray());
     }
 }
Exemplo n.º 23
0
        /// <summary>
        /// Hakee tietokannassa olevat varaukset. Palauttaa listan Varaus-objekteja.
        /// </summary>
        /// <returns></returns>
        public List <Varaus> HaeKaikkiVaraukset()
        {
            try
            {
                const string sqlLause = "SELECT varaukset.id, varaukset.asiakasID, asiakkaat.etunimi, asiakkaat.sukunimi, asiakkaat.sahkoposti, asiakkaat.puh, asiakkaat.katuosoite, asiakkaat.postinumero, asiakkaat.paikkakunta, varaukset.tilaID, tilat.nimi, tilat.katuosoite, tilat.paikkakunta, tilat.rakennus, tilat.varustus, tilat.kapasiteetti, tilat.hinta, varaukset.aloituspvm, varaukset.lopetuspvm, varaukset.maksutapa, varaukset.summa, varaukset.henkilomaara, varaukset.lisapalvelut FROM varaukset JOIN asiakkaat ON varaukset.asiakasID = asiakkaat.id JOIN tilat ON varaukset.tilaID = tilat.id ORDER BY varaukset.aloituspvm DESC;";

                var tulokset = new MySqlCommand(sqlLause, Yhteys).ExecuteReader();

                var varaukset = new List <Varaus>();

                while (tulokset.Read())
                {
                    varaukset.Add(new Varaus(
                                      tulokset.GetInt32("id"),
                                      new Asiakas(tulokset.GetString("etunimi"),
                                                  tulokset.GetString("sukunimi"),
                                                  tulokset.GetString("sahkoposti"),
                                                  tulokset.GetString("puh"),
                                                  tulokset.GetString("katuosoite"),
                                                  tulokset.GetInt32("postinumero"),
                                                  tulokset.GetString("paikkakunta")),
                                      new Tila(tulokset.GetInt32("tilaID"),
                                               tulokset.GetString("nimi"),
                                               tulokset.GetString("katuosoite"),
                                               tulokset.GetString("paikkakunta"),
                                               tulokset.GetString("rakennus"),
                                               tulokset.GetString("varustus"),
                                               tulokset.GetInt32("kapasiteetti"),
                                               tulokset.GetInt32("hinta")),
                                      tulokset.GetInt64("aloituspvm"),
                                      tulokset.GetInt64("lopetuspvm"),
                                      tulokset.GetString("maksutapa"),
                                      tulokset.GetInt32("summa"),
                                      tulokset.GetInt32("henkilomaara"),
                                      tulokset.GetString("lisapalvelut")));
                }

                tulokset.Close();

                return(varaukset);
            }
            catch (Exception e)
            {
                throw new Exception("Virhe varausten hakemisessa. ", e);
            }
        }
Exemplo n.º 24
0
Arquivo: DB.cs Projeto: Ouzx/Alfa-Vega
        /// <summary>
        /// En son satırdaki id'yi döndürür.
        /// </summary>
        /// <param name="_table">İlgili tablo</param>
        /// <returns></returns>
        public int GetLastID(string _table)
        {
            int    i = -1;
            string s = "SELECT MAX(ID) FROM " + _table;

            Connect();
            using (MySqlDataReader reader = new MySqlCommand(s, connection).ExecuteReader())
            {
                if (reader.Read())
                {
                    if (!reader.IsDBNull(0))
                    {
                        i = reader.GetInt32(0);
                    }
                }
            }
            Disconnect();
            return(i);
        }
Exemplo n.º 25
0
        public Note FindByTime(string time)
        {
            Note note = null;

            try
            {
                string          sql     = "select * from `note` where `time`='" + time + "';";
                MySqlDataReader reader  = new MySqlCommand(sql, conn).ExecuteReader();
                int             id      = reader.GetInt32("id");
                string          title   = reader.GetString("title");
                string          context = reader.GetString("context");
                string          time1   = reader.GetString("time");
                note = new Note(id, title, context, time);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(note);
        }
Exemplo n.º 26
0
Arquivo: DB.cs Projeto: Ouzx/Alfa-Vega
        /// <summary>
        /// Vega'ların bağlılık sistemi diğer birimlerden farklı olduğu için;
        /// tüm bağlılıklardan ayrı ayrı ve senksron bir şekilde veri çekmek gerekiyordu.
        /// Metot şu şekilde çalışıyor.
        /// Her bağlılık biriminin enum karşılığı alınıp(örn: 3 olsun) => Çekilen id'ye eklenir. 30005 gibi.
        /// </summary>
        public void GetVEGA()
        {
            Connect();
            for (int i = 0; i < 6; i++)
            {
                string s   = ((Settings.Unit)i).ToString();
                string cmd = "SELECT ID, NAME FROM " + s;
                using (MySqlDataReader reader = new MySqlCommand(cmd, connection).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        //string tempp = reader.GetInt32(0).ToString(i.ToString() + "0000");
                        Selected.OwnerInt.Add(Convert.ToInt32(reader.GetInt32(0).ToString(i.ToString() + "0000")));
                        Selected.OwnerName.Add(reader.GetString(1));
                    }
                }
            }

            Disconnect();
        }
Exemplo n.º 27
0
 public void Load()
 {
     using (MySqlDataReader mySqlDataReader = new MySqlCommand(string.Format("SELECT * FROM clans WHERE ID='{0}';", (object)this.ID), SQL.Handler).ExecuteReader())
     {
         mySqlDataReader.Read();
         if (!mySqlDataReader.HasRows)
         {
             return;
         }
         try
         {
             this.Name        = mySqlDataReader.GetString(1);
             this.Description = mySqlDataReader.GetString(2);
             this.Points      = mySqlDataReader.GetInt32(4);
             XDocument xdocument = XDocument.Parse(mySqlDataReader.GetString(5));
             this.ClanInfo.LoadXml(xdocument.ToString());
             foreach (XmlNode childNode in this.ClanInfo["clan_members"].ChildNodes)
             {
                 this.ProfileIds.Add(long.Parse(childNode.Attributes["profile_id"].InnerText));
             }
             XmlDocument xmlDocument1 = new XmlDocument();
             XDocument.Parse(mySqlDataReader.GetString(6));
             string xml = xdocument.ToString();
             xmlDocument1.LoadXml(xml);
             XmlDocument xmlDocument2 = new XmlDocument();
             xmlDocument2.LoadXml(mySqlDataReader.GetString(6));
             this.MasterBadge  = int.Parse(xmlDocument2["master"].Attributes["master_badge"].InnerText);
             this.MasterMark   = int.Parse(xmlDocument2["master"].Attributes["master_mark"].InnerText);
             this.MasterStripe = int.Parse(xmlDocument2["master"].Attributes["master_stripe"].InnerText);
             this.MasterNick   = xmlDocument2["master"].Attributes["nick"].InnerText;
         }
         catch
         {
         }
     }
 }
Exemplo n.º 28
0
        private void FetchData()
        {
            try
            {
                var    S = new StatystykaSQL();
                string SqlString;
                SqlString  = S.SelectObsada(Settings.Default.IdSchool.ToString(), Settings.Default.SchoolYear, rbOkres.Tag.ToString() == "S"?EndOfSemester:EndOfSchoolYear);
                SqlString += S.SelectLiczbaOcen(Settings.Default.IdSchool.ToString(), Settings.Default.SchoolYear, rbOkres.Tag.ToString());
                SqlString += S.SelectStanKlasy(Settings.Default.IdSchool.ToString(), Settings.Default.SchoolYear, rbOkres.Tag.ToString() == "S" ? EndOfSemester : EndOfSchoolYear);
                SqlString += S.SelectStanKlasyWirtualnej(Settings.Default.IdSchool.ToString(), Settings.Default.SchoolYear, rbOkres.Tag.ToString() == "S" ? EndOfSemester : EndOfSchoolYear);
                SqlString += S.CountGroupMember(Settings.Default.IdSchool.ToString(), Settings.Default.SchoolYear);

                using (var R = new MySqlCommand(SqlString, conn).ExecuteReader())
                {
                    lstObsada.Clear();
                    while (R.Read())
                    {
                        lstObsada.Add(new SubjectStaff {
                            Class = new StaffUnit {
                                ID = R.GetInt32("Klasa"), Nazwa = R.GetString("Nazwa_Klasy")
                            },
                            Subject = new SubjectUnit {
                                ID = R.GetInt32("IdPrzedmiot"), Nazwa = R.GetString("Przedmiot"), IdSzkolaPrzedmiot = R.GetInt32("IdSzkolaPrzedmiot")
                            },
                            Teacher = new StaffUnit {
                                ID = R.GetInt32("IdNauczyciel"), Nazwa = R.GetString("Nauczyciel")
                            }, IsVirtual = R.GetBoolean("Virtual")
                        }
                                      );
                    }
                    R.NextResult();

                    lstLiczbaOcen.Clear();
                    while (R.Read())
                    {
                        lstLiczbaOcen.Add(new ScoreInfo {
                            ScoreCount = R.GetInt32("LiczbaOcen"), ScoreWeight = (int)R.GetFloat("Waga"), ClassID = R.GetInt32("Klasa"), SubjectID = R.GetInt32("IdPrzedmiot"), TeacherID = R.GetInt32("Nauczyciel")
                        });
                    }
                    R.NextResult();

                    lstLiczbaUczniow.Clear();
                    while (R.Read())
                    {
                        lstLiczbaUczniow.Add(new StudentCount {
                            ClassID = R.GetInt32("Klasa"), Count = R.GetInt32("StanKlasy")
                        });
                    }
                    R.NextResult();

                    lstLiczbaUczniowNI.Clear();
                    while (R.Read())
                    {
                        lstLiczbaUczniowNI.Add(new VirtualStudentCount {
                            ClassID = R.GetInt32("Klasa"), Count = R.GetInt32("StanKlasy"), SubjectID = R.GetInt32("IdPrzedmiot"), VirtualClassID = R.GetInt32("KlasaWirtualna")
                        });
                    }
                    R.NextResult();

                    lstLiczbaUczniowGrupa.Clear();
                    while (R.Read())
                    {
                        lstLiczbaUczniowGrupa.Add(new SubjectGroupCount {
                            ClassID = R.GetInt32("Klasa"), Count = R.GetInt32("StanGrupy"), SubjectID = R.GetInt32("IdPrzedmiot"), SubjectIdBySchool = R.GetInt32("IdSzkolaPrzedmiot")
                        });
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 29
0
        internal override void Process()
        {
            using (MySqlDataReader mySqlDataReader = new MySqlCommand("SELECT * FROM clans WHERE ID='55';", SQL.Handler).ExecuteReader())
            {
                mySqlDataReader.Read();
                if (mySqlDataReader.HasRows)
                {
                    try
                    {
                        this.Name        = mySqlDataReader.GetString(1);
                        this.Description = mySqlDataReader.GetString(2);
                        this.Points      = mySqlDataReader.GetInt32(4);
                        XDocument xdocument = XDocument.Parse(mySqlDataReader.GetString(5));
                        this.ClanInfo.LoadXml(xdocument.ToString());
                        foreach (XmlNode childNode in this.ClanInfo["clan_members"].ChildNodes)
                        {
                            this.ProfileIds.Add(long.Parse(childNode.Attributes["profile_id"].InnerText));
                        }
                        XmlDocument xmlDocument1 = new XmlDocument();
                        XDocument.Parse(mySqlDataReader.GetString(6));
                        xmlDocument1.LoadXml(xdocument.ToString());
                        XmlDocument xmlDocument2 = new XmlDocument();
                        xmlDocument2.LoadXml(mySqlDataReader.GetString(6));
                        this.MasterBadge  = int.Parse(xmlDocument2["master"].Attributes["master_badge"].InnerText);
                        this.MasterMark   = int.Parse(xmlDocument2["master"].Attributes["master_mark"].InnerText);
                        this.MasterStripe = int.Parse(xmlDocument2["master"].Attributes["master_stripe"].InnerText);
                        this.MasterNick   = xmlDocument2["master"].Attributes["nick"].InnerText;
                        this.Profileid    = int.Parse(xmlDocument1["clan_member_info"].Attributes["profile_id"].InnerText);
                        this.ClanRole     = int.Parse(xmlDocument1["clan_member_info"].Attributes["clan_role"].InnerText);
                    }
                    catch
                    {
                    }
                }
            }
            XDocument xdocument1 = new XDocument();
            XElement  xelement1  = new XElement((XName)"iq");

            xelement1.Add((object)new XAttribute((XName)"type", this.Type == "get" ? (object)"result" : (object)"get"));
            xelement1.Add((object)new XAttribute((XName)"from", (object)"k01.warface"));
            xelement1.Add((object)new XAttribute((XName)"to", (object)this.User.JID));
            xelement1.Add((object)new XAttribute((XName)"id", this.Type == "get" ? (object)this.Id : (object)("uid" + this.User.Player.Random.Next(9999, int.MaxValue).ToString("x8"))));
            XElement xelement2 = new XElement(Stanza.NameSpace + "query");
            XElement xelement3 = new XElement((XName)"clan_info");
            XElement xelement4 = new XElement((XName)"clan");

            try
            {
                xelement4.Add((object)new XAttribute((XName)"name", (object)this.Name));
                xelement4.Add((object)new XAttribute((XName)"description", (object)this.Description));
                xelement4.Add((object)new XAttribute((XName)"clan_id", (object)"1"));
                xelement4.Add((object)new XAttribute((XName)"creation_date", (object)this.CreationTime));
                xelement4.Add((object)new XAttribute((XName)"leaderboard_position", (object)"1"));
                xelement4.Add((object)new XAttribute((XName)"master_badge", (object)this.MasterBadge));
                xelement4.Add((object)new XAttribute((XName)"master_stripe", (object)this.MasterStripe));
                xelement4.Add((object)new XAttribute((XName)"master_mark", (object)this.MasterMark));
                xelement4.Add((object)new XAttribute((XName)"clan_points", (object)"0"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            XElement xelement5 = new XElement((XName)"clan_member_info");

            xelement5.Add((object)new XAttribute((XName)"nickname", (object)this.MasterNick));
            xelement5.Add((object)new XAttribute((XName)"profile_id", (object)"1"));
            xelement5.Add((object)new XAttribute((XName)"experience", (object)"413979"));
            xelement5.Add((object)new XAttribute((XName)"jid", (object)this.User.JID));
            xelement5.Add((object)new XAttribute((XName)"clan_points", (object)"0"));
            xelement5.Add((object)new XAttribute((XName)"invite_date", (object)"1556976988"));
            xelement5.Add((object)new XAttribute((XName)"clan_role", (object)this.ClanRole));
            xelement5.Add((object)new XAttribute((XName)"status", (object)"9"));
            xelement4.Add((object)xelement5);
            xelement3.Add((object)xelement4);
            xelement2.Add((object)xelement3);
            xelement1.Add((object)xelement2);
            xdocument1.Add((object)xelement1);
            this.User.Send(xdocument1.ToString(SaveOptions.DisableFormatting));
        }
Exemplo n.º 30
0
        internal bool CheckIfTable(Type t)
        {
            string sqlCommandStr = "CREATE TABLE IF NOT EXISTS " + t.Name + "(";

            int SQLColumnCount = 0;

            foreach (var interfaceType in t.GetInterfaces())
            {
                if (interfaceType == typeof(DTable))
                {
                    #region Check Old Table Feature  -> set SQLColumnCount

                    string sql = "SELECT COUNT(*) FROM information_schema. COLUMNS WHERE table_schema = \'" +
                                 this.DbName + "\' AND table_name = \'" + t.Name + "\'";

                    try
                    {
                        mc.Open();

                        MySqlDataReader reader = new MySqlCommand(sql, mc).ExecuteReader();

                        while (reader.Read())
                        {
                            if (reader.HasRows)
                            {
                                SQLColumnCount = reader.GetInt32("count(*)");
                            }
                        }

                        //Console.Write(SQLColumnCount.ToString());

                        mc.Close();
                    }
                    catch (Exception e)
                    {
                        Console.Write(e.Message);

                        mc.Close();
                    }

                    #endregion

                    #region delete table if update needed

                    FieldInfo[] fields = t.GetFields();      //get Fields

                    if (fields.Length != SQLColumnCount)     // 如果存在不同版本 个人版是直接删除 高级版才是alter表 个人版可以手动做
                    {
                        //string deleteSql = "drop TABLE " + t.Name;

                        string backUpSql = "RENAME TABLE " + t.Name + " TO " + (t.Name + DateTime.Now.ToFileTime().ToString()) + ";";

                        try
                        {
                            if (this.rewriteTable)
                            {
                                if (SQLColumnCount != 0)
                                {
                                    Console.Write("Backup old Table : " + t.Name);

                                    mc.Open();

                                    new MySqlCommand(backUpSql, mc).ExecuteNonQuery();

                                    mc.Close();
                                }

                                Console.Write("Create the Table : " + t.Name);
                            }
                            else
                            {
                                Console.Write("Cannot Create Table : " + t.Name + "\nTable Name is alreally exist, And rewriteTable Function is not Actived", 0);
                            }
                        }
                        //catch (Exception e)
                        catch
                        {
                            //Console.Write("Cannot delete old Table " + t.Name + " ERROR:" + e.Message + " at:" + this.GetType().FullName, 3306);

                            Console.Write("Create the Table : " + t.Name);

                            mc.Close();
                        }
                    }
                    else
                    {
                        Console.Write("Table no changed : " + t.Name);

                        return(false);
                    }

                    #endregion

                    #region Create Table

                    foreach (FieldInfo fieldItem in fields)
                    {
                        #region Create SQL Phrase

                        sqlCommandStr = sqlCommandStr +
                                        fieldItem.Name;

                        #region check if custom type

                        bool isCustomType = false;

                        string customType = "";

                        foreach (var feature in fieldItem.GetCustomAttributes())
                        {
                            if (feature is CustomTypeAttribute)
                            {
                                isCustomType = true;

                                customType = ((CustomTypeAttribute)feature).type;
                            }
                        }

                        if (isCustomType && customType != "")
                        {
                            sqlCommandStr = sqlCommandStr + customType;
                        }
                        else
                        {
                            sqlCommandStr = sqlCommandStr + TypeMapping.GetSqlType(fieldItem.FieldType);
                        }

                        #endregion

                        foreach (var feature in fieldItem.GetCustomAttributes())
                        {
                            if (feature is IsPrimaryKeyAttribute)
                            {
                                sqlCommandStr = sqlCommandStr + DM_Strings.primaryKey;

                                if (((IsPrimaryKeyAttribute)feature).isAutoIncrement)
                                {
                                    sqlCommandStr = sqlCommandStr + DM_Strings.auto_Increment;
                                }
                            }

                            if (feature is ColumeFeaturesAttribute)
                            {
                                sqlCommandStr = sqlCommandStr + ((ColumeFeaturesAttribute)feature).Value;
                            }
                        }

                        sqlCommandStr = sqlCommandStr + ",";

                        #endregion
                    }

                    #region format sql phrase

                    sqlCommandStr = sqlCommandStr.Substring(0, sqlCommandStr.Length - 1);

                    sqlCommandStr = sqlCommandStr + ");";

                    #endregion

                    #region execute sql phrase

                    try
                    {
                        mc.Open();

                        //Console.Write("************" + sqlCommandStr);

                        new MySqlCommand(sqlCommandStr, mc).ExecuteNonQuery();

                        mc.Close();

                        return(true);
                    }
                    catch (Exception e)
                    {
                        Console.Write("Cannot check or create Table " + t.Name + " ERROR:" + e.Message + " at:" + this.GetType().FullName, 3306);
                    }

                    #endregion

                    #endregion
                }
            }

            return(false);
        }