public bool SaveCredentials(string department, string username, string password)
        {
            if (password.Length == 0)
            {
                return(false);
            }
            password = CredentialsManager.EncryptText(password);
            try
            {
                _doc.Load(_configPath);
                string      select    = XML_SERVER_INFO_LOCATION + "[@Department='" + department + "']";
                XmlNodeList userNodes = _doc.SelectNodes(select);

                XmlNode userNode = userNodes[0];

                userNode.SelectNodes("username").Item(0).InnerText = username;
                userNode.SelectNodes("password").Item(0).InnerText = password;

                _doc.Save(this._configPath);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(false);
            }
            return(true);
        }
        public string GetPassword(string department)
        {
            IDictionary <string, Tuple <string, string> > userCredentials = GetUserCredentials();

            if (userCredentials.ContainsKey(department))
            {
                string password = userCredentials[department].Item2;
                if (password.Length > 0)
                {
                    password = CredentialsManager.DecryptText(password);
                }
                return(password);
            }
            return("");
        }
        /// <summary>
        ///     <para>Get the configuration of the server by printer name.</para>
        ///     <para>
        ///         Note: If the information of the server is not found,
        ///         the function will return null.
        ///     </para>
        /// </summary>
        /// <param name="printerName">The name of the printer, eg: lj_cl_112a </param>
        /// <returns>
        /// A array of size 3 containing the information of the server
        /// </returns>
        public string[] GetServerConfig(string printerName)
        {
            IDictionary <string, string>   DepartmentPrinterMap = GetDepartmentMap();
            IDictionary <string, string[]> ServerInfo           = GetServerInfo();

            if (DepartmentPrinterMap != null && ServerInfo != null &&
                DepartmentPrinterMap.ContainsKey(printerName))
            {
                string department = DepartmentPrinterMap[printerName];
                if (ServerInfo.ContainsKey(department))
                {
                    string[] ret = new string[NUMBER_OF_INFO_FIELDS];
                    ServerInfo.TryGetValue(department, out ret);
                    ret[2] = CredentialsManager.DecryptText(ret[2]);
                    return(ret);
                }
            }
            return(null);
        }