Пример #1
0
        private void LoadData()
        {
            DAL.UnitOfWork oUnitOfWork = null;

            try
            {
                oUnitOfWork = new DAL.UnitOfWork();

                Models.Fund oFund = oUnitOfWork.FundRepository
                                    .GetById(Utility.CurrentFund.Id);

                FundNameTextBox.Text           = oFund.Name;
                FundManagerNameTextBox.Text    = oFund.ManagerName;
                FundBuildYearTextBox.Text      = oFund.FoundationYear.ToString();
                FundDepositBalanceTextBox.Text = Utility.ToRialStringFormat(FundDepositBalanceTextBox.Text.StringToMoney());
                FundRemovalLimitTextBox.Text   = oFund.RemovalLimit.ToRialStringFormat();

                RefreshLabels();

                oUnitOfWork.Save();
            }
            catch (System.Exception ex)
            {
                Infrastructure.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (oUnitOfWork != null)
                {
                    oUnitOfWork.Dispose();
                    oUnitOfWork = null;
                }
            }
        }
        private void LoginFundClick(object sender, System.Windows.RoutedEventArgs e)
        {
            Models.Fund selectedFund = FundsComboBox.SelectedItem as Models.Fund;

            string password = Dtx.Security.Hashing.GetMD5(passwordBox.Password);

            if (selectedFund.ManagerPassword == password)
            {
                Infrastructure.MessageBox.Show
                (
                    caption: Infrastructure.MessageBox.Caption.Information,
                    text: "ورود به صندوق با موفقیت انجام گردید."
                );

                Utility.CurrentFund = selectedFund;
                Utility.MainWindow.RefreshUserInterface();
                this.Close();
            }
            else
            {
                Infrastructure.MessageBox.Show
                (
                    caption: Infrastructure.MessageBox.Caption.Error,
                    text: "رمز عبور وارد شده صحیح نمی‌باشد."
                );

                return;
            }
        }
