コード例 #1
0
        private bool CheckUserExistsAndUpdate(User user)
        {
            XmlDocument dom = new XmlDocument();

            XmlHelper.CheckXMLFile(PublicParams.xmlHistory);
            dom.Load(PublicParams.xmlHistory);
            XmlNode nodeRoot = dom.SelectSingleNode("Root");

            ClearLastUserName(ref nodeRoot);
            bool result = false;

            for (int i = 0; i < nodeRoot.ChildNodes.Count; i++)
            {
                if (nodeRoot.ChildNodes[i]["Name"].InnerText == user.Name)
                {
                    result = true;
                    ((XmlElement)nodeRoot.ChildNodes[i]).SetAttribute("Last", "true");
                    nodeRoot.ChildNodes[i]["Pwd"].InnerText       = CryptHelper.Encrypt(user.Pwd);
                    nodeRoot.ChildNodes[i]["Remember"].InnerText  = cbRemberPwd.IsChecked == true ? "1" : "0";
                    nodeRoot.ChildNodes[i]["AutoLogin"].InnerText = cbAutoLogin.IsChecked == true ? "1" : "0";
                    break;
                }
                else
                {
                    continue;
                }
            }
            dom.Save(PublicParams.xmlHistory);

            return(result);
        }
コード例 #2
0
        private void SaveUser(User user)
        {
            XmlDocument dom = new XmlDocument();

            XmlHelper.CheckXMLFile(PublicParams.xmlHistory);
            dom.Load(PublicParams.xmlHistory);
            XmlNode nodeRoot = dom.SelectSingleNode("Root");

            ClearLastUserName(ref nodeRoot);
            XmlElement xe        = dom.CreateElement("User"); xe.SetAttribute("Last", "true");
            XmlElement name      = dom.CreateElement("Name"); name.InnerText = user.Name.Trim(); xe.AppendChild(name);
            XmlElement pwd       = dom.CreateElement("Pwd"); pwd.InnerText = CryptHelper.Encrypt(user.Pwd.Trim()); xe.AppendChild(pwd);
            XmlElement remember  = dom.CreateElement("Remember"); remember.InnerText = user.Remember.ToString(); xe.AppendChild(remember);
            XmlElement autoLogin = dom.CreateElement("AutoLogin"); autoLogin.InnerText = user.AutoLogin.ToString(); xe.AppendChild(autoLogin);

            nodeRoot.AppendChild(xe);
            dom.Save(PublicParams.xmlHistory);
        }