コード例 #1
0
ファイル: AddInvoiceViewModel.cs プロジェクト: syatin003/Wpf
        private void ShowInvoiceReportCommandExecuted()
        {
            var appPath = (string)ApplicationSettings.Read("DocumentsPath");
            var fileName = string.Format("{0}_{1}_{2}", _event.Name, "Invoice", DateTime.Now.ToString("g").Replace(":", "").Replace(@"/", ""));
            var reportPath = string.Concat(fileName, ".pdf");
            var exportPath = string.Concat(appPath, reportPath);

            // create a pdf file
            ReportingService.CreateInvoiceReport(Invoice, exportPath);

            // store report in the database
            var report = new Report()
            {
                ID = Guid.NewGuid(),
                EventID = _event.Event.ID,
                Date = DateTime.Now,
                Name = string.Format("Invoice"),
                Path = reportPath
            };

            _eventDataUnit.InvoicesRepository.Add(_invoice.InnerInvoice);

            _eventDataUnit.ReportsRepository.Add(report);
            _event.Reports.Add(new ReportModel(report));
            _event.RefreshReports();

            // update Updates table
            var update = new EventUpdate()
            {
                ID = Guid.NewGuid(),
                EventID = _event.Event.ID,
                Date = DateTime.Now,
                UserID = AccessService.Current.User.ID,
                Message = "Event invoice was created",
                OldValue = null,
                NewValue = _invoice.InvoiceNumber.ToString(),
                ItemId = _invoice.InnerInvoice.ID,
                ItemType = "EventInvoice",
                Field = "Invoice",
                Action = UpdateAction.Added
            };

            // add document
            var document = new Document()
            {
                ID = report.ID,
                Path = reportPath,
                Name = string.Format("Invoice for {0}", _event.Name),
                IsEnabled = true,
                IsCommon = false
            };

            _eventDataUnit.DocumentsRepository.Add(document);
            _event.Documents.Add(document);

            _eventDataUnit.EventUpdatesRepository.Add(update);

        }
コード例 #2
0
 /// <summary>
 /// Create a new Document object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="isEnabled">Initial value of the IsEnabled property.</param>
 /// <param name="isCommon">Initial value of the IsCommon property.</param>
 /// <param name="path">Initial value of the Path property.</param>
 public static Document CreateDocument(global::System.Guid id, global::System.Boolean isEnabled, global::System.Boolean isCommon, global::System.String path)
 {
     Document document = new Document();
     document.ID = id;
     document.IsEnabled = isEnabled;
     document.IsCommon = isCommon;
     document.Path = path;
     return document;
 }
コード例 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Documents EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDocuments(Document document)
 {
     base.AddObject("Documents", document);
 }
コード例 #4
0
        private void ShowFunctionSheetCommandExecuted()
        {
            var appPath = (string)ApplicationSettings.Read("DocumentsPath");

            var eventWasChanged = _event.Event.LastFunctionSheetPrint <= _event.Event.LastEditDate;
            var lastReport = _event.Reports.Where(x => x.Name == "Function Sheet").OrderByDescending(x => x.Report.Date).FirstOrDefault();

            if (!eventWasChanged && lastReport != null)
            {
                var oldExportPath = string.Concat(appPath, lastReport.Report.Path);

                if (File.Exists(oldExportPath))
                {
                    Process.Start(oldExportPath);
                    return;
                }
            }

            var fileName = string.Format("{0}_{1}_{2}", _event.Name, "Function Sheet", DateTime.Now.ToString("g").Replace(":", "").Replace(@"/", ""));
            var reportPath = string.Concat(fileName, ".pdf");
            var exportPath = string.Concat(appPath, reportPath);

            // create a pdf file
            ReportingService.CreateFunctionSheetReport(_event, exportPath);

            // store report in the database
            var report = new Report()
            {
                ID = Guid.NewGuid(),
                EventID = _event.Event.ID,
                Date = DateTime.Now,
                Name = string.Format("Function Sheet"),
                Path = reportPath
            };

            _event.Event.LastFunctionSheetPrint = DateTime.Now;

            _event.Reports.Insert(0, new ReportModel(report));
            _eventDataUnit.ReportsRepository.Add(report);
            _event.RefreshReports();

            // update Updates table
            var update = new EventUpdate()
            {
                ID = Guid.NewGuid(),
                EventID = _event.Event.ID,
                Date = DateTime.Now,
                UserID = AccessService.Current.User.ID,
                Message = Resources.MESSAGE_FUNCTION_SHEET_WAS_CREATED,
                OldValue = null,
                NewValue = report.Name,
                ItemId = report.ID,
                ItemType = "EventReport",
                Field = "FunctionSheetReport",
                Action = UpdateAction.Added
            };

            _event.EventUpdates.Insert(0, update);
            _eventDataUnit.EventUpdatesRepository.Add(update);

            var document = new Document()
            {
                ID = report.ID,
                EventID = _event.Event.ID,
                Path = reportPath,
                Name = Path.GetFileNameWithoutExtension(reportPath),
                IsEnabled = true,
                IsCommon = false
            };

            _event.Documents.Add(document);
            _eventDataUnit.DocumentsRepository.Add(document);
        }
