예제 #1
0
        private void LoadEmployeeBranchWindow(Employee loggedEmployee)
        {
            Employee employee = null;
            Branch   branch   = null;

            StackPanel sp = new StackPanel
            {
                Height = 320,
            };

            using (var context = new SystemObsługiBankuDBEntities())
            {
                employee = context.Employee
                           .Single(x => x.AuthorizationCode == loggedEmployee.AuthorizationCode);
                branch = context.Branch
                         .Single(x => x.ID == employee.BranchID);
            }

            AppButton.ActionButton btnBack = new AppButton.ActionButton("Powrót");

            sp.Children.Add(new AppDockPanel.DescriptionDockPanel("Nazwa oddziału", branch.BranchName.Trim()));
            sp.Children.Add(new AppDockPanel.DescriptionDockPanel("Adres", branch.Adress.Trim()));
            sp.Children.Add(new AppDockPanel.DescriptionDockPanel("Miasto", branch.City.Trim()));
            sp.Children.Add(new AppDockPanel.DescriptionDockPanel("Kod pocztowy", branch.PostalCode.Trim()));
            sp.Children.Add(new AppDockPanel.ButtonsDockPanel(new int[4] {
                0, 15, 0, 0
            }, btnBack));

            employeeBranchWindow.Children.Add(sp);

            btnBack.Click += DeleteWindow;

            void DeleteWindow(object o, EventArgs ev) => Close();
        }
예제 #2
0
        private void LoadEmployeeInfoWindow(Employee loggedEmployee)
        {
            Employee employee = null;

            StackPanel sp = new StackPanel
            {
                Height = 320,
            };

            using (var context = new SystemObsługiBankuDBEntities())
            {
                employee = context.Employee
                           .Single(x => x.AuthorizationCode == loggedEmployee.AuthorizationCode);
            }

            AppButton.ActionButton btnBack = new AppButton.ActionButton("Powrót");

            sp.Children.Add(new AppDockPanel.DescriptionDockPanel("Imię", employee.FirstName.Trim()));
            sp.Children.Add(new AppDockPanel.DescriptionDockPanel("Nazwisko", employee.LastName.Trim()));
            sp.Children.Add(new AppDockPanel.DescriptionDockPanel("Twój identyfikator", employee.AuthorizationCode.Trim()));
            sp.Children.Add(new AppDockPanel.DescriptionDockPanel("Data zatrudnienia", employee.HireDate.ToString("dd/MM/yyyy").Trim()));
            sp.Children.Add(new AppDockPanel.ButtonsDockPanel(new int[4] {
                0, 15, 0, 0
            }, btnBack));

            employeeInfoWindow.Children.Add(sp);

            btnBack.Click += DeleteWindow;

            void DeleteWindow(object o, EventArgs ev) => Close();
        }
예제 #3
0
        private void ApplyTransaction(List <AppDockPanel.AccountInfoDockPanel> accounts)
        {
            decimal money = 0;

            for (int i = 0; i < accounts.Count; i++)
            {
                var checkbox = accounts[i].Children[0] as CheckBox;
                var radioIn  = accounts[i].Children[1] as RadioButton;
                var radioOut = accounts[i].Children[2] as RadioButton;

                var accountName  = accounts[i].Children[3] as Label;
                var accountMoney = accounts[i].Children[4] as Label;
                var inputMoney   = accounts[i].Children[5] as TextBox;

                if (inputMoney.Text.Length == 0)
                {
                    ShowInfoMessage("Niepodano wartości pieniężnej.");
                    break;
                }
                else
                {
                    try { money = decimal.Parse(inputMoney.Text); }
                    catch (InvalidOperationException)
                    {
                        ShowInfoMessage("Podana kwota jest nieprawidłowa.");
                        break;
                    }

                    using (var context = new SystemObsługiBankuDBEntities())
                    {
                        var customerAccount = context.Account.Single(x => x.AccountName == accountName.Content.ToString());
                        if ((Convert.ToInt32(inputMoney.Text) <= money) && radioOut.IsChecked == true && checkbox.IsChecked == true)
                        {
                            customerAccount.Balance -= Convert.ToDecimal(inputMoney.Text);
                            context.SaveChanges();
                            ShowInfoMessage
                            (
                                $"Operacja dla konta {accountName.Content.ToString().Trim()} " +
                                $"zakończona pomyślnie.", MessageBoxImage.Information
                            );
                        }
                        if (radioIn.IsChecked == true && checkbox.IsChecked == true)
                        {
                            customerAccount.Balance += Convert.ToDecimal(inputMoney.Text);
                            context.SaveChanges();
                            ShowInfoMessage
                            (
                                $"Operacja dla konta {accountName.Content.ToString().Trim()} " +
                                $"zakończona pomyślnie.", MessageBoxImage.Information
                            );
                        }
                    }
                }
            }

            Close();
        }
예제 #4
0
        private async Task <Employee> FindEmployee(string password, Label label)
        {
            List <Employee> employees = new List <Employee>();
            Employee        employee  = null;

            label.Foreground = Brushes.White;
            label.Content    = "Logowanie...";

            using (var context = new SystemObsługiBankuDBEntities())
            {
                return(await Task.Run(() => employee = context.Employee.SingleOrDefault(x => x.AuthorizationCode == password)));
            }
        }
예제 #5
0
        private void AddCustomer(DatePicker bd, params TextBox[] tbxs)
        {
            bool isFieldEmpty = false;

            foreach (var item in tbxs)
            {
                if (item.Text == "")
                {
                    ShowError();

                    isFieldEmpty = true;
                    break;
                }
            }

            if (!isFieldEmpty)
            {
                string birthDate = bd.SelectedDate.Value.Date.ToString("yyyy-MM-dd");
                string id        = tbxs[0].Text;
                string firstName = tbxs[1].Text;
                string lastName  = tbxs[2].Text;
                string gender    = tbxs[3].Text;
                string adress    = tbxs[4].Text;
                string city      = tbxs[5].Text;

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    context.Customer.Add(new Customer
                    {
                        ID        = id,
                        FirstName = firstName,
                        LastName  = lastName,
                        BirthDate = Convert.ToDateTime(birthDate),
                        Gender    = gender,
                        Adress    = adress,
                        City      = city,
                    });

                    context.SaveChanges();
                }

                MessageBoxResult confirm = MessageBox.Show
                                           (
                    "Operacja zakończona pomyślnie.",
                    "Wynik operacji",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information
                                           );
            }
        }
예제 #6
0
        private void LoadCustomerPaymentWindow(Customer customer)
        {
            StackPanel sp = new StackPanel
            {
                Height = 320,
            };

            List <Account> accounts = new List <Account>();

            using (var context = new SystemObsługiBankuDBEntities())
            {
                accounts = context.Account.Where(x => x.CustomerID == customer.ID).ToList();
            }

            AppDockPanel.MultiLabelDockPanel description = new AppDockPanel.MultiLabelDockPanel(
                new string[6] {
                "Akcja", "Wpłata", "Wypłata", "Nazwa konta", "Aktualny stan", "Kwota ( ZŁ )"
            });

            AppButton.ActionButton        btnBack  = new AppButton.ActionButton("Powrót");
            AppButton.ActionButton        btnApply = new AppButton.ActionButton("Zatwierdź");
            AppDockPanel.ButtonsDockPanel buttons  = new AppDockPanel.ButtonsDockPanel(new int[4] {
                0, 10, 0, 0
            }, btnBack, btnApply);

            sp.Children.Add(description);

            List <AppDockPanel.AccountInfoDockPanel> dockPanelsAccounts = new List <AppDockPanel.AccountInfoDockPanel>();

            foreach (var item in accounts)
            {
                var x = new AppDockPanel.AccountInfoDockPanel(item.AccountName, item.Balance);
                dockPanelsAccounts.Add(x);
                sp.Children.Add(x);
            }

            sp.Children.Add(buttons);
            customerPayment.Children.Add(sp);

            btnApply.Click += CustomerPaymentTransaction;
            btnBack.Click  += DeleteWindow;

            void CustomerPaymentTransaction(object o, EventArgs ev) => ApplyTransaction(dockPanelsAccounts);
            void DeleteWindow(object o, EventArgs ev) => Close();
        }
예제 #7
0
        private void LoadRepaymentLoanWindow(Customer customer)
        {
            StackPanel sp = new StackPanel
            {
                Height = 320,
            };

            AppButton.ActionButton btnBack  = new AppButton.ActionButton("Powrót");
            AppButton.ActionButton btnApply = new AppButton.ActionButton("Spłać");

            List <Loan> loans = new List <Loan>();

            using (var context = new SystemObsługiBankuDBEntities())
            {
                loans = context.Loan.Where(x => x.CustomerID == customer.ID).ToList();
            }

            List <AppDockPanel.ActionDockPanel> dockPanelsLoans = new List <AppDockPanel.ActionDockPanel>();

            foreach (var item in loans)
            {
                var x = new AppDockPanel.ActionDockPanel(
                    ("Kwota początkowa " + Math.Round(item.Balance, 2).ToString() + " + " +
                     Math.Round(item.Balance / 100 * (item.PercentValue / ((item.EndDate - item.StartDate).Days)) *
                                (DateTime.Now - item.StartDate).Days)).ToString() + " odsetki ( ZŁ )", true);

                dockPanelsLoans.Add(x);
                sp.Children.Add(x);
            }

            AppDockPanel.ButtonsDockPanel buttons = new AppDockPanel.ButtonsDockPanel(new int[4] {
                0, 40, 0, 0
            }, btnBack, btnApply);

            sp.Children.Add(buttons);
            customerRepaymentLoan.Children.Add(sp);

            btnApply.Click += DeleteLoan;
            btnBack.Click  += DeleteWindow;

            void DeleteLoan(object o, EventArgs ev) => RepaymentLoanAction(dockPanelsLoans, customer);
            void DeleteWindow(object o, EventArgs ev) => Close();
        }
예제 #8
0
        private void LoadCustomerLoansWindow(Customer customer)
        {
            StackPanel sp = new StackPanel
            {
                Height = 320,
            };

            List <Loan> loans = new List <Loan>();

            using (var context = new SystemObsługiBankuDBEntities())
            {
                loans = context.Loan.Where(x => x.CustomerID == customer.ID).ToList();
            }

            AppDockPanel.MultiLabelDockPanel description = new AppDockPanel.MultiLabelDockPanel(
                new string[6] {
                "Kwota ( ZŁ )", "Procent", "Pożyczono", "Spłata do", "Do spłaty ( ZŁ )", "Pozostało dni"
            });

            sp.Children.Add(description);

            List <AppDockPanel.LoanInfoDockPanel> dockPanelsAccounts = new List <AppDockPanel.LoanInfoDockPanel>();

            foreach (var item in loans)
            {
                var x = new AppDockPanel.LoanInfoDockPanel(item.Balance, item.PercentValue, item.StartDate, item.EndDate);
                dockPanelsAccounts.Add(x);
                sp.Children.Add(x);
            }

            AppButton.ActionButton        btnBack = new AppButton.ActionButton("Powrót");
            AppDockPanel.ButtonsDockPanel buttons = new AppDockPanel.ButtonsDockPanel(new int[4] {
                0, 10, 0, 0
            }, btnBack);

            sp.Children.Add(buttons);
            customerLoans.Children.Add(sp);

            btnBack.Click += DeleteWindow;

            void DeleteWindow(object o, EventArgs ev) => Close();
        }
예제 #9
0
        private void LoadDeleteAccountWindow(Customer customer)
        {
            StackPanel sp = new StackPanel
            {
                Height = 320,
            };

            List <Account> accounts = new List <Account>();

            using (var context = new SystemObsługiBankuDBEntities())
            {
                accounts = context.Account.Where(x => x.CustomerID == customer.ID).ToList();
            }

            List <AppDockPanel.ActionDockPanel> dockPanelsAccounts = new List <AppDockPanel.ActionDockPanel>();

            foreach (var item in accounts)
            {
                var x = new AppDockPanel.ActionDockPanel(item.AccountName, true);
                dockPanelsAccounts.Add(x);
                sp.Children.Add(x);
            }

            AppButton.ActionButton btnBack  = new AppButton.ActionButton("Powrót");
            AppButton.ActionButton btnApply = new AppButton.ActionButton("Zatwierdź");

            AppDockPanel.ButtonsDockPanel buttons = new AppDockPanel.ButtonsDockPanel(new int[4] {
                0, 30, 0, 0
            }, btnBack, btnApply);

            sp.Children.Add(buttons);
            customerDeleteAccount.Children.Add(sp);

            btnApply.Click += DeleteCustomerAccount;
            btnBack.Click  += DeleteWindow;

            void DeleteCustomerAccount(object o, EventArgs ev) => DeleteAccount(dockPanelsAccounts);
            void DeleteWindow(object o, EventArgs ev) => Close();
        }
예제 #10
0
        private void RepaymentLoanAction(List <AppDockPanel.ActionDockPanel> loans, Customer customer)
        {
            bool isDeleted = false;

            for (int i = 0; i < loans.Count; i++)
            {
                var checkbox    = loans[i].Children[0] as CheckBox;
                var totalAmount = loans[i].Children[1] as Label;

                var startAmount = totalAmount.ToString().Substring(0, totalAmount.ToString().IndexOf("+")).Trim();

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    if (checkbox.IsChecked == true)
                    {
                        var customerLoan = context.Loan.First(x => x.CustomerID == customer.ID);
                        context.Loan.Remove(customerLoan);
                        isDeleted = true;

                        context.SaveChanges();
                        ShowInfoMessage
                        (
                            $"Pożyczka została spłacona.",
                            MessageBoxImage.Information
                        );
                    }
                }
            }

            if (!isDeleted)
            {
                ShowInfoMessage($"Nie wybrano żadnej pożyczki do spłaty.", MessageBoxImage.Information);
            }
            else
            {
                Close();
            }
        }
예제 #11
0
        private void DeleteAccount(List <AppDockPanel.ActionDockPanel> accounts)
        {
            bool isDeleted = false;

            for (int i = 0; i < accounts.Count; i++)
            {
                var checkbox    = accounts[i].Children[0] as CheckBox;
                var accountName = accounts[i].Children[1] as Label;

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    if (checkbox.IsChecked == true)
                    {
                        var customerAccount = context.Account.Single(x => x.AccountName == accountName.Content.ToString());
                        context.Account.Remove(customerAccount);
                        isDeleted = true;

                        context.SaveChanges();
                        ShowInfoMessage
                        (
                            $"Konto {accountName.Content.ToString().Trim()} zostało usunięte.",
                            MessageBoxImage.Information
                        );
                    }
                }
            }

            if (!isDeleted)
            {
                ShowInfoMessage($"Nie wybrano żadnego konta.", MessageBoxImage.Information);
            }
            else
            {
                Close();
            }
        }
