Esempio n. 1
0
        private async void BtnFinish_Click(object sender, EventArgs e)
        {
            if (pnlServices.Controls.Count < 1)
            {
                MessageBox.Show("Please select service", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            ServicesOrder order = _context.ServicesOrders.Add(new ServicesOrder
            {
                CustomerId = ((Customer)cmbCustomers.SelectedItem).Id,
                EmployeeId = employee.Id,
                Datetime   = DateTime.Now,
                Price      = int.Parse(numericUpDown1.Value.ToString())
            });

            foreach (var item in pnlServices.Controls)
            {
                Service service = _context.Services.First(serv => serv.ServiceName == ((Button)item).Text);
                _context.OrderDetailsServices.Add(new OrderDetailsService {
                    OrderId   = order.Id,
                    ServiceId = service.Id
                });
            }
            await _context.SaveChangesAsync();

            MessageBox.Show("Purchased", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
            cmbServices.SelectedIndex  = 0;
            cmbHours.SelectedIndex     = 0;
            cmbCustomers.SelectedIndex = 0;
            numericUpDown1.Value       = 0;
            pnlServices.Controls.Clear();
        }
Esempio n. 2
0
        private async void BtnCreate_Click(object sender, EventArgs e)
        {
            if (txtFname.Text == string.Empty)
            {
                MessageBox.Show("Please input a firstname / lastname", "Erorr !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtFname.Text.Length < 3)
            {
                MessageBox.Show("Firstname is too short", "Erorr !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Random random = new Random();
            int    cardNo = random.Next(100, 1000);

            while (_context.Customers.Any(c => c.CardNo == cardNo))
            {
                cardNo = random.Next(100, 1000);
            }
            _context.Customers.Add(new Customer
            {
                Firstname = txtFname.Text,
                Lastname  = txtLname.Text,
                CardNo    = cardNo
            });
            await _context.SaveChangesAsync();

            MessageBox.Show("New customer succsessfully created", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
            txtFname.Text            = txtLname.Text = "";
            dtgwCustomers.DataSource = _context.Customers.Select(c => new { c.Firstname, c.Lastname, c.CardNo }).ToArray();
        }
        private async void BtnUpdateService_Click(object sender, EventArgs e)
        {
            if (txtServiceName.Text == string.Empty || txtServiceName.Text.Length < 3)
            {
                MessageBox.Show("Service name is not valid", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtServiceName.Text != selectedService.ServiceName)
            {
                if (!_context.Services.Any(serv => serv.ServiceName == txtServiceName.Text))
                {
                    selectedService.ServiceName = txtServiceName.Text;
                }
                else
                {
                    MessageBox.Show("Servicename is duplicate", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if (numLimitlessprice.Value < 0 || numPriceperhour.Value < 0)
            {
                MessageBox.Show("Price must be larger than 0", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            selectedService.LimitlessPrice = numLimitlessprice.Value;
            selectedService.PricePerHours  = numPriceperhour.Value;
            selectedService.Status         = cbStatus.Checked;
            await _context.SaveChangesAsync();

            DtgvwUpdater();
            txtServiceName.Text      = "";
            numPriceperhour.Value    = numLimitlessprice.Value = 0;
            btnUpdateService.Enabled = false;
        }
        private async void BtnAdd_Click(object sender, EventArgs e)
        {
            if (txtIncome.Text == string.Empty || txtDesc.Text == string.Empty)
            {
                MessageBox.Show("Please fill all textboxes", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (numericUpDown1.Value < 0)
            {
                MessageBox.Show("Please input a valid price", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _context.OutComes.Add(new OutCome
            {
                WhatFor     = txtIncome.Text,
                Description = txtDesc.Text,
                Price       = int.Parse(numericUpDown1.Value.ToString())
            });
            await _context.SaveChangesAsync();

            MessageBox.Show("Outcome succsessfully added", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
            txtDesc.Text            = txtIncome.Text = "";
            numericUpDown1.Value    = 0;
            dtgwOutcomes.DataSource = _context.OutComes.ToArray();
        }
Esempio n. 5
0
        private async void BtnCreateService_Click(object sender, EventArgs e)
        {
            string serviceName    = txtServiceName.Text;
            int    pricePerHour   = (int)numPriceperhour.Value;
            int    limitlessPrice = (int)numLimitlessprice.Value;

            if (serviceName == string.Empty || serviceName.Length < 3)
            {
                MessageBox.Show("Service name is not valid", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (pricePerHour <= 0 || limitlessPrice <= 0)
            {
                MessageBox.Show("Price must be larger than 0", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (_context.Services.Any(serv => serv.ServiceName == serviceName))
            {
                MessageBox.Show("Service is duplicate", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _context.Services.Add(new Service
            {
                ServiceName    = serviceName,
                PricePerHours  = pricePerHour,
                LimitlessPrice = limitlessPrice
            });
            MessageBox.Show("Service succsessfully created", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
            await _context.SaveChangesAsync();

            DtgvwUpdater();
        }
Esempio n. 6
0
        private async void BtnUpdate_Click(object sender, EventArgs e)
        {
            if (txtPackName.Text == string.Empty || txtPackName.Text.Length < 3)
            {
                MessageBox.Show("Please input a valid package name(it must contain more than 3 chars)", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtPackName.Text != selectedPack.Name)
            {
                if (_context.Packages.Any(p => p.Name == txtPackName.Text))
                {
                    MessageBox.Show("Package is duplicate", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if (numPrice.Value <= 0)
            {
                MessageBox.Show("Please input a valid price", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (cbAllday.Checked == cbEvendays.Checked == cbOdddays.Checked == false)
            {
                MessageBox.Show("Please select which days package is active", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (pnlServices.Controls.Count == 0)
            {
                MessageBox.Show("Please select services", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _context.ServicesToPackages.RemoveRange(_context.ServicesToPackages.Where(p => p.PackagesId == selectedPack.Id));
            selectedPack.Name             = txtPackName.Text;
            selectedPack.Price            = numPrice.Value;
            selectedPack.StartTime        = new TimeSpan(dtStartTime.Value.Hour, dtStartTime.Value.Minute, dtStartTime.Value.Second);
            selectedPack.EndTime          = new TimeSpan(dtEndTime.Value.Hour, dtEndTime.Value.Minute, dtEndTime.Value.Second);
            selectedPack.isActiveAllDays  = cbAllday.Checked;
            selectedPack.isActiveEvenDays = cbEvendays.Checked;
            selectedPack.isActiveOddDays  = cbOdddays.Checked;
            selectedPack.Status           = cbStatus.Checked;
            foreach (var item in pnlServices.Controls)
            {
                _context.ServicesToPackages.Add(new ServicesToPackage
                {
                    PackagesId = selectedPack.Id,
                    ServicesId = _context.Services.First(serv => serv.ServiceName == ((Button)item).Text).Id
                });
            }
            await _context.SaveChangesAsync();

            MessageBox.Show("Package succsessfully updated", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
            DtgvwUpdater();
            txtPackName.Text = "";
            numPrice.Value   = 0;
            cbAllday.Checked = cbEvendays.Checked = cbOdddays.Checked = false;
            pnlServices.Controls.Clear();
            btnUpdate.Enabled = false;
        }
Esempio n. 7
0
        private async void BtnUpdate_Click(object sender, EventArgs e)
        {
            if (txtFname.Text == string.Empty || txtLname.Text == string.Empty)
            {
                MessageBox.Show("Firstname or Lastname is empty! Please fill these", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtUsername.Text.Length <= 3)
            {
                MessageBox.Show("Username must contain more than 3 characters", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtUsername.Text != selectedEmp.Username)
            {
                if (!_context.Employees.Any(emp => emp.Username == txtUsername.Text))
                {
                    selectedEmp.Username = txtUsername.Text;
                }
                else
                {
                    MessageBox.Show("Username is duplicate", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if (txtPassword.Text.Length >= 5)
            {
                selectedEmp.Password = GetHash(txtPassword.Text);
            }
            else
            {
                MessageBox.Show("Password is not changed.If you want change it input a valid password(longer than 5 chars)", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            selectedEmp.Firstname = txtFname.Text;
            selectedEmp.Lastname  = txtLname.Text;
            selectedEmp.RoleId    = ((Role)cmbRoles.SelectedItem).Id;
            selectedEmp.Status    = cbStatus.Checked;
            await _context.SaveChangesAsync();

            UpdateDataGridView();
            cmbRoles.SelectedIndex = 0;
            txtUsername.Text       = txtPassword.Text = txtLname.Text = txtFname.Text = "";
            btnUpdate.Enabled      = false;
        }
        private async void BtnConfirm_Click(object sender, EventArgs e)
        {
            if (txtConfirmpass.Text == string.Empty || txtCurrentpass.Text == string.Empty || txtNewpass.Text == string.Empty)
            {
                MessageBox.Show("Please fill textboxes", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!CheckHash(employee.Password, txtCurrentpass.Text))
            {
                MessageBox.Show("Current password is not valid", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtNewpass.Text.Length <= 5)
            {
                MessageBox.Show("Password must contain more than 5 characters", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtConfirmpass.Text != txtNewpass.Text)
            {
                MessageBox.Show("Passwords do not match", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Employee changedEmployee = _context.Employees.First(emp => emp.Id == employee.Id);

            changedEmployee.Password       = GetHash(txtConfirmpass.Text);
            changedEmployee.isVerifiedPass = true;
            await _context.SaveChangesAsync();

            if (employee.RoleId == 1)
            {
                Admin admin = new Admin(employee);
                admin.ShowDialog();
                return;
            }
            if (employee.RoleId == 2)
            {
                Worker worker = new Worker(employee);
                worker.ShowDialog();
                return;
            }
            Close();
        }
Esempio n. 9
0
        private async void BtnFinish_Click(object sender, EventArgs e)
        {
            if (cmbCustomers.SelectedIndex < 0)
            {
                MessageBox.Show("Please select customer", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _context.PackageOrders.Add(new PackageOrder {
                CustomerId = ((Customer)cmbCustomers.SelectedItem).Id,
                PackageId  = selectedPack.Id,
                Price      = numericUpDown1.Value,
                DateTime   = DateTime.Now,
                EmployeeId = employee.Id
            });
            await _context.SaveChangesAsync();

            cmbCustomers.SelectedIndex = -1;
            cmbCustomers.Enabled       = true;
            cmbPackages.SelectedIndex  = 0;
        }
        private async void Button1_Click(object sender, EventArgs e)
        {
            if (txtFname.Text == string.Empty || txtLname.Text == string.Empty)
            {
                MessageBox.Show("Firstname or Lastname is empty! Please fill these", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtUsername.Text.Length <= 3)
            {
                MessageBox.Show("Username must contain more than 3 characters", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (_context.Employees.Any(emp => emp.Username == txtUsername.Text))
            {
                MessageBox.Show("Username is duplicate", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtPassword.Text.Length <= 5)
            {
                MessageBox.Show("Password must contain more than 5 characters", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _context.Employees.Add(new Employee
            {
                Firstname      = txtFname.Text,
                Lastname       = txtLname.Text,
                Username       = txtUsername.Text,
                Password       = GetHash(txtPassword.Text),
                RoleId         = ((Role)cmbRoles.SelectedItem).Id,
                isVerifiedPass = false
            });
            MessageBox.Show("New employee succsessfully added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            await _context.SaveChangesAsync();

            txtUsername.Text = txtPassword.Text = txtLname.Text = txtFname.Text = "";
            UpdateDataGridView();
            cmbRoles.SelectedIndex = 0;
        }