Beispiel #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (ShowConfirmationDialog(Resources.DeleteInvoiceConfirmationMsg) == DialogResult.Yes)
     {
         if (dgvInvoices.Rows.Count > 0)
         {
             var invoiceId    = int.Parse(dgvInvoices.SelectedRows[0].Cells[0].Value.ToString());
             var invoice      = InvoiceManager.GetInvoiceById(invoiceId);
             var invoiceItems = invoice.InvoiceItems.ToList();
             MaterialManager.UpdateQuantitiesAfterDeletingInvoice(invoiceItems);
             InvoiceItemManager.DeleteInvoiceItems(invoiceItems);
             InvoicePaymentManager.DeleteInvoicePayments(invoice.InvoicePayments.ToList());
             InvoiceManager.DeleteInvoice(invoice);
             ResetForm();
         }
     }
 }
Beispiel #2
0
 public UnitOfWork(ApplicationDbContext context)
 {
     this.context       = context;
     Claims             = new ClaimManager(context);
     Departments        = new DepartmentManager(context);
     DepartmentProjects = new DepartmentProjectsManager(context);
     Engineers          = new EngineerManager(context);
     //EngineerSubTasks = new EngineerSubTasksManager(context);
     SubTaskSessions   = new SubTaskSessionManager(context);
     Projects          = new ProjectManager(context);
     SubTasks          = new SubTaskManager(context);
     Tasks             = new TaskManager(context);
     Teams             = new TeamManager(context);
     TeamTasks         = new TeamTasksManager(context);
     Invoices          = new InvoicesManager(context);
     InoviceItems      = new InvoiceItemManager(context);
     Dependency        = new DependencyManager(context);
     Notification      = new NotificationManager(context);
     NotificationUsers = new NotificationUsersManager(context);
     Files             = new FilesManager(context);
     Comments          = new CommentManager(context);
     Holiday           = new HolidayManager(context);
 }
Beispiel #3
0
        private void SaveInvoice()
        {
            ErrorProvider.Clear();
            var    isFormValid = true;
            Client newClient   = null;

            if (txtClientName.Text.IsNullOrEmptyOrWhiteSpace())
            {
                isFormValid = false;
                ErrorProvider.SetError(txtClientName, Resources.ThisFieldIsRequired);
            }
            else if (!ClientsNames.Contains(txtClientName.Text.FullTrim()))
            {
                isFormValid = ShowConfirmationDialog(Resources.ClientNotExists) == DialogResult.Yes;
                newClient   = new Client {
                    Name = txtClientName.Text.FullTrim()
                };
            }
            if (!InvoiceItemVms.Any())
            {
                isFormValid = false;
                ShowErrorMsg(Resources.InvoiceWithoutItems);
            }
            if (!isFormValid)
            {
                return;
            }
            if (!InvoiceItemVms.Any())
            {
                ShowErrorMsg(Resources.NoItemsAdded);
                return;
            }

            if (newClient != null)
            {
                ClientManager.AddClient(newClient);
            }

            var invoice = new Invoice
            {
                ClientId = ClientManager.GetClientIdByName(txtClientName.Text.FullTrim()),
                Date     = dtInvoiceDate.Value,
                Total    = (decimal)dblInTotal.Value,
                Paid     = (decimal)dblInPaid.Value,
                Discount = (decimal)dblInDiscount.Value
            };

            InvoiceManager.AddInvoice(invoice);
            InvoiceItemManager.AddInvoiceItems(InvoiceItemVms.Select(item => new InvoiceItem
            {
                InvoiceId  = invoice.Id,
                MaterialId = item.MaterialId,
                Quantity   = item.Quantity,
                Price      = item.TotalPrice,
                Notes      = item.Notes
            }).ToList());
            if (invoice.Paid > 0)
            {
                InvoicePaymentManager.AddInvoicePayment(new InvoicePayment
                {
                    InvoiceId = invoice.Id,
                    Date      = dtInvoiceDate.Value,
                    Paid      = (decimal)dblInPaid.Value
                });
            }
            MaterialManager.UpdateQuantitiesAfterCreatingInvoice(InvoiceItemVms);
            ShowInfoMsg(Resources.InvoiceCreatedSuccessfully);
            Close();
        }