예제 #12
0
        private void ServiceCustomerPanel(Customer customer, Employee loggedEmployee)
        {
            StackPanel sp = new StackPanel
            {
                Width      = 400,
                Height     = 300,
                Background = Brushes.DeepSkyBlue,
                Margin     = new Thickness(0, -120, 0, -120),
            };

            AppButton.ActionButton btnCancel = new AppButton.ActionButton("Powrót");

            Expander accountMenu = new Expander
            {
                Header     = "Konto klienta",
                Background = Brushes.LightGray,
                Padding    = new Thickness(10),
                FontWeight = FontWeights.Bold,
            };

            Expander loanMenu = new Expander
            {
                Header     = "Pożyczki klienta",
                Background = Brushes.LightGray,
                Padding    = new Thickness(10),
                FontWeight = FontWeights.Bold,
            };

            AppButton.OperationCustomerButton btnCreateAccount = new AppButton.OperationCustomerButton("Zakładanie konta");
            AppButton.OperationCustomerButton btnPayment       = new AppButton.OperationCustomerButton("Wpłata / wypłata");
            AppButton.OperationCustomerButton btnDeleteAccount = new AppButton.OperationCustomerButton("Usuń konto");
            AppButton.OperationCustomerButton btnNewLoan       = new AppButton.OperationCustomerButton("Nowa pożyczka");
            AppButton.OperationCustomerButton btnActualLoan    = new AppButton.OperationCustomerButton("Aktualne pożyczki");
            AppButton.OperationCustomerButton btnRepaymentLoan = new AppButton.OperationCustomerButton("Spłać pożyczkę");

            AppDockPanel.ButtonsDockPanel customerAccount = new AppDockPanel.ButtonsDockPanel(
                null, btnCreateAccount, btnPayment, btnDeleteAccount);
            AppDockPanel.ButtonsDockPanel customerLoan = new AppDockPanel.ButtonsDockPanel(
                null, btnNewLoan, btnActualLoan, btnRepaymentLoan);

            accountMenu.Content = customerAccount;
            loanMenu.Content    = customerLoan;

            Label lblTitle = new Label
            {
                Content    = $"Operacje dla klienta {customer.FirstName} {customer.LastName}",
                Background = Brushes.DodgerBlue,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment   = VerticalAlignment.Center,
            };

            AppDockPanel.ButtonsDockPanel dpButton = new AppDockPanel.ButtonsDockPanel(new int[4] {
                0, 15, 0, 0
            }, btnCancel);

            btnCreateAccount.Click += NewAccountWindow;
            btnPayment.Click       += PaymentWindow;
            btnDeleteAccount.Click += DeleteAccountWindow;

            btnNewLoan.Click       += NewLoanWindow;
            btnActualLoan.Click    += ActualLoanWindow;
            btnRepaymentLoan.Click += RepaymentLoanWindow;

            btnCancel.Click += DeletePanel;

            mainWindow.Children.Add(sp);
            sp.Children.Add(lblTitle);
            sp.Children.Add(accountMenu);
            sp.Children.Add(loanMenu);
            sp.Children.Add(dpButton);

            Grid.SetColumn(sp, 2);
            Grid.SetRow(sp, 3);

            void NewAccountWindow(object o, EventArgs ev)
            {
                List <Account> accounts = new List <Account>();

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    accounts = context.Account.Where(x => x.CustomerID == customer.ID).ToList();
                }

                if (accounts.Count < 2)
                {
                    CustomerNewAccount customerNewAccount = new CustomerNewAccount(customer, loggedEmployee);
                    customerNewAccount.Show();
                }
                else
                {
                    MessageBox.Show
                    (
                        $"Klient posiada maksymalną ilość kont ( {accounts.Count} ).",
                        "Informacja",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information
                    );
                }
            }

            void PaymentWindow(object o, EventArgs ev)
            {
                List <Account> accounts = new List <Account>();

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    accounts = context.Account.Where(x => x.CustomerID == customer.ID).ToList();
                }

                if (accounts.Count > 0)
                {
                    CustomerPayment customerPayment = new CustomerPayment(customer);
                    customerPayment.Show();
                }
                else
                {
                    MessageBox.Show
                    (
                        $"Klient nie posiada jeszcze konta.",
                        "Informacja",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information
                    );
                }
            }

            void DeleteAccountWindow(object o, EventArgs ev)
            {
                List <Account> accounts = new List <Account>();

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    accounts = context.Account.Where(x => x.CustomerID == customer.ID).ToList();
                }

                if (accounts.Count > 0)
                {
                    CustomerDeleteAccount customerDeleteWindow = new CustomerDeleteAccount(customer);
                    customerDeleteWindow.Show();
                }
                else
                {
                    MessageBox.Show
                    (
                        $"Klient nie posiada kont do usunięcia.",
                        "Informacja",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information
                    );
                }
            }

            void NewLoanWindow(object o, EventArgs ev)
            {
                List <Loan> loans = new List <Loan>();

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    loans = context.Loan.Where(x => x.CustomerID == customer.ID).ToList();
                }

                if (loans.Count < 2)
                {
                    CustomerNewLoan customerNewLoan = new CustomerNewLoan(customer);
                    customerNewLoan.Show();
                }
                else
                {
                    MessageBox.Show
                    (
                        $"Klient posiada maksymalną ilość pożyczek ( {loans.Count} ).",
                        "Informacja",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information
                    );
                }
            }

            void ActualLoanWindow(object o, EventArgs ev)
            {
                List <Loan> loans = new List <Loan>();

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    loans = context.Loan.Where(x => x.CustomerID == customer.ID).ToList();
                }

                if (loans.Count > 0)
                {
                    CustomerLoans customerLoans = new CustomerLoans(customer);
                    customerLoans.Show();
                }
                else
                {
                    MessageBox.Show
                    (
                        $"Klient nie posiada aktualnie pożyczek.",
                        "Informacja",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information
                    );
                }
            }

            void RepaymentLoanWindow(object o, EventArgs e)
            {
                List <Loan> loans = new List <Loan>();

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    loans = context.Loan.Where(x => x.CustomerID == customer.ID).ToList();
                }

                if (loans.Count > 0)
                {
                    CustomerRepaymentLoan customerRepaymentLoan = new CustomerRepaymentLoan(customer);
                    customerRepaymentLoan.Show();
                }
                else
                {
                    MessageBox.Show
                    (
                        $"Klient nie posiada aktualnie pożyczek do spłacenia.",
                        "Informacja",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information
                    );
                }
            }

            void DeletePanel(object o, EventArgs ev) => mainWindow.Children.RemoveAt(mainWindow.Children.Count - 1);
        }