Пример #3
0
        private void DeleteFund_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            DAL.UnitOfWork oUnitOfWork = null;

            try
            {
                oUnitOfWork = new DAL.UnitOfWork();

                System.Windows.MessageBoxResult oResult =
                    Infrastructure.MessageBox.Show
                    (
                        caption: Infrastructure.MessageBox.Caption.Question,
                        text: "آیا مطمئن به حذف صندوق می‌باشید؟"
                    );

                if (oResult == System.Windows.MessageBoxResult.Yes)
                {
                    Models.Fund oFund = oUnitOfWork.FundRepository
                                        .GetById(Utility.CurrentFund.Id);

                    if (oFund != null)
                    {
                        oUnitOfWork.FundRepository.Delete(oFund);

                        oUnitOfWork.Save();

                        Infrastructure.MessageBox.Show
                        (
                            caption: Infrastructure.MessageBox.Caption.Information,
                            text: "صندوق با موفقیت حذف گردید."
                        );

                        Utility.CurrentFund = null;

                        Utility.MainWindow.RefreshUserInterface();
                    }
                }

                oUnitOfWork.Save();
            }
            catch (System.Exception ex)
            {
                Infrastructure.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (oUnitOfWork != null)
                {
                    oUnitOfWork.Dispose();
                    oUnitOfWork = null;
                }
            }

            this.Close();
        }
        private void PayInstallmentsButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ViewModels.InstallmentViewModel oViewModel = InstallmentPerLoanGridControl.SelectedItem as ViewModels.InstallmentViewModel;

            if (oViewModel != null)
            {
                DAL.UnitOfWork oUnitOfWork = null;

                try
                {
                    oUnitOfWork = new DAL.UnitOfWork();

                    Models.Installment oInstallment = oUnitOfWork.InstallmentRepository
                                                      .GetById(oViewModel.Id);

                    var varList = oUnitOfWork.InstallmentRepository
                                  .Get()
                                  .Where(current => current.LoanId == oInstallment.LoanId)
                                  .Where(current => current.IsPayed == false)
                                  .Where(current => current.InstallmentDate < oInstallment.InstallmentDate)
                                  .OrderBy(current => current.InstallmentDate)
                                  .ToList();

                    if (varList.Count != 0)
                    {
                        Infrastructure.MessageBox.Show
                        (
                            caption: Infrastructure.MessageBox.Caption.Error,
                            text: string.Format("ابتدا بایست قسط تاریخ {0} پرداخت شود.", varList.Select(current => current.InstallmentDate).FirstOrDefault().ToPersianDate())
                        );

                        return;
                    }

                    oInstallment.IsPayed     = true;
                    oInstallment.PaymentDate = System.DateTime.Now;

                    oUnitOfWork.InstallmentRepository.Update(oInstallment);

                    Models.Member oMember = oUnitOfWork.MemberRepository
                                            .GetById(oInstallment.Loan.Member.Id);

                    oMember.Balance -= oInstallment.PaymentAmount;

                    oUnitOfWork.MemberRepository.Update(oMember);

                    Models.Fund oFund = oUnitOfWork.FundRepository
                                        .GetById(Utility.CurrentFund.Id);

                    oFund.Balance += oInstallment.PaymentAmount;

                    oUnitOfWork.FundRepository.Update(oFund);

                    Utility.CurrentFund = oFund;

                    Models.Transaction oTransaction = new Models.Transaction();

                    oTransaction.Amount          = oInstallment.PaymentAmount;
                    oTransaction.Balance         = oFund.Balance;
                    oTransaction.Date            = System.DateTime.Now;
                    oTransaction.Description     = string.Format("پرداخت قسط به مبلغ {0} ریال از {1}", oInstallment.PaymentAmount, oInstallment.Loan.Member.FullName);
                    oTransaction.TransactionType = Models.TransactionType.Installment;
                    oTransaction.MemberId        = oInstallment.Loan.Member.Id;
                    oTransaction.FundId          = oFund.Id;
                    oTransaction.InstallmentId   = oInstallment.Id;

                    oUnitOfWork.TransactionRepository.Insert(oTransaction);

                    Models.Reminder oReminder = oUnitOfWork.RemainderRepository
                                                .Get()
                                                .Where(current => current.InstallmentId == oInstallment.Id)
                                                .FirstOrDefault();

                    if (oReminder != null)
                    {
                        oUnitOfWork.RemainderRepository.Delete(oReminder);
                    }

                    oUnitOfWork.Save();

                    Models.Loan oLoan = oUnitOfWork.LoanRepository
                                        .Get()
                                        .Where(current => current.Id == oInstallment.LoanId)
                                        .Where(current => current.Installments.All(installment => installment.IsPayed == true))
                                        .FirstOrDefault();

                    if (oLoan != null)
                    {
                        oLoan.IsPayed  = true;
                        oLoan.IsActive = false;

                        oUnitOfWork.LoanRepository.Update(oLoan);

                        oUnitOfWork.Save();
                    }

                    Utility.MainWindow.RefreshUserInterface();
                    (Utility.MainWindow.SthPanel.Children[0] as MainPanelContentUserControl).MiniPersianSchedulerReminder.RefreshMonth();
                    (Utility.MainWindow.SthPanel.Children[0] as MainPanelContentUserControl).RefreshSchedulerListBox();
                }
                catch (System.Exception ex)
                {
                    Infrastructure.MessageBox.Show(ex.Message);;
                }
                finally
                {
                    if (oUnitOfWork != null)
                    {
                        oUnitOfWork.Dispose();
                        oUnitOfWork = null;
                    }
                }

                RefreshInstallmentGridControl();
            }
        }
        private void ODeleteLoanBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            DAL.UnitOfWork oUnitOfWork = null;

            try
            {
                oUnitOfWork = new DAL.UnitOfWork();

                Models.Fund oFund = oUnitOfWork.FundRepository
                                    .GetById(Utility.CurrentFund.Id);

                var varList = oUnitOfWork.InstallmentRepository
                              .Get()
                              .Where(current => current.LoanId == Utility.CurrentLoan.Id)
                              .ToList();


                if (varList.Count != 0)
                {
                    foreach (Models.Installment oInstallment in varList)
                    {
                        Models.Transaction oTransaction = oUnitOfWork.TransactionRepository
                                                          .Get()
                                                          .Where(current => current.InstallmentId == oInstallment.Id)
                                                          .FirstOrDefault();

                        Models.Member oMember = oUnitOfWork.MemberRepository
                                                .GetById((System.Guid)oTransaction.MemberId);

                        if (oInstallment.IsPayed == true)
                        {
                            oMember.Balance += oInstallment.PaymentAmount;

                            oUnitOfWork.MemberRepository.Update(oMember);
                        }

                        if (oTransaction != null)
                        {
                            oUnitOfWork.TransactionRepository.Delete(oTransaction);
                        }

                        Models.Reminder oReminder = oUnitOfWork.RemainderRepository
                                                    .Get()
                                                    .Where(current => current.InstallmentId == oInstallment.Id)
                                                    .FirstOrDefault();

                        if (oReminder != null)
                        {
                            oUnitOfWork.RemainderRepository.Delete(oReminder);
                        }

                        if (oFund != null)
                        {
                            oFund.Balance -= oInstallment.PaymentAmount;
                        }

                        oUnitOfWork.Save();
                    }

                    oUnitOfWork.FundRepository.Update(oFund);

                    oUnitOfWork.Save();

                    Utility.CurrentFund = oFund;
                }

                Models.Loan oLoan = oUnitOfWork.LoanRepository
                                    .GetById(Utility.CurrentLoan.Id);


                if (oLoan != null)
                {
                    Models.Transaction oTransaction = oUnitOfWork.TransactionRepository
                                                      .Get()
                                                      .Where(current => current.LoanId == oLoan.Id)
                                                      .FirstOrDefault();


                    Models.Member oMember = oUnitOfWork.MemberRepository
                                            .GetById(Utility.CurrentLoan.Member.Id);

                    oUnitOfWork.LoanRepository.Delete(oLoan);

                    if (oTransaction != null)
                    {
                        oUnitOfWork.TransactionRepository.Delete(oTransaction);
                    }

                    oUnitOfWork.Save();

                    oFund.Balance   += oLoan.LoanAmount;
                    oMember.Balance -= oLoan.LoanAmount;

                    oUnitOfWork.FundRepository.Update(oFund);
                    oUnitOfWork.MemberRepository.Update(oMember);
                }

                oUnitOfWork.Save();

                Utility.CurrentFund = oFund;
                Utility.CurrentLoan = null;
            }
            catch (System.Exception ex)
            {
                Infrastructure.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (oUnitOfWork != null)
                {
                    oUnitOfWork.Dispose();
                    oUnitOfWork = null;
                }
            }
        }
        private void OBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            DAL.UnitOfWork oUnitOfWork = null;

            try
            {
                oUnitOfWork = new DAL.UnitOfWork();

                var varList = oUnitOfWork.InstallmentRepository
                              .Get()
                              .Where(current => current.LoanId == Utility.CurrentLoan.Id)
                              .Where(current => current.IsPayed == false)
                              .OrderBy(current => current.InstallmentDate)
                              .ToList();


                if (varList.Count != 0)
                {
                    int count   = varList.Count;
                    int counter = 0;

                    foreach (Models.Installment oInstallment in varList)
                    {
                        int progressBarPercent = System.Convert.ToInt32(((double)(counter + 1) / varList.Count) * 100);

                        oInstallment.IsPayed     = true;
                        oInstallment.PaymentDate = System.DateTime.Now;

                        oUnitOfWork.InstallmentRepository.Update(oInstallment);

                        Models.Member oMember = oUnitOfWork.MemberRepository
                                                .GetById(oInstallment.Loan.Member.Id);

                        oMember.Balance -= oInstallment.PaymentAmount;

                        oUnitOfWork.MemberRepository.Update(oMember);

                        Models.Fund oFund = oUnitOfWork.FundRepository
                                            .GetById(Utility.CurrentFund.Id);

                        oFund.Balance += oInstallment.PaymentAmount;

                        oUnitOfWork.FundRepository.Update(oFund);

                        Utility.CurrentFund = oFund;

                        Models.Transaction oTransaction = new Models.Transaction();

                        oTransaction.Amount          = oInstallment.PaymentAmount;
                        oTransaction.Balance         = oFund.Balance;
                        oTransaction.Date            = System.DateTime.Now;
                        oTransaction.Description     = string.Format("پرداخت قسط به مبلغ {0} ریال از {1}", oInstallment.PaymentAmount, oInstallment.Loan.Member.FullName);
                        oTransaction.TransactionType = Models.TransactionType.Installment;
                        oTransaction.MemberId        = oInstallment.Loan.Member.Id;
                        oTransaction.FundId          = oFund.Id;
                        oTransaction.InstallmentId   = oInstallment.Id;

                        oUnitOfWork.TransactionRepository.Insert(oTransaction);

                        Models.Reminder oReminder = oUnitOfWork.RemainderRepository
                                                    .Get()
                                                    .Where(current => current.InstallmentId == oInstallment.Id)
                                                    .FirstOrDefault();

                        if (oReminder != null)
                        {
                            oUnitOfWork.RemainderRepository.Delete(oReminder);
                        }

                        oUnitOfWork.Save();

                        Models.Loan oLoan = oUnitOfWork.LoanRepository
                                            .Get()
                                            .Where(current => current.Id == oInstallment.LoanId)
                                            .Where(current => current.Installments.All(installment => installment.IsPayed == true))
                                            .FirstOrDefault();

                        if (oLoan != null)
                        {
                            oLoan.IsPayed  = true;
                            oLoan.IsActive = false;

                            oUnitOfWork.LoanRepository.Update(oLoan);

                            oUnitOfWork.Save();
                        }

                        (sender as System.ComponentModel.BackgroundWorker).ReportProgress(progressBarPercent);

                        counter++;
                    }
                }

                oUnitOfWork.Save();
            }
            catch (System.Exception ex)
            {
                Infrastructure.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (oUnitOfWork != null)
                {
                    oUnitOfWork.Dispose();
                    oUnitOfWork = null;
                }
            }
        }
Пример #7
0
        private void OBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            DAL.UnitOfWork oUnitOfWork = null;

            oUnitOfWork = new DAL.UnitOfWork();

            Models.Member oMember = oUnitOfWork.MemberRepository
                .GetById(Utility.CurrentMember.Id);

            Models.Fund oFund = oUnitOfWork.FundRepository
                .GetById(Utility.CurrentFund.Id);

            Models.Loan oLoan = new Models.Loan();

            this.Dispatcher.Invoke(() =>
            {
                oLoan.LoanAmount = LoanAmountTextBox.Text.StringToMoney();
                oLoan.IsActive = true;
                oLoan.IsPayed = false;
                oLoan.MemberId = Utility.CurrentMember.Id;
                oLoan.InstallmentsCount = System.Convert.ToInt32(InstallmentsCountTextBox.Text.Trim());
                oLoan.RefundAmount = LoanAmountTextBox.Text.StringToMoney();
                oLoan.StartDate = LoanDateTimeDatePicker.SelectedDateTime;
                oLoan.EndDate = LoanDateTimeDatePicker.SelectedDateTime;
                oLoan.Description = DescriptionTextBox.Text.Trim();
            });

            oUnitOfWork.LoanRepository.Insert(oLoan);

            oFund.Balance -= oLoan.LoanAmount;

            oUnitOfWork.FundRepository.Update(oFund);

            oUnitOfWork.Save();

            Utility.CurrentFund = oFund;

            Models.Transaction oTransaction = new Models.Transaction();

            oTransaction.Amount = oLoan.LoanAmount;
            oTransaction.Balance = oFund.Balance;
            oTransaction.Date = System.DateTime.Now;
            oTransaction.Description = string.Format("پرداخت وام به مبلغ {0} ریال به {1}", oLoan.LoanAmount, Utility.CurrentMember.FullName);
            oTransaction.FundId = Utility.CurrentFund.Id;
            oTransaction.TransactionType = Models.TransactionType.Loan;
            oTransaction.MemberId = Utility.CurrentMember.Id;
            oTransaction.LoanId = oLoan.Id;

            oUnitOfWork.TransactionRepository.Insert(oTransaction);

            int percent = 0;

            this.Dispatcher.Invoke(() =>
            {
                percent = (CalculatePercentCheckBox.IsChecked == true) ? Utility.CurrentFund.Percent : 0;
            });

            ViewModels.CreateLoanViewModel oCreateLoanViewModel = CalculateLoanParameters(oLoan.LoanAmount, oLoan.InstallmentsCount, percent);

            for (int index = 0; index < oLoan.InstallmentsCount; index++)
            {
                int progressBarPercent = System.Convert.ToInt32(((double)(index + 1) / oLoan.InstallmentsCount) * 100);

                Models.Installment oInstallment = new Models.Installment();

                oInstallment.PaymentAmount = oCreateLoanViewModel.Installments.ElementAt(index);
                oInstallment.IsPayed = false;
                oInstallment.InstallmentDate = oLoan.StartDate.AddMonths(index + 1);
                oInstallment.PaymentDate = null;
                oInstallment.LoanId = oLoan.Id;

                oUnitOfWork.InstallmentRepository.Insert(oInstallment);

                Models.Reminder oReminder = new Models.Reminder();

                FarsiLibrary.Utils.PersianDate oPersianDate = new FarsiLibrary.Utils.PersianDate(oInstallment.InstallmentDate);

                oReminder.DateTime = oInstallment.InstallmentDate;
                oReminder.PersianDate.Year = oPersianDate.Year;
                oReminder.PersianDate.Month = oPersianDate.Month;
                oReminder.PersianDate.Day = oPersianDate.Day;
                oReminder.EventType = Models.Event.Installment;
                oReminder.Description = string.Format("قسط {0} وام {1} به مبلغ {2}",
                    FarsiLibrary.Utils.ToWords.ToString(index + 1), Utility.CurrentMember.FullName, oInstallment.PaymentAmount.ToRialStringFormat());
                oReminder.InstallmentId = oInstallment.Id;
                oReminder.FundId = Utility.CurrentFund.Id;

                oUnitOfWork.RemainderRepository.Insert(oReminder);

                if (index == oLoan.InstallmentsCount - 1)
                {
                    oLoan.EndDate = oInstallment.InstallmentDate;
                    oLoan.RefundAmount = oCreateLoanViewModel.RefundAmount;
                    oUnitOfWork.LoanRepository.Update(oLoan);
                }

                oUnitOfWork.Save();

                (sender as System.ComponentModel.BackgroundWorker).ReportProgress(progressBarPercent);

            }

            Utility.CurrentLoan = oLoan;

            oMember.Balance += oLoan.LoanAmount;

            oUnitOfWork.MemberRepository.Update(oMember);

            oUnitOfWork.Save();
        }
        private void SimpleButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (DepositAmountTextBox.Text.StringToMoney() == 0)
            {
                Infrastructure.MessageBox.Show
                (
                    caption: Infrastructure.MessageBox.Caption.Error,
                    text: "درج مبلغ واریزی الزامی است"
                );

                return;
            }

            DAL.UnitOfWork oUnitOfWork = null;

            try
            {
                oUnitOfWork = new DAL.UnitOfWork();

                Models.Fund oFund = oUnitOfWork.FundRepository
                                    .GetById(Utility.CurrentFund.Id);

                Models.Member oMember = oUnitOfWork.MemberRepository
                                        .GetById(Utility.CurrentMember.Id);

                Models.Transaction oTransaction = new Models.Transaction();

                oTransaction.FundId          = oFund.Id;
                oTransaction.Amount          = DepositAmountTextBox.Text.StringToMoney();
                oTransaction.Balance         = oFund.Balance + oTransaction.Amount;
                oTransaction.TransactionType = Models.TransactionType.Deposit;
                oTransaction.LoanId          = null;
                oTransaction.InstallmentId   = null;
                oTransaction.MemberId        = oMember.Id;
                oTransaction.Date            = System.DateTime.Now;

                oFund.Balance   += oTransaction.Amount;
                oMember.Balance += oTransaction.Amount;

                oUnitOfWork.MemberRepository.Update(oMember);
                oUnitOfWork.FundRepository.Update(oFund);

                oUnitOfWork.TransactionRepository.Insert(oTransaction);

                oUnitOfWork.Save();

                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Information, text: "واریز به صندوق با موفقیت انجام شد");

                Utility.CurrentFund   = oFund;
                Utility.CurrentMember = oMember;

                LoadGridControl();
            }
            catch (System.Exception ex)
            {
                Infrastructure.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (oUnitOfWork != null)
                {
                    oUnitOfWork.Dispose();
                    oUnitOfWork = null;
                }
            }
        }
