Example #1
0
        /// <summary>
        /// A method for registering new guests
        /// </summary>
        private void SignUpExecute()
        {
            try
            {
                Service s = new Service();

                string name    = Guest.GuestName;
                string surname = Guest.GuestSurname;
                string jmbg    = Guest.JMBG;
                string email   = Guest.EMail;

                //JMBG validation
                if (!ValidationJMBG.CheckJMBG(jmbg))
                {
                    return;
                }

                //Check if the JMBG exists in the database
                tblGuest employee = s.GetGuestJMBG(jmbg);

                if (employee != null)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show("JMBG already exists in the database, try another.", "JMBG");
                    return;
                }

                //Check if the email exists in the database
                tblGuest employeeEmail = s.GetGuestEmail(email);

                if (employeeEmail != null)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show("E-mail already exists in the database, try another.", "E-mail");
                    return;
                }

                s.AddGuest(Guest);

                IsUpdateGuest = true;

                string poruka = "Guest: " + Guest.GuestName + " " + Guest.GuestSurname;
                Xceed.Wpf.Toolkit.MessageBox.Show(poruka, "Successfully added Guest", MessageBoxButton.OK);
                login.txtName.Text                = "";
                login.txtSurname.Text             = "";
                login.txtJMBG.Text                = "";
                login.txtEmail.Text               = "";
                login.pnlLoginGuest.Visibility    = Visibility.Visible;
                login.pnlLoginEmployee.Visibility = Visibility.Collapsed;
                login.pnlSignUpGuest.Visibility   = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show(ex.ToString());
            }
        }
        private void SignUpExecute()
        {
            try
            {
                Service s = new Service();

                string jmbg  = Employee.JMBG;
                string AN    = Employee.AccountNumber;
                string user  = Employee.UsernameLogin;
                string email = Employee.EMail;

                if (!ValidationJMBG.CheckJMBG(jmbg))
                {
                    return;
                }

                tblEmployee employee = s.GetEmployeeJMBG(jmbg);

                if (employee != null)
                {
                    MessageBox.Show("JMBG already exists in the database, try another.", "JMBG");
                    return;
                }



                tblEmployee employeeAN = s.GetEmployeeAccountNumber(AN);

                if (employeeAN != null)
                {
                    MessageBox.Show("Account Number already exists in the database, try another.", "Account Number");
                    return;
                }


                tblEmployee employeeUser = s.GetEmployeeUsername(user);

                if (employeeUser != null)
                {
                    MessageBox.Show("Username already exists in the database, try another.", "Username");
                    return;
                }


                tblEmployee employeeEmail = s.GetEmployeeEmail(email);

                if (employeeEmail != null)
                {
                    MessageBox.Show("E-mail already exists in the database, try another.", "E-mail");
                    return;
                }


                if (main.cbxSector.Text != "" && main.cbxAccessLevel.Text != "")
                {
                    Employee.SectorName  = Convert.ToInt32(Sector.SectorID);
                    Employee.AccessLevel = Convert.ToInt32(AccessLevel.AccessLevelID);
                }
                CreateManager.logName     = main.txtIme.Text.ToString();
                CreateManager.logSurname  = main.txtPrezime.Text.ToString();
                CreateManager.logJMBG     = main.txtJMBG.Text.ToString();
                CreateManager.logEmail    = main.txtEmail.Text.ToString();
                CreateManager.logUsername = main.txtKorisnickoIme.Text.ToString();
                CreateManager.logPassword = main.txtLozinkaRegistracija.Text.ToString();
                CreateManager.logSector   = main.cbxSector.Text.ToString();
                CreateManager.logAccess   = main.cbxAccessLevel.Text.ToString();
                CreateManager.logPosition = main.txtPosition.Text.ToString();

                string logMessage = $"Manager: [{CreateManager.logName} {CreateManager.logSurname }] Position: [{CreateManager.logPosition}] Sector: [{ CreateManager.logSector}] " +
                                    $"Access Level: [{ CreateManager.logAccess}] Username: [{CreateManager.logUsername }] Password: [{CreateManager.logPassword }] Email: [{ CreateManager.logEmail}] JMBG: [{CreateManager.logJMBG }] ";

                if (main.cbxSector.Text != "" && main.cbxAccessLevel.Text != "")
                {
                    Thread logThread = new Thread(() => LogMethod(logMessage));
                    logThread.Start();
                }

                s.AddEmployee(Employee);
                IsUpdateEmployee = true;
                //main.Close();
                main.NameTextBox.Text     = "";
                main.passwordBox.Password = "";
                main.txtPasswordBox.Text  = "";
                main.login.Visibility     = Visibility.Visible;
                main.Images0.Visibility   = Visibility.Collapsed;
                main.Images1.Visibility   = Visibility.Visible;
                main.SignUp.Visibility    = Visibility.Collapsed;

                string poruka = "Add Employee: " + Employee.EmployeeName + " " + Employee.EmployeeSurname;
                //if (EmployeeMenuViewModel.addEmployee != true)
                //{
                MessageBox.Show(poruka, "successfully added employee", MessageBoxButton.OK);
                //}
                main.txtIme.Text                   = "";
                main.txtPrezime.Text               = "";
                main.txtJMBG.Text                  = "";
                main.dpDatumRodjenja.Text          = "";
                main.txtAccountNumber.Text         = "";
                main.txtEmail.Text                 = "";
                main.txtKorisnickoIme.Text         = "";
                main.txtLozinkaRegistracija.Text   = "";
                main.txtReLozinkaRegistracija.Text = "";
                main.txtSalary.Text                = "";
                main.txtPosition.Text              = "";
                main.cbxSector.Text                = "";
                main.cbxAccessLevel.Text           = "";
                main.NameTextBox.Focus();
                if (EmployeeMenuViewModel.addEmployee == true)
                {
                    main.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }