天津23维预案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

460 lines
15 KiB

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using AX.NetworkSystem;
using System.Text.RegularExpressions;
public class UserInfoUI : MonoBehaviour {
public InputField UserPoliceIDInputField;
public Dropdown Dropdown_ZongD;
public Dropdown Dropdown_ZhiD;
public Dropdown Dropdown_ZhongD;
public InputField UserNameInputField;
public InputField BeiZhuInputField;
private bool flag = true;
private int currentUserParentID;
private string currentUserParentName;
private List<Dropdown.OptionData> Dropdown_ZhongDOptions = new List<Dropdown.OptionData>();
public Dictionary<int, int> ZhongDData = new Dictionary<int, int>();
private int currentUserGrandpaID;
private string currentUserGrandpaName;
private List<Dropdown.OptionData> Dropdown_ZhiDOptions = new List<Dropdown.OptionData>();
public Dictionary<int, int> ZhiDData = new Dictionary<int, int>();
private int RootID = 0;
private int currentUserRootID;
private List<Dropdown.OptionData> Dropdown_ZongDOptions = new List<Dropdown.OptionData>();
public Dictionary<int, int> ZongDData = new Dictionary<int, int>();
public Button UserInfoButton;
public Button ModifyPasswordButton;
public Button SaveUserInfo;
public Button SavePassword;
public GameObject UserInfoPanel;
public GameObject ModifyPasswordPanel;
public Text UserInfoHint_Text;
public Text ModifyPasHint_Text;
public InputField PasswordInputField;
// Use this for initialization
void Start () {
Dropdown_ZhongDOptions.Add(new Dropdown.OptionData("请选择中队"));
Dropdown_ZhiDOptions.Add(new Dropdown.OptionData("请选择支队"));
Dropdown_ZongDOptions.Add(new Dropdown.OptionData("请选择总队"));
}
// Update is called once per frame
void Update () {
if (this.GetComponent<GET_DEPTS_REPLY>().Depts.Count > 0)
{
if (flag)
{
List<DeptInfo> Depts = this.GetComponent<GET_DEPTS_REPLY>().Depts;
UserPoliceIDInputField.text = MySelf.mySelf.ID;//显示警官号
UserNameInputField.text = MySelf.mySelf.Name;//显示用户真实姓名
BeiZhuInputField.text = MySelf.mySelf.Details;//显示用户备注
flag = false;
ShowDept(Depts);//显示用户组织机构
}
}
}
/// <summary>
/// 显示用户组织机构:中队下拉框,支队下拉框,总队下拉框
/// </summary>
/// <param name="Depts"></param>
private void ShowDept(List<DeptInfo> Depts)
{
foreach (var item in Depts)
{
if (item.ID == MySelf.mySelf.DeptID)
{
if (item.Level == 3)
{
currentUserParentID = item.ParentID;
break;
}
if (item.Level == 2)
{
currentUserGrandpaID = item.ParentID;
currentUserParentName = item.Name;
break;
}
if (item.Level == 1)
{
currentUserRootID = RootID;
currentUserGrandpaName = item.Name;
break;
}
}
}
if (currentUserParentID != 0)
{
foreach (var item in Depts)
{
if (item.ID == MySelf.mySelf.DeptID)
{
currentUserParentID = item.ParentID;
break;
}
}
foreach (var item in Depts)
{
if (item.ID == currentUserParentID)
{
currentUserGrandpaID = item.ParentID;
currentUserParentName = item.Name;
break;
}
}
foreach (var item in Depts)
{
if (item.ID == currentUserGrandpaID)
{
currentUserRootID = RootID;
currentUserGrandpaName = item.Name;
break;
}
}
//总队
foreach (var item in Depts)
{
if (item.ParentID == currentUserRootID)
{
Dropdown_ZongDOptions.Add(new Dropdown.OptionData(item.Name));
ZongDData.Add(Dropdown_ZongDOptions.Count - 1, item.ID);
}
}
Dropdown_ZongD.options = Dropdown_ZongDOptions;
for (int i = 0; i < Dropdown_ZongD.options.Count; i++)
{
if (currentUserGrandpaName == Dropdown_ZongD.options[i].text)
{
Dropdown_ZongD.value = i;
break;
}
}
//支队
foreach (var item in Depts)
{
if (item.ParentID == currentUserGrandpaID)
{
Dropdown_ZhiDOptions.Add(new Dropdown.OptionData(item.Name));
//ZhiDData.Add(Dropdown_ZhiDOptions.Count - 1,item.ID);
}
}
Dropdown_ZhiD.options = Dropdown_ZhiDOptions;
for (int i = 0; i < Dropdown_ZhiD.options.Count; i++)
{
if (currentUserParentName == Dropdown_ZhiD.options[i].text)
{
Dropdown_ZhiD.value = i;
break;
}
}
//中队
foreach (var item in Depts)
{
if (item.ParentID == currentUserParentID)
{
Dropdown_ZhongDOptions.Add(new Dropdown.OptionData(item.Name));
//ZhongDData.Add(Dropdown_ZhongDOptions.Count - 1,item.ID);
}
}
Dropdown_ZhongD.options = Dropdown_ZhongDOptions;
for (int i = 0; i < Dropdown_ZhongD.options.Count; i++)
{
if (MySelf.mySelf.DeptName == Dropdown_ZhongD.options[i].text)
{
Dropdown_ZhongD.value = i;
break;
}
}
}
else
{
if (currentUserGrandpaID != 0)
{
foreach (var item in Depts)
{
if (item.ID == currentUserGrandpaID)
{
currentUserRootID = RootID;
currentUserGrandpaName = item.Name;
break;
}
}
//总队
foreach (var item in Depts)
{
if (item.ParentID == currentUserRootID)
{
Dropdown_ZongDOptions.Add(new Dropdown.OptionData(item.Name));
ZongDData.Add(Dropdown_ZongDOptions.Count - 1, item.ID);
}
}
Dropdown_ZongD.options = Dropdown_ZongDOptions;
for (int i = 0; i < Dropdown_ZongD.options.Count; i++)
{
if (currentUserGrandpaName == Dropdown_ZongD.options[i].text)
{
Dropdown_ZongD.value = i;
break;
}
}
//支队
foreach (var item in Depts)
{
if (item.ParentID == currentUserGrandpaID)
{
Dropdown_ZhiDOptions.Add(new Dropdown.OptionData(item.Name));
//ZhiDData.Add(Dropdown_ZhiDOptions.Count - 1,item.ID);
}
}
Dropdown_ZhiD.options = Dropdown_ZhiDOptions;
for (int i = 0; i < Dropdown_ZhiD.options.Count; i++)
{
if (currentUserParentName == Dropdown_ZhiD.options[i].text)
{
Dropdown_ZhiD.value = i;
break;
}
}
}
else
{
//总队
foreach (var item in Depts)
{
if (item.ParentID == currentUserRootID)
{
Dropdown_ZongDOptions.Add(new Dropdown.OptionData(item.Name));
ZongDData.Add(Dropdown_ZongDOptions.Count - 1, item.ID);
}
}
Dropdown_ZongD.options = Dropdown_ZongDOptions;
for (int i = 0; i < Dropdown_ZongD.options.Count; i++)
{
if (currentUserGrandpaName == Dropdown_ZongD.options[i].text)
{
Dropdown_ZongD.value = i;
break;
}
}
}
}
//foreach (var item in Depts)
//{
// if (item.ID == MySelf.mySelf.DeptID)
// {
// currentUserParentID = item.ParentID;
// break;
// }
//}
//foreach (var item in Depts)
//{
// if (item.ID == currentUserParentID)
// {
// currentUserGrandpaID = item.ParentID;
// currentUserParentName = item.Name;
// break;
// }
//}
//foreach (var item in Depts)
//{
// if (item.ID == currentUserGrandpaID)
// {
// currentUserRootID = RootID;
// currentUserGrandpaName = item.Name;
// break;
// }
//}
////总队
//foreach (var item in Depts)
//{
// if (item.ParentID == currentUserRootID)
// {
// Dropdown_ZongDOptions.Add(new Dropdown.OptionData(item.Name));
// ZongDData.Add(Dropdown_ZongDOptions.Count - 1,item.ID);
// }
//}
//Dropdown_ZongD.options = Dropdown_ZongDOptions;
//for (int i = 0; i < Dropdown_ZongD.options.Count; i++)
//{
// if (currentUserGrandpaName == Dropdown_ZongD.options[i].text)
// {
// Dropdown_ZongD.value = i;
// break;
// }
//}
////支队
//foreach (var item in Depts)
//{
// if (item.ParentID == currentUserGrandpaID)
// {
// Dropdown_ZhiDOptions.Add(new Dropdown.OptionData(item.Name));
// //ZhiDData.Add(Dropdown_ZhiDOptions.Count - 1,item.ID);
// }
//}
//Dropdown_ZhiD.options = Dropdown_ZhiDOptions;
//for (int i = 0; i < Dropdown_ZhiD.options.Count; i++)
//{
// if (currentUserParentName == Dropdown_ZhiD.options[i].text)
// {
// Dropdown_ZhiD.value = i;
// break;
// }
//}
////中队
//foreach (var item in Depts)
//{
// if (item.ParentID == currentUserParentID)
// {
// Dropdown_ZhongDOptions.Add(new Dropdown.OptionData(item.Name));
// //ZhongDData.Add(Dropdown_ZhongDOptions.Count - 1,item.ID);
// }
//}
//Dropdown_ZhongD.options = Dropdown_ZhongDOptions;
//for (int i = 0; i < Dropdown_ZhongD.options.Count; i++)
//{
// if (MySelf.mySelf.DeptName == Dropdown_ZhongD.options[i].text)
// {
// Dropdown_ZhongD.value = i;
// break;
// }
//}
}
public void DisplayUserInfo()
{
UserInfoHint_Text.text = "";
UserInfoPanel.SetActive(true);
ModifyPasswordPanel.SetActive(false);
}
public void DisplayUserPas()
{
ModifyPasHint_Text.text = "";
UserInfoPanel.SetActive(false);
ModifyPasswordPanel.SetActive(true);
}
public void SaveUserInfos()
{
if (Dropdown_ZhongD.value == 0 && Dropdown_ZhiD.value == 0 && Dropdown_ZongD.value == 0)
{
UserInfoHint_Text.text = "组织机构不能为空";
return;
}
if (string.IsNullOrEmpty(UserNameInputField.text))
{
UserInfoHint_Text.text = "真实姓名不能为空";
return;
}
bool flag1 = false;
bool flag2 = false;
bool flag3 = false;
if (Dropdown_ZhongD.value != 0)
{
if (ZhongDData[Dropdown_ZhongD.value] == MySelf.mySelf.DeptID) flag1 = true;
}
else
{
if (Dropdown_ZhiD.value != 0)
{
if (ZhiDData[Dropdown_ZhiD.value] == MySelf.mySelf.DeptID) flag2 = true;
}
else
{
if (Dropdown_ZongD.value != 0)
{
if (ZongDData[Dropdown_ZongD.value] == MySelf.mySelf.DeptID) flag3 = true;
}
}
}
if ((flag1
|| flag2
|| flag3)
&& UserNameInputField.text == MySelf.mySelf.Name
&& BeiZhuInputField.text == MySelf.mySelf.Details)
{
UserInfoHint_Text.text = "用户信息没有改动";
return;
}
else
{
UserInfo currentUser = new UserInfo();
currentUser.ID = MySelf.mySelf.ID;
if (Dropdown_ZhongD.value != 0)
{
currentUser.DeptID = ZhongDData[Dropdown_ZhongD.value];
currentUser.DeptName = Dropdown_ZhongD.options[Dropdown_ZhongD.value].text;
}
else
{
if (Dropdown_ZhiD.value != 0)
{
currentUser.DeptID = ZhiDData[Dropdown_ZhiD.value];
currentUser.DeptName = Dropdown_ZhiD.options[Dropdown_ZhiD.value].text;
}
else
{
if (Dropdown_ZongD.value != 0)
{
currentUser.DeptID = ZongDData[Dropdown_ZongD.value];
currentUser.DeptName = Dropdown_ZongD.options[Dropdown_ZongD.value].text;
}
}
}
//currentUser.DeptName = Dropdown_ZhongD.options[Dropdown_ZhongD.value].text;
currentUser.Name = UserNameInputField.text;
currentUser.Details = BeiZhuInputField.text;
NetworkManager.Default.SendRequestAsync("USERINFO_MODIFY_REQUEST", currentUser);
}
}
public void SaveUserPassword()
{
if (string.IsNullOrEmpty(PasswordInputField.text))
{
ModifyPasHint_Text.text = "密码不能为空";
return;
}
else
{//校验密码格式:
//由字母,0到9数字,特殊字符(~!@#$%^&*)组成;可以全字母;可以全数字,可以全特殊字符;可以任意两种的组合;三种的组合;长度1-22
string Password = PasswordInputField.text;
if (!(Regex.Match(Password, @"^[A-Za-z0-9\~\!\@\#\$\%\^\&\*]{1,22}$").Success))
{
ModifyPasHint_Text.text = "密码由22位字母,数字,特殊符号的任意组合组成";
return;
}
}
NetworkManager.Default.SendRequestAsync("PASSWORD_MODIFY_REQUEST",new string[] { MySelf.mySelf.ID, PasswordInputField.text});
}
}