コード例 #1
0
 private void UserControl_Unloaded(object sender, RoutedEventArgs e)
 {
     StatusMessage.setStatus("Ready", "");
 }
コード例 #2
0
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                userName = Txtusername.Text;
                //password = TxtPassword.Password.ToString().EncryptPassword();
                password = TxtPassword.Password;

                var focusedControl = Keyboard.FocusedElement;

                if (userName.Trim().Length <= 0)
                {
                    ShowInformationMessage(PDMsg.NotEmpty("User name"));
                    Txtusername.Focus();
                    return;
                }

                if (TxtPassword.Password.Trim().Length <= 0)
                {
                    ShowInformationMessage(PDMsg.NotEmpty("Password"));
                    TxtPassword.Focus();
                    return;
                }

                UserInformation _userInformation = new UserInformation();
                _userInformation.UserName      = userName;
                _userInformation.Dal           = loggedon.Dal;
                _userInformation.SFLPDDatabase = loggedon.DB;

                bool isForceToChangePassword;
                bool isValid = loggedon.IsValidUser(userName, password, out isForceToChangePassword);
                if (isValid)
                {
                    _userInformation.UserRole = loggedon.GetUserRole(userName);
                    _userInformation.Version  = loggedon.GetVersion();
                    if (string.IsNullOrEmpty(_userInformation.UserRole))
                    {
                        result = ShowInformationMessage(PDMsg.RoleNotDefined);
                        return;
                    }
                    Application.Current.Properties.Add("userinfo", _userInformation);
                    isForceToChangePassword = false;
                    if (isForceToChangePassword)
                    {
                        ProcessDesigner.frmChangePassword changePassword = new ProcessDesigner.frmChangePassword(_userInformation);
                        changePassword.Owner         = this;
                        changePassword.ShowInTaskbar = false;
                        changePassword.txtOldPassword.Focus();
                        changePassword.ShowDialog();

                        bool isPasswordChanged = changePassword.IsUserVerified;
                        if (!isPasswordChanged)
                        {
                            App.Current.Shutdown();
                        }
                    }

                    ProcessDesigner.MainWindow mw = new ProcessDesigner.MainWindow(_userInformation);
                    bool isAdmin = loggedon.GetisAdmin(userName);
                    if (isAdmin)
                    {
                        mw.miSecurity.Visibility = Visibility.Visible;
                        mw.miPartNumberConfiguration.Visibility = Visibility.Visible;
                        mw.miExhibit.Visibility        = Visibility.Visible;
                        mw.miLocationMaster.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        mw.miSecurity.Visibility = Visibility.Collapsed;
                        mw.miPartNumberConfiguration.Visibility = Visibility.Collapsed;
                        mw.miExhibit.Visibility        = Visibility.Collapsed;
                        mw.miLocationMaster.Visibility = Visibility.Collapsed;
                    }

                    StatusMessage.StatusBarDetails = mw.stMain;
                    StatusMessage.UserName         = userName;
                    StatusMessage.setStatus("Ready");
                    string hostname = Dns.GetHostName();
                    //  string ip = Dns.GetHostByName(hostname)[0].ToString();
                    string ip       = Dns.GetHostByName(hostname).AddressList[0].ToString();
                    string username = _userInformation.UserName;
                    bll = new ActiveUsersBLL(_userInformation);
                    bll.LogIn(username, ip, hostname);
                    mw.Show();
                    this.Close();
                }
                else
                {
                    result = ShowInformationMessage(PDMsg.WrongUNamePassword);
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowInformationMessage(PDMsg.WrongUNamePassword);
                ex.LogException();
                return;
            }
        }