public static List<SymbolModel> GetAllSymbols()
        {
            var symbolsList = new List<SymbolModel>();

            const string sql = "COMMIT; SELECT * FROM " + TblSymbols;
            MySqlDataReader reader = GetReader(sql);
            if (reader != null)
            {
                while (reader.Read())
                {
                    var symbol = new SymbolModel { SymbolId = reader.GetInt32(0), SymbolName = reader.GetString(1) };
                    symbolsList.Add(symbol);
                }

                reader.Close();
            }
            return symbolsList;
        }
        public static bool AddSymbolIntoGroup(int groupId, SymbolModel symbol)
        {
            var sql = "INSERT IGNORE INTO " + TblSymbolsInGroups
                    + " (`GroupID`, `SymbolID`, `SymbolName`)"
                    + "VALUES('" + groupId + "',"
                    + " '" + symbol.SymbolId + "',"
                    + " '" + symbol.SymbolName + "');COMMIT;";

            return DoSql(sql);
        }
        public static List<SymbolModel> GetSymbolsForUser(int userId)
        {
            var symbolsList = new List<SymbolModel>();
            MySqlDataReader reader=null;
            string sql = "SELECT * FROM " + TblSymbolsForUsers
                        + " LEFT JOIN " + TblSymbols
                        + " ON " + TblSymbolsForUsers + ".SymbolID = "
                        + TblSymbols + ".ID" + " WHERE " + TblSymbolsForUsers + ".UserID = '" + userId + "' AND " + TblSymbolsForUsers + ".TNorDN = false ; COMMIT;";
            try
            {

                reader = GetReader(sql);
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        var symbol = new SymbolModel {SymbolId = reader.GetInt32(4), SymbolName = reader.GetString(5)};
                        symbolsList.Add(symbol);
                    }

                    reader.Close();
                }
            }
            finally
            {
                if (reader != null) reader.Close();
            }

            return symbolsList;
        }
        public static List<SymbolModel> GetSymbolsInGroup(int groupId)
        {
            var symbolsList = new List<SymbolModel>();

            string sql = "SELECT * FROM " + TblSymbolsInGroups + " WHERE GroupID = '" + groupId + "' ; COMMIT;";
            var reader = GetReader(sql);
            if (reader != null)
            {
                while (reader.Read())
                {
                    var symbol = new SymbolModel { SymbolId = reader.GetInt32(2), SymbolName = reader.GetString(3) };
                    symbolsList.Add(symbol);
                }
                reader.Close();
            }
            return symbolsList;
        }
Ejemplo n.º 5
0
        private void ui_buttonX_join_Click(object sender, EventArgs e)
        {
            var symbCount = ui_listBox_symbols.SelectedItems.Count;
            var groupCount = ui_listBox_groups.SelectedItems.Count;

            if (symbCount==0)
            {
                ToastNotification.Show(this, "Please, select symbols");
                return;
            }
            if(groupCount==0)
            {
                ToastNotification.Show(this, "Please, select groups");
                return;
            }

            for (int i = 0; i < symbCount; i++)
            {
                var currSmb = ui_listBox_symbols.SelectedItems[i].ToString();
                var currSmbId = _symbols.Find(a => a.SymbolName == currSmb).SymbolId;

                for (int j = 0; j < groupCount; j++)
                {
                    var currGroup = ui_listBox_groups.SelectedItems[j].ToString();
                    var currGroupId = _groups.Find(a => a.GroupName == currGroup).GroupId;
                    var currGroupSymbols = DataNetClientDataManager.GetSymbolsInGroup(currGroupId);
                    if (!currGroupSymbols.Exists(a => a.SymbolName == currSmb))
                    {
                        var sModel = new SymbolModel { SymbolId = currSmbId, SymbolName = currSmb };
                        DataNetClientDataManager.AddSymbolIntoGroup(currGroupId, sModel);
                    }
                }

                ui_listBox_symbolsInGroup.Items.Clear();
                var currentGroup = _groups.Find(a => a.GroupName == ui_listBox_groups.SelectedItems[0].ToString());
                if (ui_listBox_groups.SelectedItems.Count == 1 && currentGroup.Privilege != GroupPrivilege.UseGroup)
                {
                    var symbolsForCurrGroup = DataNetClientDataManager.GetSymbolsInGroup(currentGroup.GroupId);

                    foreach (var symbolModel in symbolsForCurrGroup)
                    {
                        ui_listBox_symbolsInGroup.Items.Add(symbolModel.SymbolName);
                    }
                }
            }
            ToastNotification.Show(this, "Joined");
            OnUpdateGroupsEvent();
        }