/// <summary>
        /// 保存登录记录
        /// </summary>
        /// <param name="_records"></param>
        /// <returns></returns>
        public bool SaveRecord(LoginRecordsInfo _records)
        {
            bool _bolSucced = false;

            try
            {
                XmlDocument doc  = new XmlDocument();
                XmlElement  Root = doc.CreateElement("LoginInfo");       //主内容

                XmlElement UserNameNode = doc.CreateElement("UserName"); //用户名
                UserNameNode.InnerText = _records.UserName;
                Root.AppendChild(UserNameNode);

                XmlElement LoginTimeNode = doc.CreateElement("LoginTime");//最后登录时间
                LoginTimeNode.InnerText = _records.LoginTime;
                Root.AppendChild(LoginTimeNode);

                doc.AppendChild(Root);
                doc.Save("LoginInfo.xml");//保存/覆盖配置文件
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(_bolSucced);
        }
        /// <summary>
        /// 获取最后一次登录记录
        /// </summary>
        /// <returns></returns>
        public LoginRecordsInfo GetLastRecord()
        {
            LoginRecordsInfo _recordinfo = null;

            try
            {
                _recordinfo = new LoginRecordsInfo();
                if (System.IO.File.Exists("LoginInfo.xml"))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load("LoginInfo.xml");
                    XmlNodeList retrunDataList = doc.GetElementsByTagName("UserName"); //取得节点名为UserName的XmlNode集合
                    if (retrunDataList != null && retrunDataList.Count > 0)
                    {
                        _recordinfo.UserName = retrunDataList[0].InnerText;
                    }
                    retrunDataList = doc.GetElementsByTagName("LoginTime"); //取得节点名为LoginTime的XmlNode集合
                    if (retrunDataList != null && retrunDataList.Count > 0)
                    {
                        _recordinfo.LoginTime = retrunDataList[0].InnerText;
                    }
                }
                else
                {
                    _recordinfo.UserName  = "******";
                    _recordinfo.LoginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(_recordinfo);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoginFrm_Load(object sender, EventArgs e)
        {
            //1.默认数据存储路径
            DbFilepath = ConfigurationManager.AppSettings["ConnectionString"].ToString();

            UIBLL.LoginRecordsInfo _record = UIBLL.LoginRecordsManager.Instance.GetLastRecord();
            if (_record != null)
            {
                this.txtuserName.Text = _record.UserName;
            }
            else
            {
                this.txtuserName.Text = "admin";
            }
        }
 /// <summary>
 /// 获取最后一次登录记录
 /// </summary>
 /// <returns></returns>
 public LoginRecordsInfo GetLastRecord()
 {
     LoginRecordsInfo _recordinfo = null;
     try
     {
         _recordinfo = new LoginRecordsInfo();
         if (System.IO.File.Exists("LoginInfo.xml"))
         {
             XmlDocument doc = new XmlDocument();
             doc.Load("LoginInfo.xml");
             XmlNodeList retrunDataList = doc.GetElementsByTagName("UserName"); //取得节点名为UserName的XmlNode集合
             if (retrunDataList != null && retrunDataList.Count > 0)
             {
                 _recordinfo.UserName = retrunDataList[0].InnerText;
             }
             retrunDataList = doc.GetElementsByTagName("LoginTime"); //取得节点名为LoginTime的XmlNode集合
             if (retrunDataList != null && retrunDataList.Count > 0)
             {
                 _recordinfo.LoginTime = retrunDataList[0].InnerText;
             }
         }
         else
         {
             _recordinfo.UserName = "******";
             _recordinfo.LoginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return _recordinfo;
 }
        /// <summary>
        /// 保存登录记录
        /// </summary>
        /// <param name="_records"></param>
        /// <returns></returns>
        public bool SaveRecord(LoginRecordsInfo _records)
        {
            bool _bolSucced = false;
            try
            {
                XmlDocument doc = new XmlDocument();
                XmlElement Root = doc.CreateElement("LoginInfo");//主内容

                XmlElement UserNameNode = doc.CreateElement("UserName");//用户名
                UserNameNode.InnerText = _records.UserName;
                Root.AppendChild(UserNameNode);

                XmlElement LoginTimeNode = doc.CreateElement("LoginTime");//最后登录时间
                LoginTimeNode.InnerText = _records.LoginTime;
                Root.AppendChild(LoginTimeNode);

                doc.AppendChild(Root);
                doc.Save("LoginInfo.xml");//保存/覆盖配置文件
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return _bolSucced;
        }