コード例 #5
0
        private void AddFileFromHdd(string path)
        {
            var appPath = (string)ApplicationSettings.Read("DocumentsPath");
            var filePath = Path.GetFileName(path);
            var fullPath = string.Concat(appPath, filePath);

            try
            {
                if (File.Exists(fullPath))
                    File.Delete(fullPath);

                File.Copy(path, fullPath);

                var report = new ReportModel(new Report()
                {
                    ID = Guid.NewGuid(),
                    EventID = _event.Event.ID,
                    Date = DateTime.Now,
                    Name = Path.GetFileNameWithoutExtension(path),
                    Path = filePath
                });

                _event.Reports.Insert(0, report);
                _eventDataUnit.ReportsRepository.Add(report.Report);
                _event.RefreshReports();

                // update Updates table
                var update = new EventUpdate()
                {
                    ID = Guid.NewGuid(),
                    EventID = _event.Event.ID,
                    Date = DateTime.Now,
                    UserID = AccessService.Current.User.ID,
                    Message = Resources.MESSAGE_FUNCTION_SHEET_WAS_CREATED,
                    OldValue = null,
                    NewValue = report.Name,
                    ItemId = report.Report.ID,
                    ItemType = "EventReport",
                    Field = "DocumentUpload",
                    Action = UpdateAction.Added
                };

                _eventDataUnit.EventUpdatesRepository.Add(update);

                var document = new Document()
                {
                    ID = report.Report.ID,
                    EventID = _event.Event.ID,
                    Path = filePath,
                    Name = Path.GetFileNameWithoutExtension(path),
                    IsEnabled = true,
                    IsCommon = false
                };

                _event.Documents.Add(document);
                _eventDataUnit.DocumentsRepository.Add(document);

            }
            catch (Exception ex)
            {
                PopupService.ShowMessage(ex.Message, MessageType.Failed);
            }
        }
コード例 #6
0
        public async void LoadData()
        {
            IsBusy = true;

            _eventDataUnit.MailTemplatesRepository.Refresh();
            var templates = await _eventDataUnit.MailTemplatesRepository.GetAllAsync();
            MainEmailTemplate = new MailTemplateModel(templates.Where(x => x.MailTemplateCategory.Name == "Events" && x.MailTemplateType.Name == "MainEmailTemplate").FirstOrDefault());
            MailTemplates = new ObservableCollection<MailTemplateModel>(
                templates.Where(x => x.MailTemplateCategory.Name == "Events" && x.IsEnabled && x.MailTemplateType.Name != "MainEmailTemplate").OrderBy(x => x.Name).Select(x => new MailTemplateModel(x)));

            _eventDataUnit.EmailHeadersRepository.Refresh();
            var headers = await _eventDataUnit.EmailHeadersRepository.GetAllAsync();
            _allEmailHeaders = new List<EmailHeader>(headers);
            EmailHeaders = new ObservableCollection<EmailHeader>(_allEmailHeaders.Where(x => x.IsEnabled));

            var types = await _eventDataUnit.CorresponcenceTypesRepository.GetAllAsync();
            _corresponcenceTypes = new List<CorresponcenceType>(types);

            var appPath = (string)ApplicationSettings.Read("DocumentsPath");

            if (!_event.Reports.Any())
            {
                var reports = await _eventDataUnit.ReportsRepository.GetAllAsync(x => x.EventID == _event.Event.ID);
                _event.Reports = new ObservableCollection<ReportModel>(reports.OrderByDescending(x => x.Date).Select(x => new ReportModel(x)));
                _event.RefreshReports();
            }

            List<ReportModel> latestReports = _event.GetLatestReports();

            //foreach (var report in latestReports)
            //{
            //    if (!_event.Documents.Select(x => x.Path).Contains(report.Report.Path))
            //    {
            //        var document = new Document()
            //        {
            //            ID = Guid.NewGuid(),
            //            EventID = _event.Event.ID,
            //            Path = report.Report.Path,
            //            Name = Path.GetFileNameWithoutExtension(report.Report.Path),
            //            IsEnabled = true,
            //            IsCommon = false
            //        };

            //        _event.Documents.Add(document);
            //    }
            //}


            var commonDocumets = await _eventDataUnit.DocumentsRepository.GetAllAsync(x => x.IsEnabled && x.IsCommon);
            Documents = new ObservableCollection<Document>(commonDocumets.Where(x => File.Exists(string.Concat(appPath, x.Path))));

            foreach (var report in latestReports)
            {

                var eventDocument = _event.Documents.Where(doc => doc.Path == report.Report.Path).FirstOrDefault();
                if (eventDocument == null)
                {
                    eventDocument = new Document()
                                        {
                                            ID = report.Report.ID,
                                            EventID = _event.Event.ID,
                                            Path = report.Report.Path,
                                            Name = Path.GetFileNameWithoutExtension(report.Report.Path),
                                            IsEnabled = true,
                                            IsCommon = false
                                        };
                }
                Documents.Add(eventDocument);

            }

            OnLoadContacts();

            IsBusy = false;
        }