private void EmployeesForm_Load(object sender, EventArgs e)
        {
            try
            {
                DatabaseFunctions.GetAllUsers();
                DatabaseFunctions.GetAllDepartments();

                employeesLv.Items.Clear();
                foreach (var item in Users.users)
                {
                    ListViewItem lvi = new ListViewItem(item.ID.ToString());
                    lvi.SubItems.Add(item.FirstName);
                    lvi.SubItems.Add(item.LastName);
                    lvi.SubItems.Add(item.Email);
                    lvi.SubItems.Add(item.PhoneNumber);
                    lvi.SubItems.Add(item.Position.ToString());
                    lvi.SubItems.Add(item.Salary.ToString("C2", CultureInfo.CurrentCulture));
                    lvi.SubItems.Add(item.UserDepartment.Name);
                    employeesLv.Items.Add(lvi);
                }
                departmentCb.Items.Clear();
                departmentCb.Items.Add("Department");
                departmentCb.Items.Add("All Departments");
                departmentCb.SelectedIndex = 0;
                foreach (var item in Departments.departments)
                {
                    departmentCb.Items.Add(item.Name);
                }
                roleCb.SelectedIndex = 0;
            }
            catch (NoConnectionException)
            {
                MessageBox.Show("Connection unsuccessful, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (NotExistingException)
            {
                MessageBox.Show("Department is non-existent, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            AnimateWindow(this.Handle, 500, AnimateWindowFlags.AW_SLIDE);
        }
Exemple #2
0
        private void confirmBtn_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(nameTb.Text) && !string.IsNullOrWhiteSpace(priceTb.Text) && !string.IsNullOrWhiteSpace(quantityTb.Text))
            {
                if (categoryCb.SelectedIndex > 0)
                {
                    string productName = nameTb.Text;

                    double          productPrice    = double.Parse(priceTb.Text);
                    int             productQuantity = int.Parse(quantityTb.Text);
                    bool            stockRequest    = stockCbx.Checked;
                    ProductCategory type            = (ProductCategory)Enum.Parse(typeof(ProductCategory), categoryCb.Text, true);

                    if (_editProduct)
                    {
                        _productToBeEdited.Name         = productName;
                        _productToBeEdited.Price        = productPrice;
                        _productToBeEdited.Quantity     = productQuantity;
                        _productToBeEdited.Category     = type;
                        _productToBeEdited.StockRequest = stockRequest;
                        Products.UpdateProduct(_productToBeEdited);
                    }
                    else
                    {
                        Product newProduct = new Product(productName, type, productPrice, productQuantity, stockRequest);
                        Products.AddProduct(newProduct);
                    }
                    DatabaseFunctions.GetAllProducts();
                    this.Close();
                }

                else
                {
                    MessageBox.Show("Choose type!");
                }
            }
            else
            {
                MessageBox.Show("Fill in the empty fields!");
            }
        }
Exemple #3
0
        public MainForm()
        {
            InitializeComponent();

            usernameTb.Click += new EventHandler(click_username);
            usernameTb.Leave += new EventHandler(leave_username);
            passwordTb.Click += new EventHandler(click_password);
            passwordTb.Leave += new EventHandler(leave_password);
            try
            {
                if (!DatabaseFunctions.GetAllUsers() && !DatabaseFunctions.GetAllProducts())
                {
                    MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                if (!DatabaseFunctions.GetAllDepartments())
                {
                    MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }

                if (!File.Exists("idSeeder"))
                {
                    string id = (Users.LastGenUsernameId() + 1).ToString();
                    File.WriteAllLines("idSeeder", new string[] { id });
                }
            }
            catch (NoConnectionException)
            {
                MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (IOException)
            {
                MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
 private void removeBtn_Click(object sender, EventArgs e)
 {
     try
     {
         DatabaseFunctions.RemoveDepartment(_departmentToBeEdited);
         DatabaseFunctions.GetAllDepartments();
         this.Close();
     }
     catch (NoConnectionException)
     {
         MessageBox.Show("Connection unsuccessful, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (NotExistingException)
     {
         MessageBox.Show("Department is non-existent, please restart", "Error", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
     catch (UsersInDepartmentException)
     {
         MessageBox.Show("There are still employees in that department", "Error", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
Exemple #5
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            User user = Users.FindUser(usernameTb.Text.Trim());

            if (user != null)
            {
                if (user.Position == PersonPosition.Manager || user.Position == PersonPosition.Admin)
                {
                    if (user.Position == PersonPosition.Admin)
                    {
                        Users.admin = true;
                    }
                    string pass = DatabaseFunctions.PasswordByUsername(user.Username);
                    if (pass == passwordTb.Text)
                    {
                        loginPnl.Visible     = false;
                        selectionPnl.Visible = true;
                        logOutBtn.Visible    = true;
                        usernameTb.Text      = "Username";
                        passwordTb.Text      = "Password";
                        Users.Department     = user.UserDepartment.Name;
                    }
                    else
                    {
                        MessageBox.Show("Incorrect password, please try again!");
                    }
                }
                else
                {
                    MessageBox.Show("This Platform is only for managers!");
                }
            }
            else
            {
                MessageBox.Show("No such user, please try again!");
            }
        }
        private void DepartmentsForm_Load(object sender, EventArgs e)
        {
            this.StartPosition = FormStartPosition.CenterScreen;


            try
            {
                DatabaseFunctions.GetAllDepartments();
                foreach (var item in Departments.departments)
                {
                    departmentsLb.Items.Add(item.Name);
                }
            }
            catch (NoConnectionException)
            {
                MessageBox.Show("Connection unsuccessful, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (NotExistingException)
            {
                MessageBox.Show("Department is non-existent, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            AnimateWindow(this.Handle, 500, AnimateWindowFlags.AW_SLIDE);
        }
Exemple #7
0
 public static void RemoveUser(User user)
 {
     DatabaseFunctions.RemoveUser(user);
     DatabaseFunctions.GetAllUsers();
 }
Exemple #8
0
 public static void UpdateUser(User user)
 {
     DatabaseFunctions.UpdateUser(user);
     DatabaseFunctions.GetAllUsers();
 }
Exemple #9
0
 public static void AddUser(User user, bool manager = false)
 {
     DatabaseFunctions.AddUser(user, manager);
     DatabaseFunctions.GetAllUsers();
 }
Exemple #10
0
        private void confirmBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(firstNameTb.Text) && !string.IsNullOrWhiteSpace(lastNameTb.Text) &&
                    !string.IsNullOrWhiteSpace(emailTb.Text) && !string.IsNullOrWhiteSpace(salaryTb.Text))
                {
                    if (shiftCb.SelectedIndex > 0 && departmentCb.SelectedIndex > 0 && roleCb.SelectedIndex > 0)
                    {
                        const string emailPattern =
                            "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$";
                        Regex regex = new Regex(emailPattern);
                        if (regex.IsMatch(emailTb.Text))
                        {
                            string         fn         = firstNameTb.Text;
                            string         ln         = lastNameTb.Text;
                            string         email      = emailTb.Text;
                            string         salaryStr  = Regex.Replace(salaryTb.Text, "€", "");
                            double         salary     = double.Parse(salaryStr.Trim());
                            Department     department = Departments.DepartmentByName(departmentCb.SelectedItem.ToString());
                            PersonPosition position   = (PersonPosition)Enum.Parse(typeof(PersonPosition), roleCb.Text, true);
                            if ((position == PersonPosition.Manager && Users.admin) || (position != PersonPosition.Manager))
                            {
                                ShiftType type  = (ShiftType)Enum.Parse(typeof(ShiftType), shiftCb.Text, true);
                                bool[]    _days = new bool[7];
                                _days[0] = mondayCbx.Checked;
                                _days[1] = tuesdayCbx.Checked;
                                _days[2] = wednesdayCbx.Checked;
                                _days[3] = thursdayCbx.Checked;
                                _days[4] = fridayCbx.Checked;
                                _days[5] = saturdayCbx.Checked;
                                _days[6] = sundayCbx.Checked;

                                if (_edit)
                                {
                                    _userToBeEdited.FirstName      = fn;
                                    _userToBeEdited.LastName       = ln;
                                    _userToBeEdited.Email          = email;
                                    _userToBeEdited.Position       = position;
                                    _userToBeEdited.Salary         = salary;
                                    _userToBeEdited.ShiftTypeU     = type;
                                    _userToBeEdited.WorkingDays    = _days;
                                    _userToBeEdited.UserDepartment = department;
                                    Users.UpdateUser(_userToBeEdited);
                                }
                                else
                                {
                                    if (position == PersonPosition.Manager)
                                    {
                                        Users.AddUser(new User(fn, ln, email, position, salary, type, _days, department), true);
                                    }
                                    else
                                    {
                                        Users.AddUser(new User(fn, ln, email, position, salary, type, _days, department));
                                    }
                                }
                                DatabaseFunctions.GetAllUsers();
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Managers can be added just by admin profile!", "Error", MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please, select a valid Email!", "Error", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Choose valid shift!");
                    }
                }
                else
                {
                    MessageBox.Show("Fill in the empty fields!");
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Salary must be numeric!");
            }
            catch (NoConnectionException)
            {
                MessageBox.Show("Connection unsuccessful, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (NotExistingException)
            {
                MessageBox.Show("User is non-existent, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (UsernameErrorException)
            {
                MessageBox.Show("Error occured, when tried to generate username, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (IOException)
            {
                MessageBox.Show("Error loading resources, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
        private void btnGetProductStatistics_Click(object sender, EventArgs e)
        {
            lbStatistics.Items.Clear();
            if (cbProductCategories.SelectedIndex > -1)
            {
                int    categoryName       = cbProductCategories.SelectedIndex;
                double avgPrice           = 0;
                int    productsInCategory = 0;
                int    restocks           = 0;

                //int[] categories = new int[9];
                //DatabaseFunctions.GetAllProductsByCategory((ProductCategory)categoryName);
                DatabaseFunctions.GetAllProducts();
                Product mostRestocked = new Product("Bom", ProductCategory.COMPUTER, 2.2, 8, false);
                foreach (Product product in Products.products)
                {
                    if (product.Category == (ProductCategory)categoryName)
                    {
                        if (product.Quantity > restocks)
                        {
                            mostRestocked.Name     = product.Name;
                            mostRestocked.Category = product.Category;
                            mostRestocked.Price    = product.Price;
                            mostRestocked.Quantity = product.Quantity;
                            restocks = product.Quantity;
                        }
                        productsInCategory++;
                        avgPrice += product.Price;
                        //lbStatistics.Items.Add(product.ToString());
                    }
                }
                if (productsInCategory == 0)
                {
                    lbStatistics.Items.Add($"There are {productsInCategory} products in this category.");
                }
                else
                {
                    lbStatistics.Items.Add($"There are {productsInCategory} products in this category with average price of {(avgPrice / productsInCategory).ToString("C2", CultureInfo.CurrentCulture)}");
                    lbStatistics.Items.Add($"The most restocked product is: {mostRestocked.Name} Price: {mostRestocked.Price} Quantity: {mostRestocked.Quantity}");
                }
            }
            else
            {
                double  avgPrice       = 0;
                double  mostExpensive  = 0;
                Product mostExpensiveP = new Product("Test", ProductCategory.COMPUTER, 2.2, 8, false);
                DatabaseFunctions.GetAllProducts();

                foreach (Product product in Products.products)
                {
                    if (product.Price > mostExpensive)
                    {
                        mostExpensiveP.Name     = product.Name;
                        mostExpensiveP.Category = product.Category;
                        mostExpensiveP.Price    = product.Price;
                        mostExpensiveP.Quantity = product.Quantity;

                        mostExpensive = product.Price;
                    }
                    avgPrice += product.Price;
                }
                lbStatistics.Items.Add($"There are {Products.products.Count} products in total. The average price is {(avgPrice / Products.products.Count).ToString("C2", CultureInfo.CurrentCulture)}");
                lbStatistics.Items.Add($"The most expensive product is: {mostExpensiveP.Name} Price: {mostExpensiveP.Price} Quantity: {mostExpensiveP.Quantity}");
            }
        }
        private void btnEmployeeStatistics_Click(object sender, EventArgs e)
        {
            lbStatistics.Items.Clear();
            if (cbEmployeeDepartment.SelectedIndex > -1)
            {
                string departmentName = cbEmployeeDepartment.SelectedItem.ToString();
                double avgSalary      = 0;
                int[]  shifts         = new int[3];
                int    favouriteShift = 0;
                Users.GetUsers(6, departmentName);
                int employees = Users.requestedUsers.Count;
                foreach (User user in Users.requestedUsers)
                {
                    avgSalary += user.Salary;
                    if (user.ShiftTypeU == ShiftType.Day)
                    {
                        shifts[0]++;
                    }
                    else if (user.ShiftTypeU == ShiftType.Night)
                    {
                        shifts[1]++;
                    }
                    else if (user.ShiftTypeU == ShiftType.HalfDay)
                    {
                        shifts[2]++;
                    }
                }
                favouriteShift = shifts.Max();
                int index = Array.IndexOf(shifts, favouriteShift);
                lbStatistics.Items.Add($"The average salary for the department {departmentName} is: {(avgSalary / employees).ToString("C2", CultureInfo.CurrentCulture)}");
                lbStatistics.Items.Add($"The favourite shift of employees is: {(ShiftType)index}");
            }
            else
            {
                double avgSalary      = 0;
                int[]  shifts         = new int[3];
                int    favouriteShift = 0;
                DatabaseFunctions.GetAllUsers();
                int employees = Users.requestedUsers.Count;

                foreach (User user in Users.requestedUsers)
                {
                    avgSalary += user.Salary;
                    if (user.ShiftTypeU == ShiftType.Day)
                    {
                        shifts[0]++;
                    }
                    else if (user.ShiftTypeU == ShiftType.Night)
                    {
                        shifts[1]++;
                    }
                    else if (user.ShiftTypeU == ShiftType.HalfDay)
                    {
                        shifts[2]++;
                    }
                }
                favouriteShift = shifts.Max();
                int index = Array.IndexOf(shifts, favouriteShift);
                lbStatistics.Items.Add($"The average salary for all the employees is: {(avgSalary / employees).ToString("C2", CultureInfo.CurrentCulture)}");
                lbStatistics.Items.Add($"The most requested shift of all the employees is: {(ShiftType)index}");
            }
        }