public void saveUpdateCompany(Company company)
        {
            CompanyFrm cFrm = new CompanyFrm(company);
            bool result = (bool)cFrm.ShowDialog();
            cFrm.Close();

            if (result)
            {
                try
                {
                    Generic<Company> gen = new Generic<Company>();
                    if (company.Id == 0)
                        gen.Add(company);
                    else
                        gen.Update(company, company.Id);

                    gen.Dispose();
                    MessageBox.Show("The company was saved successfully", "Company saved", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    MessageBox.Show("There was a problem saving this company to the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                // reload companies and refresh ListBox
                loadCompanies();
            }
        }
Esempio n. 2
0
        public static void startApp(bool debugMode = false)
        {
            if (debugMode || showLoginFrm())
            {
                // user logged in
                // init global vars
                Generic<Company> generic = new Generic<Company>();
                Global.companies = generic.GetAll().ToList();
                generic.Dispose();

                if (debugMode)
                {
                    Global.user = new User();
                    Global.user.Role = "user";
                    Global.user.Username = "******";
                    Global.user.Company = Global.companies[0];
                    //Global.user.Role = "admin";
                    //Global.user.Username = "******";
                }

                // show main window
                MainWindow appmainwindow = new MainWindow(Global.user);
                appmainwindow.Activate();
                appmainwindow.ShowDialog();

                if (appmainwindow.logout) // user clicked logout
                {
                    Process.Start(Application.ResourceAssembly.Location); // starts new instance of program
                }
            }

            Application.Current.Shutdown();
        }
Esempio n. 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            setDefaultUsers();

            String username, password;

            username = tbUsername.Text;
            password = tbPassword.Password;

            if (Membership.ValidateUser(username, password))
            {
                user.Authenticated = true;
                user.Username = username;
                user.Membership = Membership.GetUser(username);
                result = true;

                if (Roles.IsUserInRole(username, "admin"))
                    user.Role = "admin";
                else
                    user.Role = "user";

                // get usersPerCompany
                Generic<UsersPerCompany> usersPerCompany = new Generic<UsersPerCompany>();
                UsersPerCompany userCompany = usersPerCompany.GetAll().ToList().Find(u => u.UserId == (Guid)user.Membership.ProviderUserKey);
                usersPerCompany.Dispose();

                if (userCompany != null)
                {
                    // get users company
                    Generic<Company> company = new Generic<Company>();
                    user.Company = company.Get(userCompany.CompanyId);
                    company.Dispose();
                }
                else
                {
                    // get default company - hardcoded
                    Generic<Company> company = new Generic<Company>();
                    user.Company = company.Get(1);
                    company.Dispose();
                }

                this.DialogResult = true;
                this.Close();
            }
            else
            {
                MessageBox.Show("Invalid username and/or password.");
                user.Authenticated = false;
            }
        }
        // reloads all companies and refreshes ListBox
        public void loadCompanies()
        {
            // load companies from db
            Generic<Company> generic = new Generic<Company>();
            Global.companies = generic.GetAll().ToList();
            generic.Dispose();

            // clear listbox and add companies
            lbCompanies.Items.Clear();
            foreach (Company company in Global.companies)
            {
                lbCompanies.Items.Add(company.Name);
            }
        }
 public void updateCompany(Company company)
 {
     try
     {
         Generic<Company> gen = new Generic<Company>();
         gen.Update(company, company.Id);
         gen.Dispose();
         MessageBox.Show("Your company was saved successfully", "Company saved", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     catch (Exception ex)
     {
         Console.Write(ex.ToString());
         MessageBox.Show("There was a problem saving your company to the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
     }
 }
        public SettingsFrm(User user)
        {
            InitializeComponent();

            this.user = user;
            this.company = user.Company;

            // initialize values
            tbName.Text = company.Name;
            tbStreet.Text = company.Street;
            tbZipcode.Text = company.Zipcode;
            tbCity.Text = company.City;
            tbCountry.Text = company.Country;
            tbEmail.Text = company.Email;
            tbPhone.Text = company.Phone;
            tbEmployees.Text = company.Emplyees.ToString();
            loadContracts();

            Generic<ContractFormula> generic = new Generic<ContractFormula>();
            Global.contractFormula = generic.GetAll().ToList();
            generic.Dispose();
        }
        public void getUsersForSelectedCompany()
        {
            // clear all items
            lbUsers.Items.Clear();

            // fetch usersPerCompany
            Generic<UsersPerCompany> generic = new Generic<UsersPerCompany>();
            usersPerCompany = generic.GetAll().ToList();
            generic.Dispose();

            Company selectedCompany = getSelectedCompany();
            if (selectedCompany == null) return;

            //fill listbox with usernames of users from selected company
            foreach (UsersPerCompany user in usersPerCompany)
            {
                if (user.CompanyId == selectedCompany.Id)
                {
                    String username = Membership.GetUser(user.UserId).UserName;
                    lbUsers.Items.Add(username);
                }
            }
        }
        private void loadLocations()
        {
            // load companies from db
            Generic<Location> generic = new Generic<Location>();
            Global.locations = generic.GetAll().ToList();
            generic.Dispose();

            lbLocations.Items.Clear();
            foreach (Location location in Global.locations)
            {
                lbLocations.Items.Add(String.Format("{0}", location.Name));
            }
        }
        private void loadContractFormula()
        {
            // load companies from db
            Generic<ContractFormula> generic = new Generic<ContractFormula>();
            Global.contractFormula = generic.GetAll().ToList();
            generic.Dispose();

            lbContractFormula.Items.Clear();
            foreach (ContractFormula contractFormula in Global.contractFormula)
            {
                lbContractFormula.Items.Add(String.Format("{0}", contractFormula.Description));
            }
        }
        private void loadContracts()
        {
            Generic<Contract> generic = new Generic<Contract>();
            Global.contracts = generic.GetAll().ToList();
            generic.Dispose();

            lvContracts.Items.Clear();
            foreach (Contract contract in Global.contracts)
            {
                if (showAllContracts)
                {
                    lvContracts.Items.Add(contract);
                }
                else
                {
                    int res = ((DateTime)contract.EndDate).CompareTo(DateTime.Today);
                    if (res >= 0)
                        lvContracts.Items.Add(contract);
                }

            }
        }
        private void btnDeleteLocation_Click(object sender, RoutedEventArgs e)
        {
            // return if no selection made
            int index = lbLocations.SelectedIndex;
            if (index == -1) return;

            MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this location?", "Are you sure?", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.Yes)
            {
                try
                {
                    Generic<Location> generic = new Generic<Location>();
                    generic.Delete(Global.locations[index]);
                    generic.Dispose();

                    MessageBox.Show("The location was removed successfully", "Location removed", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    MessageBox.Show("There was a problem removing the location from the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                loadLocations();
            }
        }
        private void btnStopContract_Click(object sender, RoutedEventArgs e)
        {
            if (lvContracts.SelectedIndex == -1)
                return;

            Contract contract = (Contract)lvContracts.SelectedItem;
            ContractFormula formula = Global.contractFormula.Find(f => f.Id == contract.ContractFormulaId);
            int? monthsNotice = formula.NoticePeriodInMonths;
            DateTime endDate = (DateTime)contract.EndDate;

            if (endDate < DateTime.Today)
            {
                MessageBox.Show("This contract has already endend", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (monthsNotice != null && DateTime.Today.AddMonths((int)monthsNotice) > endDate)
            {
                MessageBox.Show(String.Format("This contract can't be stopped. The contract formula requires a {0} month notice and this contract ends {1:dd-MM-yy}. ", (int)monthsNotice, endDate), "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            // check for reservations during this contract
            Generic<Reservation> generic = new Generic<Reservation>();
            Global.reservations = generic.GetAll().ToList();
            generic.Dispose();

            List<Reservation> companiesReservations = Global.reservations.FindAll(r => r.CompanyId == contract.CompanyId);
            foreach (Reservation reservation in companiesReservations)
            {
                if (reservation.StartDate <= contract.EndDate && reservation.StartDate >= contract.StartDate)
                {
                    MessageBox.Show("This contract can't be stopped. There are existing reservations during this contract");
                    return;
                }
            }

            if (monthsNotice == null)
            {
                contract.EndDate = DateTime.Today.AddDays(-1);
            }
            else
            {
                contract.EndDate = DateTime.Today.AddMonths((int)monthsNotice);
            }

            try
            {
                Generic<Contract> gen = new Generic<Contract>();
                gen.Update(contract, contract.Id);
                gen.Dispose();
                if (monthsNotice == null)
                    MessageBox.Show("The contract has been stopped successfully.", "Contract saved", MessageBoxButton.OK, MessageBoxImage.Information);
                else
                    MessageBox.Show(String.Format("The contract has a {0} months notice period. The end date has been adjusted accordingly.", (int)monthsNotice), "Contract saved", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
                MessageBox.Show("There was a problem stopping this contract. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            loadContracts();
        }
Esempio n. 13
0
 private void loadReservations()
 {
     Generic<Reservation> generic = new Generic<Reservation>();
     Global.reservations = generic.GetAll().ToList();
     generic.Dispose();
 }
        private void btnDeleteUser_Click(object sender, RoutedEventArgs e)
        {
            if (lbUsers.SelectedIndex == -1) return;

            if (MessageBoxResult.Yes == MessageBox.Show("Are you sure you want to delete this profile?", "Are you sure?", MessageBoxButton.YesNo))
            {
                try
                {
                    Company company = getSelectedCompany();

                    String username = (String)lbUsers.SelectedValue;
                    MembershipUser user = Membership.GetUser(username);
                    Membership.DeleteUser(username);

                    UsersPerCompany userCompany = new UsersPerCompany();
                    userCompany.CompanyId = company.Id;
                    userCompany.UserId = (Guid)user.ProviderUserKey;

                    Generic<UsersPerCompany> generic = new Generic<UsersPerCompany>();
                    generic.Delete(userCompany);
                    generic.Dispose();

                    MessageBox.Show("The profile was removed successfully", "Profile removed", MessageBoxButton.OK, MessageBoxImage.Information);
                    getUsersForSelectedCompany();
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    MessageBox.Show("There was a problem removing this profile from the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
Esempio n. 15
0
        private void DayBoxDoubleClicked_event(NewAppointmentEventArgs e)
        {
            if (e.StartDate < DateTime.Today)
            {
                MessageBox.Show("Sorry. No reservations can be made in the past.", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            //MessageBox.Show("You double-clicked on day " + Convert.ToDateTime(e.StartDate).ToShortDateString(), "Calendar Event", MessageBoxButton.OK);
            Reservation reservation = new Reservation();
            reservation.StartDate = Convert.ToDateTime(e.StartDate).Date + DateTime.Now.TimeOfDay;
            reservation.EndDate = Convert.ToDateTime(e.StartDate).Date + DateTime.Now.TimeOfDay;

            ReservationFrm reservationFrm = new ReservationFrm(reservation);
            bool result = (bool)reservationFrm.ShowDialog();

            if (result)
            {
                try
                {
                    Generic<Reservation> gen = new Generic<Reservation>();
                    if (reservation.Id == 0)
                        gen.Add(reservation);
                    else
                        gen.Update(reservation, reservation.Id);

                    gen.Dispose();
                    MessageBox.Show("The reservation was saved successfully", "Reservation saved", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    MessageBox.Show("There was a problem saving this Reservation to the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                // reload companies and refresh ListBox
                loadCalendar();
            }
        }
        public void createOrEditUser(bool newUser)
        {
            if (!newUser && lbUsers.SelectedIndex == -1) return;

            Company company = getSelectedCompany();
            ProfileFrm form = null;
            MembershipUser user = null;
            bool profileFrmResult = false;

            try
            {
                if (newUser)
                {
                    form = new ProfileFrm(true, company);
                    profileFrmResult = (bool)form.ShowDialog();
                    if (profileFrmResult)
                        user = Membership.CreateUser(form.username, form.password);
                } else {
                    String username = (String)lbUsers.SelectedValue;
                    user = Membership.GetUser(username);

                    form = new ProfileFrm(false, company, user);
                    profileFrmResult = (bool)form.ShowDialog();
                    if (profileFrmResult)
                        Membership.UpdateUser(user);
                }

                if (!profileFrmResult) return;

                UsersPerCompany newUserCompany = new UsersPerCompany();
                UsersPerCompany oldUserCompany = new UsersPerCompany();

                newUserCompany.CompanyId = form.company.Id;
                newUserCompany.UserId = (Guid)user.ProviderUserKey;

                oldUserCompany.CompanyId = company.Id;
                oldUserCompany.UserId = (Guid)user.ProviderUserKey;

                Generic<UsersPerCompany> generic = new Generic<UsersPerCompany>();
                if (!newUser)
                    generic.Delete(oldUserCompany);

                generic.Add(newUserCompany);
                generic.Dispose();
                form.Close();
                MessageBox.Show("The profile was saved successfully", "Company saved", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
                MessageBox.Show("There was a problem saving this profile to the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
        private void loadContracts()
        {
            Generic<Contract> generic = new Generic<Contract>();
            Global.contracts = generic.GetAll().ToList();
            generic.Dispose();

            List<Contract> tempUsersContracts = Global.contracts.FindAll(c => c.CompanyId == user.Company.Id);
            usersActiveContracts = new List<Contract>();

            lbContracts.Items.Clear();
            foreach (Contract contract in tempUsersContracts)
            {
                // add if enddate is today or after
                int res = ((DateTime)contract.EndDate).CompareTo(DateTime.Today);
                if (res >= 0)
                {
                    usersActiveContracts.Add(contract);
                    lbContracts.Items.Add(String.Format("{0:dd/MM/yy} - {1:dd/MM/yy}", contract.StartDate, contract.EndDate));
                }
            }
        }
 private void loadContracts()
 {
     Generic<Contract> generic = new Generic<Contract>();
     Global.contracts = generic.GetAll().ToList();
     generic.Dispose();
 }
        private void btnDeleteReservation_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBoxResult.Yes == MessageBox.Show("Are you sure you want to delete this reservation?", "Are you sure?", MessageBoxButton.YesNo))
            {
                try
                {
                    Generic<Reservation> generic = new Generic<Reservation>();
                    generic.Delete(reservation);
                    generic.Dispose();

                    MessageBox.Show("The reservation was removed successfully", "Reservation removed", MessageBoxButton.OK, MessageBoxImage.Information);
                    this.Close();
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    MessageBox.Show("There was a problem removing this reservation from the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
        public void saveUpdateFormula(ContractFormula contractFormula)
        {
            ContractFormulaFrm cFrm = new ContractFormulaFrm(contractFormula);
            bool result = (bool)cFrm.ShowDialog();
            cFrm.Close();

            if (result)
            {
                try
                {
                    Generic<ContractFormula> gen = new Generic<ContractFormula>();
                    if (contractFormula.Id == 0)
                        gen.Add(contractFormula);
                    else
                        gen.Update(contractFormula, contractFormula.Id);

                    gen.Dispose();
                    MessageBox.Show("The contract formula was saved successfully", "Contract formula saved", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    MessageBox.Show("There was a problem saving this contract formula to the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
        public void saveUpdateLocation(Location location)
        {
            LocationFrm cFrm = new LocationFrm(location);
            bool result = (bool)cFrm.ShowDialog();
            cFrm.Close();

            if (result)
            {
                try
                {
                    Generic<Location> gen = new Generic<Location>();
                    if (location.Id == 0)
                        gen.Add(location);
                    else
                        gen.Update(location, location.Id);

                    gen.Dispose();
                    MessageBox.Show("The location was saved successfully updated", "Location saved", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    MessageBox.Show("There was a problem saving this location to the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
Esempio n. 22
0
 private void loadLocations()
 {
     Generic<Location> generic = new Generic<Location>();
     Global.locations = generic.GetAll().ToList();
     generic.Dispose();
 }
        private void btnDeleteCompany_Click(object sender, RoutedEventArgs e)
        {
            // return if no selection made
            int index = lbCompanies.SelectedIndex;
            if (index == -1) return;

            Company company = Global.companies[index];

            // check for existing contracts
            if (Global.contracts.Find(contract => contract.CompanyId == company.Id) != null)
            {
                MessageBox.Show("You can't delete this company because it has 1 or more existing contracts.", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this company?", "Are you sure?", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.Yes)
            {
                try
                {
                    Generic<Company> generic = new Generic<Company>();
                    generic.Delete(Global.companies[index]);
                    generic.Dispose();

                    MessageBox.Show("The company was removed successfully", "Company removed", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    MessageBox.Show("There was a problem removing this company from the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                // reload companies and refresh ListBox
                loadCompanies();
            }
        }
        private void btnDeleteContract_Click(object sender, RoutedEventArgs e)
        {
            // return if no selection made
            int index = lvContracts.SelectedIndex;
            if (index == -1) return;

            MessageBoxResult result = MessageBox.Show("Are you absolutely sure you want to delete this contract?", "Are you sure?", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.Yes)
            {
                try
                {
                    Generic<Contract> generic = new Generic<Contract>();
                    generic.Delete((Contract)lvContracts.SelectedItem);
                    generic.Dispose();

                    MessageBox.Show("The contract was removed successfully", "Contract removed", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    MessageBox.Show("There was a problem removing this contract from the database. Please try again later or contact a sysadmin.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                loadContracts();
            }
        }
Esempio n. 25
0
        private void saveDefaultUsersCompany(String username)
        {
            UsersPerCompany userCompany = new UsersPerCompany();
            userCompany.UserId = (Guid)Membership.GetUser(username).ProviderUserKey;
            userCompany.CompanyId = 1;

            Generic<UsersPerCompany> generic = new Generic<UsersPerCompany>();
            generic.Add(userCompany);
            generic.Dispose();
        }