Пример #9
0
        private void AcceptClick(object sender, System.Windows.RoutedEventArgs e)
        {
            #region Error Handling Messages

            if (string.IsNullOrWhiteSpace(fundNameTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد نام صندوق الزامی است.");

                return;
            }

            if (string.IsNullOrWhiteSpace(fundManagerTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد نام مدیر صندوق الزامی می‌باشد.");

                return;
            }

            if (string.IsNullOrWhiteSpace(fundBuildYearTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد سال تاسیس الزامی می‌باشد.");

                return;
            }


            if (string.IsNullOrWhiteSpace(fundBalanceTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد تراز صندوق الزامی می‌باشد.");

                return;
            }

            if (string.IsNullOrWhiteSpace(fundRemovalLimitTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد سقف برداشت وام الزامی می‌باشد.");

                return;
            }

            if (string.IsNullOrWhiteSpace(passwordBox.Password) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد رمز عبور الزامی می‌باشد.");

                return;
            }

            if (string.IsNullOrWhiteSpace(againPasswordBox.Password) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد تکرار رمز عبور الزامی می‌باشد.");

                return;
            }

            if (PercentCheckBox.IsChecked == true)
            {
                if (string.IsNullOrWhiteSpace(PercentTextBox.Text.Trim()) == true)
                {
                    Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "در صورت فعال بودن گزینه کارمزد، تکمیل فیلد کارمزد الزامی است.");

                    return;
                }
            }

            if (Utility.StringToMoney(fundBalanceTextBox.Text) <= Utility.StringToMoney(fundRemovalLimitTextBox.Text))
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "سقف برداشت نمیتواند مقداری بیشتر از تراز صندوق داشته باشد.");

                return;
            }

            if (passwordBox.Password.Trim() != againPasswordBox.Password.Trim())
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "گذرواژه های درج شده با یکدیگر مطابقت ندارند.");

                return;
            }

            #endregion

            DAL.UnitOfWork oUnitOfWork = null;

            try
            {
                oUnitOfWork = new DAL.UnitOfWork();

                Models.Fund oFund = new Models.Fund();

                oFund.Name            = fundNameTextBox.Text.Trim();
                oFund.ManagerName     = fundManagerTextBox.Text.Trim();
                oFund.FoundationYear  = System.Convert.ToInt32(fundBuildYearTextBox.Text);
                oFund.Balance         = Utility.StringToMoney(fundBalanceTextBox.Text);
                oFund.UserId          = Utility.CurrentUser.Id;
                oFund.RemovalLimit    = Utility.StringToMoney(fundRemovalLimitTextBox.Text);
                oFund.ManagerPassword = Dtx.Security.Hashing.GetMD5(passwordBox.Password.Trim());
                oFund.Percent         = (PercentCheckBox.IsChecked == true) ? System.Convert.ToInt32(PercentTextBox.Text) : 0;

                oUnitOfWork.FundRepository.Insert(oFund);

                oUnitOfWork.Save();
                oUnitOfWork.Dispose();
                oUnitOfWork = null;

                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Information, text: "صندوق جدید با موفقیت در بانک اطلاعاتی ایجاد گردید.");

                Utility.MainWindow.RefreshUserInterface();
            }
            catch (System.Exception ex)
            {
                Infrastructure.MessageBox.Show(ex.Message);;
            }
            finally
            {
                if (oUnitOfWork != null)
                {
                    oUnitOfWork.Dispose();
                    oUnitOfWork = null;
                }
            }
        }
Пример #10
0
        private void EditFundProperties()
        {
            #region Error Handling Messages

            if (string.IsNullOrWhiteSpace(FundNameTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد نام صندوق الزامی است.");

                return;
            }

            if (string.IsNullOrWhiteSpace(FundManagerNameTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد نام مدیر صندوق الزامی می‌باشد.");

                return;
            }

            if (string.IsNullOrWhiteSpace(FundBuildYearTextBox.Text) == true)
            {
                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد سال تاسیس الزامی می‌باشد.");

                return;
            }

            if (PasswordToggleSwitch.IsChecked == true)
            {
                if (string.IsNullOrWhiteSpace(CurrentPasswordBox.Password) == true)
                {
                    Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد رمز عبور فعلی الزامی می‌باشد.");

                    return;
                }

                if (string.IsNullOrWhiteSpace(NewPasswordBox.Password) == true)
                {
                    Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد رمز عبور جدید الزامی می‌باشد.");

                    return;
                }

                if (string.IsNullOrWhiteSpace(ConfirmPasswordBox.Password) == true)
                {
                    Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "تکمیل فیلد تایید رمز عبور جدید الزامی می‌باشد.");

                    return;
                }
            }

            if (DepositBalanceToggleSwitch.IsChecked == true)
            {
                if (string.IsNullOrWhiteSpace(FundDepositBalanceTextBox.Text) == true)
                {
                    Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "در صورت فعال بودن گزینه افزایش موجودی، تکمیل فیلد افزایش موجودی الزامی است.");

                    return;
                }
            }

            if (RemovalLimitToggleSwitch.IsChecked == true)
            {
                if (string.IsNullOrWhiteSpace(FundRemovalLimitTextBox.Text) == true)
                {
                    Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "در صورت فعال بودن گزینه تغییر سقف برداشت وام، تکمیل فیلد تغییر سقف پرداخت وام الزامی است.");

                    return;
                }
            }

            if (PercentToggleSwitch.IsChecked == true)
            {
                if (string.IsNullOrWhiteSpace(FundPercentTextBox.Text.Trim()) == true)
                {
                    Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "در صورت فعال بودن گزینه کارمزد، تکمیل فیلد کارمزد الزامی است.");

                    return;
                }
            }

            #endregion

            DAL.UnitOfWork oUnitOfWork = null;

            try
            {
                oUnitOfWork = new DAL.UnitOfWork();

                Models.Fund oFund = oUnitOfWork.FundRepository
                                    .GetById(Utility.CurrentFund.Id);

                if (oFund != null)
                {
                    oFund.Name           = FundNameTextBox.Text;
                    oFund.ManagerName    = FundManagerNameTextBox.Text;
                    oFund.FoundationYear = System.Convert.ToInt32(FundBuildYearTextBox.Text.Trim());

                    if (PasswordToggleSwitch.IsChecked == true)
                    {
                        if (Dtx.Security.Hashing.GetMD5(CurrentPasswordBox.Password.Trim()) != oFund.ManagerPassword)
                        {
                            Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "رمز عبور درج شده صحیح نمی‌باشد.");

                            return;
                        }
                        if (NewPasswordBox.Password.Trim() != ConfirmPasswordBox.Password.Trim())
                        {
                            Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Error, text: "رمزهای عبور جدید درج شده دارای مطابقت نمی‌باشد.");

                            return;
                        }

                        oFund.ManagerPassword = Dtx.Security.Hashing.GetMD5(NewPasswordBox.Password);
                    }

                    if (DepositBalanceToggleSwitch.IsChecked == true)
                    {
                        oFund.Balance += (FundDepositBalanceTextBox.Text.StringToMoney());

                        Models.Transaction oTransaction = new Models.Transaction();

                        oTransaction.Amount          = FundDepositBalanceTextBox.Text.StringToMoney();
                        oTransaction.Balance         = oFund.Balance;
                        oTransaction.Date            = System.DateTime.Now;
                        oTransaction.FundId          = oFund.Id;
                        oTransaction.MemberId        = null;
                        oTransaction.TransactionType = Models.TransactionType.Deposit;
                        oTransaction.Description     = string.Format("افزایش موجودی صندوق به مبلغ {0}", oTransaction.Amount.ToRialStringFormat());

                        oUnitOfWork.TransactionRepository.Insert(oTransaction);

                        oUnitOfWork.Save();
                    }

                    if (RemovalLimitToggleSwitch.IsChecked == true)
                    {
                        oFund.RemovalLimit = FundRemovalLimitTextBox.Text.StringToMoney();
                    }

                    if (PercentToggleSwitch.IsChecked == true)
                    {
                        oFund.Percent = System.Convert.ToInt32(FundPercentTextBox.Text.Trim());
                    }

                    oUnitOfWork.FundRepository.Update(oFund);
                }

                oUnitOfWork.Save();

                Infrastructure.MessageBox.Show(caption: Infrastructure.MessageBox.Caption.Information, text: "اطلاعات صندوق با موفقیت ویرایش گردید");

                Utility.CurrentFund = oFund;

                Utility.MainWindow.RefreshUserInterface();
            }
            catch (System.Exception ex)
            {
                Infrastructure.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (oUnitOfWork != null)
                {
                    oUnitOfWork.Dispose();
                    oUnitOfWork = null;
                }
            }
        }