Esempio n. 1
0
        private void button_Save_Click(object sender, EventArgs e)
        {
            string logMSG = "Saving user preferences for '" + userName + "'";

            //  (logMSG);
            LogFile.AddMessage(System.Diagnostics.TraceLevel.Info, logMSG);
            getPreferences(dictUserPreferencesFromConfig, dictUserPreferences);
            getPreferences(dictDevicePreferencesFromConfig, dictDevicePreferences);

            if (bIsNewUser == true)
            {
                if (GetUserPreferences != null)
                {
                    GetUserPreferences(this, new EventArgs());
                }
            }
            else
            {
                string            title  = LanguageINI.GetString("headerSavingInProgress");
                RoboMessagePanel4 prompt = new GUI_Controls.RoboMessagePanel4(RoboSep_UserConsole.getInstance(), title, 500, 20);
                RoboSep_UserConsole.showOverlay();
                prompt.ShowDialog();

                RoboSep_UserConsole.hideOverlay();

                // update the user preferences file for old user
                UserDetails.SaveUserPreferences(userName, dictUserPreferences, dictDevicePreferences);

                // reload the user preferences to refresh the changes
                RoboSep_UserDB.getInstance().loadCurrentUserPreferences(userName);

                prompt.Dispose();
            }

            this.SendToBack();

            if (ClosingUserPreferencesApp != null)
            {
                ClosingUserPreferencesApp(this, new EventArgs());
            }

            this.Hide();
        }
        private void button_Save_Click(object sender, EventArgs e)
        {
            string sTempUserLoginID = textBox_NewUserLoginID.Text.Trim();

            if (string.IsNullOrEmpty(sTempUserLoginID))
            {
                // Sunny to do
                string sMSG  = LanguageINI.GetString("lblUserName");
                string sMSG1 = LanguageINI.GetString("lblIsEmpty");
                string sMSG2 = LanguageINI.GetString("lblEnterUserName");
                string sOK   = LanguageINI.GetString("Ok");
                string sMSG3 = String.Format("{0} {1}", sMSG, sMSG1);
                string sMSG4 = sMSG2;

                GUI_Controls.RoboMessagePanel prompt = new GUI_Controls.RoboMessagePanel(RoboSep_UserConsole.getInstance(), MessageIcon.MBICON_ERROR,
                                                                                         sMSG3, sMSG4, sOK);
                RoboSep_UserConsole.showOverlay();
                prompt.ShowDialog();
                RoboSep_UserConsole.hideOverlay();
                prompt.Dispose();
                return;
            }
            else if (0 <= sTempUserLoginID.IndexOf(reservedChar))
            {
                string sHeader = LanguageINI.GetString("headerReservedChar");
                string sMSG    = LanguageINI.GetString("lblUserName");
                string sMSG1   = LanguageINI.GetString("lblContainsIllegalChars");
                string sMSG2   = LanguageINI.GetString("lblEnterUserName");
                sMSG += " ";
                sMSG += sMSG1;
                string sMSG3 = String.Format(sMSG, reservedChar.ToString());
                sMSG3 += sMSG2;

                GUI_Controls.RoboMessagePanel prompt = new GUI_Controls.RoboMessagePanel(RoboSep_UserConsole.getInstance(), MessageIcon.MBICON_ERROR,
                                                                                         sMSG3, sHeader, LanguageINI.GetString("Ok"));
                RoboSep_UserConsole.showOverlay();
                prompt.ShowDialog();
                RoboSep_UserConsole.hideOverlay();
                prompt.Dispose();
                return;
            }
            else if (sTempUserLoginID.Length > maxUserLoginStringLength)
            {
                // Sunny to do
                string sMSG  = LanguageINI.GetString("lblUserName");
                string sMSG1 = LanguageINI.GetString("lblIsTooLong");
                string sTemp = LanguageINI.GetString("lblUserNameMaxLength");
                string sMSG2 = String.Format(sTemp, maxUserLoginStringLength);
                string sMSG4 = sMSG2 + LanguageINI.GetString("lblEnterUserName");
                string sMSG5 = sMSG + " " + sMSG1;

                GUI_Controls.RoboMessagePanel prompt = new GUI_Controls.RoboMessagePanel(RoboSep_UserConsole.getInstance(), MessageIcon.MBICON_ERROR,
                                                                                         sMSG4, sMSG5, LanguageINI.GetString("Ok"));
                RoboSep_UserConsole.showOverlay();
                prompt.ShowDialog();
                RoboSep_UserConsole.hideOverlay();
                prompt.Dispose();
                return;
            }

            int nIndex = sTempUserLoginID.IndexOf(spaceChar);

            if (0 < nIndex)
            {
                sTempUserLoginID = sTempUserLoginID.Replace(spaceChar, reservedChar);
            }
            string sUserLoginID = sTempUserLoginID;

            if (ValidateName(sUserLoginID) == false)
            {
                return;
            }

            string destination = DefaultImage;

            if (File.Exists(tempUser.TempImageIconPath))
            {
                // Copy image from temporary folder to image folder
                string temp = tempUser.TempImageIconPath;
                int    fileExtensionIndex = temp.LastIndexOf('.');
                string fileExtension      = temp.Substring(fileExtensionIndex);

                int    lastBackslashIndex = temp.LastIndexOf('\\'); // must escape the '\'
                string tempDirectory      = temp.Remove(lastBackslashIndex, temp.Length - lastBackslashIndex);

                string fileName = sUserLoginID;
                fileName += ImageIconFilePosfix;
                fileName += fileExtension;

                string targetDestination = systemPath + "images\\";
                if (!Directory.Exists(targetDestination))
                {
                    Directory.CreateDirectory(targetDestination);
                }

                destination = targetDestination + fileName;
                bool bContinue = false;

                for (int i = 0; i < maxSameUserLoginIDImageIconFile; i++)
                {
                    if (!File.Exists(destination))
                    {
                        bContinue = true;
                        break;
                    }
                    destination = string.Format("{0}{1}{2}{3}{4}", targetDestination, sUserLoginID, i, ImageIconFilePosfix, fileExtension);
                }

                if (bContinue != true)
                {
                    // LOG
                    string LOGmsg = "New user login screen: failed to save user info. File '";
                    LOGmsg += "' aready exists.";

                    LogFile.AddMessage(System.Diagnostics.TraceLevel.Info, LOGmsg);
                    return;
                }

                File.Copy(tempUser.TempImageIconPath, destination);

                // Remove temporary folder
                Directory.Delete(tempDirectory, true);
            }
            NewLoginID = sUserLoginID;

            // Add visual effect
            string            title  = LanguageINI.GetString("headerSavingInProgress");
            RoboMessagePanel4 saving = new GUI_Controls.RoboMessagePanel4(RoboSep_UserConsole.getInstance(), title, 500, 20);

            RoboSep_UserConsole.showOverlay();
            saving.ShowDialog();

            RoboSep_UserConsole.hideOverlay();

            if (bCreateNewUser)
            {
                // create new user info in INI file
                string strTemp = sUserLoginID + "Image";
                UserINI.IniWriteValue(sUserLoginID, strTemp, destination);
            }
            else
            {
                // rename the userlogin
                RenameUserNameInUserInfoINI(DefaultLoginID, NewLoginID);

                // rename protocols and MRUs
                RoboSep_UserDB.getInstance().RenameProtocolsAndMRUs(DefaultLoginID, NewLoginID);
            }

            // update user preferences
            string UserToBeUpdated = NewLoginID;

            if (dictUserPreferences == null && dictDevicePreferences == null)
            {
                // User preferences are not set
                dictUserPreferences   = new Dictionary <string, bool>();
                dictDevicePreferences = new Dictionary <string, bool>();

                if (bCreateNewUser)
                {
                    // Use default user and device preferences for new user.
                    RoboSep_UserDB.getInstance().getDefaultUserAndDevicePreferences(dictUserPreferences, dictDevicePreferences);
                }
                else
                {
                    RoboSep_UserDB.getInstance().getUserAndDevicePreferences(DefaultLoginID, dictUserPreferences, dictDevicePreferences);
                    if (dictUserPreferences.Count == 0 || dictDevicePreferences.Count == 0)
                    {
                        // Use default user and device preferences if the user preferences file not existed.
                        RoboSep_UserDB.getInstance().getDefaultUserAndDevicePreferences(dictUserPreferences, dictDevicePreferences);
                    }
                }
            }

            string UserLogin = bCreateNewUser ? NewLoginID : DefaultLoginID;

            // save user preferences
            UserDetails.SaveUserPreferences(UserLogin, dictUserPreferences, dictDevicePreferences);

            if (!bCreateNewUser)
            {
                // rename the user preferences file
                UserDetails.RenameUserPreferencesFile(DefaultLoginID, NewLoginID);
            }

            saving.Dispose();

            // remove Control
            this.Close();
            DialogResult = DialogResult.OK;
        }