private void dataGridView1_MouseClick(object sender, MouseEventArgs e) { if (dataGridView1.SelectedRows.Count > 1) { return; } if (e.Button == MouseButtons.Right) { ContextMenuStrip strip = new ContextMenuStrip(); int rowIndex = dataGridView1.HitTest(e.X, e.Y).RowIndex; var seqNo = FormGeneral.GetGridCellValue(dataGridView1, rowIndex, "CustomerSeqNumber"); var customerId = FormGeneral.GetGridCellValue(dataGridView1, rowIndex, "CustomerId"); var isActive = FormGeneral.GetGridCellValue(dataGridView1, rowIndex, "IsActive"); strip.Tag = new Customer() { CustomerSeqNumber = Convert.ToInt32(seqNo), CustomerId = Convert.ToInt32(customerId), IsActive = Convert.ToBoolean(isActive) }; if (rowIndex >= 0) { strip.Items.Add("Delete Customer and Txn").Name = "All"; strip.Items.Add("Delete Customer only").Name = "Cus"; strip.Items.Add("Delete Txn only").Name = "Txn"; } strip.Show(dataGridView1, new System.Drawing.Point(e.X, e.Y)); strip.ItemClicked += Strip_ItemClicked; } }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { var grid = (sender as DataGridView); var rowIndex = grid.CurrentCell.RowIndex; var seqNo = FormGeneral.GetGridCellValue(grid, rowIndex, "CustomerSeqId"); var customerId = FormGeneral.GetGridCellValue(grid, rowIndex, "CustomerId"); var txnId = FormGeneral.GetGridCellValue(grid, rowIndex, "TransactionId"); var amountReceived = FormGeneral.GetGridCellValue(grid, rowIndex, "AmountReceived"); Transaction.UpdateTransactionDetails(new Transaction() { AmountReceived = amountReceived.ToInt32(), TransactionId = txnId.ToInt32(), CustomerId = customerId.ToInt32(), CustomerSequenceNo = seqNo.ToInt32() }); }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { var grid = (sender as DataGridView); var rowIndex = grid.CurrentCell.RowIndex; var cus = grid.Rows[grid.CurrentCell.RowIndex].DataBoundItem as Customer; var seqNo = cus.CustomerSeqNumber; // FormGeneral.GetGridCellValue(grid, rowIndex, "CustomerSeqNumber"); var customerId = cus.CustomerId; // FormGeneral.GetGridCellValue(grid, rowIndex, "CustomerId"); var loanAmount = cus.LoanAmount; // FormGeneral.GetGridCellValue(grid, rowIndex, "LoanAmount"); var collectedAmount = FormGeneral.GetGridCellValue(grid, rowIndex, "CollectionAmt"); if (string.IsNullOrEmpty(collectedAmount) == false) { var txn = new Transaction() { AmountReceived = Convert.ToInt32(collectedAmount), CustomerId = customerId, CustomerSequenceNo = seqNo, TransactionId = Transaction.GetNextTransactionId(), Balance = (Transaction.GetBalance(cus) - Convert.ToInt16(collectedAmount)), // TODO: Balance is not updaed correctly eg: 71-104 - 19th july txn. TxnDate = dateTimePicker1.Value }; if (txn.Balance < 0) { MessageBox.Show("Balance is less than 0. Please check your amount. Txn Aborted!"); LogHelper.WriteLog($"Balance is less than 0. Please check your amount. Txn Aborted!", txn.CustomerId, txn.CustomerSequenceNo); return; } if (txn.Balance == 0) { MessageBox.Show("Good News, This txn will be closed!"); LogHelper.WriteLog("Good News, This txn will be closed!", txn.CustomerId, txn.CustomerSequenceNo); Customer.CloseCustomerTxn(cus, false, txn.TxnDate); // new Customer() { CustomerId = txn.CustomerId, CustomerSeqNumber = txn.CustomerSequenceNo, IsActive = false, ClosedDate = txn.TxnDate }); } txn.IsClosed = (txn.Balance <= 0); // Add new Txn. var existingTxn = Transaction.GetTransactionForDate(txn); if (existingTxn == null || existingTxn.Count == 0) { Transaction.AddDailyTransactions(txn); } else { if (existingTxn.First().AmountReceived == 0) // Customer is giving money in the same day fo given date. { Transaction.AddDailyTransactions(txn); } else { txn.TransactionId = existingTxn.First().TransactionId; Transaction.UpdateTransactionDetails(txn); } } // Update txn Closed Date if (txn.IsClosed && txn.Balance == 0) { // Update Closed Date Customer.UpdateCustomerClosedDate( new Customer() { CustomerId = txn.CustomerId, CustomerSeqNumber = txn.CustomerSequenceNo, ClosedDate = txn.TxnDate, }); } return; } //var amountGivenDate = cus.AmountGivenDate; // FormGeneral.GetGridCellValue(grid, rowIndex, "AmountGivenDate"); //var closedDate = cus.ClosedDate; // FormGeneral.GetGridCellValue(grid, rowIndex, "ClosedDate"); //var interest = cus.Interest; // FormGeneral.GetGridCellValue(grid, rowIndex, "Interest"); //var name = cus.Name; // FormGeneral.GetGridCellValue(grid, rowIndex, "Name"); // Update Customer Created Date. Customer.CorrectCustomerData(cus); //Customer.CorrectCustomerData( // new Customer() // { // CustomerId = customerId, // CustomerSeqNumber = Convert.ToInt32(seqNo), // AmountGivenDate = Convert.ToDateTime(amountGivenDate), // ClosedDate = Convert.ToDateTime(closedDate), // Interest = Convert.ToInt32(interest), // LoanAmount = Convert.ToInt32(loanAmount), // Name = name // }); }