示例#1
0
        // check username and password validity
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (IsValid())
            {
                User _user = null;
                try
                {
                    _user = (User)userBL.isItValidUser(new User(username.Text, password.Password, null));
                }
                catch (System.Data.DataException error)
                {
                    MessageBox.Show(error.Message);
                }

                if (_user != null)
                {
                    MessageBox.Show("Log in done successfully!\nPlease click OK to continue");

                    Rank _rank;
                    if (_user.Person is Customer || _user.Person is ClubMember)
                    {
                        _rank = Rank.Customer;
                    }
                    else
                    {
                        _rank = ((Employee)(_user.Person)).Rank;
                    }

                    parentWindow.user = _user;
                    parentWindow.rank = (int)_rank;

                    // display the username and permission in the main Window at the upper left square
                    parentWindow.title_name.Text = "Hey " + _user.ToString() + "!";
                    parentWindow.title_rank.Text = "Logged in as " + ((_user.Person is ClubMember) ? ("Club Member") : (_rank.ToString()));

                    parentWindow.Permissions(); // activate permissions control
                    isEndProccess = false;
                    this.Close();
                    parentWindow.Show();
                }
            }
        }
        // Add or edit
        private void AddOrEdit(object sender, RoutedEventArgs e)
        {
            if (IsValid())
            {
                Customer newObj = new Customer(int.Parse(ID.Text), firstName.Text, lastName.Text);

                //adding action
                if (isAdd)
                {
                    User newUser = new User(username.Text, password.Password, newObj);
                    if (parentWindow.AddDataEntity(newObj, newUser, 2))
                    {
                        this.Close();
                        if (isRegister)
                        {
                            MessageBox.Show("Registration to E-MART done successfully!\nPlease click OK to continue");

                            // if this is a self registration - then send the user to the main window as a customer
                            parentWindow.user = newUser;
                            parentWindow.rank = (int)Rank.Customer;

                            // display the username and permission in the main Window at the upper left square
                            parentWindow.title_name.Text = "Hey " + newUser.UserName + "!";
                            parentWindow.title_rank.Text = "Logged in as " + Rank.Customer;

                            parentWindow.Permissions(); // activate permissions control
                            parentWindow.Show();

                            login.Close();
                        }
                        else
                        {
                            MessageBox.Show("Customer was added successfully!\nPlease click OK to continue");
                        }
                    }
                }
                //editing action
                else
                {
                    newObj.CreditCard  = ((Customer)oldObj).CreditCard;
                    newObj.TranHistory = ((Customer)oldObj).TranHistory;
                    if (parentWindow.EditDataEntity(oldObj, newObj, 2))
                    {
                        this.Close();
                    }
                }
            }
        }