Esempio n. 1
0
        public Withdrawal(PassbookList pbList, Models.PassBook pb)
        {
            withDrawal = new Views.Withdrawal();
            passBook   = pb;

            placeData();

            withDrawal.btnSettlement.Click += (sender, e) =>
            {
                try
                {
                    Models.PassBook passBook   = db.PassBooks.Find(pb.PassBookID);
                    Models.User     targetUser = db.Users.Find(passBook.UserID);

                    targetUser.Wallet        += getNumber(withDrawal.txtTotalMoney.Text);
                    targetUser.SavingsWallet -= pb.Deposit;
                    passBook.Settlement       = true;

                    db.SaveChanges();

                    withDrawal.Close();
                    pbList.ShowDataGrid();
                    pbList.passBookList.dtgridSettlement.ItemsSource = Models.PassBook.getListPassBookSettlement(UserID);
                    pbList.LoadHeaderSettlement();
                }
                catch
                {
                    MessageBox.Show("Đã có lỗi xảy ra, vui lòng kiểm tra lại", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            };

            withDrawal.btnClose.Click += (sender, e) =>
            {
                withDrawal.Close();
            };
        }
Esempio n. 2
0
        public PartialWithdrawal(PassbookList pbList, Models.PassBook pb)
        {
            partialWithdrawal = new Views.PartialWithdrawal();
            passBook          = pb;

            placeData();

            partialWithdrawal.btnSave.Click += (sender, e) =>
            {
                PartialWithdrawallValidate();
                try
                {
                    Models.PassBook passBook = db.PassBooks.Find(pb.PassBookID);
                    Models.User     user     = db.Users.Find(pb.UserID);

                    if (pb.Term == 99)
                    {
                        int day = Convert.ToInt32((DateTime.Now - pb.SentDate).TotalDays);
                        if (day > 15)
                        {
                            try
                            {
                                double moneyWithdrawal = getNumber(partialWithdrawal.txtWithDrawDeposit.Text);

                                if (moneyWithdrawal < pb.Deposit && moneyWithdrawal > 0)
                                {
                                    user.Wallet        += (moneyWithdrawal + (moneyWithdrawal * (passBook.IndefiniteTerm / 100) * day) / 365);
                                    user.SavingsWallet -= moneyWithdrawal;
                                    passBook.Deposit   -= moneyWithdrawal;
                                }
                                else if (moneyWithdrawal == pb.Deposit)
                                {
                                    user.Wallet        += (moneyWithdrawal + (moneyWithdrawal * (passBook.IndefiniteTerm / 100) * day) / 365);
                                    user.SavingsWallet -= moneyWithdrawal;
                                    passBook.Settlement = true;
                                }
                                else
                                {
                                    MessageBox.Show("Số tiền rút không hợp lệ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }
                            catch { MessageBox.Show("Số tiền rút không hợp lệ", "Error", MessageBoxButton.OK, MessageBoxImage.Error); }
                        }
                        else
                        {
                            MessageBox.Show("Bạn chưa thể rút tiền. Số ngày gửi dưới 15 ngày.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        if (DateTime.Now < pb.EndDate)
                        {
                            try
                            {
                                Notification noti            = new Notification(pb);
                                int          day             = Convert.ToInt32((DateTime.Now - pb.SentDate).TotalDays);
                                double       moneyWithdrawal = getNumber(partialWithdrawal.txtWithDrawDeposit.Text);

                                if (moneyWithdrawal < pb.Deposit && moneyWithdrawal > 0)
                                {
                                    noti.ShowDialog();

                                    if (noti.flag == true)
                                    {
                                        user.Wallet        += (moneyWithdrawal + (moneyWithdrawal * (passBook.IndefiniteTerm / 100) * day) / 365);
                                        user.SavingsWallet -= moneyWithdrawal;
                                        passBook.Deposit   -= moneyWithdrawal;
                                    }
                                }
                                else if (moneyWithdrawal == pb.Deposit)
                                {
                                    noti.ShowDialog();

                                    if (noti.flag == true)
                                    {
                                        user.Wallet        += (moneyWithdrawal + (moneyWithdrawal * (passBook.IndefiniteTerm / 100) * day) / 365);
                                        user.SavingsWallet -= moneyWithdrawal;
                                        passBook.Settlement = true;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Số tiền rút không thể lớn hơn số tiện hiện có trong sổ tiết kiệm này", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }
                            catch { MessageBox.Show("Số tiền rút không hợp lệ", "Error", MessageBoxButton.OK, MessageBoxImage.Error); }
                        }
                    }

                    db.SaveChanges();
                    pbList.ShowDataGrid();
                    pbList.passBookList.dtgridSettlement.ItemsSource = Models.PassBook.getListPassBookSettlement(UserID);
                    pbList.LoadHeaderSettlement();
                }
                catch
                {
                    MessageBox.Show("Đã có lỗi xảy ra, vui lòng kiểm tra lại", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            };

            partialWithdrawal.btnClose.Click += (sender, e) =>
            {
                partialWithdrawal.Close();
            };
        }