<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FHole
{
    public partial class Worker : Form
    {
        private readonly FitnessEntities _context;
        public Worker()
        {
            InitializeComponent();
            _context = new FitnessEntities();
        }

        private void Worker_Load(object sender, EventArgs e)
        {

        }

        private void CreateCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new CreateCustomer().Show();
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FHole
{
    public partial class Admin : Form
    {
        private Employee employee;
        public Admin (Employee emp)
        
        {
            InitializeComponent();
            employee = emp;
        }

        private void Admin_Load(object sender, EventArgs e)
        {
            label1.Text = $"Hello, {employee.FirstName }. You are Wellcome ..";
            


        }

        private void Label4_Click(object sender, EventArgs e)
        {

        }

        private void Label1_Click(object sender, EventArgs e)
        {

        }

        private void Label3_Click(object sender, EventArgs e)
        {
          
        }

        private void CreateEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new AddCustomer().Show();
        }

        private void Label1_Click_1(object sender, EventArgs e)
        {

        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FHole
{
    public partial class Form1 : Form
    {
        private readonly FitnessEntities _context = new FitnessEntities();
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text.Trim();
            string password = txtPassword.Text.Trim();

            if (!_context.Employees.Any(emp => emp.username == txtUsername.Text))
            {
                MessageBox.Show("Username or password are not valid", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Employee employee = _context.Employees.First(emp => emp.username == txtUsername.Text);
            if (txtPassword.Text != employee.Password)
            {
                MessageBox.Show("Username or password are not valid", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (employee.RoleId == 1)
            {
                new Admin(employee).ShowDialog();
                return;
            }
            if (employee.RoleId == 2)
            {
                new Worker().ShowDialog();
                return;
            }

        }

        private void TxtPassword_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
<file_sep>﻿using FHole.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FHole
{
    public partial class AddCustomer : Form
    {
        private FitnessEntities db = new FitnessEntities();
        public AddCustomer()
        {
            InitializeComponent();
        }

        private void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void BtnLogin_Click(object sender, EventArgs e)
        {
            Employee newEmployee = new Employee()
            {
                FirstName = EmployeeCreateName.Text,
                LastName = EmployeeCreateSurname.Text,
                username = EmployeeCreateUsername.Text,
                RoleId = (int)((ComboboxItem)EmployeeCreateRoles.SelectedItem).Value
            };
            Random randomNumber = new Random();
            var OTP = newEmployee.username + randomNumber.Next(1000, 9999);
            newEmployee.Password = OTP;
            db.Employees.Add(newEmployee);
            db.SaveChanges();
        }

        private void CreateEmployee_Load(object sender, EventArgs e)
        {
            var roles = db.Roles.ToList();
            foreach (var item in roles)
            {

                ComboboxItem comboboxItem = new ComboboxItem()
                {
                    Value = item.id,
                    Text = item.RoleName
                };

                EmployeeCreateRoles.Items.Add(comboboxItem);
            }


            EmployeeCreateRoles.SelectedIndex = 0;
        }

        private void EmployeeCreateName_TextChanged(object sender, EventArgs e)
        {

        }

        private void EmployeeCreateRoles_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Button1_Click(object sender, EventArgs e)
        {
           
            if (EmployeeCreateName.Text == string.Empty)
            {
                MessageBox.Show("Please input name", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (EmployeeCreateSurname.Text == string.Empty)
            {
                MessageBox.Show("Please input surname", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (EmployeeCreateUsername.Text == string.Empty)
            {
                MessageBox.Show("Please input username", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (EmployeeCreatePassword.Text == string.Empty)
            {
                MessageBox.Show("Please input paswword", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (EmployeeCreateRoles.Text == string.Empty)
            {
                MessageBox.Show("Please input role", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            db.Employees.Add(new Employee
            {
                FirstName = EmployeeCreateName.Text,
                LastName = EmployeeCreateSurname.Text,
                Password = <PASSWORD>,
                username = EmployeeCreateUsername.Text,
                RoleId =Convert.ToInt32( ((ComboboxItem)EmployeeCreateRoles.SelectedItem).Value)
            });
            db.SaveChanges();
            MessageBox.Show("New employee succsessfully added", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
            EmployeeCreateName.Text = EmployeeCreatePassword.Text = EmployeeCreateSurname.Text = EmployeeCreateUsername.Text = "";
            EmployeeCreateRoles.SelectedIndex = 0;

            this.Hide();
            FHole.CreateCustomer createCustomer = new CreateCustomer();
            createCustomer.Show();

        }


        private void AddCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new AddCustomer().Show();
        }

        private void Label3_Click(object sender, EventArgs e)
        {

        }

        private void Label2_Click(object sender, EventArgs e)
        {

        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FHole
{
    public partial class CreateCustomer : Form
    {
        private readonly FitnessEntities _context;
        public CreateCustomer()
        {
            InitializeComponent();
            _context = new FitnessEntities();
        }

        private void CreateCustomer_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = _context.Customers.Select(c => new { c.FirstName, c.LastName, c.CardNo }).ToArray();
        }

        private void BtnAdd_Click(object sender, EventArgs e)
        {
            if (txtFname.Text == string.Empty || txtLname.Text == string.Empty)
            {
                MessageBox.Show("Please fill the all textboxes", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Random rnd = new Random();
            int cardNo = rnd.Next(1000, 9999);
            while (_context.Customers.Any(c=> c.CardNo == cardNo))
            {
                cardNo = rnd.Next(1000, 9999);
            }
            _context.Customers.Add(new Customer { FirstName = txtFname.Text, LastName = txtLname.Text, CardNo = cardNo});
            _context.SaveChanges();
            MessageBox.Show("New customer succsessfully added", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
            dataGridView1.DataSource = _context.Customers.Select(c => new { c.FirstName, c.LastName, c.CardNo }).ToArray();
            txtLname.Text = txtFname.Text = "";
            dataGridView1.DataSource = _context.Customers.ToList();
        }

        private void TxtLname_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
