Esempio n. 1
0
        private void customerSave_Button_Click(object sender, EventArgs e)
        {
            if (!ValidateCustomer())
            {
                return;
            }

            using (_context = new HairSpaContext())
            {
                if (CustomerIndex == null) //create new customer
                {
                    var newCustomer = new Customer();
                    SetCustomerData(newCustomer);
                    _context.Customers.Add(newCustomer);
                    _context.SaveChanges();
                }
                else //edit existing customer
                {
                    var selectedCustomer = _context.Customers.Attach(CustomerIndex);
                    SetCustomerData(selectedCustomer);
                    _context.SaveChanges();
                }
            }

            CustomerFormClosed(this, e);
            this.Close();
        }
Esempio n. 2
0
        static public void EmployeesByJobTitle(RichTextBox box, HairSpaContext context)
        {
            var list = context.Employees.OrderBy(e => e.JobTitle);

            box.AppendText($"EMPLOYEES BY JOB TITLE{newLine}");
            box.AppendText($"REPORT GENERATED: {DateTime.Now}{newLine}{newLine}");

            foreach (var emp in list)
            {
                string id          = $"ID: {emp.Id}";
                string name        = $"NAME: {emp.FirstName} {emp.LastName}";
                string address     = $"ADDRESS: {emp.Address} - {emp.City}, {emp.State}";
                string jobTitle    = $"JOB TITLE: {emp.JobTitle}";
                string pay         = $"PAY TYPE: {emp.PayType} - PAY: {emp.Pay:c}";
                string initialDate = $"INITIAL DATE: {emp.InitialDate.ToShortDateString()}";

                box.AppendText($"{id}{newLine}");
                box.AppendText($"{name}{newLine}");
                box.AppendText($"{address}{newLine}");
                box.AppendText($"{jobTitle}{newLine}");
                box.AppendText($"{pay}{newLine}");
                box.AppendText($"{initialDate}{newLine}");

                box.AppendText($"{seperator}{newLine}");
            }
        }
Esempio n. 3
0
        public void CreateCustomerTest()
        {
            using (_context = new HairSpaContext())
            {
                var customer = new Customer
                {
                    FirstName = "test", LastName = "test", Address = "123 test",
                    City      = "test city", State = "MD", Email = "*****@*****.**", Phone = "9990009999"
                };

                _context.Customers.Add(customer);
                _context.SaveChanges();

                if (_context.Customers.AsEnumerable().Contains(customer))
                {
                    Debug.WriteLine("Test 2: CreateCustomerTest Successful");
                }
                else
                {
                    Debug.WriteLine("Test 2: CreateCustomerTest Failed");
                }

                Assert.IsTrue(_context.Customers.AsEnumerable().Contains(customer));
            }
        }
Esempio n. 4
0
        private void SetDataGrids()
        {
            using (_context = new HairSpaContext())
            {
                Main.GetAllAccounts(_context);
                Main.GetAllCustomers(_context);
                Main.GetAllEmployees(_context);
                Main.GetAllAppointments(_context);

                accounts_DataGrid.DataSource     = Main.AccountList;
                customers_DataGrid.DataSource    = Main.CustomerList;
                employees_DataGrid.DataSource    = Main.EmployeeList;
                appointments_DataGrid.DataSource = Main.AppointmentList;

                HideColumns();
            }

            ChangeTimeZone();

            Main.AccountIndex     = null;
            Main.CustomerIndex    = null;
            Main.EmployeeIndex    = null;
            Main.AppointmentIndex = null;

            DeselectRows(accounts_DataGrid);
            DeselectRows(customers_DataGrid);
            DeselectRows(employees_DataGrid);
            DeselectRows(appointments_DataGrid);
        }
Esempio n. 5
0
        private void showReport_Button_Click(object sender, EventArgs e)
        {
            if (!ValidateReports())
            {
                return;
            }

            report_TextBox.Text = "";

            using (_context = new HairSpaContext())
            {
                switch (selectReport_ComboBox.SelectedItem)
                {
                case "Appointments by month":
                    AppointmentsByMonth(report_TextBox, _context);
                    break;

                case "Customers by name":
                    CustomersByName(report_TextBox, _context);
                    break;

                case "Employees by job title":
                    EmployeesByJobTitle(report_TextBox, _context);
                    break;

                default:
                    MessageBox.Show("Must select report type", "Invalid Selection");
                    break;
                }
            }
        }
Esempio n. 6
0
        private void acctSave_Button_Click(object sender, EventArgs e)
        {
            if (!ValidateAccount())
            {
                return;
            }

            using (_context = new HairSpaContext())
            {
                if (AccountIndex == null) //create
                {
                    var newAcct = new Account();
                    SetAccountData(newAcct);
                    _context.Accounts.Add(newAcct);
                    _context.SaveChanges();
                }
                else //edit
                {
                    var selectedAcct = _context.Accounts.Attach(AccountIndex);
                    SetAccountData(selectedAcct);
                    _context.SaveChanges();
                }
            }

            AccountFormClosed(this, e);
            this.Close();
        }
Esempio n. 7
0
        private void employeeSave_Button_Click(object sender, EventArgs e)
        {
            if (!ValidateEmployee())
            {
                return;
            }

            using (_context = new HairSpaContext())
            {
                if (EmployeeIndex == null) //create new employee
                {
                    var newEmployee = new Employee();
                    SetEmployeeData(newEmployee);
                    _context.Employees.Add(newEmployee);
                    _context.SaveChanges();
                }
                else // edit existing employee
                {
                    var selectedEmployee = _context.Employees.Attach(EmployeeIndex);
                    SetEmployeeData(selectedEmployee);
                    _context.SaveChanges();
                }
            }

            EmployeeFormClosed(this, e);
            this.Close();
        }
