コード例 #1
0
        private void btnAddInvoiceFormCancel_Click(object sender, EventArgs e)
        {
            InvoiceListForm newForm = new InvoiceListForm();

            newForm.Show();
            this.Close();
        }
コード例 #2
0
        private void btnAddInvoiceFormSaveChanges_Click(object sender, EventArgs e)
        {
            invoice.InvoiceDate = invoiceDateDateTimePicker.Value;
            invoice.CustomerID  = Convert.ToInt32(customerIDComboBox.SelectedValue);
            addInvDb.Invoices.Add(invoice);
            addInvDb.SaveChanges();
            this.Close();
            MessageBox.Show("Invoice added successfully.", "Invoice Added");
            InvoiceListForm invoiceListForm = new InvoiceListForm();

            invoiceListForm.Show();
        }
コード例 #3
0
        private void btnDeleteInvLineItem_Click(object sender, EventArgs e)
        {
            int invLineItemDetailIdNum = Convert.ToInt32(textBox10.Text);

            var deleteInvLineItem = (from invLineItem in invoicesDb.InvoiceLineItems
                                     where invLineItem.InvLineItemDetailID == invLineItemDetailIdNum
                                     select invLineItem).Single();

            var deleteInvLineItemServiceName = (from invLineItem in invoicesDb.InvoiceLineItems
                                                where invLineItem.InvLineItemDetailID == invLineItemDetailIdNum
                                                select invLineItem.tblService.ServiceName).Single().ToString();

            var deleteInvLineItemEmpName = (from invLineItem in invoicesDb.InvoiceLineItems
                                            where invLineItem.InvLineItemDetailID == invLineItemDetailIdNum
                                            select invLineItem.tblEmployee.EmployeeFName + " " + invLineItem.tblEmployee.EmployeeLName).Single().ToString();

            DialogResult result = MessageBox.Show($"Delete Line Item where Invoice Line Item Detail ID = {invLineItemDetailIdNum} (Service Name: {deleteInvLineItemServiceName} | Service performed by: {deleteInvLineItemEmpName})?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    invoicesDb.InvoiceLineItems.Remove(deleteInvLineItem);
                    invoicesDb.SaveChanges();
                    FilterInvoiceLineItemDataGridView();
                }
                catch (DbUpdateConcurrencyException)
                {
                    this.Close();
                    if (invoicesDb.Entry(deleteInvLineItem).State == EntityState.Detached)
                    {
                        MessageBox.Show("Another user has deleted that invoice line item.", "Concurrency Error");
                    }
                    else
                    {
                        MessageBox.Show("Another user has updated that invoice line item.", "Concurrency Error");
                    }
                }
                catch (DbUpdateException)
                {
                    this.Close();
                    MessageBox.Show("Unable to delete invoice line item. Unknown Error Occurred.", "Invoice Line Item Not Deleted");
                    InvoiceListForm newForm = new InvoiceListForm();
                    newForm.Show();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
コード例 #4
0
        private void btnDeleteInvoice_Click(object sender, EventArgs e)
        {
            if (invoiceIDTextBox.Text == "")
            {
                MessageBox.Show("No invoice selected. Please select an invoice to delete.", "Delete Error");
            }
            else
            {
                int currentInv = Convert.ToInt32(invoiceIDTextBox.Text);
                var editedInv  = (from invoice in invoicesDb.Invoices
                                  where invoice.InvoiceID == currentInv
                                  select invoice).Single();

                DialogResult result = MessageBox.Show($"Delete Invoice ID: {currentInv.ToString()}?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        invoicesDb.Invoices.Remove(editedInv);
                        invoicesDb.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        this.Close();
                        if (invoicesDb.Entry(editedInv).State == EntityState.Detached)
                        {
                            MessageBox.Show("Another user has deleted that invoice.", "Concurrency Error");
                        }
                        else
                        {
                            MessageBox.Show("Another user has updated that invoice.", "Concurrency Error");
                        }
                    }
                    catch (DbUpdateException)
                    {
                        this.Close();
                        MessageBox.Show("Unable to delete invoice. Unknown Error Occurred.", "Invoice Not Deleted");
                        InvoiceListForm newForm = new InvoiceListForm();
                        newForm.Show();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }