private void bwg_PullReport_Received_DoWork(object sender, DoWorkEventArgs e) { try { dgv_Received.Invoke(new MethodInvoker(delegate { try { dgv_Received.DataSource = _TransactionRepo.GetAllTransactions().Where(x => x.Date.Value >= dtp_Start.Value.Date && x.Date.Value <= dtp_End.Value.Date && x.CreatedBy == cmb_Subadmin.SelectedValue.ToString()).GroupBy(p => p.CreatedBy).Select(x => new { Name = x.FirstOrDefault().CreatedBy, DailyContribution = x.Where(p => p.CreatedBy == x.FirstOrDefault().CreatedBy).Sum(f => f.AmountContributed), }).ToList(); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); lb_TotalRecordsReceived.Invoke(new MethodInvoker(delegate { lb_TotalRecordsReceived.Text = dgv_Received.RowCount.ToString(); })); txt_TotalBalanceReceived.Invoke(new MethodInvoker(delegate { try { decimal grandTotal = 0m; for (int i = 0; i < dgv_Received.RowCount; i++) { if (dgv_Received.Rows[i].Cells[1].Value != null) { string total = dgv_Received.Rows[i].Cells[1].Value.ToString(); grandTotal += decimal.Parse(total); } } txt_TotalBalanceReceived.Text = Utilities.CurrencyFormat(grandTotal.ToString()); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); txt_TotalReceived.Invoke(new MethodInvoker(delegate { try { decimal grandTotal = 0m; for (int i = 0; i < dgv_Received.RowCount; i++) { if (dgv_Received.Rows[i].Cells[1].Value != null) { string total = dgv_Received.Rows[i].Cells[1].Value.ToString(); grandTotal += decimal.Parse(total); } } txt_TotalReceived.Text = Utilities.CurrencyFormat(grandTotal.ToString()); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); e.Result = "Done"; } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void bgw_PullData_DoWork(object sender, DoWorkEventArgs e) { try { dgv_CustomerTransactionRecords.Invoke(new MethodInvoker(delegate { try { dgv_CustomerTransactionRecords.DataSource = _TransactionRepo.GetAllTransactions().Where(x => x.CustomerId == _customerId).Select(x => new { CustomerName = x.CustomerName, AccountNumber = x.AccountNumber, TransactionType = x.TransactionType, AmountContributed = x.AmountContributed, AmountCollected = x.AmountCollected, Total = x.AmountContributed - x.AmountCollected, Date = x.Date, CapturedBy = x.CreatedBy }).ToList(); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); lb_Total.Invoke(new MethodInvoker(delegate { lb_Total.Text = dgv_CustomerTransactionRecords.RowCount.ToString(); })); e.Result = "Done"; } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cmb_Customers_SelectedIndexChanged(object sender, EventArgs e) { try { var ID = cmb_Customers.SelectedValue.ToString(); var customer = _CustomerRepo.GetCustomer(long.Parse(ID)); var customerTransaction = _TransactionRepo.GetAllTransactions() .OrderByDescending(x => x.TransactionId).Where(x => x.CustomerId == customer.CustomerId).FirstOrDefault(); txt_AccountNumber.Text = customer.AccountNumber.ToString(); selectedID = long.Parse(ID); txt_Commission.Text = Utilities.CurrencyFormat(customer.Commission.ToString()); txt_TotalCredit.Text = Utilities.CurrencyFormat(customerTransaction != null ? customerTransaction.AmountPayable.ToString() : 0m.ToString()); txt_TotalDebt.Text = Utilities.CurrencyFormat(customerTransaction != null ? customerTransaction.TotalDebt.ToString() : 0m.ToString()); Cursor.Current = Cursors.WaitCursor; if (!bgwGetRecords.IsBusy) { bgwGetRecords.RunWorkerAsync(); } } catch (Exception ex) { } }
private void PerformTransferCustomersProcess() { try { List <long> IDs = new List <long>(); for (int i = 0; i < dgv_Customers.SelectedRows.Count; i++) { IDs.Add(long.Parse(dgv_Customers.SelectedRows[i].Cells[0].Value.ToString())); } foreach (var id in IDs) { var customer = _CustomerRepo.GetCustomer(id); cmb_Subadmin.Invoke(new MethodInvoker(delegate { customer.CreatedBy = cmb_Subadmin.SelectedValue.ToString(); _CustomerRepo.ChangeCustomerCreator(customer); })); cmb_Subadmin.Invoke(new MethodInvoker(delegate { var customerTransactions = _TransactionRepo.GetAllTransactions().Where(x => x.CustomerId == id); foreach (var customerTransaction in customerTransactions.ToList()) { customerTransaction.CreatedBy = cmb_Subadmin.SelectedValue.ToString(); _TransactionRepo.ChangeTransactionCreator(customerTransaction); } })); } MessageBox.Show("Operation completed successfully!", "Superior Investment", MessageBoxButtons.OK, MessageBoxIcon.Information); if (!bgw_PullCustomers.IsBusy) { bgw_PullCustomers.RunWorkerAsync(); } } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void bgw_PullReport_DatesOnly_DoWork(object sender, DoWorkEventArgs e) { try { dgv_Summary.Invoke(new MethodInvoker(delegate { try { dgv_Summary.DataSource = _TransactionRepo.GetAllTransactions().Where(x => x.Date.Value >= dtp_Start.Value.Date && x.Date.Value <= dtp_End.Value.Date).Where(p => p.CreatedBy == Utilities.USERNAME) .Select(x => new { CustomerName = x.CustomerName, AccountNumber = x.AccountNumber, TransactionType = x.TransactionType, AmountContributed = x.AmountContributed, AmountCollected = x.AmountCollected, Total = x.AmountContributed - x.AmountCollected, //Commission = x.Commission, //AmountPayable = x.AmountPayable, //Debt = x.Debt, //TotalDebt = x.TotalDebt, Date = x.Date, CapturedBy = x.CreatedBy }).ToList(); // dgv_Summary.DataSource = _TransactionRepo.GetAllTransactions().Where(x => x.Date.Value.Year >= dtp_Start.Value.Year && x.Date.Value.Month >= dtp_Start.Value.Month //&& x.Date.Value.Day >= dtp_Start.Value.Day && x.Date.Value.Year <= dtp_End.Value.Year && x.Date.Value.Month <= dtp_End.Value.Month //&& x.Date.Value.Day <= dtp_End.Value.Day).ToList(); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); lb_Total.Invoke(new MethodInvoker(delegate { lb_Total.Text = dgv_Summary.RowCount.ToString(); })); txt_TotalDebit.Invoke(new MethodInvoker(delegate { try { decimal grandTotal = 0m; for (int i = 0; i < dgv_Summary.RowCount; i++) { if (dgv_Summary.Rows[i].Cells[4].Value != null) { string total = dgv_Summary.Rows[i].Cells[4].Value.ToString(); grandTotal += decimal.Parse(total); } } txt_TotalDebit.Text = Utilities.CurrencyFormat(grandTotal.ToString()); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); txt_TotalCredit.Invoke(new MethodInvoker(delegate { try { decimal grandTotal = 0m; for (int i = 0; i < dgv_Summary.RowCount; i++) { if (dgv_Summary.Rows[i].Cells[3].Value != null) { string total = dgv_Summary.Rows[i].Cells[3].Value.ToString(); grandTotal += decimal.Parse(total); } } txt_TotalCredit.Text = Utilities.CurrencyFormat(grandTotal.ToString()); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); txt_TotalCombined.Invoke(new MethodInvoker(delegate { try { decimal grandTotal = 0m; for (int i = 0; i < dgv_Summary.RowCount; i++) { if (dgv_Summary.Rows[i].Cells[5].Value != null) { string total = dgv_Summary.Rows[i].Cells[5].Value.ToString(); grandTotal += decimal.Parse(total); } } txt_TotalCombined.Text = Utilities.CurrencyFormat(grandTotal.ToString()); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); e.Result = "Done"; } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void bgw_PullData_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { cmbMonths.Invoke(new MethodInvoker(delegate { cmbMonths.DataSource = Utilities.GetAllMonthsInAYear().Select(x => new { x.Id, x.Name }).ToList(); cmbMonths.AutoCompleteMode = AutoCompleteMode.SuggestAppend; cmbMonths.AutoCompleteSource = AutoCompleteSource.ListItems; cmbMonths.DisplayMember = "Name"; cmbMonths.ValueMember = "Id"; cmbMonths.SelectedIndex = -1; })); cmbYears.Invoke(new MethodInvoker(delegate { cmbYears.DataSource = Utilities.GetValidYears(); cmbYears.AutoCompleteMode = AutoCompleteMode.SuggestAppend; cmbYears.AutoCompleteSource = AutoCompleteSource.ListItems; cmbYears.SelectedIndex = -1; })); int currentMonth = DateTime.Now.Month; int currentYear = DateTime.Now.Year; lbMonthName.Invoke(new MethodInvoker(delegate { lbMonthName.Text = $"Customer activity for the period of {Utilities.GetMonthName(currentMonth)}, {currentYear} for customer: {customerName}"; })); try { dgv_CustomerTransactionRecords.Invoke(new MethodInvoker(delegate { try { dgv_CustomerTransactionRecords.DataSource = _TransactionRepo.GetAllTransactions().Where(x => x.CustomerId == _customerId && x.CreatedDate.Value.Month == currentMonth && x.CreatedDate.Value.Year == currentYear).Select(x => new { CustomerName = x.CustomerName, AccountNumber = x.AccountNumber, TransactionType = x.TransactionType, AmountContributed = x.AmountContributed, AmountCollected = x.AmountCollected, Total = x.AmountContributed - x.AmountCollected, Date = x.Date, CapturedBy = x.CreatedBy }).ToList(); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); lb_Total.Invoke(new MethodInvoker(delegate { lb_Total.Text = dgv_CustomerTransactionRecords.RowCount.ToString(); })); txt_TotalDebit.Invoke(new MethodInvoker(delegate { try { decimal grandTotal = 0m; for (int i = 0; i < dgv_CustomerTransactionRecords.RowCount; i++) { if (dgv_CustomerTransactionRecords.Rows[i].Cells[4].Value != null) { string total = dgv_CustomerTransactionRecords.Rows[i].Cells[4].Value.ToString(); grandTotal += decimal.Parse(total); } } txt_TotalDebit.Text = Utilities.CurrencyFormat(grandTotal.ToString()); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); txt_TotalCredit.Invoke(new MethodInvoker(delegate { try { decimal grandTotal = 0m; for (int i = 0; i < dgv_CustomerTransactionRecords.RowCount; i++) { if (dgv_CustomerTransactionRecords.Rows[i].Cells[3].Value != null) { string total = dgv_CustomerTransactionRecords.Rows[i].Cells[3].Value.ToString(); grandTotal += decimal.Parse(total); } } txt_TotalCredit.Text = Utilities.CurrencyFormat(grandTotal.ToString()); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); txt_TotalDifference.Invoke(new MethodInvoker(delegate { try { decimal grandTotal = 0m; for (int i = 0; i < dgv_CustomerTransactionRecords.RowCount; i++) { if (dgv_CustomerTransactionRecords.Rows[i].Cells[5].Value != null) { string total = dgv_CustomerTransactionRecords.Rows[i].Cells[5].Value.ToString(); grandTotal += decimal.Parse(total); } } txt_TotalDifference.Text = Utilities.CurrencyFormat(grandTotal.ToString()); } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); Cursor.Current = Cursors.Default; e.Result = "Done"; } catch (Exception ex) { MessageBox.Show($"{Utilities.ERRORMESSAGE} \n Error details: {ex.Message}", "Superior Investment!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }