private static void AddUser(UserModel user) { var userValues = new ArrayList { _userIndexer, user.Name, user.FullName, user.Email, user.IpAdress }; var userRow = _userDetails.tableUsers.NewRow(); userRow.ItemArray = userValues.ToArray(); _userDetails.tableUsers.Rows.Add(userRow); _userDetails.AcceptChanges(); }
private void EditUserControl_SaveClick(object sender, EventArgs e) { var userModel = new UserModel { FullName = _editUserControl.ui_textBoxX_name.Text, Name = _editUserControl.ui_textBoxX_login.Text, Password = _editUserControl.ui_textBoxX_password.Text, Email = _editUserControl.ui_textBoxX_email.Text, Phone = _editUserControl.ui_textBoxX_phone.Text, IpAdress = _editUserControl.ui_textBoxX_ip.Text, Blocked = !_editUserControl.ui_switchButton_allowUser.Value, AllowDataNet = _editUserControl.ui_switchButton_enableDataNet.Value, AllowTickNet = _editUserControl.ui_switchButton_enableTickNet.Value, AllowLocalDb = _editUserControl.ui_switchButton_local.Value, AllowRemoteDb = _editUserControl.ui_switchButton_share.Value, AllowAnyIp = _editUserControl.ui_switchButton_any_Ip.Value, AllowMissBars = _editUserControl.ui_switchButton_allwoMissingBar.Value, AllowCollectFrCqg = _editUserControl.ui_switchButton_allowCollecting.Value, AllowDexport = _editUserControl.uiPermissionDataExport.Value }; var oldUserName = _editUserControl.OldUserLogin; if (ValidateEditControl() != "OK") { ToastNotification.Show(_editUserControl, ValidateEditControl(), eToastPosition.TopCenter); } else if ((!_users.Exists(a => a.Name == userModel.Name) && _users.Exists(a => a.Name == oldUserName)) || (userModel.Name == oldUserName && _users.Exists(a => a.Name == oldUserName))) { var userId = _users.Find(a => a.Name == oldUserName).Id; DataManager.EditUser(userId, userModel); UpdateUsersTable(); CloseEditUserControl(); if (_adminService.OnlineClients.GetAllItems().Exists(a => a.UserName == userModel.Name)) _adminService.ChangePrivilege(userModel.Name, new DataAdminMessageFactory.ChangePrivilage(userModel.AllowDataNet, userModel.AllowTickNet, userModel.AllowRemoteDb, userModel.AllowLocalDb, userModel.AllowAnyIp, userModel.AllowMissBars, userModel.AllowCollectFrCqg, userModel.AllowDexport)); } else { ToastNotification.Show(_editUserControl, @"User with this login is already exists!", eToastPosition.TopCenter); } }
private void AddNewUserControl_AddClick(object sender, EventArgs e) { try { var userModel = new UserModel { FullName = _addUserControl.ui_textBoxX_name.Text, Name = _addUserControl.ui_textBoxX_login.Text, Password = _addUserControl.ui_textBoxX_password.Text, Email = _addUserControl.ui_textBoxX_email.Text, Phone = _addUserControl.ui_textBoxX_phone.Text, IpAdress = _addUserControl.ui_textBoxX_ip.Text, Blocked = !_addUserControl.ui_switchButton_allowUser.Value, AllowDataNet = _addUserControl.ui_switchButton_enableDataNet.Value, AllowTickNet = _addUserControl.ui_switchButton_enableTickNet.Value, AllowLocalDb = _addUserControl.ui_switchButton_local.Value, AllowRemoteDb = _addUserControl.ui_switchButton_share.Value, AllowAnyIp = _addUserControl.ui_switchButton_any_Ip.Value, AllowMissBars = _addUserControl.ui_switchButton_allwoMissingBar.Value, AllowCollectFrCqg = _addUserControl.ui_switchButton_allowCollecting.Value, AllowDexport = _addUserControl.uiPermissionDexport.Value }; if (ValidateAddControl() != "OK") { ToastNotification.Show(_addUserControl, ValidateAddControl(), eToastPosition.TopCenter); } else if (!_users.Exists(a => a.Name == userModel.Name)) { DataManager.AddNewUser(userModel); UpdateUsersTable(); CloseAddUserControl(); } else { ToastNotification.Show(_addUserControl, @"User with this login is already exists!", eToastPosition.TopCenter); } } catch (PleaseDropTablesException ex) { Console.WriteLine(ex); MessageBox.Show(ex.Message, @"Sql Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
public static List<UserModel> GetUsersForGroup(int groupId, string appType) { var userList = new List<UserModel>(); var sql = "SELECT * FROM " + TblGroupsForUsers + " LEFT JOIN " + TblUsers + " ON " + TblGroupsForUsers + ".UserID = " + TblUsers + ".ID" + " WHERE GroupID = '" + groupId + "' AND " + TblGroupsForUsers + ".AppType = '" + appType + "' ; COMMIT;"; lock (LockReader) { var reader = GetReader(sql); if (reader != null) { while (reader.Read()) { var user = new UserModel(); user.AdditionalPrivilege = reader.GetString(8); user.Id = reader.GetInt32(12); user.Name = reader.GetString(13); user.Password = reader.GetString(14); user.FullName = reader.GetString(15); user.Email = reader.GetString(16); user.Phone = reader.GetString(17); user.IpAdress = reader.GetString(18); user.Blocked = reader.GetBoolean(19); user.AllowDataNet = reader.GetBoolean(20); user.AllowTickNet = reader.GetBoolean(21); user.AllowLocalDb = reader.GetBoolean(22); user.AllowRemoteDb = reader.GetBoolean(23); user.AllowAnyIp = reader.GetBoolean(24); user.AllowMissBars = reader.GetBoolean(25); user.AllowCollectFrCqg = reader.GetBoolean(26); userList.Add(user); } reader.Close(); } } return userList; }
public static List<UserModel> GetUsersForSymbol(int symbolId, string appType) { var userList = new List<UserModel>(); var sql = "SELECT * FROM " + TblSymbolsForUsers + " LEFT JOIN " + TblUsers + " ON " + TblSymbolsForUsers + ".UserID = " + TblUsers + ".ID" + " WHERE " + TblSymbolsForUsers + ".SymbolID = '" + symbolId + "' AND " + TblSymbolsForUsers + ".TNorDN = " + (appType == ApplicationType.TickNet.ToString()).ToString() + " ; COMMIT;"; lock (LockReader) { var reader = GetReader(sql); if (reader != null) { while (reader.Read()) { var user = new UserModel { Id = reader.GetInt32(4), Name = reader.GetString(5), Password = reader.GetString(6), FullName = reader.GetString(7), Email = reader.GetString(8), Phone = reader.GetString(9), IpAdress = reader.GetString(10), Blocked = reader.GetBoolean(11), AllowDataNet = reader.GetBoolean(12), AllowTickNet = reader.GetBoolean(13), AllowLocalDb = reader.GetBoolean(14), AllowRemoteDb = reader.GetBoolean(15), AllowAnyIp = reader.GetBoolean(16), AllowMissBars = reader.GetBoolean(17), AllowCollectFrCqg = reader.GetBoolean(18), }; userList.Add(user); } reader.Close(); } } return userList; }
public static UserModel GetUserData(int userId) { var user = new UserModel(); var sql = "SELECT * FROM " + TblUsers + " WHERE `ID`= " + userId; lock (LockReader) { var reader = GetReader(sql); if (reader != null) { if (reader.Read()) { user = new UserModel { Id = reader.GetInt32(0), Name = reader.GetString(1), Password = reader.GetString(2), FullName = reader.GetString(3), Email = reader.GetString(4), Phone = reader.GetString(5), IpAdress = reader.GetString(6), Blocked = reader.GetBoolean(7), AllowDataNet = reader.GetBoolean(8), AllowTickNet = reader.GetBoolean(9), AllowLocalDb = reader.GetBoolean(10), AllowRemoteDb = reader.GetBoolean(11), AllowAnyIp = reader.GetBoolean(12), AllowMissBars = reader.GetBoolean(13), AllowCollectFrCqg = reader.GetBoolean(14), AllowDexport = reader.GetBoolean(15) }; } reader.Close(); } } return user; }
public static List<UserModel> GetUsers() { var usersList = new List<UserModel>(); const string sql = "SELECT * FROM " + TblUsers; lock (LockReader) { var reader = GetReader(sql); if (reader != null) { try { while (reader.Read()) { var user = new UserModel { Id = reader.GetInt32(0), Name = reader.GetString(1), Password = reader.GetString(2), FullName = reader.GetString(3), Email = reader.GetString(4), Phone = reader.GetString(5), IpAdress = reader.GetString(6), Blocked = reader.GetBoolean(7), AllowDataNet = reader.GetBoolean(8), AllowTickNet = reader.GetBoolean(9), AllowLocalDb = reader.GetBoolean(10), AllowRemoteDb = reader.GetBoolean(11), AllowAnyIp = reader.GetBoolean(12), AllowMissBars = reader.GetBoolean(13), AllowCollectFrCqg = reader.GetBoolean(14), AllowDexport = reader.GetBoolean(15) }; usersList.Add(user); } } finally { reader.Close(); } } } return usersList; }
public static bool EditUser(int userId, UserModel user) { String query = "UPDATE " + TblUsers + " SET " + " UserName = '******', " + " UserPassword = '******', " + " UserFullName = '" + user.FullName + "', " + " UserEmail = '" + user.Email + "', " + " UserPhone = '" + user.Phone + "', " + " UserIpAddress = '" + user.IpAdress + "', " + " UserBlocked = " + user.Blocked + "," + " UserAllowDataNet = " + user.AllowDataNet + "," + " UserAllowTickNet = " + user.AllowTickNet + "," + " UserAllowLocal = " + user.AllowLocalDb + "," + " UserAllowRemote = " + user.AllowRemoteDb + "," + " UserAllowAnyIp = " + user.AllowAnyIp + "," + " UserAllowMissBars = " + user.AllowMissBars + "," + " UserAllowMissBars = " + user.AllowCollectFrCqg + "," + " UserAllowDexport = " + user.AllowDexport; query += " WHERE ID = '" + userId + "'; COMMIT;"; return DoSql(query); }
public static bool AddNewUser(UserModel user) { String query = "INSERT IGNORE INTO " + TblUsers; query += " (UserName, UserPassword, UserFullName, UserEmail, UserPhone, UserIpAddress," + " UserBlocked, UserAllowDataNet, UserAllowTickNet, UserAllowLocal," + " UserAllowRemote, UserAllowAnyIp, UserAllowMissBars, UserAllowCollectFrCQG, UserAllowDexport) VALUES"; query += "('"; query += user.Name + "',"; query += "'" + user.Password + "',"; query += "'" + user.FullName + "',"; query += "'" + user.Email + "',"; query += "'" + user.Phone + "',"; query += "'" + user.IpAdress + "',"; query += user.Blocked + ","; query += user.AllowDataNet + ","; query += user.AllowTickNet + ","; query += user.AllowLocalDb + ","; query += user.AllowRemoteDb + ","; query += user.AllowAnyIp + ","; query += user.AllowMissBars + ","; query += user.AllowCollectFrCqg + ","; query += user.AllowDexport + ");COMMIT;"; return DoSql(query); }
public void TickNetClientLogin(DataAdminMessageFactory.LoginMessage loginParams, UserModel tempUser) { if (!(Clients.GetAllItems().Exists(a => a.UserName == loginParams.UsernameMD5))) { AddClient(CurrentClient, loginParams.NetType, tempUser); return; } var clientInList = Clients.GetAllItems().Find(a => a.UserName == loginParams.UsernameMD5); if (clientInList.IsTickNetConnected == false) { clientInList.IsTickNetConnected = true; clientInList.TClientProxy = CurrentClient.GetClientProxy<IDataAdminService>(); clientInList.TnetClient = CurrentClient; var usrModel = new UserModel(); if (OnloggedInLog != null) { var msg = new DataAdminMessageFactory.LogMessage { OperationStatus = DataAdminMessageFactory.LogMessage.Status.Finished, LogType = DataAdminMessageFactory.LogMessage.Log.Login, Time = DateTime.Now, UserID = tempUser.Id, IsTickNetClient = true }; var msgMain = "Client " + usrModel.Name + " connected from " + CurrentClient.RemoteEndPoint; OnloggedInLog(msg, msgMain); } CurrentLoginTypeDnet = false; CurrentLoginTypeTnet = true; CurrentLoginTypeDexp = false; OnClientLogon(tempUser); } }
public void OnClientLogon(UserModel tempUser) { var privileges = new DataAdminMessageFactory.ChangePrivilage(tempUser.AllowDataNet, tempUser.AllowTickNet, tempUser.AllowRemoteDb, tempUser.AllowLocalDb, tempUser.AllowAnyIp, tempUser.AllowMissBars, tempUser.AllowCollectFrCqg, tempUser.AllowDexport) {ClientID = FindClientByUserName(tempUser.Name).DBId}; var cl = FindClientByUserName(tempUser.Name); var xEle = new XElement("ConnectionString", new XAttribute("Host", Properties.Settings.Default.connectionHost), new XAttribute("dbName", Properties.Settings.Default.connectionDB), new XAttribute("dbNameBar", Properties.Settings.Default.dbBar), new XAttribute("dbNameHist", Properties.Settings.Default.dbHist), new XAttribute("dbNameLive", Properties.Settings.Default.dbLive), new XAttribute("userName", Properties.Settings.Default.connectionUser), new XAttribute("password", Properties.Settings.Default.connectionPassword)); var sw = new StringWriter(); var tx = new XmlTextWriter(sw); xEle.WriteTo(tx); string str = sw.ToString(); privileges.ServerMessage = str; if (CurrentLoginTypeDnet) cl.DClientProxy.onLogon(true, privileges); if (CurrentLoginTypeTnet) cl.TClientProxy.onLogon(true, privileges); if (CurrentLoginTypeDexp) cl.DexportProxy.onLogon(true, privileges); SendToClientSymbolGroupList(tempUser.Name); SendBusySymbolListToClient(); }
public void AddClient(IScsServiceClient newClient, char listflag, UserModel usrModel) { var client = CurrentClient; //Get a proxy object to call methods of client when needed var clientProxy = CurrentClient.GetClientProxy<IDataAdminService>(); //Create a DataClient and store it in a collection bool dnet = listflag == 'd'; bool tnet = listflag == 't'; bool dexp = listflag == 'e'; var dataClient = new DataClient(usrModel.Name, usrModel.Id, dnet, tnet) {IsDexportConnected = dexp}; if (dnet) { dataClient.DClientProxy = clientProxy; dataClient.DnetClient = CurrentClient; CurrentLoginTypeDnet = true; CurrentLoginTypeTnet = false; CurrentLoginTypeDexp = false; dataClient.DexportProxy = null; dataClient.TnetClient = null; } if (tnet) { dataClient.TClientProxy = clientProxy; dataClient.TnetClient = CurrentClient; CurrentLoginTypeTnet = true; CurrentLoginTypeDnet = false; CurrentLoginTypeDexp = false; dataClient.DnetClient = null; dataClient.DexportProxy = null; } if (dexp) { dataClient.DexportProxy = clientProxy; dataClient.DexportClient = CurrentClient; CurrentLoginTypeDexp = true; CurrentLoginTypeTnet = false; CurrentLoginTypeDnet = false; dataClient.DnetClient = null; dataClient.TnetClient = null; } dataClient.IndexInAdminList = (int) client.ClientId; Clients[client.ClientId] = dataClient; //Register to Disconnected event to know when user connection is closed client.Disconnected += Client_Disconnected; //Start a new task to send user list to mainform if (OnloggedInLog != null) { var msg = new DataAdminMessageFactory.LogMessage { OperationStatus = DataAdminMessageFactory.LogMessage.Status.Finished, LogType = DataAdminMessageFactory.LogMessage.Log.Login, Time = DateTime.Now, UserID = usrModel.Id, IsDataNetClient = CurrentLoginTypeDnet, IsTickNetClient = CurrentLoginTypeTnet, }; var msgMain = "Client " + usrModel.Name + " connected from " + CurrentClient.RemoteEndPoint; OnloggedInLog(msg, msgMain); } OnClientLogon(usrModel); Task.Factory.StartNew(OnUserListChanged); }