Esempio n. 8
0
        static public void SearchCustomer(ComboBox box, TextBox search, HairSpaContext context)
        {
            IQueryable <Customer> list = null;

            CustomerList.Clear();

            switch (box.SelectedItem)
            {
            case "Id":
                list = context.Customers.Where(cu => cu.Id.ToString().Contains(search.Text));
                break;

            case "First Name":
                list = context.Customers.Where(cu => cu.FirstName.Contains(search.Text));
                break;

            case "Last Name":
                list = context.Customers.Where(cu => cu.LastName.Contains(search.Text));
                break;

            case "Address":
                list = context.Customers.Where(cu => cu.Address.Contains(search.Text));
                break;

            case "City":
                list = context.Customers.Where(cu => cu.City.Contains(search.Text));
                break;

            case "State":
                list = context.Customers.Where(cu => cu.State.Contains(search.Text));
                break;

            default:
                break;
            }

            try
            {
                if (list.ToList().Count <= 0)
                {
                    MessageBox.Show("No records were found", "No Results");
                    return;
                }
                else
                {
                    list.ToList().ForEach(cu => CustomerList.Add(cu));
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No records were found", "No Results");
                return;
            }
        }
Esempio n. 9
0
 private void accountsDelete_Button_Click(object sender, EventArgs e)
 {
     using (_context = new HairSpaContext())
     {
         if (Main.DeleteAccount(_context))
         {
             SetDataGrids();
         }
         else
         {
             return;
         }
     }
 }
Esempio n. 10
0
        static public void SearchAppointment(ComboBox box, TextBox search, HairSpaContext context)
        {
            IQueryable <Appointment> list = null;

            AppointmentList.Clear();

            switch (box.SelectedItem)
            {
            case "Id":
                list = context.Appointments.Where(ap => ap.Id.ToString().Contains(search.Text));
                break;

            case "Type":
                list = context.Appointments.Where(ap => ap.Type.Contains(search.Text));
                break;

            case "Customer Id":
                list = context.Appointments.Where(ap => ap.CustomersId.ToString().Contains(search.Text));
                break;

            case "Employee Id":
                list = context.Appointments.Where(ap => ap.EmployeesId.ToString().Contains(search.Text));
                break;

            default:
                break;
            }

            try
            {
                if (list.ToList().Count <= 0)
                {
                    MessageBox.Show("No records were found", "No Results");
                    return;
                }
                else
                {
                    list.ToList().ForEach(ap => AppointmentList.Add(ap));
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No records were found", "No Results");
                return;
            }
        }
Esempio n. 11
0
        static public bool DeleteAccount(HairSpaContext context)
        {
            bool inUse = false;

            if (AccountIndex == null)
            {
                MessageBox.Show("Must select an account", "Invalid Selection");
                return(false);
            }

            if (AccountIndex.IsActive == true)
            {
                MessageBox.Show("Cannot delete account that is currently active", "Active Account");
                return(false);
            }

            //Is there an employee using this account?
            context.Employees.ToList().ForEach(e =>
            {
                if (e.AccountsId == AccountIndex.Id)
                {
                    MessageBox.Show($"Account cannot be deleted because it is associated with employee '{e.FirstName} {e.LastName}'", "Account In Use");
                    inUse = true;
                }
            });

            if (inUse)
            {
                return(false);
            }

            var deleteMessage = MessageBox.Show("This will delete the account. Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo);

            if (deleteMessage == DialogResult.Yes)
            {
                context.Accounts.Attach(AccountIndex);
                context.Accounts.Remove(AccountIndex);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 12
0
        public void LoginTest()
        {
            using (_context = new HairSpaContext())
            {
                var credentials = _context.Accounts.FirstOrDefault(a => a.Username == "admin" && a.Password == "password1");

                if (credentials != null)
                {
                    Debug.WriteLine("Test 1: LoginTest Successful");
                }
                else
                {
                    Debug.WriteLine("Test 1: LoginTest Failed");
                }

                Assert.IsNotNull(credentials);
            }
        }
Esempio n. 13
0
        public void SearchCustomerTest()
        {
            using (_context = new HairSpaContext())
            {
                var list = _context.Customers.Where(c => c.LastName.Contains("Boyde"));

                if (list != null)
                {
                    Debug.WriteLine("Test 5: SearchCustomerTest Successful");
                }
                else
                {
                    Debug.WriteLine("Test 5: SearchCustomerTest Failed");
                }

                Assert.IsNotNull(list);
            }
        }
Esempio n. 14
0
        private void SetApptComboBoxes()
        {
            using (_context = new HairSpaContext())
            {
                _context.Customers.ToList().ForEach(cu => 
                customer_ComboBox.Items.Add($"{cu.Id} - {cu.FirstName} {cu.LastName}"));

                //Only active employees can hold an appointment
                var empList = _context.Employees.Where(emp => emp.Status == 2);
                empList.ToList().ForEach(emp =>
                employee_ComboBox.Items.Add($"{emp.Id} - {emp.FirstName} {emp.LastName}"));


                
               

            }
        }
Esempio n. 15
0
        private void SetAccountComboBox()
        {
            using (_context = new HairSpaContext())
            {
                var acct = _context.Accounts.Where(ac => ac.Employees.Count <= 0);
                acct.ToList().ForEach(ac => account_ComboBox.Items.Add($"{ac.Id} - {ac.Username}"));

                if (EmployeeIndex != null)
                {
                    var indexAcct = _context.Accounts.FirstOrDefault(ac => ac.Id == EmployeeIndex.AccountsId);
                    account_ComboBox.Items.Add($"{indexAcct.Id} - {indexAcct.Username}");
                    account_ComboBox.SelectedItem = $"{indexAcct.Id} - {indexAcct.Username}";
                }
                else if (EmployeeIndex == null)
                {
                    return;
                }
            }
        }
Esempio n. 16
0
        private void customersSearch_Button_Click(object sender, EventArgs e)
        {
            using (_context = new HairSpaContext())
            {
                switch (customersSearch_Button.Text)
                {
                case "Search":
                    Main.SearchCustomer(customersSearch_ComboBox, customersSearch_TextBox, _context);
                    customersSearch_Button.Text = "Clear";
                    break;

                case "Clear":
                    SetDataGrids();
                    customersSearch_Button.Text  = "Search";
                    customersSearch_TextBox.Text = "";
                    break;
                }
            }
        }
Esempio n. 17
0
        private void employeesSearch_Button_Click(object sender, EventArgs e)
        {
            using (_context = new HairSpaContext())
            {
                switch (employeesSearch_Button.Text)
                {
                case "Search":
                    Main.SearchEmployee(employeesSearch_ComboBox, employeesSearch_TextBox, _context);
                    employeesSearch_Button.Text = "Clear";
                    break;

                case "Clear":
                    SetDataGrids();
                    employeesSearch_Button.Text  = "Search";
                    employeesSearch_TextBox.Text = "";
                    break;
                }
            }
        }
Esempio n. 18
0
        private void accountsSearch_Button_Click(object sender, EventArgs e)
        {
            using (_context = new HairSpaContext())
            {
                switch (accountsSearch_Button.Text)
                {
                case "Search":
                    Main.SearchAccount(accountsSearch_ComboBox, accountsSearch_TextBox, _context);
                    accountsSearch_Button.Text = "Clear";
                    break;

                case "Clear":
                    SetDataGrids();
                    accountsSearch_Button.Text  = "Search";
                    accountsSearch_TextBox.Text = "";
                    break;
                }
            }
        }
Esempio n. 19
0
        static public bool AreCredentialsValid(HairSpaContext context, string username, string password)
        {
            acct = context.Accounts.FirstOrDefault(a => a.Username == username && a.Password == password);

            if (acct != null)
            {
                emp = context.Employees.FirstOrDefault(e => e.AccountsId == acct.Id);

                acct.IsActive = true;
                context.SaveChanges();

                return(true);
            }
            else
            {
                MessageBox.Show("Login attempt failed", "Invalid Login");
                return(false);
            }
        }
Esempio n. 20
0
        public void EditCustomerTest()
        {
            using (_context = new HairSpaContext())
            {
                var index = _context.Customers.FirstOrDefault(c => c.FirstName == "test");
                index.Address = "999 new drive";
                _context.Customers.Attach(index);

                if (index.Address == "999 new drive")
                {
                    Debug.WriteLine("Test 3: EditCustomerTest Successful");
                }
                else
                {
                    Debug.WriteLine("Test 3: EditCustomerTest Failed");
                }

                Assert.IsTrue(index.Address == "999 new drive");
            }
        }
Esempio n. 21
0
        public void DeleteCustomerTest()
        {
            using (_context = new HairSpaContext())
            {
                var index = _context.Customers.FirstOrDefault(c => c.FirstName == "test");
                _context.Customers.Attach(index);
                _context.Customers.Remove(index);
                _context.SaveChanges();

                if (!_context.Customers.AsEnumerable().Contains(index))
                {
                    Debug.WriteLine("Test 4: DeleteCustomerTest Successful");
                }
                else
                {
                    Debug.WriteLine("Test 4: DeleteCustomerTest Failed");
                }

                Assert.IsFalse(_context.Customers.AsEnumerable().Contains(index));
            }
        }
Esempio n. 22
0
        static public void AppointmentsByMonth(RichTextBox box, HairSpaContext context)
        {
            var list = context.Appointments.OrderBy(ap => ap.StartTime);

            box.AppendText($"APPOINTMENTS BY MONTH{newLine}");
            box.AppendText($"REPORT GENERATED: {DateTime.Now}{newLine}{newLine}");

            foreach (var ap in list)
            {
                if (ap.StartTime.Kind == DateTimeKind.Unspecified || ap.StartTime.Kind == DateTimeKind.Utc)
                {
                    ap.StartTime = DateTime.SpecifyKind(ap.StartTime, DateTimeKind.Utc).ToLocalTime();
                }

                if (ap.EndTime.Kind == DateTimeKind.Unspecified || ap.EndTime.Kind == DateTimeKind.Utc)
                {
                    ap.EndTime = DateTime.SpecifyKind(ap.EndTime, DateTimeKind.Utc).ToLocalTime();
                }


                var cu  = context.Customers.FirstOrDefault(c => c.Id == ap.CustomersId);
                var emp = context.Employees.FirstOrDefault(e => e.Id == ap.EmployeesId);

                string id       = $"ID: {ap.Id}";
                string type     = $"APPT TYPE: {ap.Type}";
                string time     = $"APPT TIME: {ap.StartTime.ToString("t")} - {ap.EndTime.ToString("t")}, {ap.StartTime.Date.ToShortDateString()}";
                string cost     = $"COST: {ap.Cost:c}";
                string customer = $"FOR CUSTOMER: {cu.FirstName} {cu.LastName}";
                string employee = $"HELD BY EMPLOYEE: {emp.FirstName} {emp.LastName}";

                box.AppendText($"{id}{newLine}");
                box.AppendText($"{type}{newLine}");
                box.AppendText($"{time}{newLine}");
                box.AppendText($"{cost}{newLine}");
                box.AppendText($"{customer}{newLine}");
                box.AppendText($"{employee}{newLine}");

                box.AppendText($"{seperator}{newLine}");
            }
        }
Esempio n. 23
0
        static public void AccountsByUsername(RichTextBox box, HairSpaContext context)
        {
            var list = context.Accounts.OrderBy(a => a.Username);

            box.AppendText($"ACCOUNTS BY USERNAME{newLine}");
            box.AppendText($"REPORT GENERATED: {DateTime.Now}{newLine}{newLine}");

            foreach (var ac in list)
            {
                var emp = ac.Employees.FirstOrDefault();

                string id       = $"ID: {ac.Id}";
                string username = $"USERNAME: {ac.Username}";
                string employee = $"ACCOUNT FOR EMPLOYEE: {emp.FirstName} {emp.LastName}";

                box.AppendText($"{id}{newLine}");
                box.AppendText($"{username}{newLine}");
                box.AppendText($"{employee}{newLine}");

                box.AppendText($"{seperator}{newLine}");
            }
        }
Esempio n. 24
0
        static public bool DeleteAppointment(HairSpaContext context)
        {
            if (AppointmentIndex == null)
            {
                MessageBox.Show("Must select an appointment", "Invalid Selection");
                return(false);
            }

            var deleteMessage = MessageBox.Show("This will delete the appointment. Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo);

            if (deleteMessage == DialogResult.Yes)
            {
                context.Appointments.Attach(AppointmentIndex);
                context.Appointments.Remove(AppointmentIndex);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 25
0
        static public bool DeleteEmployee(HairSpaContext context)
        {
            bool inUse = false;

            if (EmployeeIndex == null)
            {
                MessageBox.Show("Must select an employee", "Invalid Selection");
                return(false);
            }

            //Is this customer used in an appointment?
            context.Appointments.ToList().ForEach(ap =>
            {
                if (ap.EmployeesId == EmployeeIndex.Id)
                {
                    MessageBox.Show($"Employee cannot be deleted because it is used in appointment with ID: {ap.Id}", "Employee In Use");
                    inUse = true;
                }
            });

            if (inUse)
            {
                return(false);
            }

            var deleteMessage = MessageBox.Show("This will delete the employee. Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo);

            if (deleteMessage == DialogResult.Yes)
            {
                context.Employees.Attach(EmployeeIndex);
                context.Employees.Remove(EmployeeIndex);
                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 26
0
        static public void SearchAccount(ComboBox box, TextBox search, HairSpaContext context)
        {
            IQueryable <Account> list = null;

            AccountList.Clear();

            switch (box.SelectedItem)
            {
            case "Id":
                list = context.Accounts.Where(ac => ac.Id.ToString().Contains(search.Text));
                break;

            case "Username":
                list = context.Accounts.Where(ac => ac.Username.Contains(search.Text));
                break;

            default:
                break;
            }

            try
            {
                if (list.ToList().Count <= 0)
                {
                    MessageBox.Show("No records were found", "No Results");
                    return;
                }
                else
                {
                    list.ToList().ForEach(ac => AccountList.Add(ac));
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No records were found", "No Results");
                return;
            }
        }
Esempio n. 27
0
        static public void CustomersByName(RichTextBox box, HairSpaContext context)
        {
            var list = context.Customers.OrderBy(c => c.FirstName);

            box.AppendText($"CUSTOMERS BY NAME{newLine}");
            box.AppendText($"REPORT GENERATED: {DateTime.Now}{newLine}{newLine}");

            foreach (var cu in list)
            {
                string id      = $"ID: {cu.Id}";
                string name    = $"NAME: {cu.FirstName} {cu.LastName}";
                string address = $"ADDRESS: {cu.Address} - {cu.City}, {cu.State}";
                string phone   = $"PHONE: {cu.Phone}";
                string email   = $"EMAIL: {cu.Email}";

                box.AppendText($"{id}{newLine}");
                box.AppendText($"{name}{newLine}");
                box.AppendText($"{address}{newLine}");
                box.AppendText($"{phone}{newLine}");
                box.AppendText($"{email}{newLine}");

                box.AppendText($"{seperator}{newLine}");
            }
        }
Esempio n. 28
0
 //Account Methods
 static public void GetAllAccounts(HairSpaContext context)
 {
     //Clear account list, then add customer table records to the list.
     AccountList.ToList().ForEach(ac => AccountList.Remove(ac));
     context.Accounts.ToList().ForEach(ac => AccountList.Add(ac));
 }
Esempio n. 29
0
 //Appointment Methods
 static public void GetAllAppointments(HairSpaContext context)
 {
     //Clear appointment list, then add appointment table records to the list.
     AppointmentList.ToList().ForEach(ap => AppointmentList.Remove(ap));
     context.Appointments.ToList().ForEach(ap => AppointmentList.Add(ap));
 }
Esempio n. 30
0
        static public void SearchEmployee(ComboBox box, TextBox search, HairSpaContext context)
        {
            IQueryable <Employee> list = null;

            EmployeeList.Clear();

            switch (box.SelectedItem)
            {
            case "Id":
                list = context.Employees.Where(emp => emp.Id.ToString().Contains(search.Text));
                break;

            case "First Name":
                list = context.Employees.Where(emp => emp.FirstName.Contains(search.Text));
                break;

            case "Last Name":
                list = context.Employees.Where(emp => emp.LastName.Contains(search.Text));
                break;

            case "Address":
                list = context.Employees.Where(emp => emp.Address.Contains(search.Text));
                break;

            case "City":
                list = context.Employees.Where(emp => emp.City.Contains(search.Text));
                break;

            case "State":
                list = context.Employees.Where(emp => emp.State.Contains(search.Text));
                break;

            case "Job Title":
                list = context.Employees.Where(emp => emp.JobTitle.Contains(search.Text));
                break;

            case "Status Number":
                list = context.Employees.Where(emp => emp.Status.ToString().Contains(search.Text));
                break;

            default:
                break;
            }

            try
            {
                if (list.ToList().Count <= 0)
                {
                    MessageBox.Show("No records were found", "No Results");
                    return;
                }
                else
                {
                    list.ToList().ForEach(emp => EmployeeList.Add(emp));
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No records were found", "No Results");
                return;
            }
        }