Created
April 27, 2025 08:22
-
-
Save kashiash/613ec88f779863078078ea8830871c91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Report2DocumentController : ObjectViewController | |
| { | |
| private readonly SingleChoiceAction reportMergeAction; | |
| public Report2DocumentController() | |
| { | |
| TargetViewNesting = Nesting.Root; | |
| TargetViewType = ViewType.ListView; | |
| reportMergeAction = new SingleChoiceAction(this, $"{GetType().FullName}.{nameof(reportMergeAction)}", PredefinedCategory.Unspecified) | |
| { | |
| Caption = "Wiadomość predefiniowana", | |
| ImageName = "MailMerge", | |
| SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects, | |
| ToolTip = "Utwórz dokument z szablonu wydruku", | |
| ItemType = SingleChoiceActionItemType.ItemIsOperation, | |
| EmptyItemsBehavior = EmptyItemsBehavior.Deactivate | |
| }; | |
| reportMergeAction.Execute += MailMergeAction_Execute; | |
| } | |
| private void MailMergeAction_Execute(object sender, SingleChoiceActionExecuteEventArgs e) | |
| { | |
| IObjectSpace objectSpace = View is ListView ? Application.CreateObjectSpace() : View.ObjectSpace; | |
| var items = e.SelectedObjects; | |
| var wybranySzablon = objectSpace.GetObject((SzablonWydrukow)e.SelectedChoiceActionItem.Data); | |
| if (wybranySzablon is SzablonWydrukow szablon) | |
| { | |
| foreach (var item in items) | |
| { | |
| var rec = objectSpace.GetObject(item); | |
| var dataSource = new object[] { rec }; | |
| var factory = new WiadomosciFactory(objectSpace, szablon, dataSource); | |
| var htmlBody = factory.GetHtmlBody(); | |
| if (htmlBody != null) factory.PrepareEmail(objectSpace, htmlBody, wybranySzablon, rec); | |
| } | |
| } | |
| objectSpace.CommitChanges(); | |
| if (View is ListView) View.ObjectSpace.Refresh(); | |
| } | |
| protected override void OnActivated() { RefreshActionItems(); } | |
| protected void RefreshActionItems() | |
| { | |
| try | |
| { | |
| reportMergeAction.Items.Clear(); | |
| foreach (var szablon in ObjectSpace.GetObjects<SzablonWydrukow>()) | |
| if (szablon.DataType != null && szablon.DataType.IsAssignableFrom(View.ObjectTypeInfo.Type)) | |
| { | |
| if (true || szablon.UdostepnijNaListach && !szablon.Archiwalny) | |
| { | |
| reportMergeAction.Items.Add(new ChoiceActionItem(szablon.DisplayName, szablon)); | |
| } | |
| } | |
| } | |
| catch (Exception) { } | |
| } | |
| } | |
| [DefaultClassOptions] | |
| [ImageName("BO_Resume")] | |
| [NavigationItem("Automaty")] | |
| [XafDisplayName("Szablony wydruków")] | |
| [Appearance("SzablonWydrukowWylaczKontrolkiBezDataType", | |
| TargetItems = "MailToExpression;SubjectExpression,Criterion,SenderExpression,ReplyToExpression,EventIdExpression", | |
| Enabled = false, Criteria = "DataTypeName Is Null", Context = "DetailView")] | |
| public class SzablonWydrukow(Session session) : ReportDataV2(session), ISzablonDokumentow | |
| { | |
| RodzajeSkanowGrupy? grupaSkanu; | |
| RodzajeSkanow? rodzajSkanu; | |
| string? nazwaZalacznika; | |
| bool showDetailForm; | |
| bool udostepnijNaListach; | |
| bool emailWymagaPotwierdzenia; | |
| bool archiwalny; | |
| RodzajWiadomosci? rodzajWiadomosci; | |
| bool szablonEmail; | |
| bool szablonAutomatyczny; | |
| DateTime dataOstatniejWysylki; | |
| bool parseEventIdAsDate; | |
| DateTime godzinaWysylki; | |
| bool zalaczJakoDocX; | |
| bool zalaczJakoExcel; | |
| bool zalaczJakoPdf; | |
| bool sendOnceDaily; | |
| bool createDocumentPerRecord; | |
| [NoForeignKey] | |
| public RodzajWiadomosci? RodzajWiadomosci | |
| { | |
| get => rodzajWiadomosci; | |
| set => SetPropertyValue(nameof(RodzajWiadomosci), ref rodzajWiadomosci, value); | |
| } | |
| public bool SzablonEmail | |
| { | |
| get => szablonEmail; | |
| set => SetPropertyValue(nameof(SzablonEmail), ref szablonEmail, value); | |
| } | |
| public bool EmailWymagaPotwierdzenia | |
| { | |
| get => emailWymagaPotwierdzenia; | |
| set => SetPropertyValue(nameof(EmailWymagaPotwierdzenia), ref emailWymagaPotwierdzenia, value); | |
| } | |
| public bool SzablonAutomatyczny | |
| { | |
| get => szablonAutomatyczny; | |
| set => SetPropertyValue(nameof(SzablonAutomatyczny), ref szablonAutomatyczny, value); | |
| } | |
| [CriteriaOptions(nameof(DataType))] | |
| [Size(SizeAttribute.Unlimited)] | |
| [EditorAlias(EditorAliases.CriteriaPropertyEditor)] | |
| public string Criterion | |
| { | |
| get => GetPropertyValue<string>(nameof(Criterion)); | |
| set => SetPropertyValue(nameof(Criterion), value); | |
| } | |
| [CriteriaOptions(nameof(DataType))] | |
| [Size(SizeAttribute.Unlimited)] | |
| [EditorAlias(EditorAliases.PopupExpressionPropertyEditor)] | |
| [XafDisplayName("Temat:")] | |
| public string SubjectExpression | |
| { | |
| get => GetPropertyValue<string>(nameof(SubjectExpression)); | |
| set => SetPropertyValue(nameof(SubjectExpression), value); | |
| } | |
| [CriteriaOptions(nameof(DataType))] | |
| [Size(SizeAttribute.Unlimited)] | |
| [EditorAlias(EditorAliases.PopupExpressionPropertyEditor)] | |
| [XafDisplayName("Odbiorca:")] | |
| public string MailToExpression | |
| { | |
| get => GetPropertyValue<string>(nameof(MailToExpression)); | |
| set => SetPropertyValue(nameof(MailToExpression), value); | |
| } | |
| [CriteriaOptions(nameof(DataType))] | |
| [Size(SizeAttribute.Unlimited)] | |
| [EditorAlias(EditorAliases.PopupExpressionPropertyEditor)] | |
| [XafDisplayName("Nadawca:")] | |
| public string SenderExpression | |
| { | |
| get => GetPropertyValue<string>(nameof(SenderExpression)); | |
| set => SetPropertyValue(nameof(SenderExpression), value); | |
| } | |
| [CriteriaOptions(nameof(DataType))] | |
| [Size(SizeAttribute.Unlimited)] | |
| [EditorAlias(EditorAliases.PopupExpressionPropertyEditor)] | |
| [XafDisplayName("Odpowiedź do:")] | |
| public string ReplyToExpression | |
| { | |
| get => GetPropertyValue<string>(nameof(ReplyToExpression)); | |
| set => SetPropertyValue(nameof(ReplyToExpression), value); | |
| } | |
| [CriteriaOptions(nameof(DataType))] | |
| [Size(SizeAttribute.Unlimited)] | |
| [EditorAlias(EditorAliases.PopupExpressionPropertyEditor)] | |
| [XafDisplayName("BCC:")] | |
| public string BCCExpression | |
| { | |
| get => GetPropertyValue<string>(nameof(BCCExpression)); | |
| set => SetPropertyValue(nameof(BCCExpression), value); | |
| } | |
| [CriteriaOptions(nameof(DataType))] | |
| [Size(SizeAttribute.Unlimited)] | |
| [EditorAlias(EditorAliases.PopupExpressionPropertyEditor)] | |
| [XafDisplayName("CC:")] | |
| public string CCExpression | |
| { | |
| get => GetPropertyValue<string>(nameof(CCExpression)); | |
| set => SetPropertyValue(nameof(CCExpression), value); | |
| } | |
| [CriteriaOptions(nameof(DataType))] | |
| [Size(SizeAttribute.Unlimited)] | |
| [EditorAlias(EditorAliases.PopupExpressionPropertyEditor)] | |
| [XafDisplayName("Identyfikator:")] | |
| public string EventIdExpression | |
| { | |
| get => GetPropertyValue<string>(nameof(EventIdExpression)); | |
| set => SetPropertyValue(nameof(EventIdExpression), value); | |
| } | |
| [XafDisplayName("Grupa skanu")] | |
| public RodzajeSkanowGrupy? GrupaSkanu | |
| { | |
| get => grupaSkanu; | |
| set => SetPropertyValue(nameof(GrupaSkanu), ref grupaSkanu, value); | |
| } | |
| [DataSourceCriteria("GrupaSkanu == '@This.GrupaSkanu'")] | |
| [XafDisplayName("Rodzaj skanu")] | |
| public RodzajeSkanow? RodzajSkanu | |
| { | |
| get => rodzajSkanu; | |
| set => SetPropertyValue(nameof(RodzajSkanu), ref rodzajSkanu, value); | |
| } | |
| public bool ParseEventIdAsDate | |
| { | |
| get => parseEventIdAsDate; | |
| set => SetPropertyValue(nameof(ParseEventIdAsDate), ref parseEventIdAsDate, value); | |
| } | |
| public bool UdostepnijNaListach | |
| { | |
| get => udostepnijNaListach; | |
| set => SetPropertyValue(nameof(UdostepnijNaListach), ref udostepnijNaListach, value); | |
| } | |
| [XafDisplayName("Wyświetl wiadomość:")] | |
| public bool ShowDetailForm | |
| { | |
| get => showDetailForm; | |
| set => SetPropertyValue(nameof(ShowDetailForm), ref showDetailForm, value); | |
| } | |
| [XafDisplayName("Wysyłaj raz dziennie")] | |
| public bool SendOnceDaily | |
| { | |
| get => sendOnceDaily; | |
| set => SetPropertyValue(nameof(SendOnceDaily), ref sendOnceDaily, value); | |
| } | |
| [XafDisplayName("Wysyłaj pojedynczo")] | |
| public bool CreateDocumentPerRecord | |
| { | |
| get => createDocumentPerRecord; | |
| set => SetPropertyValue(nameof(CreateDocumentPerRecord), ref createDocumentPerRecord, value); | |
| } | |
| public bool Archiwalny | |
| { | |
| get => archiwalny; | |
| set => SetPropertyValue(nameof(Archiwalny), ref archiwalny, value); | |
| } | |
| public Type? DataType => !string.IsNullOrEmpty(DataTypeName) ? Type.GetType(DataTypeName) : null; | |
| [ModelDefault("DisplayFormat", "{0:hh:mm}")] | |
| [ModelDefault("EditMask", "hh:mm")] | |
| [ModelDefault("PropertyEditorType", "CustomDateTimeEditor")] | |
| public DateTime GodzinaWysylki | |
| { | |
| get => godzinaWysylki; | |
| set => SetPropertyValue(nameof(GodzinaWysylki), ref godzinaWysylki, value); | |
| } | |
| public DateTime DataOstatniejWysylki | |
| { | |
| get => dataOstatniejWysylki; | |
| set => SetPropertyValue(nameof(DataOstatniejWysylki), ref dataOstatniejWysylki, value); | |
| } | |
| [XafDisplayName("Nazwa załącznika")] | |
| public string? NazwaZalacznika | |
| { | |
| get => nazwaZalacznika; | |
| set => SetPropertyValue(nameof(NazwaZalacznika), ref nazwaZalacznika, value); | |
| } | |
| [XafDisplayName("Załącz jako pdf")] | |
| public bool ZalaczJakoPdf | |
| { | |
| get => zalaczJakoPdf; | |
| set => SetPropertyValue(nameof(ZalaczJakoPdf), ref zalaczJakoPdf, value); | |
| } | |
| [XafDisplayName("Załącz jako excel")] | |
| public bool ZalaczJakoExcel | |
| { | |
| get => zalaczJakoExcel; | |
| set => SetPropertyValue(nameof(ZalaczJakoExcel), ref zalaczJakoExcel, value); | |
| } | |
| [XafDisplayName("Załącz jako docx")] | |
| public bool ZalaczJakoDocX | |
| { | |
| get => zalaczJakoDocX; | |
| set => SetPropertyValue(nameof(ZalaczJakoDocX), ref zalaczJakoDocX, value); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment