private void bindingInvoice_ListChanged(object sender, ListChangedEventArgs e) { // Exit if no project list if (m_Invoices == null) { return; } // Get the item affected int index = e.NewIndex; InvoiceItem changedInvoice = null; if ((index > -1) && (index < m_Invoices.Count)) { changedInvoice = m_Invoices[index]; } // Get the type of change that occured ListChangedType changeType = e.ListChangedType; /* We only need to respond to two types of changes here; updates * and moves. Adds are handled by bindingSourceProjects_AddingNew(), * and deletes are handled by menuItemAuthorsDelete_Click(). */ // Dispatch a change handler switch (changeType) { case ListChangedType.ItemChanged: if (changedInvoice.Nomor != null) { CommandUpdateInvoice updateAuthor = new CommandUpdateInvoice(changedInvoice); m_AppController.ExecuteCommand(updateAuthor); } else { CommandDeleteInvoice deleteInvoice = new CommandDeleteInvoice(m_Invoices, changedInvoice); m_AppController.ExecuteCommand(deleteInvoice); } break; case ListChangedType.ItemMoved: // Not supported in this app break; } decimal totalValue = 0; foreach (InvoiceItem item in m_Invoices) { totalValue += item.Total; } toolStripLabel1.Text = "Total Tagihan : " + string.Format("{0:n0}", totalValue); toolStripLabel2.Text = "Count : " + string.Format("{0:n0}", m_Invoices.Count); }
private void deleteBtn_Click(object sender, EventArgs e) { // Get author InvoiceItem itemToDelete = (InvoiceItem)invoiceItemBindingSource.Current; // Confirm Delete string invoiceNumber = String.Format("{0}", itemToDelete.Nomor); string message = String.Format("Delete Invoice '{0}' and all of its item?", invoiceNumber); DialogResult result = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); // Delete author if (result == DialogResult.Yes) { CommandDeleteInvoice deleteInvoice = new CommandDeleteInvoice(m_InvoiceList, itemToDelete); m_AppController.ExecuteCommand(deleteInvoice); } }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { // Confirm Delete string message = String.Format("Delete Invoices and all of its item?"); DialogResult result = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); // Delete author if (result == DialogResult.Yes) { foreach (DataGridViewRow row in dgInvoice.SelectedRows) { InvoiceItem item = row.DataBoundItem as InvoiceItem; if (item != null) { CommandDeleteInvoice deleteInvoice = new CommandDeleteInvoice(m_Invoices, item); m_AppController.ExecuteCommand(deleteInvoice); } } } }