Exemplo n.º 1
0
 /// <summary>
 /// Show add user dialog
 /// </summary>
 public static void ShowAddUserDialog(string defaultName = "")
 {
     if (MainForm.API != null)
     {
         TextEditForm tef = new TextEditForm(defaultName, Translator.GetTranslation("ADD_USER"), Translator.GetTranslation("USERNAME_HINT"));
         if (tef.ShowDialog() == DialogResult.OK)
         {
             string         value       = tef.Value;
             UserConfigData user_config = Configuration.GetUserConfigData(MainForm.API.Username);
             string[]       users       = user_config.Following;
             bool           success     = true;
             if (value.ToLower() == MainForm.API.Username.ToLower())
             {
                 MessageBox.Show(Translator.GetTranslation("YOU_CAN_NOT_ADD_YOURSELF_MESSAGE"), Translator.GetTranslation("YOU_CAN_NOT_ADD_YOURSELF"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                 success = false;
             }
             foreach (string user in users)
             {
                 if (user.ToLower() == value.ToLower())
                 {
                     MessageBox.Show(Translator.GetTranslation("USERNAME_ALREADY_EXISTS_MESSAGE"), Translator.GetTranslation("USERNAME_ALREADY_EXISTS"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                     success = false;
                     break;
                 }
             }
             if (success)
             {
                 string[] found_users = Truckers2ConnectAPI.FindUsers(value);
                 success = false;
                 foreach (string found_user in found_users)
                 {
                     if (found_user.ToLower() == value.ToLower())
                     {
                         success = true;
                         break;
                     }
                 }
                 if (success)
                 {
                     List <string> u = new List <string>(users);
                     u.Add(value);
                     user_config.Following = u.ToArray();
                     u.Clear();
                     Configuration.Save();
                 }
                 else
                 {
                     MessageBox.Show(string.Format(Translator.GetTranslation("USER_NOT_FOUND_MESSAGE"), value), Translator.GetTranslation("USER_NOT_FOUND"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Find users
 /// </summary>
 private void FindUsers()
 {
     string[] found_users = Truckers2ConnectAPI.FindUsers(filterTextField.Text.Trim());
     foundUsersDataTable.Rows.Clear();
     foreach (string found_user in found_users)
     {
         DataRow row = foundUsersDataTable.NewRow();
         object[] data = new object[1];
         data[0] = found_user;
         row.ItemArray = data;
         foundUsersDataTable.Rows.Add(row);
     }
 }