Beispiel #1
0
        public usrMaintenanceDetail(DataContext context, int maintenanceId, bool readonlyScreen)
        {
            this.Cursor = Cursors.WaitCursor;
            _Readonly   = readonlyScreen;
            try
            {
                _DataContext = context;

                _Maintenance = _DataContext.MaintenanceSet
                               .Include(a => a.Supplier)
                               .Include(a => a.Requisition)
                               .Include(a => a.BuildingMaintenanceConfiguration)
                               .Include(a => a.DetailItems)
                               .Single(a => a.id == maintenanceId);

                _requisition = _DataContext.tblRequisitions.Single(a => a.id == _Maintenance.RequisitionId);

                _Documents = _DataContext.MaintenanceDocumentSet
                             .Where(a => a.MaintenanceId == maintenanceId)
                             .Select(a => new SupportingDocument
                {
                    Id       = a.id,
                    FileName = a.FileName
                }).ToList();

                SetupControl();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #2
0
        public usrMaintenanceDetail(DataContext context, tblRequisition requisition, BuildingMaintenanceConfiguration config, bool ignoreInvoiceNumber = false)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                _DataContext = context;
                _requisition = requisition;

                if (!ignoreInvoiceNumber)
                {
                    if (string.IsNullOrEmpty(requisition.InvoiceNumber))
                    {
                        throw new MaintenanceException("No Invoice Number found.");
                    }

                    if (!requisition.InvoiceDate.HasValue)
                    {
                        throw new MaintenanceException("No Invoice Date found.");
                    }
                }

                if (requisition.SupplierId == null)
                {
                    throw new MaintenanceException("No Supplier found.");
                }
                else if (requisition.Supplier == null)
                {
                    requisition.Supplier = _DataContext.SupplierSet.Single(a => a.id == requisition.SupplierId);
                }

                _Maintenance = _DataContext.MaintenanceSet.Include(a => a.DetailItems).SingleOrDefault(a => a.RequisitionId == requisition.id);
                if (_Maintenance == null)
                {
                    _Maintenance = new Data.MaintenanceData.Maintenance()
                    {
                        DateLogged = DateTime.Now,
                        BuildingMaintenanceConfiguration = config,
                        Requisition     = requisition,
                        Supplier        = requisition.Supplier,
                        InvoiceNumber   = requisition.InvoiceNumber,
                        InvoiceDate     = requisition.InvoiceDate == null ? requisition.trnDate : requisition.InvoiceDate.Value,
                        TotalAmount     = requisition.amount,
                        WarrentyExpires = requisition.InvoiceDate == null ? requisition.trnDate : requisition.InvoiceDate.Value,
                        DetailItems     = new List <MaintenanceDetailItem>()
                    };
                    _DataContext.MaintenanceSet.Add(_Maintenance);
                    _Documents = new List <SupportingDocument>();
                }
                else
                {
                    _Documents = _DataContext.MaintenanceDocumentSet.Where(a => a.MaintenanceId == _Maintenance.id)
                                 .Select(d => new SupportingDocument()
                    {
                        Id       = d.id,
                        FileName = d.FileName
                    }).ToList();
                }

                SetupControl();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }