您的位置:首页 > 其它

基于xml制作登录注册修改用户信息

2017-07-14 08:59 288 查看
基于xml制作登录注册修改用户信息

登录UI界面

1 using UnityEngine;
2 using System.Collections;
3 using UnityEngine.UI;
4
5 //创建创建XML用户文件时需要到的命名空间
6 using System.IO;
7 using System.Xml;
8
9 public class changemessage : MonoBehaviour {
10     public Text ui_tootip;
11     public InputField inputName;
12     public Text ui_information;
13     public GameObject Btn_change;
14     public GameObject Inputchangename;
15     public GameObject Inputchangepass;
16
17
18
19
20     public InputField inputChangename;
21     public InputField inputChangepass;
22     private string _xmlpath;  //定义用户文件存放目录路径
23
24     // Use this for initialization
25     void Start () {
26         Btn_change.SetActive (false);
27         Inputchangepass.SetActive (false);
28         Inputchangename.SetActive (false);
29
30         _xmlpath = Application.dataPath + "/user.xml";  //定义用户文件存放目录路径
31
32         if (!File.Exists (_xmlpath)){   //如果文件不在目录下
33             //创建xml实例;
34             XmlDocument xmlDoc = new XmlDocument();
35
36             //创建xml根节点,最上层节点
37             XmlElement root = xmlDoc.CreateElement("Root");
38             xmlDoc.AppendChild (root);
39
40             //创建用户子节点
41             XmlElement user = xmlDoc.CreateElement("User");
42             user.SetAttribute ("user_name","Admin"); //创建特性用户名,默认用户名为Admin
43             user.SetAttribute ("user_pass","88888888");
44             user.SetAttribute ("user_tel","18277203077");
45             user.SetAttribute ("user_qq","272779675");
46             root.AppendChild (user);                   //把user添加到root根节点下。
47             xmlDoc.Save (_xmlpath);       //xml文档一创建就自动保存到文件目录下
48             Debug.Log ("xml creat success!"); //运行提示(方便知道xml是否创建)
49
50            }
51       }
52
53
54
55     public void openchangenamewindow(){
56
57         Inputchangename.SetActive (true);
58         Inputchangepass.SetActive (false);
59
60     }
61     public void openchangepasswindow(){
62
63         Inputchangepass.SetActive (true);
64         Inputchangename.SetActive (false);
65
66     }
67
68     public void Checkname(){
69
70         if (string.IsNullOrEmpty (inputName.text)) {
71             Btn_change.SetActive (false);
72             Inputchangepass.SetActive (false);
73             Inputchangename.SetActive (false);
74             ui_information.gameObject.SetActive(false);
75             showtootip( "提示信息:请输入昵称");
76             return;
77         }
78
79
80         XmlDocument xmlDoc = new XmlDocument ();
81         xmlDoc.Load (_xmlpath);
82         XmlNodeList nodeList = xmlDoc.SelectSingleNode ("Root").ChildNodes;
83
84
85         foreach (XmlElement xe in nodeList) {
86             //判断用户是否存在
87             if (xe.GetAttribute ("user_name") == inputName.text) {
88                 //var mima = xe.GetAttribute ("user_pass");
89                 Btn_change.SetActive (true);
90                 ui_information.gameObject.SetActive(true);
91                 ui_information.text= "帐号" + xe.GetAttribute ("user_name") +"密码:"+ xe.GetAttribute ("user_pass");
92                 showtootip("提示信息:账户存在");
93                 return;
94             } else {
95                 Btn_change.SetActive (false);
96                 Inputchangepass.SetActive (false);
97                 Inputchangename.SetActive (false);
98                 showtootip( "提示信息:账户不存在" );
99                 ui_information.text = "";
100             }
101         }
102     }
103
104
105
106
107     public void Changename(){
108
109         XmlDocument xmlDoc = new XmlDocument ();
110         xmlDoc.Load (_xmlpath);
111         XmlNodeList nodeList = xmlDoc.SelectSingleNode ("Root").ChildNodes;
112
113         if (string.IsNullOrEmpty (inputName.text)) {
114             Btn_change.SetActive (false);
115             Inputchangepass.SetActive (false);
116             Inputchangename.SetActive (false);
117             ui_information.text = "";
118             showtootip("提示信息:请输入昵称");
119             return;
120         } else {
121
122             if (string.IsNullOrEmpty (inputChangename.text)) {
123                 showtootip(  "提示信息:请输入修改用户名");
124                 return;
125             }
126
127
128             foreach (XmlElement xe in nodeList) {
129                 //判断用户名是否存在
130                 if ( inputChangename.text == xe.GetAttribute ("user_name")) {
131                     showtootip ("提示信息:用户名已存在,请重新输入");
132                     inputChangename.text = "";
133                     return;
134
135                 } else {
136
137
138                     if (inputName.text == xe.GetAttribute ("user_name") ) {
139
140                         xe.SetAttribute ("user_name", inputChangename.text);
141                         ui_information.text = "帐号" + xe.GetAttribute ("user_name") + "密码:" + xe.GetAttribute ("user_pass");
142                         showtootip(  "提示信息:用户名修改成功");
143                         inputName.text = "";
144                         inputChangename.text = "";
145                         Btn_change.SetActive (false);
146                         Inputchangepass.SetActive (false);
147                         Inputchangename.SetActive (false);
148
149                     }
150
151
152                 }
153             }
154         }
155         xmlDoc.Save (_xmlpath);
156     }
157
158     public void Changepass(){
159
160         XmlDocument xmlDoc = new XmlDocument ();
161         xmlDoc.Load (_xmlpath);
162         XmlNodeList nodeList = xmlDoc.SelectSingleNode ("Root").ChildNodes;
163
164         if (string.IsNullOrEmpty (inputName.text.Trim ())) {
165             Btn_change.SetActive (false);
166             Inputchangepass.SetActive (false);
167             Inputchangename.SetActive (false);
168             showtootip( "提示信息:请输入昵称");
169             ui_information.text = "";
170             inputChangepass.text = "";
171             return;
172         } else {
173
174             if (string.IsNullOrEmpty (inputChangepass.text) || inputChangepass.text.Length != 8) {
175                 showtootip( "提示信息:请输入8位修改密码");
176                 return;
177             } else {
178
179                 foreach (XmlElement xe in nodeList) {
180                     //判断用户名是否存在
181
182                     if (xe.GetAttribute ("user_name") == inputName.text) {
183
184                         xe.SetAttribute ("user_pass", inputChangepass.text);
185                         ui_information.text = "帐号" + xe.GetAttribute ("user_name") + "密码:" + xe.GetAttribute ("user_pass");
186                         showtootip( "提示信息:密码修改成功");
187                         inputChangepass.text = "";
188                         inputName.text = "";
189                         Btn_change.SetActive (false);
190                         Inputchangepass.SetActive (false);
191                         Inputchangename.SetActive (false);
192
193                     }
194
195
196
197                 }
198             }
199         }
200         xmlDoc.Save (_xmlpath);
201     }
202
203     void clearmessage(){
204         ui_tootip.text = "";
205     }
206
207     void showtootip(string ss){
208         ui_tootip.text = ss;
209         Invoke ("clearmessage", 2F);
210     }
211
212
213
214 }


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