예제 #1
0
파일: Login.xaml.cs 프로젝트: xwgli/hrv
        /// <summary>
        /// 登录动作
        /// </summary>
        private void OnLogin()
        {
            if (String.IsNullOrEmpty(this.userText.Text) || String.IsNullOrEmpty(this.pwdText.Password))
            {
                PmtsMessageBox.CustomControl1.Show("请输入用户ID或密码", PmtsMessageBox.ServerMessageBoxButtonType.OK);
            }
            else
            {
                bool isAdd = true;
                if (objNodeXml.uList.Count > 0)
                {
                    for (int i = 0; i < objNodeXml.uList.Count; i++)
                    {
                        String nameStr = objNodeXml.uList[i].uName;
                        if (nameStr == this.userText.Text)
                        {
                            isAdd = false;
                            break;
                        }
                    }
                }
                else
                {
                    isAdd = true;
                }
                if (isAdd)
                {
                    try
                    {
                        LogUserList addUser = new LogUserList();
                        addUser.uName = this.userText.Text;
                        objNodeXml.uList.Add(addUser);
                        String        xmlTest       = "./Config/UserList.xml";
                        XmlSerializer objSerializer = new XmlSerializer(typeof(NodeXml));
                        StreamWriter  objStream     = new StreamWriter(xmlTest);
                        objSerializer.Serialize(objStream, objNodeXml);
                        objStream.Close();
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.Write("生成XML时出错:" + ex.Message + "\n");
                    }
                }
                /*-------------------------------------------------------------------------------------*/
                try
                {
                    //开始线程

/*                    Thread udpT = new Thread(OnUdpReceive);
 *                  udpT.Name = "UDP_GET_IP";
 *                  udpT.IsBackground = true;
 *                  udpT.Start();
 *                  //启用超时定时器
 *                  timeOut = new DispatcherTimer();
 *                  timeOut.Interval = new TimeSpan(0, 0, 5);
 *                  timeOut.Tick += OnUDPTimeOut;
 *                  timeOut.Start();
 * by lich*/
                    string       returnData  = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$";
                    GetIpAddress methodFroIp = OnIpChanged;
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, methodFroIp, returnData);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                /*---------------------------------------记录用户登录历史(完成后需要移动到OnIpChanged方法中)----------------------------------------------*/
                //Main mainWindow = new Main("127.0.0.1", this.userText.Text);
                //mainWindow.Show();
                //this.Close();
            }
        }
예제 #2
0
        /// <summary>
        /// 登录动作
        /// </summary>
        private void OnLogin()
        {
            if (String.IsNullOrEmpty(this.userText.Text) || String.IsNullOrEmpty(this.pwdText.Password))
            {
                PmtsMessageBox.CustomControl1.Show("请输入用户ID或密码", PmtsMessageBox.ServerMessageBoxButtonType.OK);
                return;
            }

            bool isAdd = true;

            if (objNodeXml.uList.Count > 0)
            {
                for (int i = 0; i < objNodeXml.uList.Count; i++)
                {
                    String nameStr = objNodeXml.uList[i].uName;
                    if (nameStr == this.userText.Text)
                    {
                        isAdd = false;
                        break;
                    }
                }
            }
            else
            {
                isAdd = true;
            }
            if (isAdd)
            {
                try
                {
                    LogUserList addUser = new LogUserList();
                    addUser.uName = this.userText.Text;
                    objNodeXml.uList.Add(addUser);
                    String        xmlTest       = "./Config/UserList.xml";
                    XmlSerializer objSerializer = new XmlSerializer(typeof(NodeXml));
                    StreamWriter  objStream     = new StreamWriter(xmlTest);
                    objSerializer.Serialize(objStream, objNodeXml);
                    objStream.Close();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write("生成XML时出错:" + ex.Message + "\n");
                }
            }

            try
            {
                var resp = APIClient._Login(new LoginRequest()
                {
                    username = this.userText.Text,
                    password = this.pwdText.Password,
                });

                if (null == resp || null == resp.data)
                {
                    PmtsMessageBox.CustomControl1.Show("网络异常,请稍后重试");
                }
                else if (resp.data.success != "1")
                {
                    PmtsMessageBox.CustomControl1.Show(resp.data.message);
                }
                else
                {
                    UserInfoStatic.UserInfo = resp.data.userInfo;
                    Main main = new Main("127.0.0.1", this.userText.Text);
                    main.Show();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                PmtsMessageBox.CustomControl1.Show(ex.Message);
            }
        }