コード例 #1
0
ファイル: CustomerPayment.xaml.cs プロジェクト: ultorhash/SOB
        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();
        }
コード例 #2
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
                                           );
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
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();
            }
        }
コード例 #5
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();
        }
コード例 #6
0
ファイル: DeleteCustomerPanel.cs プロジェクト: ultorhash/SOB
        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);
                }
            }
        }