예제 #13
0
        private void ServiceCustomerNumberPanel(object sender, EventArgs e)
        {
            Customer customer = null;

            AppOtherControls.PeselTextBox[] numberInput = new AppOtherControls.PeselTextBox[11];

            for (int i = 0; i < numberInput.Length; i++)
            {
                numberInput[i] = new AppOtherControls.PeselTextBox();
            }

            StackPanel sp = new StackPanel
            {
                Width      = 400,
                Height     = 300,
                Background = Brushes.DeepSkyBlue,
                Margin     = new Thickness(0, -120, 0, -120),
            };

            AppButton.ActionButton btnCancel  = new AppButton.ActionButton("Anuluj");
            AppButton.ActionButton btnConfirm = new AppButton.ActionButton("Dalej");

            Label lblTitle = new Label
            {
                Content    = "Podaj numer PESEL klienta do operacji",
                Background = Brushes.DodgerBlue,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment   = VerticalAlignment.Center,
            };

            DockPanel dpMain = new DockPanel
            {
                Height     = 200,
                Background = Brushes.LightGray,
            };

            DockPanel dpNumbers = new DockPanel
            {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            foreach (var item in numberInput)
            {
                dpNumbers.Children.Add(item);
            }

            AppDockPanel.ButtonsDockPanel dpButtons = new AppDockPanel.ButtonsDockPanel(new int[4] {
                0, 15, 0, 0
            }, btnCancel, btnConfirm);

            btnCancel.Click  += DeletePanel;
            btnConfirm.Click += ServiceCustomer;

            mainWindow.Children.Add(sp);
            dpMain.Children.Add(dpNumbers);
            sp.Children.Add(lblTitle);
            sp.Children.Add(dpMain);
            sp.Children.Add(dpButtons);

            Grid.SetColumn(sp, 2);
            Grid.SetRow(sp, 3);

            void DeletePanel(object o, EventArgs ev) => mainWindow.Children.RemoveAt(mainWindow.Children.Count - 1);

            void ServiceCustomer(object o, EventArgs ev)
            {
                bool   isSuccess      = true;
                string customerNumber = null;
                var    numbers        = ControlFinder.FindVisualChildren <TextBox>(mainWindow.Children[mainWindow.Children.Count - 1]);

                foreach (var item in numbers)
                {
                    customerNumber += item.Text;
                }

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    try
                    {
                        customer = context.Customer.Single(x => x.ID == customerNumber);
                    }
                    catch (InvalidOperationException)
                    {
                        isSuccess = false;
                        MessageBoxResult confirm = MessageBox.Show
                                                   (
                            "Operacja zakończona niepowodzeniem.\nBrak klienta o danym numerze PESEL.",
                            "Wynik operacji",
                            MessageBoxButton.OK,
                            MessageBoxImage.Error
                                                   );
                    }
                }

                if (isSuccess)
                {
                    mainWindow.Children.RemoveAt(mainWindow.Children.Count - 1);
                    ServiceCustomerPanel(customer, loggedEmployee);
                }
            }
        }
예제 #14
0
        public void CreateNewAccount(Customer customer, Employee loggedEmployee, TextBox accountName, TextBox accountMoney, params DatePicker[] dates)
        {
            bool     isValidDate = true;
            DateTime date1       = default;
            DateTime date2       = default;

            try
            {
                date1 = dates[0].SelectedDate.Value.Date;
                date2 = dates[1].SelectedDate.Value.Date;
            }
            catch (InvalidOperationException) { isValidDate = false; }
            int resultDate = DateTime.Compare(date1, date2);

            if (accountName.Text == "" ||
                accountMoney.Text == "" ||
                isValidDate == false)
            {
                ShowError("Wprowadzono niekompletne dane!");
            }
            else if (resultDate >= 0)
            {
                ShowError("Podana data zakończenia jest dniem przeszłym!");
            }
            else if (date1 >= DateTime.Now)
            {
                ShowError("Data założenia nie może być większa od dzisiejszego dnia!");
            }
            else
            {
                bool    isValidMoney = true;
                decimal balance      = 0;

                try { balance = Convert.ToDecimal(accountMoney.Text); }
                catch (FormatException)
                {
                    MessageBox.Show
                    (
                        "Wprowadzona wartość pieniężna jest nieprawidłowa!",
                        "Informacja",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error
                    );

                    isValidMoney = false;
                }

                string name      = accountName.Text;
                string openDate  = dates[0].SelectedDate.Value.Date.ToString("yyyy/MM/dd");
                string closeDate = dates[1].SelectedDate.Value.Date.ToString("yyyy/MM/dd");

                if (isValidMoney)
                {
                    using (var context = new SystemObsługiBankuDBEntities()) //logged employee null, naprawić
                    {
                        context.Account.Add(new Account
                        {
                            Balance     = balance,
                            AccountName = name,
                            OpenDate    = Convert.ToDateTime(openDate),
                            CloseDate   = Convert.ToDateTime(closeDate),
                            CustomerID  = customer.ID,
                            BranchID    = loggedEmployee.BranchID,
                        });

                        context.SaveChanges();
                        MessageBox.Show
                        (
                            "Konto zostało dodane pomyślnie.",
                            "Informacja",
                            MessageBoxButton.OK,
                            MessageBoxImage.Information
                        );
                    }
                }
            }
            Close();
        }
예제 #15
0
        private void DeleteCustomerPanel(object sender, EventArgs e)
        {
            AppOtherControls.PeselTextBox[] numberInput = new AppOtherControls.PeselTextBox[11];
            for (int i = 0; i < numberInput.Length; i++)
            {
                numberInput[i] = new AppOtherControls.PeselTextBox();
            }

            StackPanel sp = new StackPanel
            {
                Width      = 400,
                Background = Brushes.DeepSkyBlue,
                Margin     = new Thickness(0, -120, 0, -120),
            };

            AppButton.ActionButton btnCancel  = new AppButton.ActionButton("Anuluj");
            AppButton.ActionButton btnConfirm = new AppButton.ActionButton("Zatwierdź");

            Label lblTitle = new Label
            {
                Content    = "Podaj numer PESEL klienta do usunięcia",
                Background = Brushes.DodgerBlue,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment   = VerticalAlignment.Center,
            };

            Label lblWarning = new Label
            {
                Content    = "UWAGA, brak możliwości cofnięcia operacji!",
                Background = Brushes.PaleVioletRed,
                Foreground = Brushes.Maroon,
                FontWeight = FontWeights.Bold,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment   = VerticalAlignment.Center,
            };

            DockPanel dpMain = new DockPanel
            {
                Height     = 200,
                Background = Brushes.LightGray,
            };

            DockPanel dpNumbers = new DockPanel
            {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            foreach (var item in numberInput)
            {
                dpNumbers.Children.Add(item);
            }

            AppDockPanel.ButtonsDockPanel dpButtons = new AppDockPanel.ButtonsDockPanel(new int[4] {
                0, 15, 0, 0
            }, btnCancel, btnConfirm);

            btnCancel.Click  += DeletePanel;
            btnConfirm.Click += DeleteCustomer;

            mainWindow.Children.Add(sp);
            dpMain.Children.Add(dpNumbers);
            sp.Children.Add(lblTitle);
            sp.Children.Add(lblWarning);
            sp.Children.Add(dpMain);
            sp.Children.Add(dpButtons);

            Grid.SetColumn(sp, 2);
            Grid.SetRow(sp, 3);

            void DeletePanel(object o, EventArgs ev) => mainWindow.Children.RemoveAt(mainWindow.Children.Count - 1);

            void DeleteCustomer(object o, EventArgs ev)
            {
                bool   isSuccess      = true;
                string customerNumber = null;
                var    numbers        = ControlFinder.FindVisualChildren <TextBox>(mainWindow.Children[mainWindow.Children.Count - 1]);

                foreach (var item in numbers)
                {
                    customerNumber += item.Text;
                }

                using (var context = new SystemObsługiBankuDBEntities())
                {
                    try
                    {
                        var accounts = context.Account.Where(x => x.CustomerID == customerNumber).ToList();
                        if (accounts.Count != 0)
                        {
                            foreach (var item in accounts)
                            {
                                context.Account.Remove(item);
                            }
                        }

                        var loans = context.Loan.Where(x => x.CustomerID == customerNumber).ToList();
                        if (accounts.Count != 0)
                        {
                            foreach (var item in loans)
                            {
                                context.Loan.Remove(item);
                            }
                        }

                        context.Customer.Remove(context.Customer.Single(x => x.ID == customerNumber));
                        context.SaveChanges();
                    }
                    catch (InvalidOperationException) { isSuccess = false; }
                }

                MessageBoxResult confirm = MessageBox.Show
                                           (
                    isSuccess == true ? "Operacja zakończona pomyślnie.":
                    "Operacja zakończona niepowodzeniem. \nBrak klienta o danym numerze PESEL.",
                    "Wynik operacji",
                    MessageBoxButton.OK,
                    isSuccess == true ? MessageBoxImage.Information : MessageBoxImage.Error
                                           );

                if (isSuccess)
                {
                    mainWindow.Children.RemoveAt(mainWindow.Children.Count - 1);
                }
            }
        }