public FormEditGroup(bool newGroup, string[] groupTemplates, string[] existedGroups, UserModel[] users, SoapLibrary[] libraries)
		{
			InitializeComponent();

			_newGroup = newGroup;
			_existedGroups.AddRange(existedGroups);

			_users.AddRange(users);
			gridControlUsers.DataSource = _users;
			comboBoxEditName.Properties.Items.AddRange(groupTemplates);

			_libraries.Clear();
			_libraries.AddRange(libraries);
			_pages.Clear();
			_pages.AddRange(libraries.SelectMany(x => x.pages));

			gridViewLibraries.MasterRowEmpty += OnLibraryChildListIsEmpty;
			gridViewLibraries.MasterRowGetRelationCount += OnGetLibraryRelationCount;
			gridViewLibraries.MasterRowGetRelationName += OnGetLibrariesRelationName;
			gridViewLibraries.MasterRowGetChildList += OnGetLibraryChildList;
			gridControlLibraries.DataSource = _libraries;

			comboBoxEditName.Enter += FormMain.Instance.Editor_Enter;
			comboBoxEditName.MouseUp += FormMain.Instance.Editor_MouseUp;
			comboBoxEditName.MouseDown += FormMain.Instance.Editor_MouseDown;

			if (_newGroup)
				Text = "Add Group";
			else
				Text = "Edit Group";
		}
		public FormEditPage(UserModel[] users, GroupModel[] groups)
		{
			InitializeComponent();
			_users.AddRange(users);
			gridControlUsers.DataSource = _users;

			_groups.AddRange(groups);
			gridControlGroups.DataSource = _groups;

			Text = "Edit Page";
		}
		public void SetPage(string id, UserModel[] users, GroupModel[] groups, out string message)
		{
			message = string.Empty;
			var client = GetAdminClient();
			if (client != null)
			{
				try
				{
					var sessionKey = client.getSessionKey(Login, Password);
					if (!string.IsNullOrEmpty(sessionKey))
						client.setPage(sessionKey, id, users, groups);
					else
						message = "Couldn't complete operation.\nLogin or password are not correct.";
				}
				catch (Exception ex)
				{
					message = string.Format("Couldn't complete operation.\n{0}.", ex.Message);
				}
			}
			else
				message = "Couldn't complete operation.\nServer is unavailable.";
		}
 /// <remarks/>
 public void setPageAsync(string sessionKey, string id, UserModel[] assignedUsers, GroupModel[] assignedGroups, object userState) {
     if ((this.setPageOperationCompleted == null)) {
         this.setPageOperationCompleted = new System.Threading.SendOrPostCallback(this.OnsetPageOperationCompleted);
     }
     this.InvokeAsync("setPage", new object[] {
                 sessionKey,
                 id,
                 assignedUsers,
                 assignedGroups}, this.setPageOperationCompleted, userState);
 }
 /// <remarks/>
 public void setPageAsync(string sessionKey, string id, UserModel[] assignedUsers, GroupModel[] assignedGroups) {
     this.setPageAsync(sessionKey, id, assignedUsers, assignedGroups, null);
 }
 public void setPage(string sessionKey, string id, UserModel[] assignedUsers, GroupModel[] assignedGroups) {
     this.Invoke("setPage", new object[] {
                 sessionKey,
                 id,
                 assignedUsers,
                 assignedGroups});
 }
 /// <remarks/>
 public void setGroupAsync(string sessionKey, string id, string name, UserModel[] assignedUsers, SoapLibraryPage[] assignedPages, object userState) {
     if ((this.setGroupOperationCompleted == null)) {
         this.setGroupOperationCompleted = new System.Threading.SendOrPostCallback(this.OnsetGroupOperationCompleted);
     }
     this.InvokeAsync("setGroup", new object[] {
                 sessionKey,
                 id,
                 name,
                 assignedUsers,
                 assignedPages}, this.setGroupOperationCompleted, userState);
 }
 /// <remarks/>
 public void setGroupAsync(string sessionKey, string id, string name, UserModel[] assignedUsers, SoapLibraryPage[] assignedPages) {
     this.setGroupAsync(sessionKey, id, name, assignedUsers, assignedPages, null);
 }
 public void setGroup(string sessionKey, string id, string name, UserModel[] assignedUsers, SoapLibraryPage[] assignedPages) {
     this.Invoke("setGroup", new object[] {
                 sessionKey,
                 id,
                 name,
                 assignedUsers,
                 assignedPages});
 }
		public static IEnumerable<UserInfo> ImportUsers(string filePath, UserModel[] existedUsers, GroupModel[] existedGroups, bool complexPassword, out string message)
		{
			message = string.Empty;
			var userInfo = new List<UserInfo>();
			var existedGroupList = new List<GroupModel>(existedGroups);
			var existedUserLogins = new List<string>(existedUsers.Select(x => x.login));

			var connnectionString = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";", filePath);
			var connection = new OleDbConnection(connnectionString);
			try
			{
				connection.Open();
				var groupName = string.Empty;
				var dataTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
				foreach (DataRow row in dataTable.Rows)
				{
					groupName = row["TABLE_NAME"].ToString().Replace("$", "").Replace('"'.ToString(), "'").Replace("'", "");
					break;
				}
				var dataAdapter = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}$]", groupName), connection);
				dataTable = new DataTable();
				try
				{
					dataAdapter.Fill(dataTable);
					foreach (DataRow row in dataTable.Rows)
					{
						var firtsName = dataTable.Columns.Count > 0 && row[0] != null ? row[0].ToString() : String.Empty;
						var lastName = dataTable.Columns.Count > 1 && row[1] != null ? row[1].ToString() : String.Empty;
						var email = dataTable.Columns.Count > 2 && row[2] != null ? row[2].ToString() : String.Empty;
						var phone = dataTable.Columns.Count > 3 && row[3] != null ? row[3].ToString() : String.Empty;
						var login = dataTable.Columns.Count > 4 && row[4] != null ? row[4].ToString() : String.Empty;

						if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(email)) continue;

						var group = existedGroupList.FirstOrDefault(x => x.name.ToLower().Equals(groupName.Trim().ToLower()));

						var notChangedUser = group != null && existedUsers.Any(u =>
								 login.Equals(u.login, StringComparison.OrdinalIgnoreCase) &&
								 firtsName.Equals(u.firstName, StringComparison.OrdinalIgnoreCase) &&
								 lastName.Equals(u.lastName, StringComparison.OrdinalIgnoreCase) &&
								 email.Equals(u.email, StringComparison.OrdinalIgnoreCase) &&
								 phone.Equals(u.phone, StringComparison.OrdinalIgnoreCase) &&
								 u.groups.Any(existedGroup => group.name == existedGroup.name));
						if (notChangedUser) continue;

						var newUser = !existedUserLogins.Any(existedLogin => login.Equals(existedLogin, StringComparison.OrdinalIgnoreCase));
						var user = new UserInfo();
						user.Login = login.ToLower().Trim();
						user.Password = newUser ? (complexPassword ? Membership.GeneratePassword(10, 3) : (new PasswordGenerator()).Generate()) : String.Empty;
						user.FirstName = firtsName.Trim();
						user.LastName = lastName.Trim();
						user.Email = email.ToLower().Trim();
						user.Phone = phone.ToLower().Trim();

						if (group == null)
						{
							group = new GroupModel();
							group.IsNew = true;
							group.id = Guid.NewGuid().ToString();
							group.name = groupName.Trim();
							existedGroupList.Add(group);
						}
						user.Groups.Add(group);

						existedUserLogins.Add(user.Login);
						userInfo.Add(user);
					}
				}
				catch
				{
					message = "Couldn't read file";
				}
				finally
				{
					dataAdapter.Dispose();
					dataTable.Dispose();
				}
				connection.Close();
			}
			catch
			{
				message = "Couldn't connect to file";
			}
			return userInfo;
		}