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

            string sql = "SELECT * FROM " + TblSymbolsInGroups + " WHERE GroupID = '" + groupId + "' ; COMMIT;";
            lock (LockReader)
            {
                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;
        }
        public static List<SymbolModel> GetSymbols()
        {
            var symbolsList = new List<SymbolModel>();

            const string sql = "SELECT * FROM " + TblSymbols;
            lock (LockReader)
            {
                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 List<SymbolModel> GetSymbolsForUser(int userId, bool tnOrDN)
        {
            var symbolsList = new List<SymbolModel>();
            string sql = "SELECT * FROM " + TblSymbolsForUsers
                        + " LEFT JOIN " + TblSymbols
                        + " ON " + TblSymbolsForUsers + ".SymbolID = "
                        + TblSymbols + ".ID" + " WHERE " + TblSymbolsForUsers + ".UserID = '" + userId + "' AND TNorDN = " + tnOrDN + "; COMMIT;";
            lock (LockReader)
            {
                MySqlDataReader 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();
                }
            }
            return symbolsList;
        }
        public static List<SymbolModel> GetSymbolsInGroup(int groupId)
        {
            var symbolsList = new List<SymbolModel>();

            string sql = "SELECT * FROM " + TblSymbolsInGroups + " WHERE GroupID = '" + groupId + "' ORDER BY SymbolName " + (SortingModeIsAsc ? "ASC" : "DESC");
            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;
        }
        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, bool isTickNet)
        {
            var symbolsList = new List<SymbolModel>();
            string sql = "SELECT * FROM " + TblSymbolsForUsers
                        + " LEFT JOIN " + TblSymbols
                        + " ON " + TblSymbolsForUsers + ".SymbolID = "
                        + TblSymbols + ".ID" + " WHERE " + TblSymbolsForUsers + ".UserID = '" + userId + "' AND " + TblSymbolsForUsers + ".TNorDN = " + (isTickNet ? "true" : "false") + " ORDER BY SymbolName " + (SortingModeIsAsc ? "ASC" : "DESC");

            MySqlDataReader reader = GetReader(sql);
            if (reader != null)
            {
                while (reader.Read())
                {
                    try
                    {
                        var symbol = new SymbolModel { SymbolId = reader.GetInt32(4), SymbolName = reader.GetString(5) };
                        symbolsList.Add(symbol);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception.DatabaseManager.GetSymbolsForUser Msg: " + ex.Message);
                    }
                }

                reader.Close();
            }

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

            Commit();

            string sql = "SELECT * FROM " + TblSymbols + " ORDER BY SymbolName " + (SortingModeIsAsc ? "ASC" : "DESC");
            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;
        }
        private void ui_buttonX_join_Click(object sender, EventArgs e)
        {
            var message = "";
            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 currGroupName = ui_listBox_groups.SelectedItems[j].ToString();
                    var currGrp = _groups.Find(a => a.GroupName == currGroupName);
                    var currGroupId = currGrp.GroupId;
                    var currGroupSymbols = ClientDatabaseManager.GetSymbolsInGroup(currGroupId);
                    if (!currGroupSymbols.Exists(a => a.SymbolName == currSmb))
                    {
                        var sModel = new SymbolModel { SymbolId = currSmbId, SymbolName = currSmb };

                        if (GetCntTypeOfSymbol(currSmb) == currGrp.CntType)
                            ClientDatabaseManager.AddSymbolIntoGroup(currGroupId, sModel);
                        else
                            message += " Symbol: '" + currSmb + "' can't be added to '" + currGroupName + "' group";
                    }
                }

                /*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 = DatabaseManager.GetSymbolsInGroup(currentGroup.GroupId);

                    foreach (var symbolModel in symbolsForCurrGroup)
                    {
                        ui_listBox_symbolsInGroup.Items.Add(symbolModel.SymbolName);
                    }
                }*/
            }
            ToastNotification.Show(this, "Joined.");
            if (!String.IsNullOrEmpty(message))
                ToastNotification.Show(this, message);
            OnUpdateGroupsEvent();
        }
        private void buttonAddToGroup_Click(object sender, EventArgs e)
        {
            var message = "";
            var symbCount = listBoxSymbols.SelectedItems.Count;
            var groupCount = listViewGroups.SelectedItems.Count;
            if (!_isSingleGroup)
            {
                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 = listBoxSymbols.SelectedItems[i].ToString();
                    var currSmbId = _symbols.Find(a => a.SymbolName == currSmb).SymbolId;

                    for (int j = 0; j < groupCount; j++)
                    {
                        var currGroupName = listViewGroups.SelectedItems[j].SubItems[0].Text;
                        var currGrp = _groups.Find(a => a.GroupName == currGroupName);
                        var currGroupId = currGrp.GroupId;
                        var currGroupSymbols = ClientDatabaseManager.GetSymbolsInGroup(currGroupId);
                        if (!currGroupSymbols.Exists(a => a.SymbolName == currSmb))
                        {
                            var sModel = new SymbolModel { SymbolId = currSmbId, SymbolName = currSmb };

                            if (GetCntTypeOfSymbol(currSmb) == currGrp.CntType)
                            {
                                ClientDatabaseManager.AddSymbolIntoGroup(currGroupId, sModel);
                                listViewSymbolsForGroup.Items.Add(sModel.SymbolName);
                            }

                            else
                                message += " Symbol: '" + currSmb + "' can't be added to '" + currGroupName + "' group";
                        }
                    }

                }
            }
            else
            {
                if (symbCount == 0)
                {
                    ToastNotification.Show(this, "Please, select symbols");
                    return;
                }
                for (int i = 0; i < symbCount; i++)
                {
                    var currSmb = listBoxSymbols.SelectedItems[i].ToString();
                    var currSmbId = _symbols.Find(a => a.SymbolName == currSmb).SymbolId;
                    var currGroupName = _group.GroupName;
                    var currGrp = _group;
                    var currGroupId = currGrp.GroupId;
                    var currGroupSymbols = ClientDatabaseManager.GetSymbolsInGroup(currGroupId);
                    if (!currGroupSymbols.Exists(a => a.SymbolName == currSmb))
                    {
                        var sModel = new SymbolModel { SymbolId = currSmbId, SymbolName = currSmb };

                        if (GetCntTypeOfSymbol(currSmb) == currGrp.CntType)
                        {
                            ClientDatabaseManager.AddSymbolIntoGroup(currGroupId, sModel);
                            listViewSymbolsForGroup.Items.Add(sModel.SymbolName);
                        }

                        else
                            message += " Symbol: '" + currSmb + "' can't be added to '" + currGroupName + "' group";

                    }
                }
            }
            ToastNotification.Show(this, "Joined.");
            if (!String.IsNullOrEmpty(message))
                ToastNotification.Show(this, message);
        }
        private void buttonGroupADD_Click(object sender, EventArgs e)
        {
            if (_symbolsList.Count == 0)
            {
                if (textBoxGroupsFilter.Text == "" || textBoxGroupsFilter.Text.Contains(" ")) return;
                if (comboBoxConType.SelectedItem == null) return;
                if (comboBoxTF.SelectedItem == null) return;
                var groups = ClientDatabaseManager.GetGroupsForUser(_userID, ApplicationType.DataNet);
                var group = new GroupModel
                {
                    GroupName = textBoxGroupsFilter.Text,
                    TimeFrame = comboBoxTF.SelectedItem.ToString(),
                    Start = new DateTime(),
                    End = new DateTime(),
                    CntType = comboBoxConType.SelectedItem.ToString(),
                    IsAutoModeEnabled = false,

                };
                if (!groups.Exists(oo => oo.GroupName == group.GroupName) &&
                    !ClientDatabaseManager.GetAllGroups(ApplicationType.DataNet)
                        .Exists(a => a.GroupName == group.GroupName))
                {

                    if (ClientDatabaseManager.AddGroupOfSymbols(group))
                    {
                        group.GroupId = ClientDatabaseManager.GetGroupIdByName(group.GroupName);
                        ClientDatabaseManager.AddGroupForUser(_userID, group, ApplicationType.DataNet);
                        _groups = ClientDatabaseManager.GetGroupsForUser(_userID, ApplicationType.DataNet);

                        //todo ClientServiceProxy

                        ListViewItem item = new ListViewItem(group.GroupName);
                        item.SubItems.Add(group.TimeFrame);
                        item.SubItems.Add(group.CntType);
                        item.SubItems.Add(group.GroupId.ToString());
                        listViewGroups.Items.Add(item);
                    }
                }
                else
                {
                    ToastNotification.Show(this, "This group alredy exist");
                }

            }
            else
            {
                if (textBoxGroupsFilter.Text == "" || textBoxGroupsFilter.Text.Contains(" "))
                {
                    ToastNotification.Show(this, @"Please, enter group name");
                    return;
                }
                if (comboBoxTF.SelectedItem == null)
                {
                    ToastNotification.Show(this, @"Please, chose TF");
                    return;
                }
                var groups = ClientDatabaseManager.GetGroupsForUser(_userID, ApplicationType.DataNet);
                var conType = eTimeSeriesContinuationType.tsctNoContinuation.ToString();
                if (_isStandart)
                {
                    conType = eTimeSeriesContinuationType.tsctStandard.ToString();
                }

                var group = new GroupModel
                {
                    GroupName = textBoxGroupsFilter.Text,
                    TimeFrame = comboBoxTF.SelectedItem.ToString(),
                    Start = new DateTime(),
                    End = new DateTime(),
                    CntType = conType,
                    IsAutoModeEnabled = false,

                };
                if (!groups.Exists(oo => oo.GroupName == group.GroupName) &&
                    !ClientDatabaseManager.GetAllGroups(ApplicationType.DataNet)
                        .Exists(a => a.GroupName == group.GroupName))
                {

                    if (ClientDatabaseManager.AddGroupOfSymbols(group))
                    {
                        group.GroupId = ClientDatabaseManager.GetGroupIdByName(group.GroupName);
                        ClientDatabaseManager.AddGroupForUser(_userID, group, ApplicationType.DataNet);
                        _groups = ClientDatabaseManager.GetGroupsForUser(_userID, ApplicationType.DataNet);

                        //todo ClientServiceProxy

                        ListViewItem item = new ListViewItem(group.GroupName);
                        item.SubItems.Add(group.TimeFrame);
                        item.SubItems.Add(group.CntType);
                        item.SubItems.Add(group.GroupId.ToString());
                        listViewGroups.Items.Add(item);
                        for (int i = 0; i < _symbolsList.Count; i++)
                        {
                            var currSmb = _symbolsList[i];
                            var currSmbId = _symbols.Find(a => a.SymbolName == currSmb).SymbolId;
                            //var currGroupName = group.GroupName;
                            var currGrp = group;
                            var currGroupId = currGrp.GroupId;
                            var sModel = new SymbolModel { SymbolId = currSmbId, SymbolName = currSmb };

                            if (GetCntTypeOfSymbol(currSmb) == currGrp.CntType)
                            {
                                ClientDatabaseManager.AddSymbolIntoGroup(currGroupId, sModel);
                            }
                        }
                        _symbolsList.Clear();
                        buttonCopy.Text = "Copy";
                    }
                    else
                    {
                        ToastNotification.Show(this, "This group alredy exist");
                    }
                }
            }
            textBoxGroupsFilter.Text = "";
        }