Beispiel #1
0
 private void PasswordTextKeyDown(object sender, KeyRoutedEventArgs e)
 {
     if (sender != null)
     {
         try
         {
             if (e.Key == Windows.System.VirtualKey.Enter)
             {
                 if (string.IsNullOrEmpty(UsernameText.Text))
                 {
                     UsernameText.Focus(FocusState.Programmatic);
                 }
                 else if (string.IsNullOrEmpty(PasswordText.Password))
                 {
                     PasswordText.Focus(FocusState.Programmatic);
                 }
                 else
                 {
                     if (DataContext is LoginViewModel context)
                     {
                         if (context != null)
                         {
                             context.RunLogin(null);
                         }
                     }
                 }
             }
         }
         catch { }
     }
 }
        /// <summary>
        /// Validating user inputs
        /// </summary>
        private bool ValidateParameters()
        {
            if (string.IsNullOrWhiteSpace(UrlText.Text))
            {
                MessageBox.Show("Please enter SharePoint Url value.");
                UrlText.Focus();
                return(false);
            }

            if (string.IsNullOrWhiteSpace(UserText.Text))
            {
                MessageBox.Show("Please enter User value.");
                UserText.Focus();
                return(false);
            }

            if (string.IsNullOrWhiteSpace(PasswordText.Text))
            {
                MessageBox.Show("Please enter Password.");
                PasswordText.Focus();
                return(false);
            }

            return(true);
        }
Beispiel #3
0
 private void UsernameTextKeyDown(object sender, KeyRoutedEventArgs e)
 {
     if (e.Key == Windows.System.VirtualKey.Enter)
     {
         try
         {
             if (string.IsNullOrEmpty(UsernameText.Text))
             {
                 UsernameText.Focus(FocusState.Keyboard);
             }
             else
             {
                 PasswordText.Focus(FocusState.Keyboard);
             }
         }
         catch { }
     }
 }
        private void LoginBtn_Click(object sender, RoutedEventArgs e)
        {
            //登录按钮

            var username = UserName.Text.Trim();
            var password = PasswordText.Password;

            if (string.IsNullOrEmpty(username) || username == "账  号")
            {
                MessageBox.Show("请输入用户名!", "登陆失败", MessageBoxButton.OK, MessageBoxImage.Information);
                UserName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(password))
            {
                MessageBox.Show("请输入密码!", "登陆失败", MessageBoxButton.OK, MessageBoxImage.Information);
                PasswordText.Focus();
                return;
            }
            this.UserLoading.Visibility = Visibility.Visible;
            LoginBtn.IsEnabled          = false;
            UserName.IsEnabled          = false;
            PasswordText.IsEnabled      = false;
            var enPassword = password;

            if (!isMd5Pwd)
            {
                enPassword = SecureHelper.MD5(password);
            }
            string resp;
            var    dlg = new MainWindow();

            dlg.Show();
            this.Close();


            /*
             * //发送请求 发送一个异步请求
             * ThreadPool.QueueUserWorkItem((object state) =>
             * {
             *  //模拟一下等待
             *  Thread.Sleep(100);
             *  try
             *  {
             *      //从配置文件中取web地址
             *      var serverUrl = XmlHelper.GetValue("ServerUrl");
             *      if (string.IsNullOrEmpty(serverUrl))
             *      {
             *          //默认为内网测试地址
             *          serverUrl = "http://192.168.105.80:8082";
             *      }
             *      //接口的地址为 web地址+"/api/tealivelogin"
             *      serverUrl = serverUrl + "/api/tealivelogin";
             *
             *      LogHelper.AddEventLog("登录时发送的Http请求为:" + serverUrl);
             *      resp = HttpWebHelper.HttpPost(serverUrl,
             *          "u=" + username + "&p=" + enPassword);
             *      LogHelper.AddEventLog("登录时发送的Http请求返回为:" + resp);
             *      Dispatcher.Invoke(new Action(delegate
             *      {
             *          this.UserLoading.Visibility = Visibility.Collapsed;
             *          LoginBtn.IsEnabled = true;
             *          UserName.IsEnabled = true;
             *          PasswordText.IsEnabled = true;
             *      }));
             *
             *  }
             *  catch (Exception ex)
             *  {
             *      LogHelper.AddErrorLog(ex.ToString());
             *      MessageBox.Show("访问服务器失败,请检查网络连接!", "登陆失败", MessageBoxButton.OK, MessageBoxImage.Information);
             *
             *      Dispatcher.Invoke(new Action(delegate
             *      {
             *          this.UserLoading.Visibility = Visibility.Collapsed;
             *          LoginBtn.IsEnabled = true;
             *          UserName.IsEnabled = true;
             *          PasswordText.IsEnabled = true;
             *      }));
             *      return;
             *  }
             *  var list = JsonHandleHelper.DataRowFromJSON(resp);
             *  var dataJson = JsonHandleHelper.ObjectToJson(list["Data"]);
             *  var courses = JsonHandleHelper.JSONToObject<List<Course>>(dataJson);
             *  //判断是否登录成功
             *  if (list["R"].ToString() == "1")
             *  {
             *      var rtmpserverUrl = list["FMS_Url"];
             *      var trueName = list["TrueName"];
             *      var headPhoto = list["HeadPhoto"].ToString();
             *      //登录成功
             *
             *      Dispatcher.Invoke(new Action(delegate
             *      {
             *          if (RememberCheckBox.IsChecked == true && !isMd5Pwd)
             *          {
             *              //记录用户名和密码
             *              var enPwd = Base64Helper.Base64Encode(password);
             *              XmlHelper.StoreUsers(username, enPwd);
             *          }
             *      }));
             *
             *      //登陆成功后删除上传的直播的课程的VideoTemp
             *      ThreadPool.QueueUserWorkItem(o =>
             *      {
             *          FileHelper.ClearFolder(FFmpegHelper.VideoPath);
             *      });
             *      //打开直播界面
             *      Dispatcher.Invoke(new Action(delegate
             *      {
             *          var dialog = new SecondWindow();
             *          if (courses != null && courses.Count > 0)
             *          {
             *              dialog.SetCourseList(courses);
             *              dialog.SetRtmpServerUrl(rtmpserverUrl.ToString());
             *              dialog.SetTrueName(string.IsNullOrEmpty(trueName?.ToString())
             *                  ? username
             *                  : trueName.ToString());
             *              dialog.SetUserName(username);
             *              dialog.SetUserImg(headPhoto);
             *          }
             *          dialog.Show();
             *          this.Close();
             *      }));
             *  }
             *  else
             *  {
             *      //登录失败
             *      if (string.IsNullOrEmpty(list["M"].ToString()))
             *      {
             *          MessageBox.Show("用户名和密码错误,请重新输入!", "登陆失败", MessageBoxButton.OK, MessageBoxImage.Information);
             *      }
             *      else
             *      {
             *          MessageBox.Show(list["M"].ToString(), "登陆失败", MessageBoxButton.OK, MessageBoxImage.Information);
             *      }
             *  }
             * }, null);
             */
        }
Beispiel #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            password = ConfirmPassword.Text;
            //string encryptedPassword = Encrypt(password);
            int    phoneNumber = PhoneText.Text.Length;
            int    passLength  = PasswordText.Text.Length;
            string gender      = "";

            if (MaleButton.Checked)
            {
                gender = MaleButton.Text;
            }
            if (FemaleButton.Checked)
            {
                gender = FemaleButton.Text;
            }
            //this.Hide();
            //Home ss = new Home();
            // ss.Show();

            //check field empty or not
            if (string.IsNullOrEmpty(NameTextBox.Text) == true)
            {
                MessageBox.Show("Please enter First Name");
                NameTextBox.Focus();
            }
            else if (string.IsNullOrEmpty(LastNameTextBox.Text) == true)
            {
                MessageBox.Show("Please enter Last Name");
                LastNameTextBox.Focus();
            }
            else if (string.IsNullOrEmpty(EmailTextBox.Text) == true)
            {
                MessageBox.Show("Please enter Email");
                EmailTextBox.Focus();
            }
            else if (Regex.IsMatch(EmailTextBox.Text, emailValStr) == false)
            {
                MessageBox.Show("Invalid email!!");
                EmailTextBox.Focus();
            }

            else if (string.IsNullOrEmpty(StudentIDTextBox.Text) == true)
            {
                MessageBox.Show("Please enter your ID");
                StudentIDTextBox.Focus();
            }
            else if (string.IsNullOrEmpty(PhoneText.Text) == true)
            {
                MessageBox.Show("Please enter Phone Number");
                PhoneText.Focus();
            }

            else if (phoneNumber != 11)
            {
                MessageBox.Show("Please enter valid phone number");
                PhoneText.Focus();
            }
            else if (string.IsNullOrEmpty(gender) == true)
            {
                MessageBox.Show("Please select gender");
                ConfirmPassword.Focus();
            }
            else if (string.IsNullOrEmpty(PasswordText.Text) == true)
            {
                MessageBox.Show("Please type Password");
                PasswordText.Focus();
            }
            else if (passLength <= 8)
            {
                MessageBox.Show(Convert.ToString(passLength));
                MessageBox.Show("Your password should contain minimum 8 characters or numbers");
                PasswordText.Focus();
            }
            else if (string.IsNullOrEmpty(ConfirmPassword.Text) == true)
            {
                MessageBox.Show("Please type Password again");
                ConfirmPassword.Focus();
            }
            else if (PasswordText.Text != ConfirmPassword.Text)
            {
                MessageBox.Show("You typed the wrond password");
                PasswordText.Focus();
            }

            else
            {
                // conn.ConnectionString = @"Data Source=LAPTOP-UDPCMQEF;Initial Catalog=LibraryManagementSystem;Integrated Security=True";
                //  conn.Open();


                SqlCommand cmd = new SqlCommand("insert into Person" + "(first_name,last_name,password,email,student_id,gender,contact_no) values (@first_name,@last_name,aes_encrypt(@password, 'key'),@email,@student_id,@gender,@contact_no)", connDB.getConn());
                cmd.Parameters.AddWithValue("@first_name", NameTextBox.Text);
                cmd.Parameters.AddWithValue("@last_name", LastNameTextBox.Text);
                cmd.Parameters.AddWithValue("@email", EmailTextBox.Text);
                cmd.Parameters.AddWithValue("@student_id", StudentIDTextBox.Text);
                cmd.Parameters.AddWithValue("@gender", gender);
                cmd.Parameters.AddWithValue("@contact_no", PhoneText.Text);
                cmd.Parameters.AddWithValue("@password", password);
                cmd.ExecuteNonQuery();
                MessageBox.Show("You are registered now");
            }
        }
 protected override void OnShown(EventArgs e)
 {
     PasswordText.Focus();
     base.OnShown(e);
 }